Code Injection PDF
Code Injection PDF
1
Code Injection Detection
Volatility
ldrmodules Detect unlinked DLLs and non-memory-mapped files
malfind Find hidden and injected code and dump affected memory sections
ptemalfind (Vol3) Upgraded version of malfind using page tables to detect injection
MemProcFS
findevil Plugin used to identify a suite of process inconsistencies
Live Analysis
Moneta Usermode memory scanner for process injection anomalies
3
Simple DLL Injection: Attach and Allocate
1 2
5
Simple DLL Injection: Execute
6
1. Find DLLs introduced using the Windows API
• Code injected using API libraries is often present in PEB and VAD lists
• The Volatility ldrmodules plugin blends information from both
• It is normal for process executable to not be tracked in the InInit list
7
Reflective Code Injection
10
Detecting Code Injection: windows.malfind.Malfind
Purpose
• Scans process memory sections looking for indications of code
injection. Identified sections can be extracted for further analysis.
Important Parameters
• Directory to save extracted files (--dump)
• Show information for specific process IDs (--pid)
Investigative Notes
• Significantly outclassed by new malware, but surprisingly effective
• Useful to understand the challenges of injection detection
• False positives occur and disassembled code is a helpful sanity check
• You might see multiple injected sections within the same process
• Dumped sections can be reverse engineered or scanned with A/V
11
Detecting Code Injection: malfind (Meterpreter)
13
Detecting Code Injection: malfind (No MZ)
Well-known
assembly code
prologue present in
an injected memory
section (also note
lack of MZ header)
15
Detecting Code Injection: malfind (False Positive)
EXE
• Private
Heap • Application Data
• Stack and Heap
Stack
19
MemProcFS FindEvil Detections
Process Irregularities:
PROC_NOLINK Process not in the EPROCESS doubly-linked list
PRIVATE_RWX/RX Executable pages present in private process memory (data, stacks, heaps)
21
MemProcFS FindEvil Example (Emotet)
23
3. Uncover Kernel and Userland Process Inconsistencies
24
Uncovering Process Inconsistencies: windows.ldrmodules
Purpose
• DLLs are tracked in three different linked lists in the PEB for each
process. Code injection attacks often leave DLLs unlinked. This
Volatility plugin queries each list and displays the results for comparison.
Important Parameters
• Show information for specific process IDs (--pid)
Investigative Notes
• DLLs loaded via the legit Windows API will be present in all three lists
• Common false positives:
• The process executable will not be present in the "InInit" list
• Non EXE/DLL files present in image mapped memory (.fon, .mui, .winmd)
• Some legit DLLs can be present in process memory without being loaded
• Volatility 3 often marks SysWOW64 DLLs as not loaded
• Missing "MappedPath" information is another a sign of injection
25
ldrmodules Data Sources
svchost.exe
svchost.exe
26
Detecting Code Injection: ldrmodules (Stuxnet)
Irregularities
PROC_NOLINK Process not in the EPROCESS doubly-linked list
Process
PROC_PARENT Unexpected parent for process (limited checks on well-known processes)
Unusual
NOIMAGE_RWX/RX Executable pages present not mapped to a DLL/EXE location
PRIVATE_RWX/RX Executable pages present in private process memory (data, stacks, heaps)
Kernel/PEB
modification)
PE_NOLINK DLL present in VAD, but not linked in PEB lists. High false positives.
PE_PATCHED DLL modified after load time. Many false positives in 32-bit and JIT code
28
MemProcFS FindEvil Detections (2)
• A DLL hollowing attack in sdev.exe (unlinked DLL in PEB)
• notepad.exe shows evidence of reflective injection
29
MemProcFS FindEvil Next Steps
30
MemProcFS FindEvil False Positives
31
Look for Evidence of Code Injection Review
• Code injection is a very popular means for malware to
hide and launder its activities
• Three common injection methods are:
• Simple DLL Injection
• Reflective Code Injection
• Process Hollowing
• Identifying processes with injected memory sections is
difficult in disk-based forensics, but much more feasible
using memory analysis
• ldrmodules shows evidence of unlinked/unmapped DLLs
• malfind identifies and dumps suspicious memory sections and processes
• MemProcFS findevil detects a large number of common and advanced
injection techniques
32