Subverting Vista TM  Kernel For Fun And Profit Joanna Rutkowska Advanced Malware Labs SyScan’06 July 21 st , 2006, Singapore & Black Hat Briefings 2006 August 3 rd , 2006, Las Vegas
About this presentation This presentation is based on the research done exclusively for  COSEINC Research (Advanced Malware Labs) This presentation has been first presented at  SyScan’06 conference  in Singapore, on July 21 st , 2006
Content Part I Loading unsigned code into Vista Beta 2 kernel (x64) without reboot Part II Blue Pill – creating undetectable malware on x64 using Pacifica technology
Part I – getting into the kernel
Signed Drivers in Vista x64 All kernel mode drivers must be signed Vista allows to load only signed code into kernel Even administrator can not load unsigned module! This is to prevent kernel malware and anti-DRM Mechanism can be deactivated by: attaching Kernel Debugger (reboot required) Using F8 during boot (reboot required) using BCDEdit (reboot required, will not be available in later Vista versions) This protection has been for the first time implemented in Vista Beta 2 build 5384.
How to bypass? Vista allows usermode app to get raw access to disk  (provided they run with admin privileges of course) CreateFile(\\.\C:) CreateFile(\\.\PHYSICALDRIVE0) ) This allows us to read and write disk sectors which are occupied by the  pagefile  So, we can modify the contents of the pagefile, which may contain the code and data of the paged kernel drivers! No undocumented functionality required – all documented in SDK :)
Challenges How to make sure that the specific kernel code is paged out to the pagefile? How to find that code inside pagefile? How to cause the code (now modified) to be loaded into kernel again? How to make sure this new code is executed by kernel?
How to force drivers to be paged? Allocate *lots of* memory for a process (e.g. using  VirtualAlloc() ) The system will try to do its best to back up this memory with the actual physical pages At some point there will be no more physical pages available, so the system will try to page out some unused code… Guess what is going to paged now… some unused drivers :)
Eating memory…
What could be paged? Pageable sections of kernel drivers (recognized by the section name starting with ‘PAGE’ string) Driver’s data allocated from a Paged pool (e.g.  ExAllocatePool() )
Finding a target We need to find some rarely used driver, which has some of its code sections marked as pageable… How about NULL.SYS? After quick look at the code we see that its  dispatch  routine is located inside a PAGE section – one could not ask for more :) It should be noted that there are more drivers which could be used instead of NULL – finding them all is left as an exercise to  the audience ;)
Locating paged code inside pagefile This is easy – we just do a pattern search if we take a sufficiently long binary string (a few tens of bytes) its very unlikely that it will appear more then once in a page file Once we find a patter we just replace the first bytes of the dispatch function with our shellcode The next slide demonstrates how to use disk editor to do that
How to make sure our shellcode gets executed? We need to ask kernel to be kind enough and execute our driver’s routine (whose code we have just replaced in pagefile) In case of replacing driver’s dispatch routine it’s just enough to call  CreateFile()  specifying the target driver’s object to be opened This will cause the driver’s paged section to be loaded into memory and then executed!
Putting it all together Allocate lots of memory to cause unused drivers code to be paged Replace the paged out code (inside pagefile) with some shellcode Ask kernel to call the driver code which was just replaced
DEMO The above attack has been implemented in a form of a ‘1-click tool’ Special heuristics has been used to automatically find out how much memory should be allocated, before ‘knocking the driver’ The shellcode used in the demo disables signature checking, thus allowing any unsigned driver to be subsequently loaded
Creating useful shellcodes We can create a shellcode which would disable signature checking... …  or we can create a small shellcode which would allocate some memory (via  ExAllocatePool ) and then “download” the rest of the malware from ring 3…
DEMO
Possible solutions (1/3) Solution #1: Forbid raw disk access from usermode. This would probably break lots of programs: diskeditors/undeleters some AV programs? some data bases? Besides, access would still be possible from kernel mode So we can expect that lots of legal apps would provide their own drivers for raw disk access Those drivers would be signed of course, but could be used by attacker as well (no bug is required!).
Possible solutions (2/3) Solution #2: Encrypt pagefile!  Generate encryption key while system starts and keep it in kernel non-paged memory. Do not write it to disk nor to the registry! Big (?) performance impact Encrypt only those pages which were paged from ring0, keep ring3 pages unencrypted Sounds better, still introduces some performance impact (not sure how much though) You can actually enable PF encryption in a registry in Vista! (performance impact unknown)
Possible solutions (3/3)  Solution #3: Disable kernel memory paging! Disadvantage: wasting precious physical memory… On the other hand: is RAM really so precious these days? BTW, you can manually disable kernel memory paging in registry!  But it can be enabled again (reboot required), so it’s not a good solution.
Bottom line The presented attack does not rely on any implementation bug nor on any undocumented functionality MS did a good thing towards securing kernel by implementing signature check mechanism The fact that this mechanism was bypassed does not mean that Vista is completely  insecure (it’s just not that secure as it’s advertised) It’s very difficult to implement a 100% efficient kernel protection in a general purpose operating system
Part II – Blue Pill
Invisibility by Obscurity Current malware is based on a concept... e.g.  FU  unlinks EPROCESS from the list of active processes in the system e.g.  deepdoor  modifies some function pointers inside NDIS data structures …  etc… Once you know the  concept  you can write a detector!  This is boring!
Imagine a malware… …which does not rely on a concept to remain undetected… …which can not be detected, even though its algorithm (concept) is publicly known! …which can not be detected, even though it’s code is publicly known! Does this reminds you a modern crypto?
Blue Pill Idea Exploit AMD64 SVM extensions to move the operating system into the virtual machine (do it ‘on-the-fly’) Provide thin hypervisor to control the OS Hypervisor is responsible for controlling “interesting” events inside gust OS
AMD64 & SVM Secure Virtual Machine (AMD SVM) Extensions (AKA Pacifica) May 23 rd , 2006 – AMD releases Athlon 64 processors based on socket AM2 (revision F) AM2 based processors are the first to support SVM extensions AM2 based hardware is available in shops for end users as of June 2006
SVM SVM is a set of instructions which can be used to implement Secure Virtual Machines on AMD64 MSR EFER register: bit 12 (SVME) controls weather SVM mode is enabled or not EFER.SVME must be set to 1 before execution of any SVM instruction. Reference: AMD64 Architecture Programmer’s Manual Vol. 2: System Programming Rev 3.11 http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24593.pdf
The heart of SVM: VMRUN instruction
Blue Pill Idea (simplified)
BP installs itself ON THE FLY! The main idea behind BP is that it installs itself on the fly Thus, no modifications to BIOS, boot sector or system files are necessary BP, by default, does not survive system reboot But this is not a problem: servers are rarely restarted In Vista the ‘Power Off’ button does not shut down the system – it only puts it into stand by mode! And also we can intercept (this has not been yet implemented): restart events (hypervisor survives the reboot) shutdown events (emulated shutdown)
SubVirt Rootkit SubVirt has been created a few months ago by researches at MS Research and University of Michigan SubVirt uses commercial VMM (Virtual PC or VMWare) to run the original OS inside a VM
SubVirt vs. Blue Pill SV is permanent! SV has to take control before the original OS during the boot phase. SV can be detected off line. SV runs on x86, which does not allow for full virtualization (e.g. SxDT attack)  SV is based on a commercial VMM, which creates and emulates virtual hardware. This allows for easy detection Blue Pill can be installed on the fly – no reboot nor any modifications in BIOS or boot sectors are necessary. BP can not be detected off line. BP relies on AMD SVM technology which promises full virtualization BP uses ultra thin hypervisor and all the hardware is natively accessible without performance penalty
Matrix inside another Matrix What happens when you install Blue Pill inside a system which is already bluepilled? If nested virtualization is not handled correctly this will allow for trivial detection – all the detector would have to do was to try creating a test VM using a VMRUN instruction  Of course we can cheat the guest OS that the processor does not support SVM (because we control MSR registers from hypervisor), but this wouldn’t cheat more inquisitive users ;) So, we need to handle nested VMs…
Nested VMs
Detection via timing analysis We can assume that some of the instructions are always intercepted by the hypervisor VMMCALL RDMSR  – to cheat about the value of  EFER.SVME  bit So, not surprisingly, the time needed to execute  RDMSR  to read the value of EFER would be different (longer) when running from guest Detector can execute such instructions a few millions of times and measure the time.
Cheating timing analysis The first problem is that detector (usually) does not have a base line to compare the results with… But even if it had (e.g. when testing access to physical pages and while one of them being backed up by disk) still we can cheat it! SVM offers a way to fool the guest’s time stamp counter (obtained using RDTSC). All we have to do is to adjust VMCB.TSC_OFFSET accordingly before executing VMRUN (which resumes the guest)
Time dilatation for guest
Getting the real time…
Time profiling in practice Now imagine that you need to check 1000 computers in your company using the “external” stopwatch… Now imagine that you need to do this a couple of time every day… Time dilatation should make it impossible to write a self sufficient detector based on timing analysis! The challenge: we need a good ‘calibrating’ mechanism so that we know how much time to subtract.
Blue Pill based malware Blue Pill is just a way of silently moving the running OS into Matrix on the fly BP technology can be exploited in many various ways in order to create stealth malware Basically ‘sky is the limit’ here :) On the next slides we present some simple example:
Delusion Backdoor Simple Blue Pill based network backdoor Uses two DB registers to hook: R eceiveNetBufferListsHandler S endNetBufferListsComplete Blue Pill takes care about: handling #DB exception (no need for IDT[1] hooking inside guest) protecting debug registers, so that guest can not realize they are used for hooking Not even a single byte is modified in the NDIS data structures nor code! Delusion comes with its own TCP/IP stack based on lwIP
Delusion Demo (Blue Pill powered)
Blue Pill detection Two level of stealth: level 1: can not be detected even though the  concept  is publicly known (BPL1) level 2: can not be detected even if the  code  is publicly known (BPL2) Level 1 does not requite BP’s pages protection Level 2 is about avoiding signature based detection Level 2 is not needed in targeted attacks BPL2 has not been implemented yet!
Generic BP detection If we could come up with a generic program which would detect SVM virtual mode then… it would mean that SVM/Pacifica design/implementation does not support full virtualization! To be fair: AMD does not claim full virtualization in SVM documentation – it only says it is ‘Secure VM’… However it’s commonly believed that SVM == full virtualization…
Blue Pill detection We currently research some theoretical generic attacks against BPL1 It seems that the attack would only allow for crashing the system if its bluepilled It seems that the only attack against BPL2 would be based on timing analysis (or crashing when some special conditions will be met, like e.g. user removing SATA disk in a specific moment during tests)
Pacifica vs. Vanderpool Pacifica (SVM) and Vanderpool (VT-x) are not binary compatible However they seem to be very similar XEN even implements a common abstraction layer for both technologies It  seems  possible to port BP to Intel VT-x
Blue Pill Prevention Disable it in BIOS Its better not to buy SVM capable processor at all! Hypervisor built into OS What would be the criteria to allow 3 rd  party VMM (e.g. VMWare or some AV product) to load or not? Or should we stuck with “The Only Justifiable VMM”, provided by our OS vendor? ;) Not allowing to move underlying OS  on the fly  into virtual machine would not solve the problem of permanent, “classic” VM based malware or maybe another hardware solution…
Hardware Red Pill? How about creating a new instruction –  SVMCHECK : mov rax, <password> svmcheck cmp rax, 0 jnz inside_vm Password should be different for every processor Password is necessary so that it would be impossible to write a  generic  program which would behave differently inside VM and on a native machine. Users would get the passwords on certificates when they buy a new processor or computer Password would have to be entered to the AV program during its installation.
Future work Implement nested VMs Implement time dilatation for guest Intercept restart and shutdown events (controlled restart, emulated shutdown) Support for multi-core processors Implement BPL1 using Intel VT-x Implement Blue Pill Level 2 (BPL2)
Bottom line Arbitrary code can be injected into Vista x64 kernel (provided attacker gained administrative rights) This could be abused to create Blue Pill based malware on processors supporting virtualization BP installs itself on the fly and does not  introduce any modifications to BIOS nor hard disk BP can be used in many different ways to create the actual malware – Delusion was just one example BP should be undetectable in any  practical  way (when fully implemented) Blocking BP based attacks on software level will also prevent ISVs from providing their own VMMs and security products based on SVM technology Changes in hardware (processor) could allow for easy BP detection
References Dino Dai Zovi,  Hardware Virtualization Rootkits , Black Hat USA 2006 (very similar work to Blue Pill but for Intel VT-x, developed independently) MS Research and University of Michigan,  SubVirt: Implementing malware with virtual machines  (non-hardware virtualization malware)
Credits Neil Clift  for interesting discussions about Windows kernel Edgar Barbosa  for preparing shellcode for the kernel strike attack  Edgar joined COSEINC AML at the end of June! Alexander Tereshkin  AKA 90210 for thrilling  discussions about Blue Pill detection Alex is going to join COSEINC AML in August! Brandon Baker  for interesting discussions about Virtualization
Thank you! [email_address] check out http://coseinc.com/ for information about available trainings!

