SlideShare a Scribd company logo
1 of 42
Download to read offline
You’re Off the Hook:
Blinding Security Software
Alex Matrosov | Principal Research Scientist
Jeff Tang | Senior Security Researcher
Who We Are - Alex
§ Principal REsearch Scientist @CylanceInc
§ Previously @IntelSecurity / @ESET
§ Co-author of Rootkits and Bootkits: Reversing Modern
Malware and Next Generation Threats
§ @matrosov @matrosov
Who We Are - Jeff
§ Senior Security Researcher @CylanceInc
§ Formerly @VAHNA / @NSAGov
§ Hates computers – career dedicated to breaking computers
§ @mrjefftang @mrjefftang
Overview
§ Why user-mode hooks?
§ Hooking Basics
§ Hooking Vulnerabilities (Captain Hook)
§ Control Flow Guard / Return Flow Guard
§ Universal Unhooking
§ Demo / Results
Why user-mode hooking?
§ Kernel Patch Protection (KPP) a.k.a. “PatchGuard”
§ Introduced in 2005 for Windows 2003 SP1 x64 – multiple revisions since then
§ Prevents modification to the Windows kernel and kernel data structures
§ IDT, GDT, SSDT, MSR, System PE Images
§ Analysis and bypasses documented by various security researchers (skape, skywing)
§ Bypasses implemented by malware rootkits (Uroburos)
§ Incrementally updated to address deficiencies and block bypasses
§ Creates an arms race between independent software vendors (ISV) and Microsoft
§ Forces security vendors to rely on user-mode hooking in order to monitor processes for
malicious behavior
§ http://blog.talosintel.com/2014/08/the-windows-81-kernel-patch-protection.html
User-Mode Hooking Basics
§ IAT Hooking
§ Replace address of target function in IAT with address to a new function
§ Inline Hooking
§ Replaces the prologue of target functions with a jmp to a detour
§ Detour function calls a trampoline function
§ Trampoline function contains the function’s original prologue and jmp into the original function
§ Original function returns into detour
§ Detour returns to caller
§ http://jbremer.org/x86-api-hooking-demystified/
(Inline) Hooking Basics
Inline Hooking
Hooking Issues (Captain Hook)
§ Documented by the enSilo Research Team & presented at BlackHat US 2016
§ Captain Hook: Pirating AVs to Bypass Exploit Mitigations
§ Discovered 6 classes of major vulnerabilities in user-mode hooking
Hooking Issues (Captain Hook)
https://www.blackhat.com/docs/us-16/materials/us-16-Yavo-Captain-Hook-Pirating-AVs-To-Bypass-Exploit-Mitigations.pdf
Hooking Issues (Captain Hook)
§ Unsafe Injection
§ Predictable RWX (Universal)
§ Predictable RX
§ Predictable RWX (Windows 7 and below)
§ RWX Hook Code Stubs
§ RWX Hooked Modules
https://www.blackhat.com/docs/us-16/materials/us-16-Yavo-Captain-Hook-Pirating-AVs-To-Bypass-Exploit-Mitigations.pdf
Control Flow Guard (CFG)
§ Introduced with Windows 10 / Windows 8.1 Update 3
§ Requires support from the compiler/linker and operating system
§ Compiler generates CFG instrumented binaries (/guard:cf)
§ Embeds a CFG Bitmap representing valid indirect call locations
§ Inserts _guard_check_icall before indirect calls
§ Operating system supports CFG at run time:
§ Supported OS maps guard check to ntdll!LdrpValidateUserCallTarget
§ Unsupported OS is just a simple ret
§ Not perfect, there are bypasses available
§ Functions left RWX by a hooking engine bypass CFG as they can be overwritten with shellcode
Return Flow Guard (RFG)
§ Upcoming technology likely to be introduced in Windows 10 Creators Update
§ Protects return address by comparing it to the saved value on a shadow stack (fs:[rsp])
§ Requires support from the compiler/linker and operating system
§ Compiler generates an RFG instrumented binary
§ Inserts no-op padding in function prologue and epilogues
§ Operating system supports RFG at run time:
§ Overwrites prologue with instructions to save return address to shadow stack
§ Overwrites epilogue with instructions to check return address against shadow stack
§ http://xlab.tencent.com/en/2016/11/02/return-flow-guard/
Return Flow Guard (RFG)
Return Flow Guard (RFG)
Prior Work
§ Unhooking has been around for a long time
§ Generally relies on identifying specific hooking methods/signatures
§ Focuses in hooks installed in function prologues
§ https://breakdev.org/defeating-antivirus-real-time-protection-from-the-inside/
§ In-memory RFG instrumented binaries will be different than on-disk – unhooking will remove the
RFG prologue/epilogue patches
§ Endpoint detect & respond (EDR) products rely heavily on user-mode hooking for telemetry
Universal Unhooking DLL
§ For each module in PEB_LDR_DATA->InMemoryOrderModuleList:
ü Load the module from disk
ü Allocate a new memory space of NtHeader->OptionalHeader.SizeOfImage
ü Perform PE relocations based off original module base address
ü Resolve Import Address Table (IAT)
ü Compare our new copy with the original copy
ü Copy over our pristine copy if changes are detected
§ Based off of Stephen Fewer’s Reflective DLL Injection code
Universal Unhooking DLL - Loading
§ Load the file into memory
ü CreateFile(“ntdll.dll”, …)
ü CreateFileMapping(...)
ü MapViewOfFile(...)
ü <new base address> = VirtualAlloc(...,
NtHeader->Optionalheader.SizeOfImage, …)
§ Copy PE sections into correct location in memory
ü memcpy(<new base address> + SectionHeader->VirtualAddress,
SectionHeader->PointerToRawData)
Universal Unhooking DLL - Relocation
§ The normal relocation process adds an image delta to each relocation
ü delta = loaded base address - OptionalHeader.ImageBase
§ Or it adds the high/low word of the delta depending on relocation type
§ Our unhooking code performs relocation with the loaded base address of the original loaded DLL
ü delta = original base address - OptionalHeader.ImageBase
§ This gives us a binary copy of what the DLL looked like after being loaded but
before being hooked
Universal Unhooking DLL – Import Resolution
§ Need to resolve the import table without bringing in a hooked function
§ Custom GetProcAddress to parse the IMAGE_EXPORT_DIRECTORY of each module
§ Must support export forward descriptors and API Sets
§ A forward descriptor is a function that resolves to a virtual address within the
IMAGE_EXPORT_DIRECTORY address space
Universal Unhooking DLL – Import Resolution
API Set Schema
§ Introduced in Windows 7 (v2) as part of project “MinWin”
§ Updated in Windows 8.1 (v4) and Windows 10 (v6)
§ Mapping of “Virtual DLLs” to “Logical DLLs” stored in apisetschema.dll
§ Very little documented information on API Set Schema
§ http://www.geoffchappell.com/studies/windows/win32/apisetschema/index.htm
§ http://blog.quarkslab.com/runtime-dll-name-resolution-apisetschema-part-i.html
§ http://blog.quarkslab.com/runtime-dll-name-resolution-apisetschema-part-ii.html
API Set Schema - Example
API Set Schema - Evolution
API Set Schema
Universal Unhooking DLL – Compare & Restore
§ Compare each PE section of the original loaded DLL to our version
§ Replace any sections which are different
§ Return back to initial program to continue execution without hooks
Reflective DLL
§ The universal unhooking code is compiled as a reflective DLL
§ Meterpreter: post/windows/manage/reflective_dll_inject
§ Can be injected into everything!
Meterpreter
§ Meterpreter server is already delivered as a Reflective DLL
§ Security software could detect Meterpreter initialization prior to unhooking
§ Solution: Modify meterpreter server to call unhooking code before connection initialization
§ Drop in replacement for Metasploit installs
§ Copy modified metsrv.dll to metasploit-framework/data/meterpreter/
UPX
§ Why UPX?
§ It’s well known and open-source
§ Modify UPX to insert an extra section ‘UPX3’ containing arbitrary reflective DLL
§ UPX decoder stub unpacks original binary and resolves imports
§ Decoder calls the first export in the reflective DLL (ReflectiveLoader())
§ Unhooking code runs and removes any hooks detected
§ Stub decoder jumps to original entry point (OEP)
§ Note: Reflective DLL is not compressed by UPX
§ Also blows up the size of the final packed executable
UPX
UPX
§ Final basic block of UPX stub decoder
§ call sub_5C46A0 – ReflectiveLoader()
§ jmp word_46E0E6 – Original Entry Point (OEP)
§ Note: On 64-bit platforms, rsp must be 16-bit aligned
before the call to ReflectiveLoader()
UPX
§ Problem: Once UPX unpacks binary into memory, it will be different compared to on disk copy –
how does the unhooking code avoid reloading packed binary into memory?
UPX
§ Unhooking code ignores any PE section with IMAGE_SCN_MEM_WRITE (0x80000000)
§ UPX marks every section as PEFL_WRITE == IMAGE_SCN_MEM_WRITE
UPX
Demo
Results
Software Result
BitDefender Success - Bypassed
Dr. Web Success - Bypassed
ESET Blocked
Kaspersky Blocked
Symantec Success - Unaffected
McAfee Success - Unaffected
TrendMicro Success - Unaffected
EMET Success - Unaffected
Blinding Security Software
Future Work
§ Improve UPX modifications to compress/pack the reflective DLL
§ Update ReflectiveLoader() to perform unhooking checks and repairs
§ Support for other packing software?
Closing
§ User-mode hooking is fragile and easily bypassed
§ Relying on user-mode hooking for protection is ineffective
§ Critical need for OS support to provide callbacks and APIs for monitoring system behavior
§ Source code will be released soon @ https://github.com/CylanceVulnResearch/
QUESTIONS
AND
ANSWERS
THANK YOU
ZERONIGHTS 2016
You're Off the Hook: Blinding Security Software

