Enterprise incident responders and threat hunters face a persistent dilemma in modern endpoint defense: automated Endpoint Detection and Response (EDR) sensors frequently report clean memory state while covert adversary infrastructure maintains continuous access. Advanced persistent threat actors and modern Command and Control (C2) frameworks—such as Cobalt Strike, Brute Ratel, and Havoc—have systematically adapted their tradecraft to evade behavioral and static in-memory scanners.

A primary technique driving this evasion is Module Stomping (commonly referenced as DLL Hollowing or Module Overwriting), classified under MITRE ATT&CK sub-technique T1055.012. By loading a legitimate, Microsoft-signed Dynamic Link Library (DLL) into a process and overwriting its executable code section (.text) with shellcode, an adversary ensures that running threads point exclusively to on-disk, image-backed memory pages.

Deconstructing the architectural physics of process memory, page-level mapping types, and call stack telemetry illustrates why host-based agents struggle to detect module stomping—and how out-of-band network cryptographic isolation enforces definitive containment.

+-------------------------------------------------------------------------+
|              Module Stomping (DLL Hollowing) Injection Mechanics        |
|                                                                         |
|  [ Target Process (e.g. svchost.exe / runtimebroker.exe) ]              |
|                                                                         |
|  Step 1: Load Legitimate Signed DLL                                     |
|    - LoadLibraryExW("Chakra.dll", DONT_RESOLVE_DLL_REFERENCES)          |
|    - Memory mapped as MEM_IMAGE (Backed by C:\Windows\System32\...)     |
|                                                                         |
|  Step 2: Modify Protection & Stomp Code Section                         |
|    - VirtualProtect(BaseAddress + .text, Size, PAGE_READWRITE)          |
|    - Overwrite original instructions with C2 Beacon Payload             |
|    - VirtualProtect(BaseAddress + .text, Size, PAGE_EXECUTE_READ)       |
|                                                                         |
|  Step 3: Execution & EDR Thread Inspection                              |
|    - CreateThread(StartAddress = Chakra.dll!EntryPoint)                 |
|    - EDR checks RIP -> RIP lies within signed Chakra.dll (.text)        |
|    - QueryVirtualMemory -> Type = MEM_IMAGE (Clean, Not Floating)       |
|         |                                                               |
|         | Malicious Thread Executes C2 Beacon                           |
|         v                                                               |
|  [ Outbound Socket Egress to External C2 Controller ]                   |
+-------------------------------------------------------------------------+

The Physics of Floating Memory and Why Unbacked Pages Trigger EDR Alerts

To understand why adversaries deploy Module Stomping, one must examine standard memory inspection heuristics implemented by modern EDR agents.

When a classic injector deploys shellcode, it allocates memory via VirtualAlloc or NtAllocateVirtualMemory. The Windows Memory Manager designates these regions as MEM_PRIVATE. If the memory protection is configured as PAGE_EXECUTE_READWRITE (RWX) or transitioned from PAGE_READWRITE to PAGE_EXECUTE_READ (RX), security telemetry tools (such as Process Hacker, Moneta, and Pe-sieve) flag the region as floating unbacked executable memory:

  • Unbacked Memory Anomaly: The executable page is not associated with any Portable Executable (PE) file residing on disk. Legitimate software binaries load their executable code exclusively from PE files mapped through CreateFileMapping and MapViewOfSection, creating MEM_IMAGE page types.
  • Thread Call Stack Inspection: When an EDR thread worker queries the instruction pointer (RIP on x64), it examines the loaded module base table (PEB.Ldr). If RIP falls outside all known loaded module boundaries, the agent immediately classifies the thread as an injected payload.

Adversaries recognized that unbacked memory allocations represent an immediate operational indicator. Module Stomping was engineered specifically to neutralize this heuristic.

Mechanics of Module Stomping and Overwriting Signed Image Sections

The execution workflow of a refined Module Stomping attack proceeds through several deterministic phases:

1. Target Module Selection and Loading

The loader process selects a benign, signed system DLL that is either rarely utilized by the target process or loaded solely as a sacrificial container. Common targets include Chakra.dll, d3d10.dll, or legacy multimedia components in System32. The malware loads the library:

HMODULE hSacrificial = LoadLibraryExW(
    L"Chakra.dll", 
    NULL, 
    DONT_RESOLVE_DLL_REFERENCES
);

Using DONT_RESOLVE_DLL_REFERENCES ensures that the DLL entry point (DllMain) is not executed, preventing unintended initialization side effects while mapping the full PE structure into memory.

2. Locating the Code Section (.text)

The loader parses the DOS Header (IMAGE_DOS_HEADER) and NT Headers (IMAGE_NT_HEADERS) of the mapped DLL in memory, iterating through the Section Header array (IMAGE_SECTION_HEADER) to locate .text:

  • VirtualAddress: The relative virtual address (RVA) of the executable code.
  • Misc.VirtualSize: The length of the memory region available for overwriting.

The adversary must verify that VirtualSize equals or exceeds the compiled length of their C2 beacon shellcode to avoid memory access violations (STATUS_ACCESS_VIOLATION).

3. Modifying Protection and Writing Payload

The memory protection of .text is natively PAGE_EXECUTE_READ. The loader modifies this to writable memory:

DWORD oldProtect;
VirtualProtect(codeBase, payloadSize, PAGE_READWRITE, &oldProtect);
memcpy(codeBase, beaconPayload, payloadSize);
VirtualProtect(codeBase, payloadSize, PAGE_EXECUTE_READ, &oldProtect);

Once overwritten, the code section contains the malicious shellcode, yet its Windows memory descriptor (MEMORY_BASIC_INFORMATION) continues to report Type = MEM_IMAGE and points to the signed path on disk.