More Related Content

PDF
Android Boot Time Optimization
PPT
Learning AOSP - Android Booting Process
PDF
Android Custom Kernel/ROM design
PDF
Timings of Init : Android Ramdisks for the Practical Hacker
DOC
Taishaun_OwnensCNS-533_Lab
PPTX
Defeating x64: Modern Trends of Kernel-Mode Rootkits
PPT
Android booting sequece and setup and debugging
PDF
Modern Bootkit Trends: Bypassing Kernel-Mode Signing Policy
Android Boot Time Optimization
Learning AOSP - Android Booting Process
Android Custom Kernel/ROM design
Timings of Init : Android Ramdisks for the Practical Hacker
Taishaun_OwnensCNS-533_Lab
Defeating x64: Modern Trends of Kernel-Mode Rootkits
Android booting sequece and setup and debugging
Modern Bootkit Trends: Bypassing Kernel-Mode Signing Policy

What's hot (20)

PDF
BlueHat Seattle 2019 || Guarding Against Physical Attacks: The Xbox One Story
PDF
Star wind iscsi-san-software-handson-review-1-eng
PDF
Medooze MCU Video Multiconference Server Installation and configuration guide...
PDF
sponsorAVAST-VB2014
PDF
Defeating x64: The Evolution of the TDL Rootkit
DOCX
Backtrack Manual Part2
PDF
[Hackito2012] Hardware backdooring is practical
PDF
BIOS and Secure Boot Attacks Uncovered
PDF
[Ruxcon 2011] Post Memory Corruption Memory Analysis
PDF
Configuration management: automating and rationalizing server setup with CFEn...
PDF
Spectre meltdown performance_tests - v0.3
PDF
PDF
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
PPTX
Когда предрелизный не только софт
PDF
OSSNA18: Xen Beginners Training
PDF
Smart pos stepbystep-v2-0
PPT
IT103Microsoft Windows XP/OS Chap02
PDF
Command reference nos-v3_5
BlueHat Seattle 2019 || Guarding Against Physical Attacks: The Xbox One Story
Star wind iscsi-san-software-handson-review-1-eng
Medooze MCU Video Multiconference Server Installation and configuration guide...
sponsorAVAST-VB2014
Defeating x64: The Evolution of the TDL Rootkit
Backtrack Manual Part2
[Hackito2012] Hardware backdooring is practical
BIOS and Secure Boot Attacks Uncovered
[Ruxcon 2011] Post Memory Corruption Memory Analysis
Configuration management: automating and rationalizing server setup with CFEn...
Spectre meltdown performance_tests - v0.3
Qi -- Lightweight Boot Loader Applied in Mobile and Embedded Devices
Когда предрелизный не только софт
OSSNA18: Xen Beginners Training
Smart pos stepbystep-v2-0
IT103Microsoft Windows XP/OS Chap02
Command reference nos-v3_5
Ad