More Related Content

What's hot

Tracking vulnerable JARs
Tracking vulnerable JARsTracking vulnerable JARs
Tracking vulnerable JARs
David Jorm
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty
 
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
CanSecWest
 
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
Macpaul Lin
 
Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharing
James Hsieh
 

What's hot (20)

Breaking paravirtualized devices
Breaking paravirtualized devicesBreaking paravirtualized devices
Breaking paravirtualized devices
 
PowerShell Inside Out: Applied .NET Hacking for Enhanced Visibility by Satosh...
PowerShell Inside Out: Applied .NET Hacking for Enhanced Visibility by Satosh...PowerShell Inside Out: Applied .NET Hacking for Enhanced Visibility by Satosh...
PowerShell Inside Out: Applied .NET Hacking for Enhanced Visibility by Satosh...
 
A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...
A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...
A New Era of SSRF - Exploiting URL Parser in Trending Programming Languages! ...
 
Digging for Android Kernel Bugs
Digging for Android Kernel BugsDigging for Android Kernel Bugs
Digging for Android Kernel Bugs
 
Tracking vulnerable JARs
Tracking vulnerable JARsTracking vulnerable JARs
Tracking vulnerable JARs
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
 
Find your own iOS kernel bug
Find your own iOS kernel bugFind your own iOS kernel bug
Find your own iOS kernel bug
 
