Master the fundamental concepts of binary exploitation through this focused micro-challenge.
You have read the whole brief, and the concepts above stay free on every task. Writing and running the code needs a plan.
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it worksA ROP chain is a carefully constructed sequence of gadget addresses placed on the stack. Each gadget performs a small operation and ends with ret, which loads the next gadget address. By chaining enough gadgets, attackers perform arbitrary computations without injecting new code.
Find gadgets with tools like ROPgadget, ropper, or objdump. For calling system("/bin/sh") on x86-64 Linux:
cLoading…
Challenges include NULL bytes in addresses (terminate strcpy), 16-byte stack alignment before system(), and ASLR randomizing all addresses.
You will write the chain simulator itself: given the four gadget addresses and the stack quadwords laid out by the overflow, walk the chain exactly as the CPU would: each ret pops the next value, pop rdi; ret and pop rsi; ret consume an argument slot, and reaching system() consumes its slot. You will then verify the System V stack alignment at system()'s entry, the exact mistake that causes the infamous movaps crash.
ROPgadget scans executable segments for sequences ending in ret. Libc is gadget-rich because it contains millions of instructions compiled from C source. Useful gadgets need not be full functions; pop rdi; ret is just two instructions. Defenders deploy Control Flow Integrity and shadow stacks, but understanding basic chain construction remains essential for CTF competitions and vulnerability research on unpatched services.
Write a C program that simulates executing a ROP chain.
Requirements:
Success Criteria: