SlideShare a Scribd company logo
Bypassing patchguard on Windows 8.1 and Windows 10 
Mark Ermolov, Artem Shishkin 
Positive Technologies
What is patchguard? 
―“Please don’t patch our kernels” call from MS 
―Even if your kernel patch is correct, you’ll catch a BSOD 
•0x109 CRITICAL_STRUCTURE_CORRUPTION 
―Protected structures 
•System images: ntoskrnl.exe, win32k.sys, hal.dll etc. 
•System structures: IDT, GDT, Syscalltables etc. 
―Periodic checksums validation for protected stuff 
―Doesn’t work on Windows 9
What if we really need to? 
―Go for it! 
―But… 
•Patchguard developers are prepared for reverse engineers 
•Hyper-inlinedobfuscation © Alex Ionescu 
•Anti-debugging tricks 
•Several ways of checks invocation
Code obfuscation 
―Symbol stripping
Code obfuscation 
―Misleading names
Code obfuscation 
―Code junk generation 
•Loop unrolling 
•Dead code insertion 
•Indirect calls and variable accesses
Anti-debugging 
―Works only on free builds without kernel debugger!
Anti-debugging 
―Randomly inserted checks for debugger presence
Anti-debugging 
―If you use breakpoints, they will be included to a patchguard checksum, leading to a 0x109 bugcheck 
―If you use hardware breakpoints, well…
Non-linear code flow 
―Active usage of Vectored Exception Handling
Reverse-engineering 
―For dynamic analysis with KD (with windbgf.e.) 
•Remove all kdpresence checks manually 
—Look them up with IDA scripting 
—Apply patches in KD with pykd 
—Do it before “Phase1InitializationDiscard“ 
―For static analysis with IDA 
•Try not to give up waiting for patchguard initialization function decompilation 
―Use something else, like hypervisor-based debugger ;)
Reverse-engineering 
―Since patchguard is developed incrementally, the key functions in reversing it are 
•KiFilterFiberContext–chooses the way for invoking patchguard checks 
•Unnamed sub inside KiFilterFiberContext–creates a structure aka patchguard context and schedules it’s verification 
•Other functions (like context checkers) can be misleadingly named, but you can look them up around KiFilterFiberContextsince they are located in a single compilation unit
Bypassing patchguard 
―There are different approaches 
•patch kernel image so that patchguard will just not start 
•hook KeBugCheckExand restore the state of a system 
•modify checkers so that they would be always valid 
•de-schedule contexts verification 
—This is what we’ve implemented
Contexts verification scheduling 
―Context verification might be launched with 
•KeSetCoalescableTimer 
—A timer that periodically launches context verification 
•Prcb.AcpiReserved 
—A certain ACPI event (f.e. Idle transition) 
•Prcb.HalReserved 
—A haltimer clock 
•PsCreateSystemThread 
—A queued system thread that sleeps a random amount of time 
•KeInsertQueueApc 
—A queued regular kernel APC 
•KiBalanceSetManagerPeriodicDpc 
—A periodic event which happens every "KiBalanceSetManagerPeriod" ticks
Contexts verification descheduling 
―So we’ve got to deschedulecontext verification once and for all 
•KeSetCoalescableTimer 
—Timer? Disable! 
•Prcb.AcpiReserved 
—Zero out this field 
•Prcb.HalReserved 
—Same here 
•PsCreateSystemThread 
—Scan sleeping worker threads and set wait time to infinite for suitable 
•KeInsertQueueApc 
—Same here 
•KiBalanceSetManagerPeriodicDpc 
—Revert to KiBalanceSetManagerDeferredRoutine
•research [at] ptsecurity[dot] com 
•www.ptsecurity.com 
•blog.ptsecurity.com 
Thank you!

More Related Content

PPTX
Injection on Steroids: Codeless code injection and 0-day techniques
PDF
Process injection - Malware style
PPTX
Steelcon 2014 - Process Injection with Python
PPTX
Practical Windows Kernel Exploitation
PPTX
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
PPTX
Security research over Windows #defcon china
PDF
Is That A Penguin In My Windows?
PDF
Practical Malware Analysis Ch12
Injection on Steroids: Codeless code injection and 0-day techniques
Process injection - Malware style
Steelcon 2014 - Process Injection with Python
Practical Windows Kernel Exploitation
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Security research over Windows #defcon china
Is That A Penguin In My Windows?
Practical Malware Analysis Ch12

What's hot (20)

