Domain 3Exploit Dev & AV EvasionCORE

Module Selection Criteria

Complete guide to selecting the right module for exploitation. Covers ASLR, DEP, SafeSEH, Rebase, and signature analysis. Provides systematic module evaluation and selection process.

Domain: Domain 3: Exploit Mechanics & AV Evasion•Updated: 2026-09-01
#modules#aslr#dep#safeseh#exploit-development#oscp

Module Selection Criteria

Domain 10: Fixing Exploits — Topic 9

Mastering module selection is the single most important skill that separates a script-kiddie from a competent exploit developer. A poorly chosen module turns a working exploit into a blue-screen-of-death (BSOD) generator. A well-chosen module makes exploitation trivial.


Table of Contents

  1. Why Module Selection Matters
  2. The Module Checklist — !mona modules
  3. Module Evaluation Table — Safe vs Unsafe Properties
  4. ASLR Deep Dive
  5. DEP Deep Dive
  6. SafeSEH Deep Dive
  7. Rebase and Signature
  8. Module Selection Process — Decision Tree
  9. Ideal Module Characteristics
  10. When All Modules Are Protected — Fallback Strategies
  11. Real-World Examples
  12. Quick Reference Card
  13. Common Pitfalls and Debugging Tips

Why Module Selection Matters

When you develop an exploit, you need a predictable, controllable memory location to point your instruction pointer (EIP) to. The most common technique is to redirect EIP to a JMP ESP (or similar) instruction inside a loaded DLL/module, which then pivots execution to your shellcode sitting on the stack or in a buffer.

If you pick the wrong module, everything breaks:

Bad Choice Consequence
Module has ASLR Its base address changes every run — your JMP ESP address is stale
Module has DEP Your shellcode on the stack cannot execute — access violation
Module has SafeSEH SEH overwrite attacks fail — the exception handler is rejected
Module is Rebased May load at inconsistent addresses across reboots
Module has a digital signature Windows may enforce additional protections

The goal: Find a module that is ASLR=No, DEP=No, SafeSEH=No — a “safe” module where you can reliably place your pivot instruction and shellcode.


The Module Checklist — !mona modules

Running the Command

In x64dbg / Immunity Debugger with mona.py loaded:

!mona modules

This generates two outputs:

  1. A table printed to the debugger console
  2. A file saved at \mona\modlist.com (or .txt depending on version)

What the Output Looks Like

[+] Modules
    Name                 Address   Delay   ASLR    DEP     SafeSEH  Rebase  Signature
    -----------------------------------------------------------------------------
    vulnapp.exe          0x00400000 No      N/A     N/A      N/A     N/A     N/A
    msvcrt.dll           0x77C00000 No      No      No       No      No      N/A
    kernel32.dll         0x76BC0000 No      Yes     Yes      Yes     Yes     Valid
    ntdll.dll            0x77D00000 No      Yes     Yes      Yes     Yes     Valid
    user32.dll           0x76FD0000 No      Yes     Yes      Yes     Yes     Valid
    wininet.dll          0x6D5A0000 No      No      No       No      No      N/A
    urlmon.dll           0x77070000 No      Yes     Yes      Yes     Yes     Valid
    shlwapi.dll          0x77220000 No      Yes     Yes      Yes     Yes     Valid
    ws2_32.dll           0x76F30000 No      Yes     Yes      Yes     Yes     Valid
    rpcrt4.dll           0x76EA0000 No      Yes     Yes      Yes     Yes     Valid

Column-by-Column Breakdown

Name

The module filename. This is what you’ll reference when searching for instructions with !mona find -s "\xff\xe4" -m wininet.dll.

Address

The current load address of the module in memory. This is what you see at THIS moment in the debugger. If ASLR is enabled, this changes on every run. If ASLR is disabled, this stays the same across runs (on the same system).

Critical insight: Even if ASLR says “No”, the address can still differ between different machines or Windows versions. Always verify on the target machine.

Delay

Whether the module uses delay loading. Delay-loaded modules are not loaded at process startup but are loaded on-demand when a function from them is first called.

  • No = Loaded at process start (predictable, good)
  • Yes = Loaded on-demand (may not be loaded when your exploit runs — risky)

For exploit development, prefer modules with Delay = No because you can be certain they’re in memory.

ASLR (Address Space Layout Randomization)

  • No = The module loads at a fixed base address every time. GOLD STAR.
  • Yes = The module’s base address is randomized each load. Your hardcoded address will be wrong.