Crash Dump Analysis 101
Crash Dump Analysis 101Crash Dump Analysis 101
Crash Dump Analysis 101
 
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
 
Lecture1: NGS Analysis on Beocat and an introduction to Perl programming for ...
Lecture1: NGS Analysis on Beocat and an introduction to Perl programming for ...Lecture1: NGS Analysis on Beocat and an introduction to Perl programming for ...
Lecture1: NGS Analysis on Beocat and an introduction to Perl programming for ...
 
Automotive Grade Linux and systemd
Automotive Grade Linux and systemdAutomotive Grade Linux and systemd
Automotive Grade Linux and systemd
 
Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!Ice Age melting down: Intel features considered usefull!
Ice Age melting down: Intel features considered usefull!
 
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applications
 
Tip: How to enable wireless debugging with Android?
Tip: How to enable wireless debugging with Android?Tip: How to enable wireless debugging with Android?
Tip: How to enable wireless debugging with Android?
 
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
從u-boot 移植 NDS32 談 嵌入式系統開放原始碼開發的 一些經驗
 
How to Root 10 Million Phones with One Exploit
How to Root 10 Million Phones with One ExploitHow to Root 10 Million Phones with One Exploit
How to Root 10 Million Phones with One Exploit
 
Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharing
 
Rainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could ExpectRainbow Over the Windows: More Colors Than You Could Expect
Rainbow Over the Windows: More Colors Than You Could Expect
 
