Domain 3Exploit Dev & AV EvasionCORE

Process Injection Techniques

Deep dive into process injection techniques including process hollowing, process doppelganging, reflective DLL injection, APC injection, thread hijacking, and detection/evasion strategies.

Domain: Domain 3: Exploit Mechanics & AV Evasion•Updated: 2026-09-01
#process-injection#hollowing#reflective-dll#apc#doppelganging

Process Injection Techniques

Why Process Injection?

Process injection is the act of executing arbitrary code in the address space of another running process. It is a cornerstone technique for AV/EDR evasion and is heavily tested on OSCP-adjacent exams (CRTO, CRTE, OSEP). The core motivations are:

  1. Hiding — Malicious code runs inside a legitimate process (e.g., svchost.exe, explorer.exe), making it harder to spot in task lists.
  2. Persistence — Injecting into a long-lived process helps survive user logoff or simple reboots.
  3. Privilege Inheritance — Code injected into a high-privilege process inherits its token, enabling privilege escalation.
  4. Evasion — Many AV/EDR solutions focus on process creation and PE loading; injection bypasses these hooks by reusing an already-trusted process.
  5. Sandbox Escape — Sandboxes often monitor new process creation; injection into existing processes may go unnoticed.

1. Process Hollowing

Process hollowing creates a suspended legitimate process, unmaps its original image, allocates new memory, writes a malicious payload, and redirects execution.

Step-by-Step Breakdown

Step API Call Purpose
1 CreateProcessA Launch a legitimate binary (e.g., notepad.exe) with CREATE_SUSPENDED flag — the main thread is suspended before it runs
2 NtUnmapViewOfSection Unmap the original PE image from the process’s address space, freeing the memory region
3 VirtualAllocEx Allocate new RWX (or RW then X) memory at the same base address where the original image was mapped
4 WriteProcessMemory Write the malicious PE image into the newly allocated memory, respecting the section table (headers, sections, relocations)
5 ResumeThread Resume the suspended main thread, now pointing to the malicious payload’s entry point

Key Implementation Details

  • Parse the malicious PE’s IMAGE_DOS_HEADER and IMAGE_NT_HEADERS to determine the SizeOfImage and SectionAlignment.
  • Use GetThreadContext to read the suspended thread’s context, then SetThreadContext to update Ebx (base address) and Eax (entry point) before resuming.
  • Handle relocations if the image is loaded at a non-preferred base address.

Detection

  • Monitor NtUnmapViewOfSection calls — legitimate software rarely unmmaps its own image.
  • EDRs hook CreateProcess + NtUnmapViewOfSection sequences.
  • Sysmon Event ID 10 (ProcessAccess) with PROCESS_VM_OPERATION + PROCESS_VM_WRITE + PROCESS_VM_READ on suspicious targets.
  • Memory forensics: Volatility malfind plugin detects RWX regions and unusual memory mappings.

Evasion

  • Use manual PE mapping instead of NtUnmapViewOfSection (inline with reflective loading).
  • Delay between API calls to avoid behavioral correlation.
  • Use indirect API calls (syscall stagers) to avoid user-mode hooks.

2. Process Doppelganging

Process doppelganging abuses transactional NTFS (available on Windows 7/Server 2008+) to execute payloads while leaving the file system in a clean state — making forensic detection extremely difficult.

Step-by-Step Breakdown

Step API / Mechanism Purpose
1 CreateTransaction Create a new NTFS transaction scope
2 CreateProcessWithTransactionW Launch a legitimate process inside the transaction (suspended)
3 NtSetInformationProcess (ProcessImageFileName) Replace the process’s image path with the malicious binary’s path
4 NtCreateSection Create a section from the malicious PE file within the transaction
5 MapViewOfSection Map the malicious section into the hollowed process
6 RollbackTransaction Roll back the transaction — all file system changes are undone, leaving no trace

Why It’s Dangerous

  • The file system shows no evidence of the malicious binary being accessed.
  • MFT entries, LMR (Last Modified Record), and USN Journal remain clean after rollback.
  • Only in-memory artifacts remain — requiring live memory analysis.

Detection

  • Monitor CreateTransaction + CreateProcessWithTransactionW sequences.
  • ETW Provider Microsoft-Windows-TransactionServer events.
  • Sysmon Event ID 1 with CreateProcessWithTransactionW parent process anomalies.
  • Memory scanning for orphaned sections not backed by disk files.

Evasion

  • Use NtCreateTransaction directly instead of the documented API.
  • Combine with process hollowing for double-layer evasion.

