SlideShare a Scribd company logo
June 12, 2017
Hunting In Memory
Jared Atkinson, Joe Desimone
Who are we
▪ Jared Atkinson
• Defensive Service Technical Director - Specter Ops
• Microsoft Cloud and Datacenter Management MVP (PowerShell)
• Lead Developer PowerForensics
▪ Joe Desimone
• Senior Malware Researcher - Endgame
• Developer, Hunter, Reverse Engineer
Overview
▪ Why hunting in memory is important
▪ Memory based attacker techniques
▪ Existing tools and approaches
▪ New powershell tool for hunting at scale
Importance of Memory Hunting
▪ Memory resident malware has been in use for over a decade, and is now ubiquitous
▪ Once a staple of ‘APT’; now commonplace for crimeware
▪ Designed to evade PSPs and YOU
▪ Great signal to noise ratio; easy button hunting
Attacker Techniques
▪ Classic memory/shellcode injection
▪ Reflective DLLs
▪ Memory Module
▪ Process and Module Hollowing
▪ PEB Unlinking
▪ Gargoyle (ROP/APCs)
Classic Injection
▪ OpenProcess - Grab handle to target process
▪ VirtualAllocEx - Allocate a new chunk of memory in targe
▪ WriteProcessMemory - Write the shellcode/payload into target
▪ CreateRemoteThread - Start a new thread to execute the payload
Classic Injection - Poison Ivy
Poison Ivy
Poison Ivy
Poison Ivy Thread
Reflective DLL Injection
▪ DLL that maps itself into memory - original design and code by Steven Fewer [1]
▪ Handy from attacker perspective - makes for a ‘dumb’ injector
▪ No longer have to code in assembly (like PI)
▪ Very common technique (ex: meterpreter, powershell empire)
▪ Allocate memory, map sections, resolve imports, fixup relocations, call entry
[1] https://github.com/stephenfewer/ReflectiveDLLInjection
Meterpreter
▪ Classic DLL Reflection, such as meterpreter, is easy to find
Meterpreter
Memory Module
▪ Similar to Reflective technique, except loader does all the work [1]
▪ Payload DLL doesn’t need any special modifications
▪ Loader re-implements LoadLibrary(), but works on a buffer in memory
▪ Can map into local or remote process [2]
▪ Typical implementations avoid RWX
[1] Memory Module - https://github.com/fancycode/MemoryModule
[2] Manual Map - https://github.com/DarthTon/Blackbone
NetTraveler - Memory Layout
▪ Uses legitimate looking permissions
NetTraveler - Active Thread
Winnti - Memory Layout
Winnti - Header Wipe
Process Hollowing
▪ Create new, suspended process
▪ Allocate new memory, unmap (hollow) existing code
▪ Write payload
▪ Redirect execution - SetThreadContext() and ResumeThread()
▪ 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
▪ Module Overwriting avoids this, making it more difficult to detect
▪ Flame and Careto are examples
▪ Map an unused module into target process
▪ Overwrite legitimate module with payload
▪ Odinaff had a similar trick but overwrote its own executable
Image Credit: https://kasperskycontenthub.com/wp-content/uploads/sites/43/vlpdfs/unveilingthemask_v1.0.pdf
Odinaff
In Memory On Disk
PEB Unlinking
▪ Not an in memory technique, but rather an evasion
▪ Hide loaded DLL from security products, admins, hunters
▪ HackingTeam used this technique in their RAT
▪ Flame also unlinked shell32.dll
▪ 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
▪ Technique developed by Josh Lospinoso to
hide injected code from security products
▪ Payload lies dormant, with read only
permissions
▪ Periodically ‘wakes up.’ Sets payload
executable with an asynchronous procedure
call and ROP. Permissions reverted, cycle
repeats.
▪ 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
▪ PowerShell module written by Matt Graeber (@mattifestation)
• https://github.com/mattifestation/PSReflect
▪ Avoids the compilation artifacts associated with P/Invoke
• IMO the cleanest way to deal with Win32 API from PowerShell
▪ Library to abstract the complexities of calling Win32 functions via Reflection
▪ Intuitive “domain specific language” for defining enums, structs, and P/Invoke function
signatures
▪ Must include PSReflect code in your scripts/modules
PSReflect
▪ Built on PSReflect
▪ PowerShell function to identify injected threads via detection methodology:
• Use Windows Toolhelp API to get all threads
• Iterate through each thread
• Identify the thread’s Base (Memory) Address
• Query the memory page for which the Base Address belongs to
• Check if the memory page’s state is MEM_COMMIT
• Check if the memory page’s type is not MEM_IMAGE
▪ Returns details regarding offending process and thread
• Check memory page permissions
• Look for unnecessary privileges or integrity level
• Identify abnormal user tokens
Get-InjectedThread
▪ Injected Process Information
• Process Id
• Name
• File Path (PEB and EPROCESS)
• Command Line
▪ Thread Information
• Thread Id
• Unique Thread Token
• Base Priority
• Does thread have unique token?
▪ Memory Segment
• Base Address
• Size
• Protection
• State
• Type
• First 100 Bytes
▪ Token (Thread or Process)
• Integrity Level
• Enabled Privileges
• SID / UserName
• Logon Session Start Time
• Logon Type
• Authentication Package
Get-InjectedThread Output
▪ Delivered as .zip file via Google Drive
▪ Zip archive contains one file
• 2nd Myanmar Industrial Resource Development Symposium.exe
• File has PowerPoint icon to trick users into opening
▪ Drops files upon execution
• %USERPROFILE%<random>RealNetwork.exe (Legitimate Application)
• %USERPROFILE%<random>main.dll (Loaded by MPAMedia.dll)
• %USERPROFILE%<ramdom>mpapluginsMPAMedia.dll (DLL Side Loading)
• Ppt
∙ Opened in PowerPoint to keep up the ruse
Our Threat - 9002 Trojan
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?