+-------------------------------------------------------------------------+
|        Process Memory Layout: Classic Injection vs Module Stomping      |
|                                                                         |
|  [ Classic Shellcode Injection ]                                        |
|    - Base Address: 0x0000021A`B8000000                                  |
|    - Region Type: MEM_PRIVATE                                           |
|    - Disk Backing: None (Floating Memory)                               |
|    - EDR Assessment: MALICIOUS (Immediate Detection)                    |
|                                                                         |
|  [ Module Stomped Injection ]                                           |
|    - Base Address: 0x00007FF8`41201000                                  |
|    - Region Type: MEM_IMAGE                                             |
|    - Disk Backing: C:\Windows\System32\Chakra.dll                       |
|    - EDR Assessment: BENIGN (Evades Shallow Thread Inspection)          |
+-------------------------------------------------------------------------+

Inspecting Memory Discrepancies: Page Hashes, CFG, and Call Stack Inconsistencies

While Module Stomping evades basic image-type filters, comprehensive endpoint detection mechanisms apply advanced heuristics to identify stomped artifacts:

1. In-Memory Page Hash Verification

High-assurance endpoint monitoring engines perform periodic integrity comparisons. The agent reads the physical DLL from C:\Windows\System32\, calculates SHA-256 hashes of the disk-based .text pages, and compares them against the current in-memory pages. A mismatch reveals that the memory content has been tampered with after initial load.

2. Control Flow Guard (CFG) Violations

If the stomped process enforces Microsoft Control Flow Guard (CFG), the kernel tracks valid indirect call targets via a bitmap. When an attacker redirects execution to an unaligned offset within the stomped DLL, the CPU raises an exception (STATUS_STACK_BUFFER_OVERRUN) prior to shellcode execution.

3. Call Stack Return Address Discrepancies

When the C2 beacon performs subsequent system calls (such as sleep timers or socket communications), the return address on the call stack points into the stomped DLL. Advanced EDR tools correlate the return address against exported function addresses. If the return address lies within dead space or unexported internal byte sequences, the thread is flagged for forensic analysis.

Network C2 Egress Constraints and Inherent Host-Level Telemetry Blind Spots

Regardless of how stealthily shellcode resides within host memory, it cannot fulfill its operational purpose without network egress. The stomped C2 beacon must periodically beacon out to retrieve tasking, exfiltrate stolen credentials, or execute lateral movement commands.

Relying exclusively on host-based endpoint sensors leaves enterprises vulnerable to telemetry blindness:

  • Kernel EDR Blinding: Advanced malware often pairs Module Stomping with vulnerable signed kernel drivers (BYOVD) to unhook EDR kernel callbacks or clear Event Tracing for Windows (ETW-Ti) subscriptions.
  • Synthetic Socket Context: The outbound socket opened by the stomped thread inherits the security context of the legitimate host process (such as runtimebroker.exe or spoolsv.exe), blending seamlessly into normal operating system traffic.

Consequently, modern security architecture dictates that endpoint telemetry must be validated and constrained by an independent, uncompromised network isolation layer.

Defensive Hardening: Out-of-Band Network Cryptography and WireGuard Isolation

Defeating advanced in-memory evasion requires an out-of-band defensive perimeter that functions outside the compromised host's kernel space. A compromised operating system cannot subvert hardware-level packet routing enforced by an upstream cryptographic gateway.

Deploying a hardened Layer 3 tunnel via VPNRice neutralizes Module Stomping egress threats through several coordinated mechanisms:

+-------------------------------------------------------------------------+
|         Defending Stomped Endpoints via WireGuard Layer 3 Transit       |
|                                                                         |
|  [ Compromised Workstation ]                                            |
|    - In-memory Module Stomped C2 Beacon (Inside svchost.exe)            |
|    - Host EDR potentially blinded or evading detection                 |
|         |                                                               |
|         | Outbound Socket Connection Attempt (TCP/UDP)                  |
|         v                                                               |
|  [ Network Layer: WireGuard Kernel Module (wg0 / VPNRice Engine) ]      |
|    - Encapsulates all egress in ChaCha20-Poly1305 cryptotunnel          |
|    - PersistentKeepalive = 25 enforces strict state tracking            |
|         |                                                               |
|         v                                                               |
|  [ Hardened Out-of-Band Recursive DNS & Egress Inspection Gateway ]     |
|    - DNS Sinkholing: Blocks dynamic C2 domain generation algorithms     |
|    - Zero Trust Egress Policy: Restricts rogue port egress              |
|    - Lateral Movement Denial: Strict client-to-client isolation         |
+-------------------------------------------------------------------------+

1. Mandatory Encrypted Layer 3 Tunneling

All outbound traffic generated by the workstation is forced through a dedicated WireGuard kernel interface (wg0). The stomped beacon cannot establish rogue direct IP sockets to foreign autonomous systems without traversing the encrypted tunnel.

2. DNS Egress Filtering and Automated Sinkholing

Adversary C2 infrastructure heavily relies on dynamic DNS domains, Fast Flux networks, and bulletproof hosting providers. By directing all DNS queries across the WireGuard tunnel to non-logging, security-hardened recursive resolvers:

  • Requests to known C2 staging domains are instantly sinkholed.
  • Anomalous DNS queries (such as base64-encoded DNS tunneling) are detected and suppressed before payloads execute.

3. Lateral Movement Neutralization

Even if an attacker establishes an interactive shell via Module Stomping, the WireGuard gateway enforces strict microsegmentation. The infected endpoint is isolated from adjacent enterprise subnets, preventing lateral spread via SMB (port 445), WinRM (port 5985), or RDP (port 3389).

By coupling rigorous memory scanning with kernel-enforced Layer 3 cryptographic transit, organizations dismantle the stealth advantages of Module Stomping and establish an unyielding containment perimeter.