Process Injection

Process Injection

One-liner: A defense evasion technique where attackers inject malicious code into legitimate running processes to execute stealthily and evade security controls.

🎯 What Is It?

Process injection (MITRE ATT&CK T1055) is a method used by adversaries to execute arbitrary code within the address space of a separate, legitimate process. By injecting code into trusted processes (like explorer.exe, svchost.exe), attackers can:

πŸ”¬ How It Works

Common Injection Techniques

Technique Description MITRE Sub-Technique
DLL Injection Load malicious DLL into target process T1055.001
PE Injection Inject entire executable into memory T1055.002
Thread Execution Hijacking Hijack existing thread's execution T1055.003
Process Hollowing Replace legitimate code with malicious code T1055.012
Thread Local Storage Abuse TLS callbacks for code execution T1055.005
NTFS Transaction Hollowing Use transacted file operations T1055.013

Classic DLL Injection Flow

1. OpenProcess()        β†’ Get handle to target process
2. VirtualAllocEx()     β†’ Allocate memory in target process
3. WriteProcessMemory() β†’ Write malicious DLL path/code
4. CreateRemoteThread() β†’ Execute code in target process

Process Hollowing Flow

1. CreateProcess()      β†’ Start legitimate process (SUSPENDED)
2. NtUnmapViewOfSection() β†’ Hollow out the process image
3. VirtualAllocEx()     β†’ Allocate space for malicious code
4. WriteProcessMemory() β†’ Write malicious executable
5. SetThreadContext()   β†’ Point entry to malicious code
6. ResumeThread()       β†’ Execute the malicious payload

πŸ•΅οΈ Detection & Prevention

How to Detect

Data Source Detection Method
Sysmon Event ID 8 CreateRemoteThread β€” Process creates thread in another process
Sysmon Event ID 10 ProcessAccess β€” Unusual process access with PROCESS_VM_WRITE
Sysmon Event ID 1 Process creation with suspicious parent-child relationships
API Monitoring Calls to VirtualAllocEx, WriteProcessMemory, CreateRemoteThread
Memory Analysis Unbacked executable memory regions (no file on disk)

KQL Example (from THM Threat Hunting Foothold)

# Hunt for CreateRemoteThread events
host.name: WKSTN-* AND winlog.event_id: 8

Suspicious Indicators

How to Prevent / Mitigate

πŸ“Š Common Target Processes

Process Why Targeted
explorer.exe Always running, user context, network access
svchost.exe Multiple instances, SYSTEM privileges
lsass.exe Credential access (e.g., Mimikatz)
spoolsv.exe Printer service, often overlooked
wuauclt.exe Windows Update, trusted by default

🎀 Interview Angles

Common Questions

STAR Story

Situation: EDR flagged unusual activity but couldn't identify the sourceβ€”malicious behavior appeared to come from explorer.exe.
Task: Investigate the alert and determine if it was a true positive.
Action: Used Sysmon Event ID 8 (CreateRemoteThread) to identify that a downloaded chrome.exe from C:\Users\...\Downloads had injected into explorer.exe. Correlated with Event ID 11 showing the file was downloaded via browser.
Result: Confirmed process injection attack. Isolated the endpoint, extracted the malicious binary for analysis, and created detection rule for CreateRemoteThread from user-writable directories.

βœ… Best Practices

❌ Common Misconceptions

πŸ“š References