DEP (Data Execution Prevention)

  • No = Memory pages in this module can be marked as executable. Shellcode can run.
  • Yes = Memory pages are marked non-executable. Attempting to execute code from this module’s pages causes an access violation.
  • N/A = The module is the main executable, and DEP status depends on process-level settings.

SafeSEH (Safe Structured Exception Handling)

  • No = The module does NOT maintain a list of valid exception handlers. SEH overwrite attacks can work.
  • Yes = The module maintains a whitelist of valid exception handlers. SEH overwrite to an arbitrary address will be rejected.
  • N/A = Not applicable (typically the main executable or modules compiled without SafeSEH support).

Rebase

  • No = The module is compiled to load at a specific preferred base address. If that address is free, it loads there. Predictable.
  • Yes = The module can be rebased (relocated) if its preferred address is taken. This adds uncertainty to its load address.

Signature

  • Valid = The module has a valid digital signature (typically a Microsoft-signed system DLL).
  • N/A = No signature or not applicable.

Signed modules often have additional protections and are maintained by Microsoft, making them less likely to be the “easy target.”


Module Evaluation Table — Safe vs Unsafe Properties

The Safety Matrix

┌─────────────┬──────────────────────────┬──────────────────────────┐
│  Property    │  SAFE for Exploitation    │  UNSAFE for Exploitation │
├─────────────┼──────────────────────────┼──────────────────────────┤
│  ASLR        │  No                      │  Yes                     │
│  DEP         │  No                      │  Yes                     │
│  SafeSEH     │  No                      │  Yes                     │
│  Rebase      │  No                      │  Yes                     │
│  Delay       │  No                      │  Yes                     │
│  Signature   │  N/A                     │  Valid                   │
└─────────────┴──────────────────────────┴──────────────────────────┘

Priority Ranking (Most to Least Important)

1. ASLR = No        ← MUST HAVE (non-negotiable for reliable exploits)
2. DEP = No         ← MUST HAVE (or you need ROP to bypass)
3. SafeSEH = No     ← MUST HAVE (if using SEH overwrite technique)
4. Rebase = No      ← PREFERRED (adds reliability)
5. Delay = No       ← PREFERRED (guarantees module is loaded)
6. Signature = N/A  ← PREFERRED (less scrutiny)

Quick Scoring System

Assign points to each module. The lowest score is the best target:

Property        Score if "No" / "N/A"    Score if "Yes" / "Valid"
──────────────────────────────────────────────────────────────────
ASLR                    0                            10
DEP                     0                            8
SafeSEH                 0                            7
Rebase                  0                            3
Delay                   0                            2
Signature (Valid)       1                            1

Total: Lower is better. Target = 0-2 points.

ASLR Deep Dive

What Is ASLR?

Address Space Layout Randomization (ASLR) is a memory-protection technology that randomly arranges the address space positions of key data areas of a process, including the base of the executable and the positions of the stack, heap, and libraries.

How ASLR Works Internally

Without ASLR:                          With ASLR:
┌─────────────┐                       ┌─────────────┐
│ 0x76BC0000  │  kernel32.dll         │ 0x74A20000  │  kernel32.dll
├─────────────┤                       ├─────────────┤
│ 0x77C00000  │  msvcrt.dll           │ 0x75F30000  │  msvcrt.dll
├─────────────┤                       ├─────────────┤
│ 0x77D00000  │  ntdll.dll            │ 0x76B10000  │  ntdll.dll
└─────────────┘                       └─────────────┘
  Same address every time               Different every process

When a module is compiled with ASLR support (the /DYNAMICBASE linker flag), the PE header contains the IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE flag. The Windows loader then:

  1. Generates a random offset
  2. Adds it to the module’s preferred base address
  3. Applies all relocations so the module functions correctly at the new address

Why ASLR Breaks Exploits

Your exploit relies on hardcoded addresses. If you find a JMP ESP at 0x76BC1234 in kernel32.dll during your first debug session, that address is meaningless in your second session because ASLR relocated the entire module.

Session 1:  JMP ESP found at 0x76BC1234 → Exploit works
Session 2:  kernel32.dll loaded at 0x74A20000 instead of 0x76BC0000
            JMP ESP is now at 0x74A21234 → Your exploit uses stale 0x76BC1234 → CRASH

How to Detect ASLR

Method 1: mona modules (easiest)

!mona modules
# Look at the ASLR column

Method 2: PE Header Inspection

