Hunting in memory
Hunting in memory
▪ Jared Atkinson
▪ Joe Desimone
▪ Memory resident malware has been in use for over a decade, and is now ubiquitous
▪ Reflective DLLs
▪ Memory Module
▪ PEB Unlinking
▪ Gargoyle (ROP/APCs)
Classic Injection
▪ DLL that maps itself into memory - original design and code by Steven Fewer [1]
▪ Allocate memory, map sections, resolve imports, fixup relocations, call entry
[1] https://github.com/stephenfewer/ReflectiveDLLInjection
Meterpreter
▪ Similar to Reflective technique, except loader does all the work [1]
▪ Write payload
▪ Stealthy variants
• Create/Map sections to avoid WriteProcessMemory
• Modify entry point instead of SetThreadContext
DarkComet - Process Hollowing
DarkComet
Module Overwriting
▪ Up until now, all examples have lead to non-image backed code executing
In Memory On Disk
PEB Unlinking
▪ To find peb unlinking, you could compare what the Win32 API reports as ‘loaded’
versus what you find is actually loaded with VirtualQuery/GetSectionName
Gargoyle
▪ https://jlospinoso.github.io/security/assembly/c/cpp/developing/sof
tware/2017/03/04/gargoyle-memory-analysis-evasion.html
Available Tools
▪ Volatility / malfind
▪ GRR
▪ Rekall
▪ inVtero
Detecting Injection
w/ PowerShell
PSReflect
▪ PowerShell module written by Matt Graeber (@mattifestation)
• https://github.com/mattifestation/PSReflect
▪ Intuitive “domain specific language” for defining enums, structs, and P/Invoke function
signatures
http://researchcenter.paloaltonetworks.com/2016/07/unit-42-attack-delivers-9002-trojan-through-google-drive/
Response
▪ Kill Thread
• Stop-Thread
• Built on Window’s TerminateThread API
▪ Process Minidump
• Out-Minidump (PowerSploit)
• https://github.com/PowerShellMafia/PowerSploit/blob/master/Exfiltration/Out-Minidump.ps1
▪ Thread Dump
• Dump-Thread
Questions?