Kernel Recipes 2015: Anatomy of an atomic KMS driver
Kernel Recipes 2015: Anatomy of an atomic KMS driverKernel Recipes 2015: Anatomy of an atomic KMS driver
Kernel Recipes 2015: Anatomy of an atomic KMS driver
 

Viewers also liked

CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_markCSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
CanSecWest
 
CSW2017 Qidan he+Gengming liu_cansecwest2017
CSW2017 Qidan he+Gengming liu_cansecwest2017CSW2017 Qidan he+Gengming liu_cansecwest2017
CSW2017 Qidan he+Gengming liu_cansecwest2017
CanSecWest
 

Viewers also liked (18)

Embracing Threat Intelligence and Finding ROI in Your Decision
Embracing Threat Intelligence and Finding ROI in Your DecisionEmbracing Threat Intelligence and Finding ROI in Your Decision
Embracing Threat Intelligence and Finding ROI in Your Decision
 
Exploring the Capabilities and Economics of Cybercrime
Exploring the Capabilities and Economics of CybercrimeExploring the Capabilities and Economics of Cybercrime
Exploring the Capabilities and Economics of Cybercrime
 
Corporations - the new victims of targeted ransomware
Corporations - the new victims of targeted ransomwareCorporations - the new victims of targeted ransomware
Corporations - the new victims of targeted ransomware
 
UEFI Firmware Rootkits: Myths and Reality
UEFI Firmware Rootkits: Myths and RealityUEFI Firmware Rootkits: Myths and Reality
UEFI Firmware Rootkits: Myths and Reality
 
Zeronights 2016 | A blow under the belt. How to avoid WAF/IPS/DLP | Удар ниже...
Zeronights 2016 | A blow under the belt. How to avoid WAF/IPS/DLP | Удар ниже...Zeronights 2016 | A blow under the belt. How to avoid WAF/IPS/DLP | Удар ниже...
Zeronights 2016 | A blow under the belt. How to avoid WAF/IPS/DLP | Удар ниже...
 
Presentación cylance
Presentación cylancePresentación cylance
Presentación cylance
 
DeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows KernelDeathNote of Microsoft Windows Kernel
DeathNote of Microsoft Windows Kernel
 
Robots are among us, but who takes responsibility?
Robots are among us, but who takes responsibility?Robots are among us, but who takes responsibility?
Robots are among us, but who takes responsibility?
 
Cylance Protect-Next-Generation Antivirus-Overview
Cylance Protect-Next-Generation Antivirus-OverviewCylance Protect-Next-Generation Antivirus-Overview
Cylance Protect-Next-Generation Antivirus-Overview
 
The Case For Continuous Security
The Case For Continuous SecurityThe Case For Continuous Security
The Case For Continuous Security
 
Cylance Information Security: Compromise Assessment Datasheet
Cylance Information Security: Compromise Assessment DatasheetCylance Information Security: Compromise Assessment Datasheet
Cylance Information Security: Compromise Assessment Datasheet
 
How to Close the SecOps Gap
How to Close the SecOps GapHow to Close the SecOps Gap
How to Close the SecOps Gap
 
10 Hot Digital UK Start-ups To Watch In 2017
10 Hot Digital UK Start-ups To Watch In 201710 Hot Digital UK Start-ups To Watch In 2017
10 Hot Digital UK Start-ups To Watch In 2017
 
end-to-end service management with ServiceNow (English)
end-to-end service management with ServiceNow (English)end-to-end service management with ServiceNow (English)
end-to-end service management with ServiceNow (English)
 
Applying eTOM (enhanced Telecom Operations Map) Framework to Non-Telecommunic...
Applying eTOM (enhanced Telecom Operations Map) Framework to Non-Telecommunic...Applying eTOM (enhanced Telecom Operations Map) Framework to Non-Telecommunic...
Applying eTOM (enhanced Telecom Operations Map) Framework to Non-Telecommunic...
 
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_markCSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
CSW2017 Peng qiu+shefang-zhong win32k -dark_composition_finnal_finnal_rm_mark
 