Viewers also liked (7)

PPTX
Svm on cloud (presntation)
PDF
Probability
PPTX
Support Vector Machine
PPTX
Android ppt
PPTX
Final year project presentation in android application
PPTX
Machine Learning using Support Vector Machine
PPTX
Android Project Presentation
Svm on cloud (presntation)
Probability
Support Vector Machine
Android ppt
Final year project presentation in android application
Machine Learning using Support Vector Machine
Android Project Presentation
Ad

Similar to Joanna Rutkowska Subverting Vista Kernel (20)

PDF
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode
PDF
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
PDF
Oleksyk applied-anti-forensics
PPTX
Divide et Impera: MemoryRanger Runs Drivers in Isolated Kernel Spaces
PDF
D1 t2 jonathan brossard - breaking virtualization by switching to virtual 8...
PPTX
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
PPT
Rootkit Hunting & Compromise Detection
PDF
Windows Offender: Reverse Engineering Windows Defender's Antivirus Emulator
PDF
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
PDF
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
PDF
Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...
PDF
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
PDF
Kernel Mode Threats and Practical Defenses
PDF
Csw2016 economou nissim-getting_physical
PPTX
File inflection techniques
PDF
CPU vulnerabilities - where are we now?
PDF
BlueHat v18 || Return of the kernel rootkit malware (on windows 10)
PPT
[HackInTheBox] Breaking virtualization by any means
PPTX
Metasploit & Windows Kernel Exploitation
PDF
Kernel Hijacking Is Not an Option: MemoryRanger Comes to The Rescue Again
[Ruxcon] Breaking virtualization by switching the cpu to virtual 8086 mode
DEF CON 27 - JESSE MICHAEL - get off the kernel if you can't drive
Oleksyk applied-anti-forensics
Divide et Impera: MemoryRanger Runs Drivers in Isolated Kernel Spaces
D1 t2 jonathan brossard - breaking virtualization by switching to virtual 8...
Windows Kernel Exploitation : This Time Font hunt you down in 4 bytes
Rootkit Hunting & Compromise Detection
Windows Offender: Reverse Engineering Windows Defender's Antivirus Emulator
Hunting and Exploiting Bugs in Kernel Drivers - DefCamp 2012
Don't Tell Joanna the Virtualized Rootkit is Dead (Blackhat 2007)
Kernel Memory Protection by an Insertable Hypervisor which has VM Introspec...
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
Kernel Mode Threats and Practical Defenses
Csw2016 economou nissim-getting_physical
File inflection techniques
CPU vulnerabilities - where are we now?
BlueHat v18 || Return of the kernel rootkit malware (on windows 10)
[HackInTheBox] Breaking virtualization by any means
Metasploit & Windows Kernel Exploitation
Kernel Hijacking Is Not an Option: MemoryRanger Comes to The Rescue Again

