Article Details

Original Article Text

Click to Toggle View

Critical Rust flaw enables Windows command injection attacks. Threat actors can exploit a security vulnerability in the Rust standard library to target Windows systems in command injection attacks. Tracked as CVE-2024-24576, this flaw is due to OS command and argument injection weaknesses that can let attackers execute unexpected and potentially malicious commands on the operating system. GitHub rated this vulnerability as critical severity with a maximum CVSS base score of 10/10. Unauthenticated attackers can exploit it remotely, in low-complexity attacks, and without user interaction. "The Rust Security Response WG was notified that the Rust standard library did not properly escape arguments when invoking batch files (with the bat and cmd extensions) on Windows using the Command API," the Rust Security Response working group said. "An attacker able to control the arguments passed to the spawned process could execute arbitrary shell commands by bypassing the escaping. The severity of this vulnerability is critical if you are invoking batch files on Windows with untrusted arguments. No other platform or use is affected." All Rust versions before 1.77.2 on Windows are affected if a program's code or one of its dependencies invokes and executes batch files with untrusted arguments. ​The Rust security team faced a significant challenge when dealing with cmd.exe's complexity since they couldn't find a solution that would correctly escape arguments in all cases.  As a result, they had to improve the robustness of the escaping code and modify the Command API. If the Command API cannot safely escape an argument while spawning the process, it returns an InvalidInput error. "If you implement the escaping yourself or only handle trusted inputs, on Windows you can also use the CommandExt::raw_arg method to bypass the standard library's escaping logic," the Rust Security Response WG added. Flatt Security engineer Ryotak discovered the vulnerability and dubbed it BatBadBut, says the flaw also impacts the following programming languages—however, not all of them have released patches: "To prevent the unexpected execution of batch files, you should consider moving the batch files to a directory that is not included in the PATH environment variable," Ryotak advised. "In this case, the batch files won’t be executed unless the full path is specified, so the unexpected execution of batch files can be prevented." In February, the White House Office of the National Cyber Director (ONCD) urged technology companies to adopt memory-safe programming languages like Rust. The end goal is to improve software security by minimizing the number of memory safety vulnerabilities. Update: Added info on other vulnerable programming languages.

Daily Brief Summary

MALWARE // Critical Rust Library Flaw Triggers Windows Command Injection

A critical security vulnerability in the Rust standard library, identified as CVE-2024-24576, allows threat actors to perform command injection attacks on Windows systems.

The flaw is due to OS command and argument injection weaknesses, enabling attackers to execute unexpected and potentially harmful commands without user interaction.

GitHub has assigned this vulnerability a maximum severity rating of 10/10, emphasizing its critical nature for unauthenticated and remote exploitation.

All versions of Rust prior to 1.77.2 on Windows are at risk, particularly if they employ batch files (.bat and .cmd) with untrusted arguments.

The Rust Security Response WG improved the Command API to deal with cmd.exe's complexity after failing to find a universally safe method for argument escaping.

In certain cases, if argument escaping is not possible, the Rust Command API now returns an InvalidInput error, encouraging developers to handle escaping on their own or use trusted inputs.

Additional vulnerabilities were revealed by Flatt Security engineer Ryotak, affecting other programming languages, though not all have issued patches.

Ryotak also advised moving batch files to a directory outside the PATH environment variable to mitigate risks of unintended execution.