CVSS 9.2(严重) — nginx 中的预认证堆缓冲区溢出 + 信息泄露 受影响版本:nginx 0.9.6 – 1.30.3 / 1.31.2 | 已修复版本:1.30.4 / 1.31.3
┌─────────────────────────────────────┐
│ 宿主机 │
│ │
PoC 脚本 ─────────┤ :8080 ──► nginx-vuln (1.26.x) │
│ │ 存在漏洞 │
│ ▼ │
│ backend (Python echo) │
│ ▲ │
│ │ │
│ :8081 ──► nginx-patched (1.30.4) │
│ 安全 │
└─────────────────────────────────────┘
# Build and start
docker compose up --build -d
# Verify
curl http://localhost:8080/health
curl http://localhost:8081/health
# Run PoC
python3 poc_overflow.py # Heap overflow (crash worker)
python3 poc_infoleak.py # Info leak (heap residue)
bash poc_curl.sh # Quick curl-based tests
# Compare with patched
python3 poc_overflow.py localhost 8081
python3 poc_infoleak.py localhost 8081
# Check for crashes
docker logs nginx-vuln 2>&1 | grep -iE 'signal|segfault|abort'
# Cleanup
docker compose down
nginx 使用共享的可变数组 r->captures,以两遍方式求值指令值
(proxy_set_header、return、add_header 等):
| 遍次 | 用途 | 读取 r->captures |
|---|---|---|
| LEN | 测量所需缓冲区大小 | 是 — 以获取 $1 长度 |
(正则 map 在此处求值,覆盖 r->captures) | ||
| VALUE | 将数据写入已分配的缓冲区 | 是 — 但此时 $1 指向了别处 |
map $http_user_agent $is_bot {
~*(bot|crawl|spider) 1; # ← regex map = clobber trigger
default 0;
}
location ~ "^/api/v1/(.+)$" { # ← regex capture source
proxy_set_header X-Route "$1 — $is_bot"; # ← two-pass sink
# ^^ ^^^^^^^
# capture ref + map var in same buffer = BUG
}
| 方向 | URI 大小 | Map 输入大小 | 结果 |
|---|---|---|---|
| 溢出 | 短(3 B) | 长(4096 B) | LEN 分配小缓冲区,VALUE 写入大数据 → 堆溢出 |
| 信息泄露 | 长(8000 B) | 短(5 B) | LEN 分配大缓冲区,VALUE 写入小数据 → 响应中残留堆数据 |
| 端点 | 汇聚点 | Map 触发条件 | 演示 |
|---|---|---|---|
/api/v1/{path} | proxy_set_header | $is_bot (User-Agent) | 溢出 |
/leak/{path} | return + add_header | $ref_domain (Referer) | 信息泄露 |
/rce/{path} | set + return | $is_bot (User-Agent) | 溢出 |
/safe/{path} | return(无 map) | 无 | 对照(安全) |
| 文件 | 用途 |
|---|---|
docker-compose.yml | 实验环境编排 |
Dockerfile.nginx-vuln | 存在漏洞的 nginx 1.26.x |
Dockerfile.nginx-patched | 已修复的 nginx 1.30.4 |
nginx-vuln.conf | 带注释模式的存在漏洞配置 |
backend.py | 用于检查代理头的回显服务器 |
poc_overflow.py | 堆溢出 PoC(递增载荷大小) |
poc_infoleak.py | 信息泄露 PoC(堆残留检测) |
poc_curl.sh | 基于 curl 的快速测试 |
使用配置扫描器:
python3 nginx_capture_clobber_scan.py /etc/nginx/nginx.conf
map 中使用 ~ / ~* 正则模式仅供教育和授权安全测试使用。