iammerrida-source/nginx-rift-detect
GitHub: iammerrida-source/nginx-rift-detect
针对 NGINX rewrite 模块堆溢出漏洞 CVE-2026-42945 的行为检测脚本,通过触发 worker 崩溃来判断目标是否存在风险,不执行实际利用。
Stars: 0 | Forks: 0
# nginx-rift-detect
针对 **CVE-2026-42945** (NGINX Rift) 的行为检测脚本 — 这是自 2008 年以来 nginx 中 `ngx_http_rewrite_module` 存在的一个堆缓冲区溢出漏洞。




## ⚠️ 免责声明
本工具**仅用于授权的安全测试和研究**。
仅对您拥有或获得**明确书面授权**进行测试的系统运行此工具。
未经授权的使用可能违反您所在司法管辖区的计算机犯罪法律。
作者对因滥用此工具造成的任何误用或损害概不负责。
## 背景
**CVE-2026-42945** 是 nginx 的 rewrite 脚本引擎 (`ngx_http_rewrite_module`) 中的一个堆缓冲区溢出漏洞,该漏洞在版本 `0.6.27` (2008) 中引入,已存在约 18 年。
该漏洞源于 rewrite 引擎两次遍历之间的不匹配:
- **Pass 1** (长度计算):检测到 `is_args = 0` → 分配一个小型缓冲区
- **Pass 2** (数据复制):检测到 `is_args = 1` → 调用 `ngx_escape_uri`,将每个可转义字节(例如 `+`)扩展为其大小的 3 倍 → **导致堆缓冲区溢出**
这允许未经身份验证的远程代码执行。
**受影响版本:**
| 产品 | 受漏洞影响 | 已修复 |
|---|---|---|
| NGINX Open Source | 0.6.27 – 1.30.0 | 1.30.1, 1.31.0+ |
| NGINX Plus | R32 – R36 | R36 P4, R35 P2, R32 P6 |
**参考链接:**
- [原始研究与 PoC — DepthFirstDisclosures](https://github.com/DepthFirstDisclosures/Nginx-Rift)
- [F5 安全公告 K000160932](https://my.f5.com/manage/s/article/K000160932)
## 检测原理
本脚本**不会**尝试 RCE。它使用原始套接字模拟 PoC 的流程:
1. **Canary** — 发送 3 个正常请求,以确认测试前服务器的稳定性
2. **堆喷射 (Heap spray)** — 开启 20 个连接以占用内存
3. **触发器 (Trigger)** — 发送 `GET /api/<349×A><969×+>` 作为部分 HTTP 请求
4. **探测 (Probe)** — 如果触发器套接字意外关闭(worker 进程崩溃并重启),则将目标标记为易受攻击
## 使用方法
```
# 单一目标 (HTTP)
python3 detect-CVE-2026-42945.py --host 127.0.0.1 --port 80
# 单一目标 (HTTPS)
python3 detect-CVE-2026-42945.py --host example.com --port 443 --tls
# 目标列表
python3 detect-CVE-2026-42945.py -l targets.txt
# 使用线程和输出文件
python3 detect-CVE-2026-42945.py -l targets.txt --threads 10 -o vulnerable.txt
# 针对不稳定目标的更多尝试
python3 detect-CVE-2026-42945.py --host 10.0.0.1 --port 8080 --tries 5
```
**`targets.txt` 格式** — 每行一个:
```
http://example.com
https://example.com:8443
192.168.1.1
192.168.1.1:8080
```
**选项:**
```
--host Single target host
--port Port (default: 80, or 443 with --tls)
--tls Use TLS/HTTPS for single target
-l, --list File with list of targets
--tries Detection attempts per target (default: 3)
--threads Concurrent threads for list scan (default: 5)
-o, --output Save vulnerable targets to CSV file
```
## 示例输出
```
[*] CVE-2026-42945 NGINX Rift Detection | targets=2 threads=5 tries=3
[*] http://192.168.1.1:80 - nginx/1.28.0
[*] http://192.168.1.2:8080 - nginx/1.31.0
[!!!] VULNERABLE | http://192.168.1.1:80 | nginx/1.28.0 | worker crash (trigger connection closed — worker respawned)
[+] http://192.168.1.2:8080 - not vulnerable (or timing miss, try --tries 5)
==================================================
[*] Scan complete. 2 targets scanned.
[!!!] 1 VULNERABLE target(s):
http://192.168.1.1:80 (nginx/1.28.0)
==================================================
```
## 在实验环境中测试
原始代码仓库包含一个 Docker 实验环境:
```
git clone https://github.com/DepthFirstDisclosures/Nginx-Rift
cd Nginx-Rift
chmod +x setup.sh && ./setup.sh
docker compose -f env/docker-compose.yml up -d
python3 detect-CVE-2026-42945.py --host 127.0.0.1 --port 19321
```
## 许可证
MIT — 详见 [LICENSE](LICENSE)
*原始漏洞研究与 PoC:[DepthFirstDisclosures](https://github.com/DepthFirstDisclosures/Nginx-Rift)*
标签:CISA项目, CVE-2026-42945, DoS, Maven, NGINX, ngx_http_rewrite_module, Python, Web安全, 堆溢出, 安全测试, 安全漏洞, 崩溃检测, 拒绝服务, 攻击性安全, 数据展示, 无后门, 无服务器架构, 漏洞验证, 红队, 缓冲区溢出, 网络安全, 蓝队分析, 行为检测, 请求拦截, 逆向工具, 隐私保护