Skip to main content
Be Bitwise

Gadget Identification

Three small instruction sequences (gadgets) each ending in RET. Call them individually to see each one perform its single operation.

A ROP gadget is a short sequence of instructions ending in RET that already exists somewhere in a program's executable code. Because these instructions are part of the legitimate binary, they are always marked executable — even when DEP/NX prevents injected code from running. Attackers catalogue available gadgets and chain them together to perform arbitrary operations. Each gadget does one small thing (load a register, add values, store to memory) and then returns.

Simulator

Loading simulator...

Walkthrough Guide

  1. 1

    Call gadget 1: set a register

    Do this: Step through CALL gadget1, then MOV R0, #3 and RET inside the gadget

    Watch for: R0 = 3 after the gadget executes. RET returns to the main code

    Gadget 1 sets R0 to 3. It is only 2 instructions: MOV R0, #3 ; RET. This is a 'register load' gadget — one of the most common types in real binaries.

  2. 2

    Call gadget 2: set another register

    Do this: Step through CALL gadget2, then MOV R1, #5 and RET

    Watch for: R1 = 5 after the gadget executes

    Gadget 2 sets R1 to 5. Combined with gadget 1, we now have two registers set to chosen values. In a real ROP chain, this is how you prepare arguments.

  3. 3

    Call gadget 3: compute a result

    Do this: Step through CALL gadget3, then ADD R0, R1 and RET

    Watch for: R0 = 8 (3 + 5)

    Gadget 3 adds R0 and R1. By chaining these three gadgets, we have loaded two values and computed their sum — all using pre-existing code snippets, never writing new instructions.

Objectives

  • •See gadget1 set R0 = 3 and return
  • •See gadget2 set R1 = 5 and return
  • •See gadget3 compute R0 = 3 + 5 = 8 and return
  • •Notice each gadget is just 1-2 instructions plus RET - small and reusable

Hints

  • These same gadgets will be chained together in the rop-chain-demo without using CALL