PoC for CVE-2026-42945 (nginx Rift) — ngx_http_rewrite_module 中的堆缓冲区溢出漏洞。包含检测/探测/利用模式、双夹具 Docker 实验环境、经验地址发现、OOB 验证的偏移扫描。首次披露:depthfirst。
针对 CVE-2026-42945 的 RCE 概念验证,这是一个 NGINX 的 ngx_http_rewrite_module 中自 2008 年引入的严重堆缓冲区溢出漏洞。可在使用 rewrite ... ?... + set 捕获组合的服务器上实现未经认证的远程代码执行。
原始漏洞披露:depthfirst —— 与 CVE-2026-42946、CVE-2026-40701、CVE-2026-42934 一同通过其自主源代码审计系统发现。
poc-CVE-2026-42945/
├── exploit.py — 改进版 PoC(3 种模式:--check / --probe / --exploit)
├── poc.py.orig — 原始 depthfirst PoC(参考)
├── env/ — 双容器 Docker 实验环境
│ ├── Dockerfile (漏洞版本:nginx commit 98fc3bb78)
│ ├── Dockerfile.patched (修复版本:release-1.31.0)
│ ├── docker-compose.yml (两个服务)
│ ├── nginx.conf (存在漏洞的 rewrite + set 配置)
│ ├── entrypoint.sh (在 setarch -R 下运行——ASLR 关闭)
│ └── server.py (后端桩程序)
├── discover-addresses.sh — 从运行中的容器提取 HEAP_BASE / LIBC_BASE / system() 偏移量
├── verify.sh — 双容器验证脚本(攻击漏洞版本,确认修复版本拦截)
├── setup.sh — 构建辅助脚本(旧版单镜像方式)
├── references.md — 完整的漏洞机制、利用策略、缓解措施
└── README.md — 本文件
两遍脚本引擎中 is_args 标志不同步:
is_args = 0 → 分配原始捕获长度is_args = 1 → ngx_escape_uri(NGX_ESCAPE_ARGS) 3 倍扩展 → 堆溢出利用方式:通过 POST /spray 请求体进行堆风水(请求体允许 NUL 字节,植入伪造的 ngx_pool_cleanup_s)+ 通过 URI 溢出破坏相邻的 ngx_pool_t.cleanup 链表头。池销毁 → system(cmd)。
完整机制及利用策略见 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 |
厂商公告:https://my.f5.com/manage/s/article/K000160932
# 构建两个容器
docker compose -f env/docker-compose.yml build
# 启动实验环境(漏洞版本=:19321,修复版本=:19421)
docker compose -f env/docker-compose.yml up -d
# 仅检测(不触发溢出)
python3 exploit.py --check --host 127.0.0.1 --port 19321
# 完整利用
python3 exploit.py --exploit --host 127.0.0.1 --port 19321 \
--cmd 'echo pwned > /tmp/rift'
docker exec nginx-rift-vuln cat /tmp/rift
# 双容器验证(攻击漏洞版本 + 确认修复版本拦截)
./verify.sh
# 关闭实验环境
docker compose -f env/docker-compose.yml down
非本地主机目标需要添加 --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 调用中
setarch -R 禁用了 ASLR。真实目标启用了 ASLR——需要额外的信息泄露原语。rewrite ... ? + set $X $N 组合。许多真实配置缺少此条件。--check 检测模式、--probe 偏移枚举、修复版本容器、地址发现辅助工具、双容器验证脚本。| 模式 | 使用场景 | 副作用 |
|---|
--check | 检测 rewrite 表面是否存在 | 无——仅发送小量探测 URI |
--probe | 针对当前构建枚举 spray 着陆偏移量 | 搜索过程中导致工作进程崩溃;不执行命令 |
--exploit | 完整的 RCE 链 | 工作进程崩溃 + 使用 --cmd 调用 system() |