Binary exploitation is one of the most fascinating areas in cybersecurity, and Return-Oriented Programming (ROP) is a powerful technique to bypass modern security mechanisms. If you're just getting started or looking to refine your workflow, this post covers the essential tools every ROP exploit developer should know and use.
π 1. checksec
: Know Your Battlefield
Before writing a single byte of shellcode or ROP chain, always run checksec.
This tool reveals critical binary defenses like:
-
NX (No-eXecute) – If enabled, you can't execute shellcode on the stack.
-
PIE (Position-Independent Executable) – Makes addresses random at each run.
-
Canary – Detects stack smashing.
-
RELRO – Hardens the GOT.
π§ Pro Tip: If NX is enabled, you can't inject raw shellcode — ROP is your friend.
π§ 2. GDB
: The Exploiter’s Microscope
Use GDB to analyze crashes, inspect memory, and test your payloads.'
Useful GDB commands:
-
run
– Start the binary -
pattern_create
/pattern_offset
– Find overflow offset (if usingpwndbg
) -
x/20x $rsp
– Inspect the stack -
info functions
– List available functions (likesystem
)
Use enhanced GDB plugins like:
π Goal: Determine where your buffer overflow occurs and where to pivot control.
π 3. chmod
: Set It Executable
If you're working with downloaded or compiled binaries. This ensures you can run or analyze the binary directly.
π 4. grep
: Filter the Noise
When you're hunting for gadgets, functions, or strings, grep
helps speed things up. Filter only what matters — like locating /bin/sh
or a useful gadget.
𧨠5. RopGadget
: Find the Building Blocks
ROP chains are built from gadgets — small instruction sequences ending in ret
. Look for essential gadgets:
-
pop rdi; ret
→ Load the first argument for function calls -
ret
→ Useful for stack alignment -
mov [rdi], rsi; ret
→ Write memory if needed
π§ Tip: Use grep
to locate gadgets faster.
π 6. Pwntools (pwn
): Automate the Exploit
Python's pwntools
makes building and testing exploits efficient.
π Automate everything: From calculating offsets to sending payloads and interacting with shells.
𧬠Full ROP Workflow Recap:
Step | Tool | Purpose |
---|---|---|
1 | checksec | Inspect binary protections |
2 | gdb + plugins | Debug crashes, find overflow, analyze memory |
3 | grep | Search strings or gadgets |
4 | RopGadget | Discover ROP chain gadgets |
5 | chmod | Make binary executable |
6 | pwntools | Script and test exploit |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | from pwn import * elf = ELF('./vuln_binary') rop = ROP(elf) p = process('./vuln_binary') pop_rdi = rop.find_gadget(['pop rdi', 'ret'])[0] binsh = next(elf.search(b'/bin/sh')) system = elf.symbols['system'] payload = b'A' * 72 # Adjust offset as needed payload += p64(pop_rdi) payload += p64(binsh) payload += p64(system) p.sendline(payload) p.interactive() |
No comments:
Post a Comment