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

64-bit ret2libc: Arguments Go in Registers (System V)

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.
  • On x86-64, the first six integer/pointer args are passed in registers, not on the stack: RDI, RSI, RDX, RCX, R8, R9
  • So system("/bin/sh") needs RDI = &"/bin/sh" before we call system.
  • A plain "return into system" no longer works — nothing sets RDI for us.
  • We need a gadget that loads RDI from the stack, typically: pop rdi ; ret
  • This is the doorway from ret2libc into full ROP.