ROP Chain
Place gadget addresses on the stack and let RET chain through them - no CALL instructions needed. This is the core ROP mechanism.
In a Return-Oriented Programming attack, the attacker arranges gadget addresses on the stack so that each RET pops the next gadget's address and jumps there. No CALL instructions are needed — RET alone chains the execution. Because each gadget is legitimate code from the original binary, this technique bypasses DEP/NX protections that prevent executing injected code. The 'program' exists entirely as a sequence of return addresses on the stack.
Simulator
Walkthrough Guide
- 1
Execute the first two gadgets
Do this: Step through CALL g1 (MOV R0, #3, RET) and CALL g2 (MOV R1, #5, RET)
Watch for: R0 = 3, R1 = 5. Watch the stack push and pop return addresses for each call
Each gadget does a single operation and returns. In a real ROP attack, these addresses would be pre-loaded on the stack by the attacker rather than executed via CALL.
- 2
Chain the arithmetic gadget
Do this: Step through CALL g3 (ADD R0, R1, RET)
Watch for: R0 = 8 (3 + 5). RET chains back to the main code
Gadget 3 combines the two values set by the previous gadgets. This demonstrates how individual gadgets compose: each one does a small piece of the overall operation.
- 3
Final gadget: store the result
Do this: Step through CALL g4 (MOV R2, #128 / STORE [R2], R0 / RET)
Watch for: Value 8 appears at memory address 128
The last gadget writes the computed result to memory. The four gadgets together loaded two values, added them, and stored the result — a complete computation built entirely from small reusable fragments.
Objectives
- •Watch four gadgets execute in sequence, each doing one operation
- •See R0 = 3 after g1, R1 = 5 after g2, R0 = 8 after g3
- •See the final result (8) stored at memory address 128 by g4
- •Notice each gadget's RET hands control to the next - this is the chaining mechanism
Hints
- In a real ROP attack, the attacker places g1/g2/g3/g4 addresses on the stack - RET pops each one automatically