kcve.ai취약점 정보 · 내 자산 확인

CVE-2024-24576 Rusts's `std::process::Command` did not properly escape arguments of batch files on Windows

Rusts의 `std::process::Command`가 Windows에서 배치 파일의 인수를 제대로 이스케이프하지 못했습니다.

설명

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.

Rust는 프로그래밍 언어입니다. Rust 보안 응답 WG는 명령 `을 사용하여 Windows에서 일괄 파일(`bat` 및 `cmd` 확장 포함)을 호출할 때 버전 1.77.2 이전의 Rust 표준 라이브러리가 인수를 제대로 탈출하지 못했다는 것을 알렸습니다. 스폰된 프로세스에 전달된 인수를 제어할 수 있는 공격자는 이스케이프를 우회하여 임의의 셸 명령을 실행할 수 있습니다. 이 취약점의 심각성은 신뢰할 수 없는 인수를 사용하여 Windows에서 배치 파일을 호출하는 사용자에게 중요합니다. 다른 플랫폼이나 사용에는 영향을 주지 않습니다. `Command::arg`와 `Command::args` API는 그들의 문서에 인수가 인수의 내용에 관계없이 스폰된 프로세스 그대로 전달되고 쉘에 의해 평가되지 않을 것이라고 명시합니다. 즉, 신뢰할 수 없는 입력을 인수로 전달하는 것이 안전해야 합니다. Windows에서는 이 구현이 다른 플랫폼보다 복잡합니다. Windows API는 생성 된 프로세스에 대한 모든 인수를 포함하는 단일 문자열만 제공하기 때문에 이를 분할하는 것은 스폰 된 프로세스에 달려 있습니다. 대부분의 프로그램은 표준 C 런타임 argv를 사용하며, 실제로 이는 인수가 분할되는 대부분의 일관된 방식으로 발생합니다. 하지만 예외로 `cmd.exe` (배치 파일을 실행하기 위해 다른 것들 중에서 사용됨)가 있는데, 이 경우 논리를 분할하는 자체 인수가 있습니다. 이에 따라 표준 라이브러리는 일괄 파일에 전달된 인수에 대해 사용자 지정 이스케이프를 구현해야 합니다. 불행히도 우리의 이스케이프 로직이 충분히 철저하지 않다는 것이 보고되었고, 임의의 쉘 실행을 초래할 악의적인 주장을 전달할 수 있었습니다. `cmd.exe`의 복잡성으로 인해 모든 경우에 인수를 올바르게 이스케이프하는 솔루션을 찾지 못했습니다. API 보증을 유지하기 위해 이스케이프 코드의 견고성을 개선하고 `Command` API를 변경하여 인수를 안전하게 이스케이프할 수 없을 때 `InvalidInput` 오류를 반환했습니다. 이 오류는 프로세스를 스폰할 때 발생합니다. 이 수정사항은 Rust 1.77.2에 포함되어 있습니다. 배치 파일에 대한 새로운 이스케이프 로직은 보수적인 측면에서 오류가 발생하고 유효한 인수를 거부할 수 있습니다. 이스케이프를 스스로 구현하거나 Windows에서 신뢰할 수 있는 입력만 처리하는 사람들은 `CommandExt::raw_arg` 메서드를 사용하여 표준 라이브러리의 이스케이프 논리를 우회할 수도 있습니다.

영향 받는 제품 제품 1개

  • rust-lang

    rust

    해결 버전 있음

    영향 받는 버전

    • 1.77.2 미만

    해결 버전

    • 1.77.2 이상

참고 자료 12건

‹ 목록

점검 지원 범위 문의

도입 문의