Week 7 DEP & Return-Oriented Programming

Updated 4 Oct 2026

CSS484 — Week 7 Cheat Sheet: DEP & Return-Oriented Programming

"The defense that stopped shellcode, and the technique that turned the program's own code against it." One sentence to carry away: DEP stopped attackers running their own code, so they turned the program's own code into a weapon; defense controls permission, exploitation shifts to control flow.


1. The Defense — Data Execution Prevention (DEP)

Why memory exploits used to be easy (recap of Week 6)

Early systems drew no line between data and code, so a buffer full of attacker bytes could simply be run as instructions.

The classic attack (Week 6's whole story):

StepWhat happened
Data and code shared memoryTo the CPU, memory was just memory — no distinction
Shellcode went into a bufferAttackers wrote machine code straight into a stack buffer
The return address was overwrittenThe overflow redirected EIP back into that same buffer
Stack and heap were executableSo the CPU happily ran the attacker's bytes as code
Control of EIP was enoughPoint the instruction pointer at your shellcode, and win
No bypass requiredThis was raw, direct code execution — clean and devastating

This is exactly what you did in Week 6. The whole attack rested on one assumption: that memory holding your input could also be executed. DEP breaks that assumption.

Virtual memory and page permissions — the foundation DEP is built on

Memory is divided into fixed-size pages, and each page carries hardware-enforced permissions: read, write, execute.

  • Divided into pages — each process gets its own virtual address space, split into pages
  • Typically 4 KB each — a fixed, uniform chunk size the hardware can track efficiently
  • Each page has R/W/X bits — readable, writable, executable, in any combination
  • Enforced by the MMU — the CPU's memory management unit checks every single access

A real process's page permissions:

RegionPermission
.text (code)R‑X
.data (globals)RW‑
heapRW‑
stackRW‑

The permissions are not advisory. The hardware checks them on every read, write, and instruction fetch, and raises an exception the instant a rule is broken.

DEP: write XOR execute (W^X) — the core rule

WRITABLE  (stack, heap, data: you can put bytes here)
                    XOR   (never both)
EXECUTABLE  (.text code only: the CPU may run this)
PropertyDetail
Injected shellcode cannot runEven with full control of EIP, the CPU refuses to execute stack bytes
Enforced by OS + CPU togetherThe loader sets the bits; the hardware enforces them at runtime
Default on modern systemsCalled DEP on Windows, NX / W^X on Linux and others

The core rule, in three characters: W ^ X. A page may be writable OR executable, but never both at once. That single rule is what makes injected shellcode a dead end.

Analogy: It's like a building with two kinds of rooms — storage rooms (writable) where you can put anything, and stages (executable) where performances happen — but no room is ever both at once. You can't smuggle a performer into a storage room and have them perform there.

The NX (No-eXecute) bit — the hardware that enforces DEP

A single bit in each page table entry decides whether the CPU is allowed to fetch instructions from that page.

NX valueMeaning
NX = 1Execution forbidden — the CPU refuses to run instructions from this page
NX = 0Execution allowed — normal code pages, like .text, run fine

On every instruction fetch:

  1. CPU wants to fetch from the address in EIP
  2. Check the NX bit for that page, in the page table
  3. NX set? Stop. Raise an exception immediately, run nothing.
  • Lives in the page table entry — one bit per page, checked by the CPU during instruction fetch
  • x86-64 calls it NX; ARM calls it XN — same idea across architectures: execute-never

There is no best effort. The instruction never partially runs. The moment the CPU sees NX set on a fetch, it stops dead — which is why DEP is so hard to bypass head-on.

DEP in a real process layout

PROCESS ADDRESS SPACE
.text  (code)        →  EXECUTABLE
.data / .bss          →  non-exec
heap                   →  non-exec
stack                  →  non-exec
loaded DLLs / libs     →  EXECUTABLE
RuleDetail
Code is executable, not writable.text and libraries hold instructions the CPU runs, but the program cannot modify them
Data is writable, not executable.data, .bss, heap, and stack hold values — can be written but never run
Set by the loader, enforced at runtimePermissions assigned when the program starts, checked on every access thereafter
Libraries follow the same rulesEven dynamically loaded DLLs get the same W^X treatment, consistently

⭐ Notice what stays executable: the program's own code AND all its libraries. Remember that — it is the raw material the attacker will turn against the program later (this is the whole setup for ret2libc/ROP).

What happens on a DEP violation — the classic attack meets the wall

StepWhat happens
Attacker overwrites the return addressPoints EIP into the stack buffer, just like Week 6 — so far, flawless
Control flow is hijackedFrom the attacker's view, everything looks like it's working
CPU fetches from the stack pageIt checks the NX bit for that page, and the bit is set
Hardware exception raisedExecution stops; the OS faults the process and terminates it
→ Access ViolationReported by the OS as an access violation or segmentation fault. Not one instruction of the attacker's shellcode ever runs.

Successful control-flow hijacking has become a dead end — that is what made DEP a genuine game-changer. The exploit did everything right, and still failed. That gap — between hijacking control flow and actually running code — is the whole problem the attacker now has to solve.


2. The Gap DEP Leaves — Changed, Not Stopped

DEP controls where code runs, never whether control flow can be hijacked.

DEP ended a strategy, not the war

What DEP stoppedWhat it left untouched
Classic shellcode injectionBuffer overflows still exist
Executing bytes written to the stackReturn addresses can still be overwritten
Executing bytes written to the heapFunction pointers can still be corrupted
The simple inject-and-jump exploitThe attacker can still control EIP/RIP

The new question that defines modern exploitation: "If I cannot execute new code, what code already in memory can I reuse?" That question leads straight to ret2libc and ROP.

Returning into existing code

DEP prevents execution of newly injected code. It does nothing to prevent misuse of the legitimate code already sitting in executable memory.

Jump to code you WROTEJump to code that EXISTS
Shellcode injected into a buffer sits in non-executable memoryCode in libc or kernel32 is already in executable memory, and trusted
❌ BLOCKED BY DEP✅ PERFECTLY LEGAL
  • DEP checks where, not why — it only asks: is this page executable? Not: should execution be here?
  • Every loaded library is a vast reservoir of legitimate, executable code — thousands of instructions exist
  • "Run my code" becomes "abuse yours" — the attacker reuses trusted code to do untrusted things

The kicker: the attacker can no longer jump to new code they wrote, but they can still jump to existing code the program already trusts. DEP has no opinion about that.

Control-flow hijacking still matters

The CPU still blindly follows the instruction pointer. DEP never validates intent, so redirecting execution remains as powerful as ever.

FactMeaning
Overwrite still redirects executionA corrupted return address still sends the CPU wherever the attacker chooses
The CPU follows EIP blindlyIt does not ask whether a jump makes sense; it simply fetches and runs
DEP validates permission, not intentAs long as the target is an executable page, execution proceeds unquestioned
Stack corruption still steers flowThe same overflow that overwrote a return address still controls the program
The goal shifts to destinationsNot "inject code" but "choose useful existing code to run"
Control without injection is potentRedirecting to the right existing code is enough to win

DEP stopped one kind of payload; it did not touch the power to redirect. Attackers just have to be smarter about where they send execution. Which raises the question: where?


3. First Adaptation — Return-to-libc (ret2libc)

Do not inject code — borrow a whole function that is already there.

The technique: borrow int system(const char *command)

Overwrite the return address with the address of a real library function, and arrange the stack so it receives the arguments you choose. No injected code at all.

The crafted stack (bottom → top, RET pops here first):

AAAA (padding)          ← fills buffer
AAAA (padding)
addr of system()        ← RET pops here, overwrites RET     ← "first ↑"
fake return addr        ← return target (where system() returns to — often irrelevant/junk)
addr of "/bin/sh"        ← system() arg

What happens:

  1. RET jumps to system() — the overwritten return address is the real libc system() address
  2. system() reads its argument — it looks on the stack for its parameter and finds the pointer to "/bin/sh"
  3. A shell is spawned — system("/bin/sh") executes. The attacker has a shell, DEP untouched.

From the OS's view, nothing illegal happened: a legitimate function was called from an executable page. DEP is satisfied, and the attacker still wins.

Why return-to-libc was never enough

LimitationWhy it hurts
Limited to whole functionsYou call a complete function as-is — you cannot run just part of one
The function must already existIf no suitable function is present, you are simply stuck
Calling conventions constrain youArguments must be laid out exactly right, and that is not always possible
Chaining calls is clumsyStringing several function calls together on the stack is fragile
Complex logic gets messyMultiple steps — allocate, then change permissions, then jump — are awkward

**Attackers wanted a scalpel — not whole functions, but the freedom to stitch together tiny operations.**The limitation is granularity: ret2libc gives you whole functions when what you really want is individual operations you can freely combine. That desire leads straight to ROP.


4. The Breakthrough — Return-Oriented Programming (ROP)

Chain tiny fragments of existing code into any computation you want.

The insight ROP is built on

The CPU has no concept of a "function." It executes instructions from an address, and it will happily start in the middle of one.

PrincipleMeaning
Code is a sequence of instructionsNothing more — the CPU reads one, runs it, moves to the next
Functions are not special"Function" is a human idea. The CPU only knows addresses
Execution can start anywherePoint EIP mid-function and the CPU runs from exactly there
Libraries hold millions of instructionsA vast landscape of executable bytes to choose from
Many sequences end in retAnd any such sequence can be reused on its own

"Enter anywhere" — example inside a libc excerpt:

mov  edx, ecx
add  esp, 8
pop  eax    ← start HERE  (jumping mid-function, ignoring everything before)
ret
push ebp
...

This is the breakthrough: if execution can start at any instruction, then every short run of instructions ending in ret is a reusable building block. Those blocks are called gadgets.

What a ROP gadget is

A gadget is a short sequence of existing instructions that ends in ret. It does one small thing, then hands control back to the stack for the next gadget.

Real gadgets (found in libraries):

0x080481c9: pop eax ; ret         → load next stack value into EAX
0x080de7ad: pop ebx ; ret         → load next stack value into EBX
0x0806f350: mov [ebx], eax ; ret  → write EAX to the address in EBX

With just these three, an attacker can write any value to any writable address — a **"write-what-where"**primitive.

Gadget propertyDetail
Short — often 1 to 5 instructionsJust enough to do one small, useful operation
Ends in retThe ret is what lets gadgets be chained together
Found in existing codeNot injected: located inside libraries and the binary itself
Fully DEP-compatibleIt is legitimate, already-executable code — DEP is satisfied

A gadget does something small, then returns. pop eax loads a value; ret hands control back to the stack. Each gadget is one tiny step in a larger, attacker-authored program.

The stack becomes the program

Because every gadget ends in ret, and ret takes its next address from the stack, a stack full of gadget addresses drives execution from one gadget to the next.

The stack (attacker-controlled) and how execution flows:

→ addr: pop eax ; ret       1. ret pops the first address → jumps to pop eax gadget
0xDEADBEEF                  2. pop eax runs → pops 0xDEADBEEF into EAX, then its ret fires
→ addr: pop ebx ; ret       3. ret pops the next address → jumps to pop ebx gadget, loads addr into EBX
0x08049f00
→ addr: mov [ebx],eax;ret   4. the chain continues — each gadget's ret pulls the next address
→ addr: system() ...

Addresses on the stack = gadgets (instructions); values = data they consume. **The stack is a to-do list.**Each address on the stack is one instruction of a fake program; ret is the engine that steps through it. The attacker programs the target using nothing but a carefully arranged stack.

From one return to many

CLASSIC: one returnROP: a chain of returns
Overwrite the return address once, jump to one place, and hope it does everythingThe first return kicks off gadget one → its ret triggers gadget two → that ret triggers gadget three → ...and so on, for as long as needed

The mechanics of the chain:

  1. First overwritten RET redirects — execution begins at the attacker's first gadget
  2. Code runs until the next ret — the gadget does its small job, then hits its own ret
  3. That ret reads the next value — it pops the next gadget address off the attacker's stack
  4. Execution becomes a chain — a scripted sequence of returns: the core of ROP chaining

Each ret advances the stack pointer to the next target. One return was a jump. Many returns, in sequence, are a program. That is the whole trick, repeated.

Why ROP is so powerful

PropertyDetail
Arbitrary computationWith enough gadgets, ROP is Turing-complete — it can compute anything
Bypasses DEP without disabling itEvery instruction executed is legitimate, already-executable code
No writable + executable memory neededIt never violates W^X, so there is nothing for DEP to catch
Works on real binaries and OSesLarge programs and libraries supply more than enough gadgets
Can call system APIsSet up registers and arguments, then invoke real OS functions
Foundation of modern exploitsIt can ultimately make injected code executable again

The irony is exquisite: DEP forced attackers to reuse the program's own trusted code, and in doing so turned every executable byte into a weapon. Defenses since then protect control flow, not just permissions.


5. ROP in Practice — What ROP Is Really For

ROP is not the final payload. Attackers do not want to compute forever in gadgets. What they want is what they always wanted: to run real shellcode. ROP just gets them there.

The misconception vs. the reality

❌ THE MISCONCEPTION✅ THE REALITY
"The attacker writes the whole exploit as an endless chain of tiny gadgets"The goal is still arbitrary code execution, the same as always. ROP is only the setup phase that makes running real shellcode possible again

What a ROP chain actually does (three-part structure):

  1. A short chain that prepares the environment for real code
  2. Defeat DEP's restriction — make some memory executable, so a payload can finally run
  3. Jump into the real shellcode — hand over to a proper payload, e.g. a reverse TCP shell

ROP is the bridge, not the destination. Its job is to undo DEP's one restriction, so that classic arbitrary code execution becomes possible once more.

What a ROP chain actually does — the 5-step recipe

StepAction
1Prepare registers & arguments — use pop gadgets to load the exact arguments the API call needs
2Call a memory-management API — VirtualAlloc/VirtualProtect on Windows, or mprotect on Linux
3Get executable memory — allocate a fresh region, or flip an existing page to RWX
4Write shellcode into it — copy the payload into the now-executable region
5Jump to the shellcode — redirect execution into it. DEP no longer applies; it is executable

The APIs attackers borrow (all normal, exported functions — the OS cannot tell a malicious caller from a legitimate one):

  • VirtualAlloc (Windows) — allocate new memory, request it executable
  • VirtualProtect (Windows) — change an existing page's permissions to executable
  • mprotect (Linux) — change a page's protection to include execute

The chain turns DEP off for one page, legitimately. Once a page is executable, ROP has done its job, and the attacker regains full, classic code execution.

Concrete example — reverse TCP shell (the full attack, tied together)

1. ROP sets up RWX memory          → chain calls VirtualProtect/mprotect to make a page executable
2. Shellcode placed in it           → the reverse-shell payload is written into that executable region
3. EIP redirected to shellcode      → now legal: the page is executable, so DEP raises no objection
4. Outbound TCP connection          → the shellcode connects back to the attacker's host and port
5. Interactive shell obtained       → stdin/stdout are wired to the socket — the attacker has a shell

The first three steps are the ROP; the last two are the payload. Once the shellcode runs in executable memory, it is a textbook reverse shell. ROP's only job was to get it there past DEP.

Why this works despite DEP — none of it breaks the rules

DEP enforces execution permissionDEP does not enforce control flowROP uses only executable pages
It controls which pages may run code — that is all it doesIt never checks whether a jump or return is legitimateEvery gadget lives in code that is already allowed to run
The APIs are meant to be calledThe OS cannot see intentSo DEP alone is not enough
VirtualProtect and mprotect are legitimate, callable functionsA malicious call is byte-for-byte identical to a legitimate oneStopping ROP needs control-flow defenses

DEP enforces where code runs, never why it runs. ROP stays entirely within DEP's rules while achieving arbitrary code execution — exactly why modern defenses had to go further (e.g. CFG/CFI, stack canaries, ASLR combined together).

Worked real-world example — a VirtualProtect() ROP chain (mona.py output)

VirtualProtect(lpAddress, dwSize, flNewProtect, lpflOldProtect) · 0x40 = PAGE_EXECUTE_READWRITE → make the stack executable.

# mona.py, -cpb "\x00\x09\x0a\x0d\x1a"   (avoid these "bad" bytes in every gadget address)
def create_rop_chain():
    rop = [
        0x10015af0, # POP EAX # RETN
        0xfffffdff, #   -0x201 (0x201 has 00 bytes)
        0x1005f9aa, # NEG EAX # RETN     EAX = 0x201
        0x10015b12, # XCHG EAX,EBX       EBX = dwSize
        0x10015af0, # POP EAX # RETN
        0xffffffc0, #   -0x40   (0x40 has 00 bytes)
        0x1005f9aa, # NEG EAX # RETN     EAX = 0x40
        0x10015f77, # XCHG EAX,EDX       EDX = 0x40 (RWX)
        0x1002c3d1, # POP ECX # RETN
        0x101082ac, #   ECX = &writable (lpflOldProtect)
        0x10015b90, # POP EBP # RETN
        0x100222c5, #   EBP = JMP ESP (VirtualProtect return addr)
        0x10038f21, # POP ESI # RETN
        0x100337c8, #   ESI = JMP [EAX] (fires the call)
        0x10024b0e, # POP EDI # RETN
        0x1001b2e6, #   EDI = RETN (ROP NOP)
        0x10015af0, # POP EAX # RETN
        0x1006a130, #   EAX = &VirtualProtect
        0x1001d7a5, # PUSHAD # RETN      build frame + fire
    ]
    return b''.join(pack('<I', v) for v in rop)

How to read this chain (worked interpretation):

  • Notice the trick with NEG EAX: you can't have a 00 byte in an address (it would terminate a C-string copy), so instead of pushing 0x201 or 0x40 directly, the chain pushes the negative of the value (which has no null bytes) and then negates it back with a NEG EAX gadget — a classic "bad character" workaround
  • PUSHAD at the end pushes all 8 general-purpose registers at once onto the stack in one instruction — this is a common trick to build the entire VirtualProtect call frame (its 4 arguments) in one shot, using the register values the earlier gadgets carefully set up
  • EBP = JMP ESP is set as the fake return address for VirtualProtect itself — so when VirtualProtect finishes and returns, it jumps straight to whatever is currently at ESP (which the attacker has arranged to be the shellcode)

No injected byte executes to make this happen. A ROP chain calls a legitimate API — VirtualProtect — to turn the stack RWX, then jmp esp runs the shellcode. W^X is reconfigured through code that was allowed to run, never broken — which is why DEP alone can't stop it.

Tooling — mona: automating the tedium

Building a ROP chain by hand means sifting thousands of instructions for usable gadgets. mona automates that analysis, which is why we can teach and use ROP at all.

Without mona, by handWith mona
Inspect thousands of instructions in memoryA helper for exploit development that analyses a program's memory and executable code
Find sequences that end in ret and do something usefulFinds usable gadgets automatically
Check addresses for bad characters (nulls, newlines)Filters out bad-character addresses
Check which addresses are stable despite ASLRHelps assemble a working chain
Confirm each gadget lives in executable memory
Track stack layout and offsets entirely by hand

Doing all this by hand is slow, error-prone, and unrealistic. mona exists to automate the analysis so you can focus on the ideas.


6. Wrap-Up — The Duel, in Summary

A defense that changed the rules, and an attack that changed them back.

The whole lecture in seven ideas:

IdeaStatement
DEP / W^XData pages are non-executable, so injected shellcode cannot run
Enforced in hardwareThe NX bit is checked on every instruction fetch; no best effort
Control flow still hijackableDEP guards permission, not intent — EIP can still be seized
Reuse existing coderet2libc borrows whole functions; ROP borrows tiny gadgets
The stack becomes a programChained gadget addresses, driven by ret, compute anything
ROP re-enables executionIt calls mprotect/VirtualProtect, then runs real shellcode

One sentence to carry away: DEP stopped attackers running their own code, so they turned the program's own code into a weapon; defense controls permission, exploitation shifts to control flow.


7. 🖥️ Practical Section — Building a ROP Attack (No Separate Workshop PDF This Week)

No dedicated Week 7 workshop file was provided alongside this lecture — but the lecture itself walks through a full, real ROP chain (the mona.py VirtualProtect example above). This section turns that into a step-by-step reference in case the lab follows the same pattern as previous weeks (building on the Week 6 vulnerable binary).

The conceptual workflow attackers (and you, in a lab) follow

  1. Confirm DEP/NX is ON (unlike Week 6, where it was deliberately disabled)

    checksec --file=./vuln
    # want to see: NX: NX enabled
  2. Confirm the classic Week 6 shellcode-injection approach now fails — injecting shellcode into the buffer and pointing EIP at it will crash with an access violation / segfault, because the stack page has NX=1

  3. Find gadgets in the binary and its loaded libraries using a gadget-finding tool (the lecture names mona for Windows/Immunity Debugger workflows; on Linux, equivalents include ROPgadget and objdump):

    # ROPgadget (Linux equivalent workflow)
    ROPgadget --binary ./vuln > gadgets.txt
    grep "pop eax ; ret" gadgets.txt
    grep "pop ebx ; ret" gadgets.txt
  4. Identify a memory-permission API to call — on Linux, this is typically mprotect; on Windows, VirtualProtect/VirtualAlloc

  5. Build the gadget chain — use pop gadgets to load each argument the API needs into the right register, then chain a call to the API, then redirect to your shellcode:

    from pwn import *
    # illustrative structure, not a literal working exploit:
    payload  = b"A" * offset                  # fill to the return address (from Week 6's method)
    payload += p32(pop_eax_ret)                # gadget: pop eax ; ret
    payload += p32(target_value)               # value to load
    payload += p32(mprotect_addr)               # call mprotect (or the next gadget in the chain)
    payload += p32(fake_return)                 # where mprotect "returns" to
    payload += p32(page_addr) + p32(size) + p32(prot_flags)  # mprotect's arguments
    payload += shellcode                        # your real payload, now landing on an executable page
  6. Verify in a debugger (edb/gdb) exactly as in Week 6 — single-step through each gadget, confirm each register is set as intended, and confirm the final jump lands inside now-executable memory rather than faulting

Why this connects directly to Week 6: the offset-finding technique (cyclic patterns + cyclic_find) from Week 6 is still exactly how you find where your gadget chain begins on the stack — DEP changes what you put after the offset, not how you find the offset itself.

Key troubleshooting reasoning (the kind of "why did this fail" question the instructor tests)

  • Chain crashes immediately on the first gadget? The gadget address itself may contain a bad character (e.g. a 0x00 byte) that a null-terminated input function truncates — this is exactly why the mona example uses NEG EAXtricks to avoid embedding 0x00 bytes in pushed values
  • VirtualProtect/mprotect call appears to run but shellcode still doesn't execute? Double-check the permission flags argument (e.g. 0x40 = PAGE_EXECUTE_READWRITE on Windows) — if the flag is wrong, the page stays non-executable and DEP still blocks the jump
  • Gadget addresses work in one run but not the next? This is ASLR reintroducing itself — gadget/library addresses shift between runs unless ASLR is disabled for the session, exactly as in Week 6's randomize_va_spacesetting

8. Rapid-Fire Recall Table (Last-Minute Review)

ConceptOne-liner
DEP / NX / W^XA page may be writable OR executable, never both — enforced by a hardware NX bit checked on every instruction fetch
Why DEP stops Week 6's attackShellcode injected into the stack now sits on a non-executable page — jumping to it raises an access violation instead of running
What DEP does NOT stopBuffer overflows, overwriting return addresses, or hijacking EIP/RIP — DEP checks where code runs, never why
ret2libcOverwrite the return address with a real library function's address (e.g. system()), craft the stack so it receives your chosen arguments — no injected code
ret2libc's limitationWhole functions only, rigid calling conventions, clumsy to chain — leads to ROP for finer control
ROP core insightThe CPU has no concept of "function" — execution can start at any instruction, so any sequence ending in ret is reusable
GadgetA short (1–5 instruction) sequence ending in ret, found in existing executable code — fully DEP-compatible
How gadgets chainEach gadget's ret pops the next address off the attacker's stack — "the stack becomes the program"
Why ROP bypasses DEPEvery instruction executed is legitimate, already-executable code — never violates W^X, so DEP has nothing to catch
ROP is Turing-completeWith enough gadgets, ROP can compute anything
ROP's actual goalNOT to compute forever in gadgets — it's the setup to re-enable real shellcode execution (make a page executable, then jump to shellcode)
APIs ROP typically callsVirtualAlloc/VirtualProtect (Windows), mprotect (Linux) — legitimate, exported, indistinguishable from legitimate calls
Why DEP alone can't stop ROPDEP enforces permission, not control flow or intent — a malicious API call is byte-for-byte identical to a legitimate one
What stops ROP (implied)Control-flow defenses beyond DEP — e.g. stack canaries, ASLR, CFG/CFI (combined, layered defense)
monaAutomates gadget-finding, bad-character filtering, and chain assembly — makes ROP practical to build without manual instruction-by-instruction search
Bad character trickValues like 0x00 truncate string copies — chains use tricks like pushing a negative value then NEG EAX to avoid embedding null bytes