!mona pe -m kernel32.dll
# Look for "ASLR canary" and "Dynamic base" fields

Method 3: Manual PE Analysis The DllCharacteristics field in the Optional Header:

Bit 7 (0x0080) = IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE
If set → ASLR enabled
If clear → ASLR disabled

Method 4: Run Multiple Times

Run the vulnerable app 3 times in the debugger.
Check if the module address changes.
If it changes → ASLR is active (or the module is rebased).

ASLR Bypass Techniques (Advanced)

When all modules have ASLR, you need bypass strategies:

  1. Information Leak: Find a vulnerability that leaks a pointer to an ASLR’d module. Use the leak to calculate the base address and adjust your payload dynamically.

  2. Partial Overwrite: If you can only overwrite the lower bytes of an address, and ASLR entropy is limited (e.g., only 8-12 bits of randomization), you can brute-force the lower bytes.

  3. Non-ASLR Module: Some third-party or older DLLs may not have ASLR even on modern systems.

  4. ROP with ASLR’d Module: If you can leak one address, you can calculate offsets to other functions within the same module and build a ROP chain.


DEP Deep Dive

What Is DEP?

Data Execution Prevention (DEP) marks certain areas of memory as non-executable. If code attempts to execute from a non-executable page, the CPU raises a hardware exception (Access Violation).

Hardware DEP vs Software DEP

┌─────────────────────┬──────────────────────────────────────────────┐
│  Hardware DEP (NX)  │  Software DEP (SEHOP / Soft-DEP)             │
├─────────────────────┼──────────────────────────────────────────────┤
│  CPU-level feature  │  OS-level enforcement                        │
│  AMD: NX bit        │  NGEN images, /NXCOMPAT linker flag          │
│  Intel: XD bit      │  Validates SEH chain integrity               │
│  Mark pages as      │  Works on older CPUs without NX/XD           │
│  non-executable     │                                              │
│  Enforced by MMU    │  Enforced by loader and runtime              │
└─────────────────────┴──────────────────────────────────────────────┘

How DEP Works at the Page Level

Memory Layout with DEP:

Stack Region:
┌─────────────────────────────────┐
│ 0x0012FE00                      │
│ ...                             │
│ [Shellcode here] ← EXECUTION    │
│ ATTEMPTED                       │
│ Result: STATUS_ACCESS_VIOLATION │  ← Page is PAGE_READWRITE, not PAGE_EXECUTE
│ ...                             │
│ 0x00120000                      │
└─────────────────────────────────┘
  Attributes: PAGE_READWRITE (RW-)

Heap Region:
┌─────────────────────────────────┐
│ 0x03450000                      │
│ ...                             │
│ [Shellcode here]                │
│ Result: STATUS_ACCESS_VIOLATION │  ← Page is PAGE_READWRITE
│ ...                             │
│ 0x03400000                      │
└─────────────────────────────────┘
  Attributes: PAGE_READWRITE (RW-)

Code Region (Module):
┌─────────────────────────────────┐
│ 0x76BC0000  kernel32.dll        │
│ ...                             │
│ [Legitimate code]               │
│ Result: Executes fine           │  ← Page is PAGE_EXECUTE_READ
│ ...                             │
│ 0x76C00000                      │
└─────────────────────────────────┘
  Attributes: PAGE_EXECUTE_READ (R-X)

Why DEP Blocks Shellcode

When you overflow a buffer and place shellcode on the stack, then redirect EIP to the stack, the CPU tries to execute instructions from a memory page marked as data (read-write). The hardware NX/XD bit triggers a page fault, and Windows delivers an ACCESS_VIOLATION exception.

DEP in mona’s Module List

DEP = No   → The module's pages CAN be executable. Shellcode placed 
             in this module's memory space can run.

DEP = Yes  → The module's pages are NON-EXECUTABLE. You CANNOT 
             run shellcode from this module's pages.

DEP = N/A  → Usually the main executable. DEP status depends on 
             whether the process was started with DEP enabled.

DEP Bypass Techniques

When DEP is enabled, you cannot execute shellcode directly. You must use:

  1. Return-Oriented Programming (ROP): Chain together small code snippets (“gadgets”) ending in RET instructions that already exist in executable memory. Use gadgets to call VirtualProtect() or VirtualAlloc() to change memory protection, then execute shellcode.

  2. VirtualProtect ROP Chain:

