CVSS 9.2 (Critical) — 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 はディレクティブの値 (proxy_set_header、return、add_header など) を、
共有された可変配列 r->captures を用いて 二段階 で評価します:
| パス | 目的 | r->captures を読み取る |
|---|---|---|
| LEN | 必要なバッファサイズを測定 | はい — $1 の長さを取得するため |
(regex 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 ベースのテスト |
config scanner を使用してください:
python3 nginx_capture_clobber_scan.py /etc/nginx/nginx.conf
map 内で ~ / ~* regex パターンを避ける教育および許可されたセキュリティテスト専用。