F2u0a0d3/CVE-2026-42945-nginx-rift-poc

GitHub: F2u0a0d3/CVE-2026-42945-nginx-rift-poc

针对 CVE-2026-42945(NGINX ngx_http_rewrite_module 堆缓冲区溢出漏洞)的 RCE 概念验证工具,含检测、探测、利用三种模式及双环境 Docker 实验室。

Stars: 1 | Forks: 0

# NGINX Rift — CVE-2026-42945 **CVE-2026-42945** 的 RCE 概念验证,这是 NGINX 的 `ngx_http_rewrite_module` 中于 2008 年引入的一个严重的堆缓冲区溢出漏洞。可针对使用 `rewrite ... ?...` + `set` 捕获组合的服务器实现未经身份验证的远程代码执行。 原始漏洞披露:[depthfirst](https://depthfirst.com/research/nginx-rift-achieving-nginx-rce-via-an-18-year-old-vulnerability) — 通过其自主源代码审计系统与 CVE-2026-42946、CVE-2026-40701、CVE-2026-42934 一同发现。 ## 目录结构 ``` poc-CVE-2026-42945/ ├── exploit.py — improved PoC (3 modes: --check / --probe / --exploit) ├── poc.py.orig — original depthfirst PoC (reference) ├── env/ — dual-fixture Docker lab │ ├── Dockerfile (vuln: nginx commit 98fc3bb78) │ ├── Dockerfile.patched (patched: release-1.31.0) │ ├── docker-compose.yml (both services) │ ├── nginx.conf (vulnerable rewrite + set config) │ ├── entrypoint.sh (runs under setarch -R — ASLR off) │ └── server.py (backend stub) ├── discover-addresses.sh — extract HEAP_BASE / LIBC_BASE / system() offset from running container ├── verify.sh — dual-fixture reproducer (exploit vuln, prove patched blocks) ├── setup.sh — build helper (legacy single-image) ├── references.md — full bug mechanics, exploitation strategy, mitigations └── README.md — this file ``` ## 漏洞详情 (TL;DR) 双趟脚本引擎,`is_args` 标志位不同步: - **长度计算趟** 看到 `is_args = 0` → 分配原始捕获长度 - **拷贝趟** 看到 `is_args = 1` → `ngx_escape_uri(NGX_ESCAPE_ARGS)` 3 倍扩展 → 堆溢出 漏洞利用:通过 POST `/spray` body 进行堆风水(body 中允许 NUL 字节,植入伪造的 `ngx_pool_cleanup_s`)+ URI 溢出破坏相邻的 `ngx_pool_t.cleanup` 头。池销毁 → `system(cmd)`。 完整的机制与利用策略详见 [references.md](references.md)。 ## 受影响与已修复版本 | 产品 | 受影响 | 已修复 | |-------------------|------------------|--------------------------| | 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 | 厂商安全通告: ## 快速开始 ``` # 构建两个 fixtures docker compose -f env/docker-compose.yml build # 启动 lab (vuln=:19321, patched=:19421) docker compose -f env/docker-compose.yml up -d # 仅检测(不触发 overflow) python3 exploit.py --check --host 127.0.0.1 --port 19321 # 完整 exploit python3 exploit.py --exploit --host 127.0.0.1 --port 19321 \ --cmd 'echo pwned > /tmp/rift' docker exec nginx-rift-vuln cat /tmp/rift # 双重 fixture 验证(exploit vuln + 确认拦截 patched) ./verify.sh # Teardown docker compose -f env/docker-compose.yml down ``` ## 模式 | 模式 | 用例 | 副作用 | |---|---|---| | `--check` | 检测是否存在 rewrite 攻击面 | 无 — 仅发送小型探测 URI | | `--probe` | 枚举当前构建版本的 spray-landing 偏移量 | 搜索期间会导致 worker 崩溃;无代码执行 | | `--exploit` | 完整的 RCE 链 | Worker 崩溃 + 通过 `--cmd` 执行 `system()` 调用 | 非 localhost 目标需要使用 `--i-have-tested-this` 标志(确认硬编码的偏移量与部署的构建版本相匹配)。 ## 地址发现 默认的 `--heap-base` / `--libc-base` / `--system-offset` 是内置实验室的值(Ubuntu 22.04 / glibc 2.35 / nginx commit 98fc3bb78 / 关闭 ASLR)。对于全新的构建或不同的 libc: ``` docker compose -f env/docker-compose.yml up -d nginx-vuln ./discover-addresses.sh # 将值复制到 exploit.py 调用中 ``` ## 注意事项 - **仅限实验室。** 硬编码的偏移量仅在内置测试环境中保持稳定。生产环境利用需要针对每个目标推导偏移量(信息泄露 + 偏移枚举)。 - **ASLR。** 实验室通过 `setarch -R` 禁用 ASLR。真实目标启用了 ASLR — 需要额外的信息泄露原语。 - **配置依赖。** 漏洞攻击面要求部署的 nginx.conf 中包含 `rewrite ... ?` + `set $X $N` 组合。许多真实配置缺少此项。 ## 致谢 - 漏洞发现 + 原始 PoC:[depthfirst](https://depthfirst.com) - 本分支:添加了 `--check` 检测模式、`--probe` 偏移枚举、修补的测试环境、地址发现辅助工具、双环境验证器
标签:CISA项目, Docker靶场, Nginx, 堆溢出, 应用安全, 编程工具, 请求拦截, 远程代码执行, 逆向工具