Gadget 1: POP EBP ; RET    →  Set up arguments
Gadget 2: POP EDI ; RET    →  Address of stack region
Gadget 3: POP ESI ; RET    →  Size of region
Gadget 4: POP EBX ; RET    →  New protection (0x40 = PAGE_EXECUTE_READWRITE)
Gadget 5: MOV EAX, 0 ; RET →  Clear EAX (old protection pointer)
Gadget 6: Call VirtualProtect → Changes stack to executable
Gadget 7: JMP ESP            →  Execute shellcode
  1. WriteWhatWhere + CallWhat: mona can generate ROP chains automatically:
!mona rop -m <module_without_dep>
!mona suggest
  1. Stack Pivot + Module Shellcode: If a module without DEP contains writable AND executable pages, you can write shellcode there and jump to it.

SafeSEH Deep Dive

What Is SafeSEH?

Safe Structured Exception Handling (SafeSEH) is a Microsoft compiler/linker feature that prevents SEH overwrite attacks by maintaining a whitelist of valid exception handler addresses for each module.

How SEH Works (Without SafeSEH)

Stack-based SEH Chain:

Higher Addresses
┌─────────────────────────────────────┐
│ Next SEH Record (pointer)           │  ← Points to next record
│ Exception Handler (pointer)         │  ← Address of handler function
├─────────────────────────────────────┤
│ Next SEH Record (pointer)           │
│ Exception Handler (pointer)         │
├─────────────────────────────────────┤
│ ... more SEH records ...            │
├─────────────────────────────────────┤
│ EXCEPTION_REGISTRATION_RECORD       │  ← Head of chain (FS:[0])
│   Next = 0xFFFFFFFF                 │
│   Handler = kernel handler          │
└─────────────────────────────────────┘
Lower Addresses (Grows Down)

When an exception occurs, Windows walks this chain calling each handler until one returns EXCEPTION_CONTINUE_EXECUTION.

The Attack: Overflow the buffer → overwrite the “Exception Handler” pointer → point it to your shellcode or a POP/POP/RET gadget → trigger an exception → your code runs.

How SafeSEH Blocks the Attack

When a module is compiled with SafeSEH support (/SAFESEH linker flag):

  1. The linker generates a SafeSEH table embedded in the module’s PE header
  2. This table contains the addresses of all valid exception handlers in that module
  3. When an exception occurs and Windows walks the SEH chain, it validates each handler address against this table
  4. If the handler address is NOT in the table → the exception is not dispatched → access violation / crash
Without SafeSEH:                  With SafeSEH:
┌──────────────────┐              ┌──────────────────┐
│ Handler Ptr →    │              │ Handler Ptr →    │
│ 0x0012FF00       │              │ 0x0012FF00       │
│ (your shellcode) │              │ (your shellcode) │
│                  │              │                  │
│ Windows calls it │              │ Windows checks:  │
│ Shellcode runs ✓ │              │ "Is 0x0012FF00   │
│                  │              │  in the SafeSEH   │
│                  │              │  table?"          │
│                  │              │ "No."            │
│                  │              │ CRASH ✗           │
└──────────────────┘              └──────────────────┘

SafeSEH in mona’s Module List

SafeSEH = No   → Module does NOT have a SafeSEH table. SEH overwrite 
                 attacks CAN work against exceptions in this module.

SafeSEH = Yes  → Module HAS a SafeSEH table. SEH overwrite to arbitrary 
                 addresses will be REJECTED.

SafeSEH = N/A  → Module was not compiled with SafeSEH support. 
                 SEH overwrite MAY work (depends on compiler).

SafeSEH Bypass Considerations

If you must use SEH overwrite but all modules have SafeSEH:

  1. Target the main executable (often SafeSEH = N/A)
  2. Use a module with SafeSEH = No (third-party DLLs often lack this)
  3. Don’t use SEH overwrite at all — use EIP overwrite with a JMP ESP instead
  4. Abuse SEH record fields — the “Next SEH” pointer (first 4 bytes of the SEH record) can still be overwritten even with SafeSEH; use a 4-byte overwrite + POP/POP/RET technique

Rebase and Signature

Rebase

What Does “Rebase” Mean?

Every PE module has a preferred base address — the address the linker expects it to load at. If that address is already occupied when the module loads, the loader must rebase (relocate) the module to a different address.

Module: evil.dll
Preferred Base: 0x10000000

Scenario 1 — Address Free:
┌──────────────────┐
│ 0x10000000       │  evil.dll loads here ✓
│ ...              │  No rebasing needed
│ 0x10050000       │
└──────────────────┘

