So far our chains have set a single argument — one pop rdi to steer one call, as in Natural Jumps (x64). This challenge raises the bar: three functions, each taking three arguments, all of which must be called in order before we see the flag. It is the moment return-oriented programming stops being a trick and starts being programming: we are building a small program out of borrowed pieces.
When we run the binary, it greets us and waits for input:
./challcallme by ROP Emporiumx86_64Hello!>There is no canary and no PIE, so this is a plain buffer overflow into a ROP chain — the only new work is arranging the registers.
callme asks us to call callme_one(), callme_two(), and callme_three(), in that order, each with the arguments 0xdeadbeefdeadbeef, 0xcafebabecafebabe, and 0xd00df00dd00df00d. Each function checks all three arguments and that it was called in sequence; miss either and it bails out with "Incorrect parameters". Only once all three have been called correctly does callme_three() print the flag.
The three targets are right there in the binary:
info functions callmeAll functions matching regular expression "callme":Non-debugging symbols:0x00000000004012fe callme_one0x000000000040136d callme_two0x00000000004013dd callme_threeOn x64 the first three integer arguments live in rdi, rsi, and rdx. Earlier one pop rdi; ret was enough; now we need all three set before every call. We could hunt down three separate gadgets, but the cleanest approach is a single gadget that pops all three in one go. ROPgadget finds exactly that:
ROPgadget --binary chall --only "pop|ret" | grep "pop rdi"0x000000000040144c : pop rdi ; pop rsi ; pop rdx ; retThat one gadget — pop rdi ; pop rsi ; pop rdx ; ret — takes the next three values off the stack into our argument registers and then returns wherever we point it. It is the workhorse of the whole chain.
Each call is the same four-part unit laid onto the stack: the gadget, the three argument values it will pop into rdi/rsi/rdx, then the address of the function to run. The gadget's final ret lands us in the function; when that function returns, execution falls through to the next unit. We stack three of these, one per callme_N, in order.
The padding to the saved return address is 0x28 — a 0x20 buffer plus the saved base pointer. After that, the chain:
1from pwn import *
2
3elf = context.binary = ELF("./chall")
4p =The flat() helper packs each integer to the right width and leaves the byte-string padding untouched, so the loop reads exactly like the stack picture: gadget, three arguments, function — three times over.
Running it walks through all three calls in sequence and drops the flag:
python3 exploit.pycallme_one() called correctlycallme_two() called correctlycallme_three() called correctlyIFC{PL4C3H0LD3R_FL4G_H3R3!}Each function confirms it was called correctly, and callme_three() hands us the flag. You have just written a three-call program entirely out of a single gadget and some addresses — that is the core skill every later ROP technique builds on.