CSW2017 Qidan he+Gengming liu_cansecwest2017
CSW2017 Qidan he+Gengming liu_cansecwest2017CSW2017 Qidan he+Gengming liu_cansecwest2017
CSW2017 Qidan he+Gengming liu_cansecwest2017
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Similar to You're Off the Hook: Blinding Security Software

Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
Priyanka Aash
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerun
idsecconf
 

Similar to You're Off the Hook: Blinding Security Software (20)

Buffer overflow – Smashing The Stack
Buffer overflow – Smashing The StackBuffer overflow – Smashing The Stack
Buffer overflow – Smashing The Stack
 
Shellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and ConceptShellcode Analysis - Basic and Concept
Shellcode Analysis - Basic and Concept
 
OpenSCAP Overview(security scanning for docker image and container)
OpenSCAP Overview(security scanning for docker image and container)OpenSCAP Overview(security scanning for docker image and container)
OpenSCAP Overview(security scanning for docker image and container)
 
Buffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the StackBuffer Overflow - Smashing the Stack
Buffer Overflow - Smashing the Stack
 
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
Smash the Stack: Writing a Buffer Overflow Exploit (Win32)
 
Ropython-windbg-python-extensions
Ropython-windbg-python-extensionsRopython-windbg-python-extensions
Ropython-windbg-python-extensions
 
How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...
 
The Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldThe Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote World
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
 
Using VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear ContainersUsing VPP and SRIO-V with Clear Containers
Using VPP and SRIO-V with Clear Containers
 
Finding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated DisassemblyFinding Xori: Malware Analysis Triage with Automated Disassembly
Finding Xori: Malware Analysis Triage with Automated Disassembly
 
App container rkt
App container rktApp container rkt
App container rkt
 
Linux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - WonokaerunLinux kernel-rootkit-dev - Wonokaerun
Linux kernel-rootkit-dev - Wonokaerun
 
Spark Summit EU talk by Jorg Schad
Spark Summit EU talk by Jorg SchadSpark Summit EU talk by Jorg Schad
Spark Summit EU talk by Jorg Schad
 
Squash Those IoT Security Bugs with a Hardened System Profile
Squash Those IoT Security Bugs with a Hardened System ProfileSquash Those IoT Security Bugs with a Hardened System Profile
Squash Those IoT Security Bugs with a Hardened System Profile
 
PTK 1.0 official presentation
PTK 1.0 official presentationPTK 1.0 official presentation
PTK 1.0 official presentation
 
FortranCon2020: Highly Parallel Fortran and OpenACC Directives
FortranCon2020: Highly Parallel Fortran and OpenACC DirectivesFortranCon2020: Highly Parallel Fortran and OpenACC Directives
FortranCon2020: Highly Parallel Fortran and OpenACC Directives
 
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
 
Chasing the Adder. A tale from the APT world...
Chasing the Adder. A tale from the APT world...Chasing the Adder. A tale from the APT world...
Chasing the Adder. A tale from the APT world...
 
Nodejs Intro Part One
Nodejs Intro Part OneNodejs Intro Part One
Nodejs Intro Part One
 

Recently uploaded

Recently uploaded (20)

Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 

