
Docker lab che riproduce CVE-2026-42533, un heap overflow pre-auth in nginx e info leak tramite two-pass capture clobbering, con script PoC e confronto con la versione patchata.
CVSS 9.2 (Critico) — Heap buffer overflow pre-auth + info leak in nginx Interessato: nginx 0.9.6 – 1.30.3 / 1.31.2 | Corretto: 1.30.4 / 1.31.3
┌─────────────────────────────────────┐
│ Host machine │
│ │
PoC scripts ──────┤ :8080 ──► nginx-vuln (1.26.x) │
│ │ VULNERABLE │
│ ▼ │
│ backend (Python echo) │
│ ▲ │
│ │ │
│ :8081 ──► nginx-patched (1.30.4) │
│ SAFE │
└─────────────────────────────────────┘
# 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 valuta i valori delle direttive (proxy_set_header, return, add_header, ecc.)
in due passaggi utilizzando un array mutabile condiviso r->captures:
| Passaggio | Scopo | Legge r->captures |
|---|---|---|
| LEN | Misura la dimensione del buffer necessaria | Sì — per ottenere la lunghezza di $1 |
(la regex map viene valutata qui, CLOBBERANDO r->captures) | ||
| VALUE | Scrive i dati nel buffer allocato | Sì — ma ora $1 punta altrove |
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
}
| Direzione | Dimensione URI | Dimensione input map | Risultato |
|---|---|---|---|
| Overflow | Corta (3 B) | Lunga (4096 B) | LEN alloca poco, VALUE scrive molto → heap overflow |
| Info Leak | Lunga (8000 B) | Corta (5 B) | LEN alloca molto, VALUE scrive poco → residuo heap nella risposta |
| Endpoint | Sink | Trigger Map | Demo |
|---|---|---|---|
/api/v1/{path} | proxy_set_header | $is_bot (User-Agent) | Overflow |
/leak/{path} | return + add_header | $ref_domain (Referer) | Info leak |
/rce/{path} | set + return | $is_bot (User-Agent) | Overflow |
/safe/{path} | return (no map) | Nessuno | Controllo (sicuro) |
| File | Scopo |
|---|---|
docker-compose.yml | Orchestrazione del lab |
Dockerfile.nginx-vuln | nginx 1.26.x vulnerabile |
Dockerfile.nginx-patched | nginx 1.30.4 corretto |
nginx-vuln.conf | Configurazione vulnerabile con pattern annotati |
backend.py | Server echo per ispezionare gli header proxati |
poc_overflow.py | PoC heap overflow (dimensioni payload crescenti) |
poc_infoleak.py | PoC info leak (rilevamento residuo heap) |
poc_curl.sh | Test rapidi basati su curl |
Usa il config scanner:
python3 nginx_capture_clobber_scan.py /etc/nginx/nginx.conf
~ / ~* in map quando le catture sono usate altroveSOLO PER TEST DI SICUREZZA EDUCATIVI E AUTORIZZATI.