Skip to main content
Be Bitwise

DEP / NX Concept

Write the bytes of two instructions into a data area and jump there. Our simulator has no NX bit, so the injected code runs; a real CPU with DEP would fault and terminate the process.

Data Execution Prevention (DEP), also called NX (No-Execute), marks memory pages as either writable or executable, but not both. Code lives in read-execute pages; stack and heap data live in read-write pages. If an attacker injects shellcode onto the stack and tries to jump there, the CPU checks the page permissions and triggers a fault — the injected code never runs. This mitigation is enforced by hardware (the NX bit in page table entries) and is why ROP was invented: it reuses existing executable code instead of injecting new code.

Simulator

Loading simulator...

Walkthrough Guide

  1. 1

    Write instruction bytes to a data area

    Do this: Step through the MOV / STORE pairs that write to addresses 200-202

    Watch for: Bytes 0x23, 0x2A and 0x08 appear at addresses 200, 201 and 202. Address 203 stays 0

    Every instruction on this CPU is two bytes. MOV R3, #42 encodes as 0x232A and HALT as 0x0800, so these four bytes are a tiny program. To the STORE instructions they are just data written to a data area.

  2. 2

    Jump into the data area

    Do this: Step through JUMP #200

    Watch for: PC = 200. The CPU now fetches its next instruction from the bytes we just wrote

    On a real CPU with DEP, this is where the process dies: the page holding address 200 is marked non-executable, so the fetch faults and the OS terminates the program. Our simulator has no page table, so nothing stops it.

  3. 3

    The injected code runs

    Do this: Step twice more

    Watch for: R3 = 42, then the CPU halts with PC = 204

    The CPU decodes 0x232A as MOV R3, #42 and 0x0800 as HALT. R3 = 42 proves that bytes written as data ran as code. That is exactly what DEP exists to prevent, and why attackers turned to ROP.

Objectives

  • •See the instruction bytes written to addresses 200-202 (a data region)
  • •Watch PC jump to 200 and the CPU execute bytes that were written as data
  • •Verify R3 = 42, set by the injected MOV R3, #42
  • •Consider how ROP (Module 17) bypasses DEP by reusing existing executable code

Hints

  • DEP is enforced by hardware - the CPU checks page permissions before executing. Our simplified simulator has no page table, so it cannot enforce this.