PDF
PPTX
Fun With Dr Brown
PPTX
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
PPTX
[若渴計畫] Black Hat 2017之過去閱讀相關整理
PDF
Us 16-subverting apple-graphics_practical_approaches_to_remotely_gaining_root...
PDF
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
PPTX
Vulnerability desing patterns
PPTX
Guardians of your CODE
PPTX
Back to the CORE
ODP
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
PPTX
Memory Corruption: from sandbox to SMM
PDF
Rainbow Over the Windows: More Colors Than You Could Expect
PDF
CNIT 126: 10: Kernel Debugging with WinDbg
PPTX
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
PDF
BlueHat v18 || Memory resident implants - code injection is alive and well
PPTX
Racing with Droids
PPTX
BH Arsenal '14 TurboTalk: The Veil-framework
PDF
Metasploit - The Exploit Learning Tree
PPTX
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
PDF
Practical Malware Analysis Ch13
Fun With Dr Brown
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
[若渴計畫] Black Hat 2017之過去閱讀相關整理
Us 16-subverting apple-graphics_practical_approaches_to_remotely_gaining_root...
CSW2017Richard Johnson_harnessing intel processor trace on windows for vulner...
Vulnerability desing patterns
Guardians of your CODE
Back to the CORE
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Memory Corruption: from sandbox to SMM
Rainbow Over the Windows: More Colors Than You Could Expect
CNIT 126: 10: Kernel Debugging with WinDbg
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
BlueHat v18 || Memory resident implants - code injection is alive and well
Racing with Droids
BH Arsenal '14 TurboTalk: The Veil-framework
Metasploit - The Exploit Learning Tree
Introduction of ShinoBOT (Black Hat USA 2013 Arsenal)
Practical Malware Analysis Ch13
Ad

Viewers also liked (12)

PDF
Designing and Attacking DRM (RSA 2008)
PPTX
PDF
Alexander Matrosov, Eugene Rodionov - Modern technologies in malware programs...
PDF
Deobfuscation and beyond (ZeroNights, 2014)
PPTX
Linkmeup v23-compass-eos
DOCX
Chuyên
DOCX
Resume 2014 x3
ODP
βολος
PPTX
Why is linkedIn vital for B2B marketing
PPTX
6460 oc public forum 12 nov 14
DOCX
Chuyên
PPTX
business finance
Designing and Attacking DRM (RSA 2008)
Alexander Matrosov, Eugene Rodionov - Modern technologies in malware programs...
Deobfuscation and beyond (ZeroNights, 2014)
Linkmeup v23-compass-eos
Chuyên
Resume 2014 x3
βολος
Why is linkedIn vital for B2B marketing
6460 oc public forum 12 nov 14
Chuyên
business finance
Ad

Similar to Bypassing patchguard on Windows 8.1 and Windows 10 (20)

PDF
Typhoon Managed Execution Toolkit
PPTX
Owning computers without shell access 2
PPTX
Static Code Analysis for Projects, Built on Unreal Engine
PDF
Keeping your Kubernetes Cluster Secure
PDF
MFF UK - Advanced iOS Topics
PPTX
Евгений Напрягло ".NET Framework Hosting API Overview"
PPT
Jenkins Overview
PDF
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
PPTX
Simics - Break the Rules of Product Development
PPTX
Kubernetes in Adform
PDF
how-to-bypass-AM-PPL
PDF
Anatomy of an Attack: Detecting and Defeating CRASHOVERRIDE
PPTX
Code quality
PDF
UVM TUTORIAL;
PPTX
Securing the continuous integration
PDF
Secure all things with CBSecurity 3
PPTX
Part of the DLM Story: Automated database build and test with TeamCity
PDF
Efficient Bytecode Analysis: Linespeed Shellcode Detection
PDF
Continuous Delivery the hard way with Kubernetes
PDF
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg
Typhoon Managed Execution Toolkit
Owning computers without shell access 2
Static Code Analysis for Projects, Built on Unreal Engine
Keeping your Kubernetes Cluster Secure
MFF UK - Advanced iOS Topics
Евгений Напрягло ".NET Framework Hosting API Overview"
Jenkins Overview
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
Simics - Break the Rules of Product Development
Kubernetes in Adform
how-to-bypass-AM-PPL
Anatomy of an Attack: Detecting and Defeating CRASHOVERRIDE
Code quality
UVM TUTORIAL;
Securing the continuous integration
Secure all things with CBSecurity 3
Part of the DLM Story: Automated database build and test with TeamCity
Efficient Bytecode Analysis: Linespeed Shellcode Detection
Continuous Delivery the hard way with Kubernetes
Practical Malware Analysis: Ch 10: Kernel Debugging with WinDbg