Recently uploaded (20)

PDF
Financial discipline for educational purpose
PPTX
Q1 PE AND HEALTH 5 WEEK 5 DAY 1 powerpoint template
PDF
The Right Social Media Strategy Can Transform Your Business
PPTX
2. RBI.pptx202029291023i38039013i92292992
PDF
2018_Simulating Hedge Fund Strategies Generalising Fund Performance Presentat...
PPTX
Maths science sst hindi english cucumber
PDF
GVCParticipation_Automation_Climate_India
PDF
International Financial Management, 9th Edition, Cheol Eun, Bruce Resnick Tuu...
PPTX
Group Presentation Development Econ and Envi..pptx
PDF
Buy Verified Payoneer Accounts for Sale - Secure and.pdf
PDF
Pitch Deck.pdf .pdf all about finance in
PDF
Pension Trustee Training (1).pdf From Salih Shah
PDF
CLIMATE CHANGE AS A THREAT MULTIPLIER: ASSESSING ITS IMPACT ON RESOURCE SCARC...
PPTX
INDIAN FINANCIAL SYSTEM (Financial institutions, Financial Markets & Services)
PDF
Best Accounting Outsourcing Companies in The USA
PDF
Principal of magaement is good fundamentals in economics
PDF
HCWM AND HAI FOR BHCM STUDENTS(1).Pdf and ptts
PDF
2012_The dark side of valuation a jedi guide to valuing difficult to value co...
PDF
Management Accounting Information for Decision-Making and Strategy Execution ...
PDF
Unkipdf.pdf of work in the economy we are
Financial discipline for educational purpose
Q1 PE AND HEALTH 5 WEEK 5 DAY 1 powerpoint template
The Right Social Media Strategy Can Transform Your Business
2. RBI.pptx202029291023i38039013i92292992
2018_Simulating Hedge Fund Strategies Generalising Fund Performance Presentat...
Maths science sst hindi english cucumber
GVCParticipation_Automation_Climate_India
International Financial Management, 9th Edition, Cheol Eun, Bruce Resnick Tuu...
Group Presentation Development Econ and Envi..pptx
Buy Verified Payoneer Accounts for Sale - Secure and.pdf
Pitch Deck.pdf .pdf all about finance in
Pension Trustee Training (1).pdf From Salih Shah
CLIMATE CHANGE AS A THREAT MULTIPLIER: ASSESSING ITS IMPACT ON RESOURCE SCARC...
INDIAN FINANCIAL SYSTEM (Financial institutions, Financial Markets & Services)
Best Accounting Outsourcing Companies in The USA
Principal of magaement is good fundamentals in economics
HCWM AND HAI FOR BHCM STUDENTS(1).Pdf and ptts
2012_The dark side of valuation a jedi guide to valuing difficult to value co...
Management Accounting Information for Decision-Making and Strategy Execution ...
Unkipdf.pdf of work in the economy we are