Scenario 2 — Address Taken:
┌──────────────────┐
│ 0x10000000       │  [Another module here]
│ ...              │
├──────────────────┤
│ 0x10050000       │  evil.dll REBASED here
│ ...              │  Different address! ✗
│ 0x100A0000       │
└──────────────────┘

Rebase Column in mona

Rebase = No   → The module is NOT marked for rebasing. It will ALWAYS 
                load at its preferred base (or fail). Most predictable.

Rebase = Yes  → The module CAN be rebased. Its load address may vary 
                if the preferred base is taken. Less predictable.

Why Rebase Matters for Exploits

If Rebase = Yes, the module might load at different addresses on different machines or even different runs (if another module sometimes occupies its preferred base). This makes your hardcoded JMP ESP address unreliable.

Combined with ASLR: If a module has both ASLR = Yes AND Rebase = Yes, its address is essentially unpredictable. Avoid it.

ASLR = No but Rebase = Yes: The module usually loads at its preferred base, but there’s a small chance of rebasing. Still relatively safe, but verify across multiple runs.

Signature

What Does a Digital Signature Mean?

A digitally signed module has a cryptographic signature (typically from Microsoft) that verifies its authenticity and integrity.

Signature = Valid  → The module is signed (usually a Microsoft system DLL 
                     like kernel32.dll, ntdll.dll, user32.dll, etc.)

Signature = N/A    → The module is not signed (usually third-party DLLs, 
                     custom plugins, or the main executable)

Why Signature Matters

  1. System DLLs are heavily protected: Signed modules are typically core Windows components with ASLR, DEP, and SafeSEH enabled.

  2. Third-party modules are often unprotected: Unsigned DLLs (especially custom plugin DLLs) are frequently compiled without modern protections — making them ideal exploit targets.

  3. PatchGuard and integrity: On some systems, tampering with signed modules triggers additional security responses.

Rule of thumb: Prefer unsigned (N/A) modules as targets. They’re more likely to lack protections.


Module Selection Process — Decision Tree

The Systematic Selection Flow