3. Reflective DLL Injection

Developed by Stephen Fewer (2010), reflective DLL injection loads a DLL into a process without calling LoadLibrary — bypassing DLL load hooks entirely.

How It Works

  1. The DLL is modified at compile time to include a custom “reflective loader” stub in a dedicated section (.reflectiveloader).
  2. Raw DLL bytes are read into memory (via CreateFile + ReadFile or embedded as a resource).
  3. The reflective loader stub is executed — it:
    • Parses the PE headers of itself in memory.
    • Allocates RWX memory at the DLL’s preferred base address via VirtualAlloc.
    • Copies all sections to their correct virtual addresses.
    • Processes the Import Address Table (IAT) by resolving imports via GetProcAddress.
    • Applies base relocations if loaded at a non-preferred address.
    • Calls the original DllMain with DLL_PROCESS_ATTACH.

Key Advantages

  • No LoadLibrary call — bypasses API monitoring.
  • No LdrLoadDll — invisible to pebldr Volatility plugin.
  • Fully in-memory — no disk artifacts.

Detection

  • Unusual VirtualAlloc + VirtualProtect sequences creating RWX regions.
  • Scanning heap/stack for PE magic bytes (MZ / 4D5A).
  • ETW ImageLoad events will not fire — absence can be suspicious in monitored processes.
  • Monitor for shellcode-like behavior patterns in allocated memory.

Evasion

  • Use VirtualAlloc with PAGE_READWRITE, then VirtualProtect to PAGE_EXECUTE_READ (two-step avoids direct RWX allocation).
  • Encrypt or encode the DLL bytes and decode at runtime.
  • Use NtAllocateVirtualMemory (native API) instead of VirtualAlloc to bypass user-mode hooks.

OSCP Relevance

  • pe_injector.py from the OSCP toolkit uses reflective DLL injection concepts.
  • Understanding this technique helps in custom payload development for CRTO/CRTE.

4. APC Injection (Asynchronous Procedure Call)

APC injection queues a user-mode APC (asynchronous procedure call) to a target thread. When the thread enters an alertable state, the APC routine executes in the target thread’s context.

Step-by-Step Breakdown

Step API Call Purpose
1 OpenProcess Open the target process with PROCESS_CREATE_THREAD, PROCESS_VM_OPERATION, PROCESS_VM_WRITE
2 VirtualAllocEx Allocate memory in the target process for the shellcode
3 WriteProcessMemory Write the shellcode payload into the allocated memory
4 OpenThread Open a handle to a target thread in the suspended process
5 QueueUserAPC Queue the APC routine (pointing to the shellcode) to the target thread
6 ResumeThread Resume the thread — when it enters an alertable state, the APC fires

Key Detail

  • The target thread must enter an alertable state (via SleepEx, WaitForSingleObjectEx, MsgWaitForMultipleObjectsEx, etc.) for the APC to execute.
  • If the thread never enters an alertable state, the APC sits in the queue indefinitely.

Detection

  • Sysmon Event ID 28 (PipeEvent) and Event ID 10 showing suspicious thread access patterns.
  • Monitor QueueUserAPC calls from untrusted processes.
  • EDRs track APC queue depth and anomalous APC routines.

Evasion

  • Target threads that are known to enter alertable states (e.g., GUI message loops).
  • Use NtQueueApcThread (native API) instead of QueueUserAPC.

5. Thread Hijacking (Context Theft)

Thread hijacking suspends a target thread, modifies its execution context (instruction pointer and stack), and resumes it — redirecting execution to attacker-controlled code.

Step-by-Step Breakdown

Step API Call Purpose
1 OpenProcess Open the target process
2 OpenThread Open a handle to the target thread
3 SuspendThread Suspend the thread to freeze execution
4 GetThreadContext Read the current CPU registers
5 VirtualAllocEx + WriteProcessMemory Allocate and write shellcode in the target
6 SetThreadContext Modify Eip/Rip to point to the shellcode; optionally modify Esp/Rsp
7 ResumeThread Resume — the thread now executes the injected code

Detection

  • Sysmon Event ID 10 with THREAD_SET_CONTEXT access.
  • Monitor SuspendThread + SetThreadContext + ResumeThread sequences.
  • EDRs flag context modifications on threads in trusted processes.

6. Advanced Techniques

Early Bird APC

  • Combines APC injection with process creation.
  • Uses CreateProcess with CREATE_SUSPENDED, then QueueUserAPC to the suspended thread.
  • Calls NtTestAlert or resumes the thread — the APC executes before the original entry point runs.
  • Effective because the payload runs before the legitimate code, and the process appears normal afterward.