Recently uploaded (20)

PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Sustainable Sites - Green Building Construction
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PPT
Project quality management in manufacturing
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
Digital Logic Computer Design lecture notes
PDF
Well-logging-methods_new................
PDF
composite construction of structures.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Sustainable Sites - Green Building Construction
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
additive manufacturing of ss316l using mig welding
CYBER-CRIMES AND SECURITY A guide to understanding
Embodied AI: Ushering in the Next Era of Intelligent Systems
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Lecture Notes Electrical Wiring System Components
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Project quality management in manufacturing
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
Digital Logic Computer Design lecture notes
Well-logging-methods_new................
composite construction of structures.pdf

Bypassing patchguard on Windows 8.1 and Windows 10

  • 1. Bypassing patchguard on Windows 8.1 and Windows 10 Mark Ermolov, Artem Shishkin Positive Technologies
  • 2. What is patchguard? ―“Please don’t patch our kernels” call from MS ―Even if your kernel patch is correct, you’ll catch a BSOD •0x109 CRITICAL_STRUCTURE_CORRUPTION ―Protected structures •System images: ntoskrnl.exe, win32k.sys, hal.dll etc. •System structures: IDT, GDT, Syscalltables etc. ―Periodic checksums validation for protected stuff ―Doesn’t work on Windows 9
  • 3. What if we really need to? ―Go for it! ―But… •Patchguard developers are prepared for reverse engineers •Hyper-inlinedobfuscation © Alex Ionescu •Anti-debugging tricks •Several ways of checks invocation
  • 6. Code obfuscation ―Code junk generation •Loop unrolling •Dead code insertion •Indirect calls and variable accesses
  • 7. Anti-debugging ―Works only on free builds without kernel debugger!
  • 8. Anti-debugging ―Randomly inserted checks for debugger presence
  • 9. Anti-debugging ―If you use breakpoints, they will be included to a patchguard checksum, leading to a 0x109 bugcheck ―If you use hardware breakpoints, well…
  • 10. Non-linear code flow ―Active usage of Vectored Exception Handling
  • 11. Reverse-engineering ―For dynamic analysis with KD (with windbgf.e.) •Remove all kdpresence checks manually —Look them up with IDA scripting —Apply patches in KD with pykd —Do it before “Phase1InitializationDiscard“ ―For static analysis with IDA •Try not to give up waiting for patchguard initialization function decompilation ―Use something else, like hypervisor-based debugger ;)
  • 12. Reverse-engineering ―Since patchguard is developed incrementally, the key functions in reversing it are •KiFilterFiberContext–chooses the way for invoking patchguard checks •Unnamed sub inside KiFilterFiberContext–creates a structure aka patchguard context and schedules it’s verification •Other functions (like context checkers) can be misleadingly named, but you can look them up around KiFilterFiberContextsince they are located in a single compilation unit
  • 13. Bypassing patchguard ―There are different approaches •patch kernel image so that patchguard will just not start •hook KeBugCheckExand restore the state of a system •modify checkers so that they would be always valid •de-schedule contexts verification —This is what we’ve implemented
  • 14. Contexts verification scheduling ―Context verification might be launched with •KeSetCoalescableTimer —A timer that periodically launches context verification •Prcb.AcpiReserved —A certain ACPI event (f.e. Idle transition) •Prcb.HalReserved —A haltimer clock •PsCreateSystemThread —A queued system thread that sleeps a random amount of time •KeInsertQueueApc —A queued regular kernel APC •KiBalanceSetManagerPeriodicDpc —A periodic event which happens every "KiBalanceSetManagerPeriod" ticks
  • 15. Contexts verification descheduling ―So we’ve got to deschedulecontext verification once and for all •KeSetCoalescableTimer —Timer? Disable! •Prcb.AcpiReserved —Zero out this field •Prcb.HalReserved —Same here •PsCreateSystemThread —Scan sleeping worker threads and set wait time to infinite for suitable •KeInsertQueueApc —Same here •KiBalanceSetManagerPeriodicDpc —Revert to KiBalanceSetManagerDeferredRoutine
  • 16. •research [at] ptsecurity[dot] com •www.ptsecurity.com •blog.ptsecurity.com Thank you!