rust: Improper Neutralization of Special Elements used in an OS Command
CVE-2024-24576 is a critical-severity improper neutralization of special elements used in an OS command vulnerability in rust from Rust-lang, with a CVSS 3.1 base score of 10.0 out of 10. It can be exploited remotely over the network by an unauthenticated attacker, without any action from a user. The record lists version 1.77.2 as the first without the flaw, so updating rust to that release or later removes the exposure. There is no confirmed exploitation so far. EPSS estimates a 20.3% chance of exploitation within 30 days, which is in the top 2.48% of all scored CVEs.
Critical severity: a successful attack would have severe impact.
What to do
- Update rust to 1.77.2 or a later version.
- Read the advisory on github.com for workarounds and exact fixed builds.
- Until you can update, restrict network access to the affected service so it is not reachable from untrusted networks.
Affected products and versions
| Vendor | Product | Affected versions | Fixed in |
|---|---|---|---|
| Rust-lang | rust | < 1.77.2; before 1.77.2 | 1.77.2 |
| Fedora Project | Fedora | 38; 39; 40 | Not stated |
Version data comes from the organisation that assigned the CVE. Confirm against the vendor advisory before deciding you are unaffected.
How the severity score breaks down
- Attack vector
- NetworkCan be exploited remotely over a network, including the internet.
- Attack complexity
- LowNo special conditions are needed; the attack works reliably.
- Privileges required
- NoneNo account or login is needed.
- User interaction
- NoneNo action by a victim is required.
- Scope
- ChangedThe attack can reach beyond the vulnerable component into other systems.
- Confidentiality
- HighAll data handled by the component can be read.
- Integrity
- HighData or code can be modified at will.
- Availability
- HighThe component can be taken down completely.
Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H. Scored by NVD.
| Scoring system | Score | Severity | Scored by |
|---|---|---|---|
| CVSS 3.1 | 10.0 | Critical | CNA (github.com) |
| CVSS 3.1 | 10.0 | Critical | NVD |
Official description
Rust is a programming language. The Rust Security Response WG was notified that the Rust standard library prior to version 1.77.2 did not properly escape arguments when invoking batch files (with the `bat` and `cmd` extensions) on Windows using the `Command`. 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 for those who invoke batch files on Windows with untrusted arguments. No other platform or use is affected. The `Command::arg` and `Command::args` APIs state in their documentation that the arguments will be passed to the spawned process as-is, regardless of the content of the arguments, and will not be evaluated by a shell. This means it should be safe to pass untrusted input as an argument. On Windows, the implementation of this is more complex than other platforms, because the Windows API only provides a single string containing all the arguments to the spawned process, and it's up to the spawned process to split them. Most programs use the standard C run-time argv, which in practice results in a mostly consistent way arguments are splitted. One exception though is `cmd.exe` (used among other things to execute batch files), which has its own argument splitting logic. That forces the standard library to implement custom escaping for arguments passed to batch files. Unfortunately it was reported that our escaping logic was not thorough enough, and it was possible to pass malicious arguments that would result in arbitrary shell execution. Due to the complexity of `cmd.exe`, we didn't identify a solution that would correctly escape arguments in all cases. To maintain our API guarantees, we improved the robustness of the escaping code, and changed the `Command` API to return an `InvalidInput` error when it cannot safely escape an argument. This error will be emitted when spawning the process. The fix is included in Rust 1.77.2. Note that the new escaping logic for batch files errs on the conservative side, and could reject valid arguments. Those who implement the escaping themselves or only handle trusted inputs on Windows can also use the `CommandExt::raw_arg` method to bypass the standard library's escaping logic.
Source: the CVE record as published by its numbering authority, via NVD and CVE.org.
The underlying weakness: Improper Neutralization of Special Elements used in an OS Command
The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command before it is sent to a downstream component.
How developers prevent this class of flaw
- If at all possible, use library calls rather than external processes to recreate the desired functionality.
- For any data that will be used to generate a command to be executed, keep as much of that data out of external control as possible. For example, in web applications, this may require storing the data locally in the session's state instead of sending it out to the client in a hidden form field.
- For any security checks that are performed on the client side, ensure that these checks are duplicated on the server side, in order to avoid CWE-602. Attackers can bypass the client-side checks by modifying values after the checks have been performed, or by changing the client to remove the client-side checks entirely. Then, these modified values would be submitted to the server.
More Improper Neutralization of Special Elements used in an OS Command vulnerabilities (CWE-78)
Timeline
- CVE record published.
- CISA published its SSVC assessment (exploitation: poc, automatable: yes, technical impact: total).
- Record last changed materially (score, affected products, status or references).
References
Advisories
- github.com/rust-lang/rust/security/advisories/GHSA-q455-m56c-85mhMitigation
- lists.fedoraproject.org/archives/list/[email protected]/message/N323QAEEUVTJ354BTVQ7UB…Mailing List
- lists.fedoraproject.org/archives/list/[email protected]/message/RPH3PF7DVSS2LVIRLW254V…Mailing List
- lists.fedoraproject.org/archives/list/[email protected]/message/W7WRFOIAZXYUPGXGR5UEEW…Mailing List
Third-party and government advisories
- openwall.com/lists/oss-security/2024/04/09/16Mailing List, Third Party Advisory
- kb.cert.org/vuls/id/123335Third Party Advisory
Other references
- doc.rust-lang.org/std/io/enum.ErrorKind.html#variant.InvalidInputTechnical Description
- doc.rust-lang.org/std/os/windows/process/trait.CommandExt.html#tymethod.raw_argTechnical Description
- doc.rust-lang.org/std/process/struct.Command.htmlTechnical Description
- doc.rust-lang.org/std/process/struct.Command.html#method.argTechnical Description
- doc.rust-lang.org/std/process/struct.Command.html#method.argsTechnical Description
- github.com/rust-lang/rust/issuesIssue Tracking
- rust-lang.org/policies/securityTechnical Description
Other vulnerabilities in rust
- 8.8 High severity
- 9.8 Critical severity
Recent Improper Neutralization of Special Elements used in an OS Command vulnerabilities
- 9.8 Critical severity
- 8.8 High severity
- 8.8 High severity
- 7.2 High severity
- 7.2 High severity
- 7.2 High severity
Spotted an error? Tell us.