You're Off the Hook: Blinding Security Software

  • 1. You’re Off the Hook: Blinding Security Software Alex Matrosov | Principal Research Scientist Jeff Tang | Senior Security Researcher
  • 2. Who We Are - Alex § Principal REsearch Scientist @CylanceInc § Previously @IntelSecurity / @ESET § Co-author of Rootkits and Bootkits: Reversing Modern Malware and Next Generation Threats § @matrosov @matrosov
  • 3. Who We Are - Jeff § Senior Security Researcher @CylanceInc § Formerly @VAHNA / @NSAGov § Hates computers – career dedicated to breaking computers § @mrjefftang @mrjefftang
  • 4. Overview § Why user-mode hooks? § Hooking Basics § Hooking Vulnerabilities (Captain Hook) § Control Flow Guard / Return Flow Guard § Universal Unhooking § Demo / Results
  • 5. Why user-mode hooking? § Kernel Patch Protection (KPP) a.k.a. “PatchGuard” § Introduced in 2005 for Windows 2003 SP1 x64 – multiple revisions since then § Prevents modification to the Windows kernel and kernel data structures § IDT, GDT, SSDT, MSR, System PE Images § Analysis and bypasses documented by various security researchers (skape, skywing) § Bypasses implemented by malware rootkits (Uroburos) § Incrementally updated to address deficiencies and block bypasses § Creates an arms race between independent software vendors (ISV) and Microsoft § Forces security vendors to rely on user-mode hooking in order to monitor processes for malicious behavior § http://blog.talosintel.com/2014/08/the-windows-81-kernel-patch-protection.html
  • 6. User-Mode Hooking Basics § IAT Hooking § Replace address of target function in IAT with address to a new function § Inline Hooking § Replaces the prologue of target functions with a jmp to a detour § Detour function calls a trampoline function § Trampoline function contains the function’s original prologue and jmp into the original function § Original function returns into detour § Detour returns to caller § http://jbremer.org/x86-api-hooking-demystified/
  • 9. Hooking Issues (Captain Hook) § Documented by the enSilo Research Team & presented at BlackHat US 2016 § Captain Hook: Pirating AVs to Bypass Exploit Mitigations § Discovered 6 classes of major vulnerabilities in user-mode hooking
  • 10. Hooking Issues (Captain Hook) https://www.blackhat.com/docs/us-16/materials/us-16-Yavo-Captain-Hook-Pirating-AVs-To-Bypass-Exploit-Mitigations.pdf
  • 11. Hooking Issues (Captain Hook) § Unsafe Injection § Predictable RWX (Universal) § Predictable RX § Predictable RWX (Windows 7 and below) § RWX Hook Code Stubs § RWX Hooked Modules https://www.blackhat.com/docs/us-16/materials/us-16-Yavo-Captain-Hook-Pirating-AVs-To-Bypass-Exploit-Mitigations.pdf
  • 12. Control Flow Guard (CFG) § Introduced with Windows 10 / Windows 8.1 Update 3 § Requires support from the compiler/linker and operating system § Compiler generates CFG instrumented binaries (/guard:cf) § Embeds a CFG Bitmap representing valid indirect call locations § Inserts _guard_check_icall before indirect calls § Operating system supports CFG at run time: § Supported OS maps guard check to ntdll!LdrpValidateUserCallTarget § Unsupported OS is just a simple ret § Not perfect, there are bypasses available § Functions left RWX by a hooking engine bypass CFG as they can be overwritten with shellcode
  • 13. Return Flow Guard (RFG) § Upcoming technology likely to be introduced in Windows 10 Creators Update § Protects return address by comparing it to the saved value on a shadow stack (fs:[rsp]) § Requires support from the compiler/linker and operating system § Compiler generates an RFG instrumented binary § Inserts no-op padding in function prologue and epilogues § Operating system supports RFG at run time: § Overwrites prologue with instructions to save return address to shadow stack § Overwrites epilogue with instructions to check return address against shadow stack § http://xlab.tencent.com/en/2016/11/02/return-flow-guard/
  • 16. Prior Work § Unhooking has been around for a long time § Generally relies on identifying specific hooking methods/signatures § Focuses in hooks installed in function prologues § https://breakdev.org/defeating-antivirus-real-time-protection-from-the-inside/ § In-memory RFG instrumented binaries will be different than on-disk – unhooking will remove the RFG prologue/epilogue patches § Endpoint detect & respond (EDR) products rely heavily on user-mode hooking for telemetry
  • 17. Universal Unhooking DLL § For each module in PEB_LDR_DATA->InMemoryOrderModuleList: ü Load the module from disk ü Allocate a new memory space of NtHeader->OptionalHeader.SizeOfImage ü Perform PE relocations based off original module base address ü Resolve Import Address Table (IAT) ü Compare our new copy with the original copy ü Copy over our pristine copy if changes are detected § Based off of Stephen Fewer’s Reflective DLL Injection code
  • 18. Universal Unhooking DLL - Loading § Load the file into memory ü CreateFile(“ntdll.dll”, …) ü CreateFileMapping(...) ü MapViewOfFile(...) ü <new base address> = VirtualAlloc(..., NtHeader->Optionalheader.SizeOfImage, …) § Copy PE sections into correct location in memory ü memcpy(<new base address> + SectionHeader->VirtualAddress, SectionHeader->PointerToRawData)
  • 19. Universal Unhooking DLL - Relocation § The normal relocation process adds an image delta to each relocation ü delta = loaded base address - OptionalHeader.ImageBase § Or it adds the high/low word of the delta depending on relocation type § Our unhooking code performs relocation with the loaded base address of the original loaded DLL ü delta = original base address - OptionalHeader.ImageBase § This gives us a binary copy of what the DLL looked like after being loaded but before being hooked
  • 20. Universal Unhooking DLL – Import Resolution § Need to resolve the import table without bringing in a hooked function § Custom GetProcAddress to parse the IMAGE_EXPORT_DIRECTORY of each module § Must support export forward descriptors and API Sets § A forward descriptor is a function that resolves to a virtual address within the IMAGE_EXPORT_DIRECTORY address space
  • 21. Universal Unhooking DLL – Import Resolution
  • 22. API Set Schema § Introduced in Windows 7 (v2) as part of project “MinWin” § Updated in Windows 8.1 (v4) and Windows 10 (v6) § Mapping of “Virtual DLLs” to “Logical DLLs” stored in apisetschema.dll § Very little documented information on API Set Schema § http://www.geoffchappell.com/studies/windows/win32/apisetschema/index.htm § http://blog.quarkslab.com/runtime-dll-name-resolution-apisetschema-part-i.html § http://blog.quarkslab.com/runtime-dll-name-resolution-apisetschema-part-ii.html
  • 23. API Set Schema - Example
  • 24. API Set Schema - Evolution
  • 26. Universal Unhooking DLL – Compare & Restore § Compare each PE section of the original loaded DLL to our version § Replace any sections which are different § Return back to initial program to continue execution without hooks
  • 27. Reflective DLL § The universal unhooking code is compiled as a reflective DLL § Meterpreter: post/windows/manage/reflective_dll_inject § Can be injected into everything!
  • 28. Meterpreter § Meterpreter server is already delivered as a Reflective DLL § Security software could detect Meterpreter initialization prior to unhooking § Solution: Modify meterpreter server to call unhooking code before connection initialization § Drop in replacement for Metasploit installs § Copy modified metsrv.dll to metasploit-framework/data/meterpreter/
  • 29. UPX § Why UPX? § It’s well known and open-source § Modify UPX to insert an extra section ‘UPX3’ containing arbitrary reflective DLL § UPX decoder stub unpacks original binary and resolves imports § Decoder calls the first export in the reflective DLL (ReflectiveLoader()) § Unhooking code runs and removes any hooks detected § Stub decoder jumps to original entry point (OEP) § Note: Reflective DLL is not compressed by UPX § Also blows up the size of the final packed executable
  • 30. UPX
  • 31. UPX § Final basic block of UPX stub decoder § call sub_5C46A0 – ReflectiveLoader() § jmp word_46E0E6 – Original Entry Point (OEP) § Note: On 64-bit platforms, rsp must be 16-bit aligned before the call to ReflectiveLoader()
  • 32. UPX § Problem: Once UPX unpacks binary into memory, it will be different compared to on disk copy – how does the unhooking code avoid reloading packed binary into memory?
  • 33. UPX § Unhooking code ignores any PE section with IMAGE_SCN_MEM_WRITE (0x80000000) § UPX marks every section as PEFL_WRITE == IMAGE_SCN_MEM_WRITE
  • 34. UPX
  • 35. Demo
  • 36. Results Software Result BitDefender Success - Bypassed Dr. Web Success - Bypassed ESET Blocked Kaspersky Blocked Symantec Success - Unaffected McAfee Success - Unaffected TrendMicro Success - Unaffected EMET Success - Unaffected
  • 38. Future Work § Improve UPX modifications to compress/pack the reflective DLL § Update ReflectiveLoader() to perform unhooking checks and repairs § Support for other packing software?
  • 39. Closing § User-mode hooking is fragile and easily bypassed § Relying on user-mode hooking for protection is ineffective § Critical need for OS support to provide callbacks and APIs for monitoring system behavior § Source code will be released soon @ https://github.com/CylanceVulnResearch/