Joanna Rutkowska Subverting Vista Kernel

  • 1. Subverting Vista TM Kernel For Fun And Profit Joanna Rutkowska Advanced Malware Labs SyScan’06 July 21 st , 2006, Singapore & Black Hat Briefings 2006 August 3 rd , 2006, Las Vegas
  • 2. About this presentation This presentation is based on the research done exclusively for COSEINC Research (Advanced Malware Labs) This presentation has been first presented at SyScan’06 conference in Singapore, on July 21 st , 2006
  • 3. Content Part I Loading unsigned code into Vista Beta 2 kernel (x64) without reboot Part II Blue Pill – creating undetectable malware on x64 using Pacifica technology
  • 4. Part I – getting into the kernel
  • 5. Signed Drivers in Vista x64 All kernel mode drivers must be signed Vista allows to load only signed code into kernel Even administrator can not load unsigned module! This is to prevent kernel malware and anti-DRM Mechanism can be deactivated by: attaching Kernel Debugger (reboot required) Using F8 during boot (reboot required) using BCDEdit (reboot required, will not be available in later Vista versions) This protection has been for the first time implemented in Vista Beta 2 build 5384.
  • 6. How to bypass? Vista allows usermode app to get raw access to disk (provided they run with admin privileges of course) CreateFile(\\.\C:) CreateFile(\\.\PHYSICALDRIVE0) ) This allows us to read and write disk sectors which are occupied by the pagefile So, we can modify the contents of the pagefile, which may contain the code and data of the paged kernel drivers! No undocumented functionality required – all documented in SDK :)
  • 7. Challenges How to make sure that the specific kernel code is paged out to the pagefile? How to find that code inside pagefile? How to cause the code (now modified) to be loaded into kernel again? How to make sure this new code is executed by kernel?
  • 8. How to force drivers to be paged? Allocate *lots of* memory for a process (e.g. using VirtualAlloc() ) The system will try to do its best to back up this memory with the actual physical pages At some point there will be no more physical pages available, so the system will try to page out some unused code… Guess what is going to paged now… some unused drivers :)
  • 10. What could be paged? Pageable sections of kernel drivers (recognized by the section name starting with ‘PAGE’ string) Driver’s data allocated from a Paged pool (e.g. ExAllocatePool() )
  • 11. Finding a target We need to find some rarely used driver, which has some of its code sections marked as pageable… How about NULL.SYS? After quick look at the code we see that its dispatch routine is located inside a PAGE section – one could not ask for more :) It should be noted that there are more drivers which could be used instead of NULL – finding them all is left as an exercise to the audience ;)
  • 12. Locating paged code inside pagefile This is easy – we just do a pattern search if we take a sufficiently long binary string (a few tens of bytes) its very unlikely that it will appear more then once in a page file Once we find a patter we just replace the first bytes of the dispatch function with our shellcode The next slide demonstrates how to use disk editor to do that
  • 13. How to make sure our shellcode gets executed? We need to ask kernel to be kind enough and execute our driver’s routine (whose code we have just replaced in pagefile) In case of replacing driver’s dispatch routine it’s just enough to call CreateFile() specifying the target driver’s object to be opened This will cause the driver’s paged section to be loaded into memory and then executed!
  • 14. Putting it all together Allocate lots of memory to cause unused drivers code to be paged Replace the paged out code (inside pagefile) with some shellcode Ask kernel to call the driver code which was just replaced
  • 15. DEMO The above attack has been implemented in a form of a ‘1-click tool’ Special heuristics has been used to automatically find out how much memory should be allocated, before ‘knocking the driver’ The shellcode used in the demo disables signature checking, thus allowing any unsigned driver to be subsequently loaded
  • 16. Creating useful shellcodes We can create a shellcode which would disable signature checking... … or we can create a small shellcode which would allocate some memory (via ExAllocatePool ) and then “download” the rest of the malware from ring 3…
  • 17. DEMO
  • 18. Possible solutions (1/3) Solution #1: Forbid raw disk access from usermode. This would probably break lots of programs: diskeditors/undeleters some AV programs? some data bases? Besides, access would still be possible from kernel mode So we can expect that lots of legal apps would provide their own drivers for raw disk access Those drivers would be signed of course, but could be used by attacker as well (no bug is required!).
  • 19. Possible solutions (2/3) Solution #2: Encrypt pagefile! Generate encryption key while system starts and keep it in kernel non-paged memory. Do not write it to disk nor to the registry! Big (?) performance impact Encrypt only those pages which were paged from ring0, keep ring3 pages unencrypted Sounds better, still introduces some performance impact (not sure how much though) You can actually enable PF encryption in a registry in Vista! (performance impact unknown)
  • 20. Possible solutions (3/3) Solution #3: Disable kernel memory paging! Disadvantage: wasting precious physical memory… On the other hand: is RAM really so precious these days? BTW, you can manually disable kernel memory paging in registry! But it can be enabled again (reboot required), so it’s not a good solution.
  • 21. Bottom line The presented attack does not rely on any implementation bug nor on any undocumented functionality MS did a good thing towards securing kernel by implementing signature check mechanism The fact that this mechanism was bypassed does not mean that Vista is completely insecure (it’s just not that secure as it’s advertised) It’s very difficult to implement a 100% efficient kernel protection in a general purpose operating system
  • 22. Part II – Blue Pill
  • 23. Invisibility by Obscurity Current malware is based on a concept... e.g. FU unlinks EPROCESS from the list of active processes in the system e.g. deepdoor modifies some function pointers inside NDIS data structures … etc… Once you know the concept you can write a detector! This is boring!
  • 24. Imagine a malware… …which does not rely on a concept to remain undetected… …which can not be detected, even though its algorithm (concept) is publicly known! …which can not be detected, even though it’s code is publicly known! Does this reminds you a modern crypto?
  • 25. Blue Pill Idea Exploit AMD64 SVM extensions to move the operating system into the virtual machine (do it ‘on-the-fly’) Provide thin hypervisor to control the OS Hypervisor is responsible for controlling “interesting” events inside gust OS
  • 26. AMD64 & SVM Secure Virtual Machine (AMD SVM) Extensions (AKA Pacifica) May 23 rd , 2006 – AMD releases Athlon 64 processors based on socket AM2 (revision F) AM2 based processors are the first to support SVM extensions AM2 based hardware is available in shops for end users as of June 2006
  • 27. SVM SVM is a set of instructions which can be used to implement Secure Virtual Machines on AMD64 MSR EFER register: bit 12 (SVME) controls weather SVM mode is enabled or not EFER.SVME must be set to 1 before execution of any SVM instruction. Reference: AMD64 Architecture Programmer’s Manual Vol. 2: System Programming Rev 3.11 http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24593.pdf
  • 28. The heart of SVM: VMRUN instruction
  • 29. Blue Pill Idea (simplified)
  • 30. BP installs itself ON THE FLY! The main idea behind BP is that it installs itself on the fly Thus, no modifications to BIOS, boot sector or system files are necessary BP, by default, does not survive system reboot But this is not a problem: servers are rarely restarted In Vista the ‘Power Off’ button does not shut down the system – it only puts it into stand by mode! And also we can intercept (this has not been yet implemented): restart events (hypervisor survives the reboot) shutdown events (emulated shutdown)
  • 31. SubVirt Rootkit SubVirt has been created a few months ago by researches at MS Research and University of Michigan SubVirt uses commercial VMM (Virtual PC or VMWare) to run the original OS inside a VM
  • 32. SubVirt vs. Blue Pill SV is permanent! SV has to take control before the original OS during the boot phase. SV can be detected off line. SV runs on x86, which does not allow for full virtualization (e.g. SxDT attack) SV is based on a commercial VMM, which creates and emulates virtual hardware. This allows for easy detection Blue Pill can be installed on the fly – no reboot nor any modifications in BIOS or boot sectors are necessary. BP can not be detected off line. BP relies on AMD SVM technology which promises full virtualization BP uses ultra thin hypervisor and all the hardware is natively accessible without performance penalty
  • 33. Matrix inside another Matrix What happens when you install Blue Pill inside a system which is already bluepilled? If nested virtualization is not handled correctly this will allow for trivial detection – all the detector would have to do was to try creating a test VM using a VMRUN instruction Of course we can cheat the guest OS that the processor does not support SVM (because we control MSR registers from hypervisor), but this wouldn’t cheat more inquisitive users ;) So, we need to handle nested VMs…
  • 35. Detection via timing analysis We can assume that some of the instructions are always intercepted by the hypervisor VMMCALL RDMSR – to cheat about the value of EFER.SVME bit So, not surprisingly, the time needed to execute RDMSR to read the value of EFER would be different (longer) when running from guest Detector can execute such instructions a few millions of times and measure the time.
  • 36. Cheating timing analysis The first problem is that detector (usually) does not have a base line to compare the results with… But even if it had (e.g. when testing access to physical pages and while one of them being backed up by disk) still we can cheat it! SVM offers a way to fool the guest’s time stamp counter (obtained using RDTSC). All we have to do is to adjust VMCB.TSC_OFFSET accordingly before executing VMRUN (which resumes the guest)
  • 38. Getting the real time…
  • 39. Time profiling in practice Now imagine that you need to check 1000 computers in your company using the “external” stopwatch… Now imagine that you need to do this a couple of time every day… Time dilatation should make it impossible to write a self sufficient detector based on timing analysis! The challenge: we need a good ‘calibrating’ mechanism so that we know how much time to subtract.
  • 40. Blue Pill based malware Blue Pill is just a way of silently moving the running OS into Matrix on the fly BP technology can be exploited in many various ways in order to create stealth malware Basically ‘sky is the limit’ here :) On the next slides we present some simple example:
  • 41. Delusion Backdoor Simple Blue Pill based network backdoor Uses two DB registers to hook: R eceiveNetBufferListsHandler S endNetBufferListsComplete Blue Pill takes care about: handling #DB exception (no need for IDT[1] hooking inside guest) protecting debug registers, so that guest can not realize they are used for hooking Not even a single byte is modified in the NDIS data structures nor code! Delusion comes with its own TCP/IP stack based on lwIP
  • 42. Delusion Demo (Blue Pill powered)
  • 43. Blue Pill detection Two level of stealth: level 1: can not be detected even though the concept is publicly known (BPL1) level 2: can not be detected even if the code is publicly known (BPL2) Level 1 does not requite BP’s pages protection Level 2 is about avoiding signature based detection Level 2 is not needed in targeted attacks BPL2 has not been implemented yet!
  • 44. Generic BP detection If we could come up with a generic program which would detect SVM virtual mode then… it would mean that SVM/Pacifica design/implementation does not support full virtualization! To be fair: AMD does not claim full virtualization in SVM documentation – it only says it is ‘Secure VM’… However it’s commonly believed that SVM == full virtualization…
  • 45. Blue Pill detection We currently research some theoretical generic attacks against BPL1 It seems that the attack would only allow for crashing the system if its bluepilled It seems that the only attack against BPL2 would be based on timing analysis (or crashing when some special conditions will be met, like e.g. user removing SATA disk in a specific moment during tests)
  • 46. Pacifica vs. Vanderpool Pacifica (SVM) and Vanderpool (VT-x) are not binary compatible However they seem to be very similar XEN even implements a common abstraction layer for both technologies It seems possible to port BP to Intel VT-x
  • 47. Blue Pill Prevention Disable it in BIOS Its better not to buy SVM capable processor at all! Hypervisor built into OS What would be the criteria to allow 3 rd party VMM (e.g. VMWare or some AV product) to load or not? Or should we stuck with “The Only Justifiable VMM”, provided by our OS vendor? ;) Not allowing to move underlying OS on the fly into virtual machine would not solve the problem of permanent, “classic” VM based malware or maybe another hardware solution…
  • 48. Hardware Red Pill? How about creating a new instruction – SVMCHECK : mov rax, <password> svmcheck cmp rax, 0 jnz inside_vm Password should be different for every processor Password is necessary so that it would be impossible to write a generic program which would behave differently inside VM and on a native machine. Users would get the passwords on certificates when they buy a new processor or computer Password would have to be entered to the AV program during its installation.
  • 49. Future work Implement nested VMs Implement time dilatation for guest Intercept restart and shutdown events (controlled restart, emulated shutdown) Support for multi-core processors Implement BPL1 using Intel VT-x Implement Blue Pill Level 2 (BPL2)
  • 50. Bottom line Arbitrary code can be injected into Vista x64 kernel (provided attacker gained administrative rights) This could be abused to create Blue Pill based malware on processors supporting virtualization BP installs itself on the fly and does not introduce any modifications to BIOS nor hard disk BP can be used in many different ways to create the actual malware – Delusion was just one example BP should be undetectable in any practical way (when fully implemented) Blocking BP based attacks on software level will also prevent ISVs from providing their own VMMs and security products based on SVM technology Changes in hardware (processor) could allow for easy BP detection
  • 51. References Dino Dai Zovi, Hardware Virtualization Rootkits , Black Hat USA 2006 (very similar work to Blue Pill but for Intel VT-x, developed independently) MS Research and University of Michigan, SubVirt: Implementing malware with virtual machines (non-hardware virtualization malware)
  • 52. Credits Neil Clift for interesting discussions about Windows kernel Edgar Barbosa for preparing shellcode for the kernel strike attack Edgar joined COSEINC AML at the end of June! Alexander Tereshkin AKA 90210 for thrilling discussions about Blue Pill detection Alex is going to join COSEINC AML in August! Brandon Baker for interesting discussions about Virtualization
  • 53. Thank you! [email_address] check out http://coseinc.com/ for information about available trainings!