NtCreateThreadEx

  • Native API (undocumented, exported by ntdll.dll) that creates a new thread in a remote process.
  • Unlike CreateRemoteThread, it is used by the Windows kernel for many legitimate operations, making it less suspicious.
  • Bypasses some AV/EDR solutions that only hook CreateRemoteThread.
  • Used by modern loaders and frameworks (e.g., Cobalt Strike, Sliver).

Atom Bombing

  • Abuses the Windows Global Atom Table (AddAtomA, FindAtomA, GlobalGetAtomNameA).
  • Stage 1: Write shellcode to a process’s heap, then use AddAtomA to store a pointer to the shellcode in the global atom table.
  • Stage 2: In the target process, call FindAtomA to retrieve the pointer, then GlobalGetAtomNameA to copy the shellcode to a controlled buffer, and execute it.
  • Useful for cross-process data exfiltration and staged payload delivery.
  • Detected by monitoring AddAtomA calls with suspicious data patterns.

Detection Summary Table

Technique Primary Detection Vector Sysmon Event EDR Hook Point
Process Hollowing NtUnmapViewOfSection Event 10 NtCreateSection, NtUnmapViewOfSection
Process Doppelganging Transactional API sequence Event 1 CreateTransaction, NtCreateSection
Reflective DLL RWX allocation + PE headers in memory N/A (in-memory) VirtualAlloc, heap scanning
APC Injection QueueUserAPC from untrusted source Event 10 NtQueueApcThread
Thread Hijacking SetThreadContext on remote thread Event 10 NtSetInformationThread
Early Bird APC APC before entry point execution Event 1 + 10 NtTestAlert, APC queue depth
Atom Bombing AddAtomA with executable data N/A Atom table monitoring

Evasion Strategies (General)

  1. Indirect Syscalls — Use SysWhispers or DirectSyscall to invoke native APIs directly, bypassing user-mode EDR hooks in ntdll.dll.
  2. API Hashing — Resolve API addresses at runtime via hash lookup in the PEB LDR module list instead of static imports.
  3. Sleep Obfuscation — Use RtlSetSleepTime or NtDelayExecution with entropy checks to defeat sleep scanning.
  4. Memory Protection — Avoid RWX allocations; use read-write-then-execute patterns with VirtualProtect.
  5. Timing Delays — Insert random delays between API calls to break behavioral correlation rules.
  6. Legitimate Code Guardring — Wrap malicious calls with legitimate API calls to confuse heuristic analysis.

OSCP Exam Relevance

  • Process injection tools like psexec, procdump, and mimikatz use injection-like techniques internally.
  • Understanding hollowing helps explain how psexec.exe operates (it hollows services.exe).
  • Reflective DLL injection is the basis for many post-exploitation tools on the exam.
  • For CRTO/CRTE, deep knowledge of these techniques is essential for custom payload development.
  • On OSCP, focus on practical usage of existing tools rather than manual implementation — but understanding the mechanics helps with troubleshooting and write-ups.

Key APIs Quick Reference

CreateProcessA / CreateProcessW           — Create suspended process
NtUnmapViewOfSection                       — Unmap PE image (hollowing)
VirtualAllocEx / NtAllocateVirtualMemory  — Remote memory allocation
WriteProcessMemory / NtWriteVirtualMemory  — Write to remote process
ReadProcessMemory / NtReadVirtualMemory    — Read from remote process
SetThreadContext / GetThreadContext        — Hijack thread execution
QueueUserAPC / NtQueueApcThread            — APC injection
CreateRemoteThread / NtCreateThreadEx      — Remote thread creation
OpenProcess / OpenThread                   — Handle acquisition
SuspendThread / ResumeThread               — Thread control
CreateTransaction / RollbackTransaction    — Transactional NTFS (doppelganging)
AddAtomA / FindAtomA / GlobalGetAtomNameA  — Atom bombing
VirtualProtect / NtProtectVirtualMemory    — Change memory protection

Tool Purpose
psexec.exe Study process hollowing in action
mimikatz privilege::debug + sekurlsa::logonpasswords uses injection
Sysinternals Procmon Monitor API call sequences for detection research
Volatility 3 windows.pslist, windows.malfind, windows.pebins for memory forensics
Sysmon + SwiftOnSecurity config Baseline detection rules for injection techniques
Comodot / SysWhispers2 Generate indirect syscall stubs for evasion

This chapter is part of the AV Evasion domain. Master these techniques to understand how modern malware evades detection and how defenders build countermeasures.