Week 7 DEP & Return-Oriented Programming
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):
| Step | What happened |
|---|---|
| Data and code shared memory | To the CPU, memory was just memory — no distinction |
| Shellcode went into a buffer | Attackers wrote machine code straight into a stack buffer |
| The return address was overwritten | The overflow redirected EIP back into that same buffer |
| Stack and heap were executable | So the CPU happily ran the attacker's bytes as code |
| Control of EIP was enough | Point the instruction pointer at your shellcode, and win |
| No bypass required | This 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:
| Region | Permission |
|---|---|
.text (code) | R‑X |
.data (globals) | RW‑ |
| heap | RW‑ |
| stack | RW‑ |
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)
| Property | Detail |
|---|---|
| Injected shellcode cannot run | Even with full control of EIP, the CPU refuses to execute stack bytes |
| Enforced by OS + CPU together | The loader sets the bits; the hardware enforces them at runtime |
| Default on modern systems | Called 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 value | Meaning |
|---|---|
| NX = 1 | Execution forbidden — the CPU refuses to run instructions from this page |
| NX = 0 | Execution allowed — normal code pages, like .text, run fine |
On every instruction fetch:
- CPU wants to fetch from the address in EIP
- Check the NX bit for that page, in the page table
- 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
| Rule | Detail |
|---|---|
| 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 runtime | Permissions assigned when the program starts, checked on every access thereafter |
| Libraries follow the same rules | Even 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
| Step | What happens |
|---|---|
| Attacker overwrites the return address | Points EIP into the stack buffer, just like Week 6 — so far, flawless |
| Control flow is hijacked | From the attacker's view, everything looks like it's working |
| CPU fetches from the stack page | It checks the NX bit for that page, and the bit is set |
| Hardware exception raised | Execution stops; the OS faults the process and terminates it |
| → Access Violation | Reported 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 stopped | What it left untouched |
|---|---|
| Classic shellcode injection | Buffer overflows still exist |
| Executing bytes written to the stack | Return addresses can still be overwritten |
| Executing bytes written to the heap | Function pointers can still be corrupted |
| The simple inject-and-jump exploit | The 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 WROTE | Jump to code that EXISTS |
|---|---|
| Shellcode injected into a buffer sits in non-executable memory | Code 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.
| Fact | Meaning |
|---|---|
| Overwrite still redirects execution | A corrupted return address still sends the CPU wherever the attacker chooses |
| The CPU follows EIP blindly | It does not ask whether a jump makes sense; it simply fetches and runs |
| DEP validates permission, not intent | As long as the target is an executable page, execution proceeds unquestioned |
| Stack corruption still steers flow | The same overflow that overwrote a return address still controls the program |
| The goal shifts to destinations | Not "inject code" but "choose useful existing code to run" |
| Control without injection is potent | Redirecting 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:
- RET jumps to
system()— the overwritten return address is the real libcsystem()address system()reads its argument — it looks on the stack for its parameter and finds the pointer to"/bin/sh"- 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
| Limitation | Why it hurts |
|---|---|
| Limited to whole functions | You call a complete function as-is — you cannot run just part of one |
| The function must already exist | If no suitable function is present, you are simply stuck |
| Calling conventions constrain you | Arguments must be laid out exactly right, and that is not always possible |
| Chaining calls is clumsy | Stringing several function calls together on the stack is fragile |
| Complex logic gets messy | Multiple 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.
| Principle | Meaning |
|---|---|
| Code is a sequence of instructions | Nothing 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 anywhere | Point EIP mid-function and the CPU runs from exactly there |
| Libraries hold millions of instructions | A vast landscape of executable bytes to choose from |
Many sequences end in ret | And 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
retis 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 property | Detail |
|---|---|
| Short — often 1 to 5 instructions | Just enough to do one small, useful operation |
Ends in ret | The ret is what lets gadgets be chained together |
| Found in existing code | Not injected: located inside libraries and the binary itself |
| Fully DEP-compatible | It is legitimate, already-executable code — DEP is satisfied |
A gadget does something small, then returns.
pop eaxloads a value;rethands 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, andrettakes 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;
retis 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 return | ROP: a chain of returns |
|---|---|
| Overwrite the return address once, jump to one place, and hope it does everything | The 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:
- First overwritten RET redirects — execution begins at the attacker's first gadget
- Code runs until the next
ret— the gadget does its small job, then hits its ownret - That
retreads the next value — it pops the next gadget address off the attacker's stack - Execution becomes a chain — a scripted sequence of returns: the core of ROP chaining
Each
retadvances 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
| Property | Detail |
|---|---|
| Arbitrary computation | With enough gadgets, ROP is Turing-complete — it can compute anything |
| Bypasses DEP without disabling it | Every instruction executed is legitimate, already-executable code |
| No writable + executable memory needed | It never violates W^X, so there is nothing for DEP to catch |
| Works on real binaries and OSes | Large programs and libraries supply more than enough gadgets |
| Can call system APIs | Set up registers and arguments, then invoke real OS functions |
| Foundation of modern exploits | It 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):
- A short chain that prepares the environment for real code
- Defeat DEP's restriction — make some memory executable, so a payload can finally run
- 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
| Step | Action |
|---|---|
| 1 | Prepare registers & arguments — use pop gadgets to load the exact arguments the API call needs |
| 2 | Call a memory-management API — VirtualAlloc/VirtualProtect on Windows, or mprotect on Linux |
| 3 | Get executable memory — allocate a fresh region, or flip an existing page to RWX |
| 4 | Write shellcode into it — copy the payload into the now-executable region |
| 5 | Jump 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 executableVirtualProtect(Windows) — change an existing page's permissions to executablemprotect(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 permission | DEP does not enforce control flow | ROP uses only executable pages |
|---|---|---|
| It controls which pages may run code — that is all it does | It never checks whether a jump or return is legitimate | Every gadget lives in code that is already allowed to run |
| The APIs are meant to be called | The OS cannot see intent | So DEP alone is not enough |
|---|---|---|
VirtualProtect and mprotect are legitimate, callable functions | A malicious call is byte-for-byte identical to a legitimate one | Stopping 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 a00byte in an address (it would terminate a C-string copy), so instead of pushing0x201or0x40directly, the chain pushes the negative of the value (which has no null bytes) and then negates it back with aNEG EAXgadget — a classic "bad character" workaround PUSHADat the end pushes all 8 general-purpose registers at once onto the stack in one instruction — this is a common trick to build the entireVirtualProtectcall frame (its 4 arguments) in one shot, using the register values the earlier gadgets carefully set upEBP = JMP ESPis set as the fake return address forVirtualProtectitself — so whenVirtualProtectfinishes 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, thenjmp espruns 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.
monaautomates that analysis, which is why we can teach and use ROP at all.
| Without mona, by hand | With mona |
|---|---|
| Inspect thousands of instructions in memory | A helper for exploit development that analyses a program's memory and executable code |
Find sequences that end in ret and do something useful | Finds usable gadgets automatically |
| Check addresses for bad characters (nulls, newlines) | Filters out bad-character addresses |
| Check which addresses are stable despite ASLR | Helps 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.
monaexists 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:
| Idea | Statement |
|---|---|
| DEP / W^X | Data pages are non-executable, so injected shellcode cannot run |
| Enforced in hardware | The NX bit is checked on every instruction fetch; no best effort |
| Control flow still hijackable | DEP guards permission, not intent — EIP can still be seized |
| Reuse existing code | ret2libc borrows whole functions; ROP borrows tiny gadgets |
| The stack becomes a program | Chained gadget addresses, driven by ret, compute anything |
| ROP re-enables execution | It 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.pyVirtualProtectexample 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
-
Confirm DEP/NX is ON (unlike Week 6, where it was deliberately disabled)
checksec --file=./vuln # want to see: NX: NX enabled -
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
-
Find gadgets in the binary and its loaded libraries using a gadget-finding tool (the lecture names
monafor Windows/Immunity Debugger workflows; on Linux, equivalents includeROPgadgetandobjdump):# ROPgadget (Linux equivalent workflow) ROPgadget --binary ./vuln > gadgets.txt grep "pop eax ; ret" gadgets.txt grep "pop ebx ; ret" gadgets.txt -
Identify a memory-permission API to call — on Linux, this is typically
mprotect; on Windows,VirtualProtect/VirtualAlloc -
Build the gadget chain — use
popgadgets 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 -
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
0x00byte) that a null-terminated input function truncates — this is exactly why the mona example usesNEG EAXtricks to avoid embedding0x00bytes in pushed values VirtualProtect/mprotectcall appears to run but shellcode still doesn't execute? Double-check the permission flags argument (e.g.0x40=PAGE_EXECUTE_READWRITEon 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)
| Concept | One-liner |
|---|---|
| DEP / NX / W^X | A 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 attack | Shellcode 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 stop | Buffer overflows, overwriting return addresses, or hijacking EIP/RIP — DEP checks where code runs, never why |
| ret2libc | Overwrite 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 limitation | Whole functions only, rigid calling conventions, clumsy to chain — leads to ROP for finer control |
| ROP core insight | The CPU has no concept of "function" — execution can start at any instruction, so any sequence ending in ret is reusable |
| Gadget | A short (1–5 instruction) sequence ending in ret, found in existing executable code — fully DEP-compatible |
| How gadgets chain | Each gadget's ret pops the next address off the attacker's stack — "the stack becomes the program" |
| Why ROP bypasses DEP | Every instruction executed is legitimate, already-executable code — never violates W^X, so DEP has nothing to catch |
| ROP is Turing-complete | With enough gadgets, ROP can compute anything |
| ROP's actual goal | NOT 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 calls | VirtualAlloc/VirtualProtect (Windows), mprotect (Linux) — legitimate, exported, indistinguishable from legitimate calls |
| Why DEP alone can't stop ROP | DEP 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) |
| mona | Automates gadget-finding, bad-character filtering, and chain assembly — makes ROP practical to build without manual instruction-by-instruction search |
| Bad character trick | Values like 0x00 truncate string copies — chains use tricks like pushing a negative value then NEG EAX to avoid embedding null bytes |