flowchart TD
    A[Run !mona modules] --> B{Any module with<br>ASLR=No, DEP=No,<br>SafeSEH=No?}
    
    B -->|Yes| C[Select the module with<br>lowest protection score]
    B -->|No| D{Can you find a module<br>with ASLR=No, DEP=No?}
    
    D -->|Yes| E[Use SEH overwrite on<br>SafeSEH=No module<br>OR use EIP overwrite]
    D -->|No| F{Any module with<br>ASLR=No?}
    
    F -->|Yes| G[Use ROP to bypass DEP<br>!mona rop -m module]
    F -->|No| H[All modules have ASLR<br>Need ASLR bypass]
    
    C --> I[Verify address stability<br>across 3+ runs]
    I --> J[Find JMP ESP in module<br>!mona find -s \"\xff\xe4\" -m module]
    J --> K[Build exploit with<br>stable module address]
    
    E --> L[Proceed with DEP-bypass<br>exploit development]
    G --> L
    H --> M[Information leak +<br>dynamic address calculation]
    
    L --> K
    M --> K

Step-by-Step Selection Process

Step 1: Generate the Module List

!mona modules

Read the output and identify all modules.

Step 2: Filter by ASLR

Cross out every module with ASLR = Yes.
Keep only ASLR = No modules.

If no modules remain, you need an ASLR bypass strategy. Go to the fallback section.

Step 3: Filter by DEP

Among ASLR=No modules, cross out DEP = Yes.
Keep only DEP = No modules.

If no modules remain, you’ll need ROP to bypass DEP. Pick an ASLR=No module and build a ROP chain.

Step 4: Filter by SafeSEH (if using SEH overwrite)

Among remaining modules, cross out SafeSEH = Yes.
Keep SafeSEH = No or N/A modules.

If no modules remain for SEH overwrite, switch to EIP overwrite technique instead.

Step 5: Score the Remaining Modules

For each remaining module:
  +1 if Rebase = Yes
  +1 if Delay = Yes
  +1 if Signature = Valid

Pick the module with the LOWEST score.

Step 6: Verify Address Stability

1. Note the module's base address
2. Restart the application 3 times
3. Confirm the address is the same each time
4. If different, the module is NOT safe — go back to Step 2

Step 7: Find Instructions in the Module

!mona find -s "\xff\xe4" -m <chosen_module.dll>
# Finds JMP ESP instructions

!mona find -s "\x5d\x5a\x8b\xec\x83\xc4\x40\x51\x56\x57\xff\xe0" -m <module>
# Finds POP POP RET sequences (for SEH overwrite)

Step 8: Record the Address

The output gives you addresses like:
0x10001234 : jmp esp (3 bytes)

Use 0x10001234 (little-endian: \x34\x12\x00\x10) in your exploit.

Ideal Module Characteristics

The Perfect Target Module Profile

┌─────────────────────────────────────────────────────────┐
│                 THE IDEAL MODULE                         │
├─────────────┬───────────────────────────────────────────┤
│  Property    │  Ideal Value                              │
├─────────────┼───────────────────────────────────────────┤
│  ASLR        │  No                                       │
│  DEP         │  No                                       │
│  SafeSEH     │  No                                       │
│  Rebase      │  No                                       │
│  Delay       │  No                                       │
│  Signature   │  N/A                                     │
│  Size        │  Large (more instructions to choose from) │
│  Type        │  Third-party / custom DLL                 │
│  Location    │  Same directory as vulnerable app         │
└─────────────┴───────────────────────────────────────────┘

Why Third-Party DLLs Are Gold

Vulnerable applications often load third-party DLLs for:

  • PDF rendering
  • Image processing
  • Database connectivity
  • Compression
  • Cryptography
  • Plugin systems

These DLLs are frequently:

  • Compiled with older toolchains (no modern protections)
  • Not updated with security patches
  • Not digitally signed
  • Loaded at fixed addresses

Common culprits in OSCP labs:

  • libeay32.dll / ssleay32.dll (OpenSSL)
  • sqlite3.dll
  • zlib1.dll
  • iconv.dll
  • libxml2.dll
  • Custom plugin DLLs

Module Size Matters

Larger modules have more instructions, giving you more options for:

  • JMP ESP / CALL ESP / PUSH ESP + RET
  • POP POP RET sequences
  • ROP gadgets
  • NOP sleds (large contiguous NOP regions)
!mona pe -m <module>
# Check "Size of image" — larger is better

When All Modules Are Protected — Fallback Strategies

Scenario 1: All Modules Have ASLR

Strategy A: Information Leak If the vulnerability leaks memory contents (e.g., a read-based buffer overflow), use it to leak a pointer to an ASLR’d module. Calculate the base address and adjust your payload dynamically.

Strategy B: Partial Overwrite If you can overwrite only the lower 2 bytes of EIP, and ASLR randomizes only the upper bits, you can hit a target address with probability. On 32-bit Windows, ASLR typically randomizes 8-12 bits — a 2-byte overwrite gives you 1 in 256 to 1 in 4096 chance.

Strategy C: Module Without ASLR Some systems have at least one module without ASLR. Check thoroughly — sometimes a lesser-known DLL slips through.

Scenario 2: All Modules Have DEP

Strategy: ROP Chain

!mona rop -m <aslr_no_module>

This generates:

  • ropdb.txt — Database of ROP gadgets
  • ropchain.py — Python script to build the ROP chain
  • ropchain.nse — Immunity debugger script

Key gadgets to find:

POP EBP ; RET     → Argument setup
POP EDI ; RET     → Argument setup  
POP ESI ; RET     → Argument setup
POP EBX ; RET     → Argument setup
XOR EAX, EAX ; RET → Clear EAX
MOV DWORD PTR [ECX], AL → Write null bytes
CALL VirtualProtect  → Change memory protection
JMP ESP              → Execute shellcode

Strategy: Return to Libc-Style Instead of shellcode, call WinExec("calc", 1) or System("cmd") directly from a module function.

Scenario 3: All Modules Have SafeSEH

Strategy A: Switch to EIP Overwrite If you control EIP directly (not just SEH), you don’t need SafeSEH to be disabled. Find a JMP ESP in any ASLR=No, DEP=No module and redirect EIP there.

Strategy B: 4-Byte SEH Overwrite Overwrite only the first 4 bytes (Next SEH pointer) of the SEH record with a carefully chosen value, then use a POP POP RET gadget in the handler field. This technique works because SafeSEH only validates the handler field, not the Next SEH field.

Scenario 4: Everything Is Protected

This is the hardest case. Your options:

  1. Exploit a different vulnerability in the same application that has fewer protections
  2. Use a heap-based attack with heap spraying (more reliable against randomization)
  3. Combine multiple techniques: Information leak + ROP + dynamic payload
  4. Target a different component: Maybe a plugin, browser extension, or helper application has weaker protections

Real-World Examples

Example 1: Mutillidae / Web Application

[+] Modules
    Name                 Address   Delay   ASLR    DEP     SafeSEH  Rebase  Signature
    -----------------------------------------------------------------------------
    mutillidae.exe       0x00400000 No      N/A     N/A      N/A     N/A     N/A
    msvcrt.dll           0x77C00000 No      No      No       No      No      N/A
    kernel32.dll         0x76BC0000 No      Yes     Yes      Yes     Yes     Valid
    ntdll.dll            0x77D00000 No      Yes     Yes      Yes     Yes     Valid

Analysis:
- msvcrt.dll: ASLR=No, DEP=No, SafeSEH=No, Rebase=No, Sig=N/A → PERFECT TARGET
- Score: 0 points — ideal module
- Verify: Run app 3 times, confirm 0x77C00000 stays constant
- Find JMP ESP: !mona find -s "\xff\xe4" -m msvcrt.dll

Example 2: FMSoft Total Validator (Classic OSCP Lab)

[+] Modules
    Name                 Address   Delay   ASLR    DEP     SafeSEH  Rebase  Signature
    -----------------------------------------------------------------------------
    TotalValidator.exe   0x00400000 No      N/A     N/A      N/A     N/A     N/A
    msvcrt.dll           0x77C00000 No      No      No       No      No      N/A
    kernel32.dll         0x76BC0000 No      Yes     Yes      Yes     Yes     Valid
    ntdll.dll            0x77D00000 No      Yes     Yes      Yes     Yes     Valid
    urlmon.dll           0x77070000 No      Yes     Yes      Yes     Yes     Valid
    wininet.dll          0x6D5A0000 No      No      No       No      No      N/A

Analysis:
- Two excellent targets: msvcrt.dll AND wininet.dll
- Both have ASLR=No, DEP=No, SafeSEH=No, Rebase=No, Sig=N/A
- wininet.dll is a third-party-style DLL — often larger, more gadgets
- Recommendation: Use wininet.dll (larger, more instruction options)
- Verify stability, then find JMP ESP in wininet.dll

Example 3: Modern Application (All Protected)

[+] Modules
    Name                 Address   Delay   ASLR    DEP     SafeSEH  Rebase  Signature
    -----------------------------------------------------------------------------
    modernapp.exe        0x00F80000 No      Yes     Yes      Yes     Yes     Valid
    kernel32.dll         0x74A20000 No      Yes     Yes      Yes     Yes     Valid
    ntdll.dll            0x76B10000 No      Yes     Yes      Yes     Yes     Valid
    user32.dll           0x75F30000 No      Yes     Yes      Yes     Yes     Valid
    advapi32.dll         0x74C10000 No      Yes     Yes      Yes     Yes     Valid

Analysis:
- ALL modules have ASLR, DEP, and SafeSEH enabled
- No easy target exists
- Required approach:
  1. Find information leak vulnerability to defeat ASLR
  2. Build ROP chain to defeat DEP
  3. Use EIP overwrite (not SEH) to avoid SafeSEH
- This is an advanced scenario beyond basic OSCP requirements
- In OSCP labs, there's ALWAYS at least one unprotected module

Example 4: Application with Plugin Architecture

[+] Modules
    Name                 Address   Delay   ASLR    DEP     SafeSEH  Rebase  Signature
    -----------------------------------------------------------------------------
    pdfreader.exe        0x00400000 No      Yes     Yes      Yes     Yes     Valid
    kernel32.dll         0x76BC0000 No      Yes     Yes      Yes     Yes     Valid
    ntdll.dll            0x77D00000 No      Yes     Yes      Yes     Yes     Valid
    libpdf.dll           0x10000000 No      No      No       No      No      N/A
    jpeglib.dll          0x20000000 No      No      No       No      No      N/A
    zlib1.dll            0x30000000 No      No      No       No      No      N/A

Analysis:
- Main app and system DLLs are fully protected
- BUT three plugin DLLs are completely unprotected:
  - libpdf.dll: Score 0 — PERFECT
  - jpeglib.dll: Score 0 — PERFECT
  - zlib1.dll: Score 0 — PERFECT
- Choose the largest module for most instruction options
- These are classic OSCP-style targets

Quick Reference Card

Module Selection Checklist

□ Run !mona modules
□ Identify all ASLR=No modules
□ Among those, identify DEP=No modules
□ Among those, identify SafeSEH=No modules (if using SEH overwrite)
□ Score remaining modules (Rebase, Delay, Signature)
□ Pick lowest-score module
□ Verify address stability across 3+ runs
□ Find JMP ESP: !mona find -s "\xff\xe4" -m <module>
□ Record address in little-endian format
□ Build exploit

Common mona Commands for Module Work

!mona modules                    # List all loaded modules
!mona modules -n                 # List only unprotected modules
!mona pe -m <module>             # Detailed PE header info for a module
!mona find -s "\xff\xe4" -m <m> # Find JMP ESP in module
!mona find -s "\x5d\x5a\x8b\xec" -m <m> # Find POP POP RET in module
!mona noaslr                     # Quick list of non-ASLR modules
!mona nop <length>               # Generate NOP sled
!mona suggest                    # Suggest exploit approach based on findings
!mona rop -m <module>            # Generate ROP gadgets from module

Byte Sequences to Search For

Instruction          Bytes (hex)         Use Case
─────────────────────────────────────────────────────────────
JMP ESP              \xff\xe4            EIP overwrite → shellcode on stack
CALL ESP             \xff\xd4            EIP overwrite → shellcode on stack
PUSH ESP ; RET       \x54\xc3            EIP overwrite → shellcode on stack
JMP EAX              \xff\xe0            ROP chain → shellcode in EAX
CALL EAX             \xff\xd0            ROP chain → function in EAX
POP POP RET          \x5d\x5a\x8b\xec... SEH overwrite → pivot
XCHG EAX, ESP        \x94                SEH overwrite → pivot

Common Pitfalls and Debugging Tips

Pitfall 1: Address Changes Between Runs

Symptom: Your exploit works in the debugger but crashes outside.

Cause: The module address differs between the debugged and non-debugged process, or between machines.

Fix:

  • Verify with !mona modules on the actual target machine
  • Use !mona config -set working <path> consistently
  • Test on the actual target OS version

Pitfall 2: Module Not Loaded

Symptom: The JMP ESP address causes an access violation.

Cause: The module uses delay loading and isn’t loaded when your exploit runs.

Fix:

  • Check the Delay column — pick Delay = No modules
  • Force the module to load by triggering the feature that uses it

Pitfall 3: Bad Characters Break the Address

Symptom: The address bytes contain a “bad character” (like \x00).

Cause: Your buffer overflow null-terminates at \x00, truncating the address.

Fix:

  • Find another JMP ESP in the same module that doesn’t contain bad chars
  • Use !mona find -s "\xff\xe4" -m <module> -n <num> to find multiple options
  • Pick an address without your bad characters

Pitfall 4: DEP Hits Even Though Module Says DEP=No

Symptom: You redirect to the module, but execution fails with access violation.

Cause: The module’s pages may have mixed protection, or the process has global DEP enabled.

Fix:

  • Check with !mona got to see DEP status of the process
  • Use !mona pcg to check page protections
  • Consider ROP as fallback

Pitfall 5: SafeSEH Blocks SEH Overwrite

Symptom: Exception occurs but your handler never runs.

Cause: You targeted a module with SafeSEH = Yes.

Fix:

  • Switch to a SafeSEH = No module
  • Or switch from SEH overwrite to EIP overwrite technique

Debugging Workflow

1. Crash the app in the debugger
2. Run !mona modules
3. Pick your target module
4. Run !mona find -s "\xff\xe4" -m <target>
5. Note the address
6. Update your exploit with the new address
7. Test in debugger
8. If it works in debugger but not outside → address mismatch
9. If it crashes with ACCESS_VIOLATION → DEP issue
10. If exception doesn't dispatch → SafeSEH issue

Summary

Module selection is a systematic filtering process:

  1. Start with !mona modules
  2. Eliminate modules with ASLR (address unpredictability)
  3. Eliminate modules with DEP (execution prevention)
  4. Eliminate modules with SafeSEH (if using SEH overwrite)
  5. Score remaining modules by Rebase, Delay, and Signature
  6. Pick the lowest-score module
  7. Verify address stability across multiple runs
  8. Find your pivot instruction (JMP ESP, POP POP RET, etc.)
  9. Build your exploit with the verified address

The golden rule: A module with ASLR=No, DEP=No, SafeSEH=No, Rebase=No, Delay=No, Signature=N/A is your ideal target. In OSCP labs, such modules always exist. Find it, verify it, and exploit it.


This study guide covers the complete module selection process for exploit development. Master this topic and you’ll solve the module-selection portion of any OSCP exploit challenge with confidence.