WCU / Cybersecurity
~/CSC 472/Class 07/KP 09
Class 07 · KP 09 / 18

Finding Gadgets: ROPgadget and ropper

attacker stackpadding A*N→ pop rdi ; retgadgetarg1in RDI→ pop rsi ; retgadgetarg2in RSI→ system()target.text / libcexisting code
A ROP chain: each 'ret' launches the next gadget already present in the code.

Search the binary (and libc) for sequences ending in ret:

# ROPgadget
ROPgadget --binary ./vuln | grep ": pop rdi ; ret"
# -> 0x000000000040123b : pop rdi ; ret

# ropper (alternative, similar output)
ropper --file ./vuln --search "pop rdi"

# find the "/bin/sh" string inside libc
strings -a -t x libc.so.6 | grep /bin/sh
  • Addresses in a PIE/libc are offsets until you know the load base (that base comes from a leak — Class 08 / ASLR).
  • Non-PIE binaries give you fixed addresses for the program's own gadgets.