Skip to main content
Be Bitwise

Use-After-Free

Free a memory region, allocate a new object in the same space, then read through the old pointer - it sees the new object's data.

Use-after-free is a vulnerability where a program keeps a pointer to memory that has been freed and later reallocated for a different purpose. When the program reads through the old (dangling) pointer, it sees the new object's data instead of the original data. An attacker can exploit this by controlling what gets allocated in the freed region, effectively controlling what the victim code reads or writes through its stale pointer.

Simulator

Loading simulator...

Walkthrough Guide

  1. 1

    Allocate and populate the original object

    Do this: Step through MOV R0, #128 / MOV R1, #10 / STORE [R0], R1

    Watch for: Value 10 appears at address 128

    An object is allocated at address 128 with value 10. In a real program, this might be a user struct or a session token.

  2. 2

    Save the pointer and free the object

    Do this: Step through MOV R2, R0 (save pointer) then MOV R1, #0 / STORE [R0], R1 (free)

    Watch for: R2 = 128 (dangling pointer saved). Address 128 changes from 10 to 0 (freed)

    R2 now holds a pointer to freed memory — a dangling pointer. The memory is cleared to simulate freeing. In a real allocator, this address would be returned to the free list.

  3. 3

    Attacker allocates in the same space

    Do this: Step through MOV R1, #15 / STORE [R0], R1

    Watch for: Address 128 changes from 0 to 15 (attacker's data)

    A new allocation reuses address 128. The attacker controls this allocation and writes their chosen value (15). This is realistic — real allocators frequently reuse recently freed addresses.

  4. 4

    Victim reads through the dangling pointer

    Do this: Step through LOAD R3, [R2]

    Watch for: R3 = 15 (attacker's data), not 10 (original data)

    The victim code reads through R2, which still points to address 128. But address 128 now contains the attacker's data (15), not the original data (10). The victim is unknowingly working with attacker-controlled data.

Objectives

  • •See address 128 initially hold value 10 (original object)
  • •Watch address 128 get cleared to 0 (simulated free)
  • •See address 128 receive value 15 (new allocation with attacker data)
  • •Verify R3 = 15 - the old pointer reads the attacker's data, not 10

Hints

  • R2 never changes after being set to 128 - it's the dangling pointer that outlives the original object