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

Why "pop rdi ; ret" Is the Star Gadget

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.
  • pop rdi takes the next 8 bytes off the stack into RDI; ret then jumps to the value after it.
  • So placing [&(pop rdi;ret)][value][&next] on the stack means: "set RDI = value, then continue to next."
  • Analogous gadgets fill the other argument registers:
  • pop rsi ; ret → arg2
  • pop rdx ; ret → arg3
  • Real binaries rarely have clean single-register pops; you often get pop rsi ; pop r15 ; ret and must supply a junk value for r15.