Skip to main content
Be Bitwise

Controlled Overflow

An attacker deliberately overwrites the return address with a chosen value, redirecting execution to their target address.

A controlled overflow goes beyond an accidental crash. The attacker knows the buffer size and the exact offset to the return address. They fill the buffer with padding bytes, then place their chosen address at precisely the right offset. When the function returns, the CPU jumps to the attacker's address instead of the legitimate return point. This is the fundamental technique behind code execution exploits.

Simulator

Loading simulator...

Walkthrough Guide

  1. 1

    Set up the legitimate return address

    Do this: Step through the setup instructions

    Watch for: Return address 15 stored at address 203

    The attacker knows the return address is at address 203 and the buffer starts at 200. That means 3 bytes of padding are needed to reach the return address.

  2. 2

    Attacker fills buffer with padding

    Do this: Step through the three STORE instructions for addresses 200, 201, 202

    Watch for: Zeros appear at addresses 200, 201, 202 (padding). Address 203 still holds 15

    The attacker writes padding (zeros) to fill the buffer. The content does not matter — its only purpose is to advance the write position to the return address.

  3. 3

    Overwrite the return address

    Do this: Step through MOV R6, #7 and STORE [R0], R6

    Watch for: Address 203 changes from 15 to 7 — the attacker's chosen address

    The attacker writes 7 (their chosen target address) to the return address location. This is deliberate, not accidental. The attacker controls exactly where the CPU will jump.

  4. 4

    Verify the hijack

    Do this: Step through LOAD R5, [R3] and HALT

    Watch for: R5 = 7. The return address now points to the attacker's target

    R5 confirms the return address was changed from 15 to 7. If this function executed RET, execution would jump to address 7 — whatever code the attacker placed there.

Objectives

  • •See padding zeros fill the buffer at addresses 200, 201, 202
  • •Watch the attacker's chosen value (7) overwrite the return address at 203
  • •Verify R5 = 7 - the attacker controls where RET would jump
  • •Understand the difference between accidental and deliberate overflow

Hints

  • The attacker knows the buffer is 3 bytes and the return address is at offset 3 - they write exactly the right amount