More Related Content

PDF
CISSP Prep: Ch 1: Security Governance Through Principles and Policies
PDF
Rothke secure360 building a security operations center (soc)
PPTX
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 1, 2, 3
PPTX
ATT&CKing with Threat Intelligence
PDF
ATT&CKing Your Adversaries - Operationalizing cyber intelligence in your own ...
PPTX
Threat hunting foundations: People, process and technology.pptx
PPTX
CISSP - Security Assessment
PDF
Building a Security Operations Center (SOC).pdf
CISSP Prep: Ch 1: Security Governance Through Principles and Policies
Rothke secure360 building a security operations center (soc)
Beyaz Şapkalı Hacker CEH Eğitimi - Bölüm 1, 2, 3
ATT&CKing with Threat Intelligence
ATT&CKing Your Adversaries - Operationalizing cyber intelligence in your own ...
Threat hunting foundations: People, process and technology.pptx
CISSP - Security Assessment
Building a Security Operations Center (SOC).pdf

What's hot (20)

PPTX
Metasploit framwork
PPTX
Security testing
PDF
Local File Inclusion to Remote Code Execution
PPTX
VAPT PRESENTATION full.pptx
PDF
How to Hunt for Lateral Movement on Your Network
PPTX
Rest API Security
PPTX
Catch Me If You Can: PowerShell Red vs Blue
PPTX
Client side attacks using PowerShell
PPTX
[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...
PPTX
Windows Forensic 101
PPTX
Threat hunting for Beginners
PDF
Hunting for Credentials Dumping in Windows Environment
PPTX
Password Attack
PDF
PPTX
Invoke-Obfuscation DerbyCon 2016
PDF
Privilege escalation from 1 to 0 Workshop
PPTX
OWASP Top 10 2021 What's New
PDF
Bug Bounty Hunter Methodology - Nullcon 2016
PDF
MITRE AttACK framework it is time you took notice_v1.0
Metasploit framwork
Security testing
Local File Inclusion to Remote Code Execution
VAPT PRESENTATION full.pptx
How to Hunt for Lateral Movement on Your Network
Rest API Security
Catch Me If You Can: PowerShell Red vs Blue
Client side attacks using PowerShell
[CB16] Invoke-Obfuscation: PowerShell obFUsk8tion Techniques & How To (Try To...
Windows Forensic 101
Threat hunting for Beginners
Hunting for Credentials Dumping in Windows Environment
Password Attack
Invoke-Obfuscation DerbyCon 2016
Privilege escalation from 1 to 0 Workshop
OWASP Top 10 2021 What's New
Bug Bounty Hunter Methodology - Nullcon 2016
MITRE AttACK framework it is time you took notice_v1.0
Ad

Similar to Taking Hunting to the Next Level: Hunting in Memory (20)

PDF
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
PDF
Process injection - Malware style
PPTX
Attack on the Core
PPTX
0x02 - Windows Privilege Esc - A Low Level Explanation of Token Theft
PPTX
0x002 - Windows Priv Esc - A Low Level Explanation of Token Theft
PPTX
Ice Age melting down: Intel features considered usefull!
PPTX
Advanced windows debugging
PDF
One-Byte Modification for Breaking Memory Forensic Analysis
PPTX
Practical Windows Kernel Exploitation
PPTX
Injection on Steroids: Codeless code injection and 0-day techniques
PPTX
Offensive Python for Pentesting
PDF
Application Profiling for Memory and Performance
PPTX
Metasploit & Windows Kernel Exploitation
PDF
C++ Programming and the Persistent Memory Developers Kit
PPTX
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
PPTX
Application Profiling for Memory and Performance
KEY
No locked doors, no windows barred: hacking OpenAM infrastructure
PPT
JavaScript Event Loop
PPTX
Owning computers without shell access 2
PPTX
Racing with Droids
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
Process injection - Malware style
Attack on the Core
0x02 - Windows Privilege Esc - A Low Level Explanation of Token Theft
0x002 - Windows Priv Esc - A Low Level Explanation of Token Theft
Ice Age melting down: Intel features considered usefull!
Advanced windows debugging
One-Byte Modification for Breaking Memory Forensic Analysis
Practical Windows Kernel Exploitation
Injection on Steroids: Codeless code injection and 0-day techniques
Offensive Python for Pentesting
Application Profiling for Memory and Performance
Metasploit & Windows Kernel Exploitation
C++ Programming and the Persistent Memory Developers Kit
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Application Profiling for Memory and Performance
No locked doors, no windows barred: hacking OpenAM infrastructure
JavaScript Event Loop
Owning computers without shell access 2
Racing with Droids
Ad

Recently uploaded (20)

PPTX
A Presentation on Artificial Intelligence
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Spectroscopy.pptx food analysis technology
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
1. Introduction to Computer Programming.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation theory and applications.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
A Presentation on Artificial Intelligence
Network Security Unit 5.pdf for BCA BBA.
MIND Revenue Release Quarter 2 2025 Press Release
Spectroscopy.pptx food analysis technology
20250228 LYD VKU AI Blended-Learning.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
1. Introduction to Computer Programming.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Digital-Transformation-Roadmap-for-Companies.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf
Unlocking AI with Model Context Protocol (MCP)
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation theory and applications.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Encapsulation_ Review paper, used for researhc scholars
SOPHOS-XG Firewall Administrator PPT.pptx
Assigned Numbers - 2025 - Bluetooth® Document

Taking Hunting to the Next Level: Hunting in Memory

  • 1. June 12, 2017 Hunting In Memory Jared Atkinson, Joe Desimone
  • 2. Who are we ▪ Jared Atkinson • Defensive Service Technical Director - Specter Ops • Microsoft Cloud and Datacenter Management MVP (PowerShell) • Lead Developer PowerForensics ▪ Joe Desimone • Senior Malware Researcher - Endgame • Developer, Hunter, Reverse Engineer
  • 3. Overview ▪ Why hunting in memory is important ▪ Memory based attacker techniques ▪ Existing tools and approaches ▪ New powershell tool for hunting at scale
  • 4. Importance of Memory Hunting ▪ Memory resident malware has been in use for over a decade, and is now ubiquitous ▪ Once a staple of ‘APT’; now commonplace for crimeware ▪ Designed to evade PSPs and YOU ▪ Great signal to noise ratio; easy button hunting
  • 5. Attacker Techniques ▪ Classic memory/shellcode injection ▪ Reflective DLLs ▪ Memory Module ▪ Process and Module Hollowing ▪ PEB Unlinking ▪ Gargoyle (ROP/APCs)
  • 6. Classic Injection ▪ OpenProcess - Grab handle to target process ▪ VirtualAllocEx - Allocate a new chunk of memory in targe ▪ WriteProcessMemory - Write the shellcode/payload into target ▪ CreateRemoteThread - Start a new thread to execute the payload
  • 7. Classic Injection - Poison Ivy
  • 11. Reflective DLL Injection ▪ DLL that maps itself into memory - original design and code by Steven Fewer [1] ▪ Handy from attacker perspective - makes for a ‘dumb’ injector ▪ No longer have to code in assembly (like PI) ▪ Very common technique (ex: meterpreter, powershell empire) ▪ Allocate memory, map sections, resolve imports, fixup relocations, call entry [1] https://github.com/stephenfewer/ReflectiveDLLInjection
  • 12. Meterpreter ▪ Classic DLL Reflection, such as meterpreter, is easy to find
  • 14. Memory Module ▪ Similar to Reflective technique, except loader does all the work [1] ▪ Payload DLL doesn’t need any special modifications ▪ Loader re-implements LoadLibrary(), but works on a buffer in memory ▪ Can map into local or remote process [2] ▪ Typical implementations avoid RWX [1] Memory Module - https://github.com/fancycode/MemoryModule [2] Manual Map - https://github.com/DarthTon/Blackbone
  • 15. NetTraveler - Memory Layout ▪ Uses legitimate looking permissions
  • 17. Winnti - Memory Layout
  • 19. Process Hollowing ▪ Create new, suspended process ▪ Allocate new memory, unmap (hollow) existing code ▪ Write payload ▪ Redirect execution - SetThreadContext() and ResumeThread() ▪ Stealthy variants • Create/Map sections to avoid WriteProcessMemory • Modify entry point instead of SetThreadContext
  • 20. DarkComet - Process Hollowing
  • 22. Module Overwriting ▪ Up until now, all examples have lead to non-image backed code executing ▪ Module Overwriting avoids this, making it more difficult to detect ▪ Flame and Careto are examples ▪ Map an unused module into target process ▪ Overwrite legitimate module with payload ▪ Odinaff had a similar trick but overwrote its own executable Image Credit: https://kasperskycontenthub.com/wp-content/uploads/sites/43/vlpdfs/unveilingthemask_v1.0.pdf
  • 24. PEB Unlinking ▪ Not an in memory technique, but rather an evasion ▪ Hide loaded DLL from security products, admins, hunters ▪ HackingTeam used this technique in their RAT ▪ Flame also unlinked shell32.dll ▪ To find peb unlinking, you could compare what the Win32 API reports as ‘loaded’ versus what you find is actually loaded with VirtualQuery/GetSectionName
  • 25. Gargoyle ▪ Technique developed by Josh Lospinoso to hide injected code from security products ▪ Payload lies dormant, with read only permissions ▪ Periodically ‘wakes up.’ Sets payload executable with an asynchronous procedure call and ROP. Permissions reverted, cycle repeats. ▪ https://jlospinoso.github.io/security/assembly/c/cpp/developing/sof tware/2017/03/04/gargoyle-memory-analysis-evasion.html
  • 26. Available Tools ▪ Volatility / malfind ▪ GRR ▪ Rekall ▪ inVtero
  • 28. ▪ PowerShell module written by Matt Graeber (@mattifestation) • https://github.com/mattifestation/PSReflect ▪ Avoids the compilation artifacts associated with P/Invoke • IMO the cleanest way to deal with Win32 API from PowerShell ▪ Library to abstract the complexities of calling Win32 functions via Reflection ▪ Intuitive “domain specific language” for defining enums, structs, and P/Invoke function signatures ▪ Must include PSReflect code in your scripts/modules PSReflect
  • 29. ▪ Built on PSReflect ▪ PowerShell function to identify injected threads via detection methodology: • Use Windows Toolhelp API to get all threads • Iterate through each thread • Identify the thread’s Base (Memory) Address • Query the memory page for which the Base Address belongs to • Check if the memory page’s state is MEM_COMMIT • Check if the memory page’s type is not MEM_IMAGE ▪ Returns details regarding offending process and thread • Check memory page permissions • Look for unnecessary privileges or integrity level • Identify abnormal user tokens Get-InjectedThread
  • 30. ▪ Injected Process Information • Process Id • Name • File Path (PEB and EPROCESS) • Command Line ▪ Thread Information • Thread Id • Unique Thread Token • Base Priority • Does thread have unique token? ▪ Memory Segment • Base Address • Size • Protection • State • Type • First 100 Bytes ▪ Token (Thread or Process) • Integrity Level • Enabled Privileges • SID / UserName • Logon Session Start Time • Logon Type • Authentication Package Get-InjectedThread Output
  • 31. ▪ Delivered as .zip file via Google Drive ▪ Zip archive contains one file • 2nd Myanmar Industrial Resource Development Symposium.exe • File has PowerPoint icon to trick users into opening ▪ Drops files upon execution • %USERPROFILE%<random>RealNetwork.exe (Legitimate Application) • %USERPROFILE%<random>main.dll (Loaded by MPAMedia.dll) • %USERPROFILE%<ramdom>mpapluginsMPAMedia.dll (DLL Side Loading) • Ppt ∙ Opened in PowerPoint to keep up the ruse Our Threat - 9002 Trojan http://researchcenter.paloaltonetworks.com/2016/07/unit-42-attack-delivers-9002-trojan-through-google-drive/
  • 32. 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