15.08.2015 Views

Attacking Hypervisors via Firmware and Hardware

nd5ln5n

nd5ln5n

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Attacking</strong> <strong>Hypervisors</strong><strong>via</strong> <strong>Firmware</strong> <strong>and</strong> <strong>Hardware</strong>Mikhail Gorobets, Oleks<strong>and</strong>r Bazhaniuk, Alex Matrosov,Andrew Furtak, Yuriy BulyginAdvanced Threat Research


AgendaHypervisor based isolation<strong>Firmware</strong> rootkit vs hypervisor<strong>Attacking</strong> hypervisor emulation of hardware devices<strong>Attacking</strong> hypervisors through system firmwareTools <strong>and</strong> mitigationsConclusions


Image sourceHypervisor Based Isolation


Hypervisor Based IsolationVirtual MachineVirtual MachineAppAppAppAppOperating SystemOperating SystemPrivilegeVMM / HypervisorSystem <strong>Firmware</strong>(BIOS, U/EFI firmware, SMI h<strong>and</strong>lers, Coreboot…)Memory<strong>Hardware</strong>CPUGraphicsI/ONetwork


Hypervisor Based IsolationVirtual MachineVirtual MachineAppAppAppAttackOperating SystemOperating SystemPrivilegeVMM / HypervisorSystem <strong>Firmware</strong>(BIOS, U/EFI firmware, SMI h<strong>and</strong>lers, Coreboot…)Memory<strong>Hardware</strong>CPUGraphicsI/ONetwork


Hypervisor ProtectionsSoftware IsolationCPU / SoC: traps to hypervisor (VM Exits),MSR & I/O permissions bitmaps, rings (PV)…Memory / MMIO: hardware page tables (e.g.EPT, NPT), software shadow page tablesDevices IsolationCPU / SoC: interrupt remappingMemory / MMIO: IOMMU, No-DMA ranges


CPU Virtualization (simplified)VM Guest OSInstructions,exceptions,interrupts… Access to CPUMSRs(e.g. DEBUGCTL)Access toI/O portsAccess to (e.g. 0xB2)memory(EPT violations)Hypervisor Traps (VM Exits)VMM HostVM Exit H<strong>and</strong>lerVM ControlStructure (VMCS)MSR BitmapsExtended PageTablesI/O Bitmaps


Protecting Memory with HW Assisted PagingVM Guest OSVMM HostProcess VirtualMemoryCR3Guest PhysicalMemoryGPA0VMCSEPTPHost PhysicalMemoryHPA0VA0Guest Page TablesGPA1EPTHPA1VA1GPA2GPA0 HPA3HPA2VA2GPA3GPA2 HPA5HPA3VA3VA4…GPA4GPA5GPA6GPA4 HPA4(1:1 mapping)GPA6 blockHPA4HPA5HPA6……


Hypervisor ProtectionsSystem <strong>Firmware</strong> Isolation


<strong>Firmware</strong> Rootkitvs HypervisorImage source


What is firmware rootkit?Virtual MachineVirtual MachineAppAppAppAppOperating SystemOperating SystemPrivilegeVMM / HypervisorSystem <strong>Firmware</strong>Rootkit(e.g. DXE driver)Memory<strong>Hardware</strong>CPUGraphicsI/ONetwork


<strong>Firmware</strong> rootkit can open a backdoor foran attacker VM to access all other VMsVirtual MachineApp AppOperating SystemAttacker VMApp AppOperating System3. Now using thisbackdoor, attacker VMcan access all ofmemory of victim VMsVMM / HypervisorSystem <strong>Firmware</strong>BackdoorRootkit2. During each bootrootkit installs abackdoor for anattacker controlled VM1. At some pointsystem firmware gotinfected with a rootkitstaying persistent


“Backdoor” for attacker’s VM1. <strong>Firmware</strong> rootkitsearches & modifies VM’sVMCS(B), VMM page tables2. Rootkit added pagetable entries to attackerVM which expose entirephysical memoryNow attacker VM has fullaccess to physical memoryof VMM <strong>and</strong> other VMs


So how would one install a rootkit inthe firmware?


Using hardware SPI flash programmer…


USB & exploiting weak firmware protections...


Software access <strong>and</strong> exploiting somevulnerability in firmware …From privileged guest (e.g. Dom0). Requiresprivesc from normal guest (e.g. DomU) or remoteFrom the host OS before/in parallel to VMMFrom normal guest if firmware is exposed to theguest by VMMFor example, if firmware is not adequatelywrite protected in system flash memory


Image sourceDEMORootkit in System <strong>Firmware</strong> ExposesSecrets from Virtual Machines


Installing rootkit in firmware from root partition


Attacker VM exposes secrets of other VMsthrough a backdoor opened by the rootkit


We flashed rootkited part of firmware imagefrom within a root partition to install the rootkitThe system doesn’t properly protectfirmware in SPI flash memory so we couldbypass write-protectionFinally more systems protect firmware on theflash memorycommon.bios_wpCHIPSEC module to test write-protectionMalware can exploit vulnerabilities in firmwareto install a rootkit on such systems<strong>Attacking</strong> <strong>and</strong> Defending BIOS in 2015


VMM “forensics”With the help of a rootkit in firmware any VM guestcan extract all information about hypervisor <strong>and</strong> otherVMs … <strong>and</strong> just from memory• VMCS structures, MSR <strong>and</strong> I/O bitmaps for each VM guest• EPT for each VM guest• Regular page tables for hypervisor <strong>and</strong> each VM guest• IOMMU pages tables for each IOMMU device• Full hypervisor memory map, VM exit h<strong>and</strong>ler…• Real hardware configuration (registers for real PCIe devices,MMIO contents…)


VMCS, MSR <strong>and</strong> I/O bitmaps..


VMM <strong>Hardware</strong> Page Tables…


Image source<strong>Attacking</strong> Hypervisor Emulation of<strong>Hardware</strong> Devices


XSA-75SYSRET…XSA-108…MS13-092XSA-122…CloudburstCVE-2014-0983…VENOMXSA-138…<strong>Hardware</strong> Emulation Attack VectorsVM Guest OSInstructions(CPUID…)Access toCPU MSRsHypercallAPIAccess todevice MMIO,CMD buffers…Access todevice I/OportsVMMHostHypervisorINSTREmulationCPU MSREmulationHypercallImplDeviceMMIO/BuffersEmulationDevice I/OEmulation


Did you know that VMMs emulate virtualdevices of other VMMs?So Cloudburst was fixed in VMWare but … QEMU <strong>and</strong>VirtualBox also emulate VMWare virtual SVGA deviceVirtual MachineAppAppOperating SystemVirtual sVGA DeviceSVGA_CMD_RECT_FILL…Host / HypervisorFrame buffersVGA comm<strong>and</strong>sFIFO buffer


Guest to Host Memory CorruptionQEMU / KVMCVE-2014-36893 vulnerabilities in the vmware-vga driver in QEMU allows local guestto write to QEMU memory <strong>and</strong> gain host/hypervisor privileges <strong>via</strong>unspecified parameters related to rectangle h<strong>and</strong>lingOracle VirtualBox (Jan 2015 Critical Patch Update)CVE-2014-6588Memory corruption in VMSVGAGMRTRANSFERCVE-2014-6589, CVE-2014-6590Memory corruptions in VMSVGAFIFOLOOPCVE-2015-0427Integer overflow memory corruption in VMSVGAFIFOGETCMDBUFFER


Crashing Host or Guest from Ring3 …CVE-2015-0377Writing arbitrary data to upper 32 bits of IA32_APIC_BASE MSRcauses VMM <strong>and</strong> host OS to crash on Oracle VirtualBox 3.2,4.0.x-4.2.x# chipsec_util.py msr 0x1B 0xFEE00900 0xDEADBEEFCVE-2015-0418, CVE-2014-3646VirtualBox <strong>and</strong> KVM guest crash when executing INVEPT/INVVPIDinstructions in Ring3VirtualBoxINVEPT : VM crashINVVPID : VM crashVMCALL : #UD faultVMLAUNCH : #UD faultVMRESUME : #UD faultKVMINVEPT : VM crashINVVPID : VM crashVMCALL : No ExceptionVMLAUNCH : #UD faultVMRESUME : #UD fault


<strong>Attacking</strong> <strong>Hypervisors</strong> throughSystem <strong>Firmware</strong>(with OS kernel access)Image source


Pointer Vulnerabilities in SMI H<strong>and</strong>lersPhys MemoryRAX (code)RBX (pointer)RCX (function)RDXRSIRDISMISMI H<strong>and</strong>lers inSMRAMFake structure inside SMRAMOS MemoryExploit tricks SMI h<strong>and</strong>ler to write to an address inside SMRAM<strong>Attacking</strong> <strong>and</strong> Defending BIOS in 2015


SMI PointerExploiting firmware SMI h<strong>and</strong>ler to attack VMMVirtual Machine(child partition)AppAppOperating SystemRoot partitionApp AttackOperating SystemVMM allows VM toinvoke SMI h<strong>and</strong>lers(grants access to SWSMI I/O port 0xB2)MemoryHypervisorSMI H<strong>and</strong>lersSystem <strong>Firmware</strong>I/O<strong>Hardware</strong>CPUNetworkGraphicsCompromised VMinjects SMM payloadthrough the inputpointer vulnerability inSMI h<strong>and</strong>lerSMM firmwarepayload modifieshypervisor code orVMCS/EPT to installa backdoor


DEMO<strong>Attacking</strong> Hypervisor <strong>via</strong>Poisonous Pointers in <strong>Firmware</strong> SMI h<strong>and</strong>lers


Root cause? Port B2h is open to VM in I/O bitmap


So that’s a firmware issue! <strong>Firmware</strong> hasto validate pointersPhys MemoryRAX (code)RBX (pointer)RCX (function)RDXRSIRDISMISMI H<strong>and</strong>lers inSMRAMHypervisor Memory(Protected by EPT)<strong>Firmware</strong> SMI h<strong>and</strong>ler validates input pointers to ensure theyare outside of SMRAM preventing overwrite of SMI code/data


Point SMI h<strong>and</strong>ler to overwrite VMM page!Phys MemoryRAX (code)RBX (pointer)SMISMI H<strong>and</strong>lers inSMRAMRCX (function)RDXRSIRDIHypervisor Memory(Protected by EPT)VMM Protected PageVMMProtectionsare OFF• VT state <strong>and</strong> EPT protections are OFF in SMM (without STM)• SMI h<strong>and</strong>ler writes to a protected page <strong>via</strong> supplied pointer


<strong>Attacking</strong> VMM by proxying through SMI h<strong>and</strong>lerVirtual Machine(child partition)AppAppOperating SystemRoot partitionApp AttackOperating SystemVM with direct access toSMIs invokes SMIh<strong>and</strong>ler <strong>and</strong> supplies apointer to some VMMpageVMM / HypervisorMemorySMI H<strong>and</strong>lersSystem <strong>Firmware</strong><strong>Hardware</strong>CPUGraphicsSMI h<strong>and</strong>ler writes tothe supplied pointeroverwriting contents ofprotected VMM pageI/ONetwork


Sometimes attacker doesn’t need avulnerability in firmware…When VMM grants VM direct access tofirmware or hardware interfacesVM exploit doesn’t always need to exploitfirmware first through these interfacesIt may use firmware or hardware as aconfused deputy <strong>and</strong> attack VMM throughsome function on behalf of firmwareRead excellent paper <strong>Hardware</strong> InvolvedSoftware Attacks by Jeff Forristal


Do <strong>Hypervisors</strong> Dreamof Electric Sheep?Vulnerability used in this section is VU#976132 a.k.a. S3 ResumeBoot Script Vulnerability independently discovered by ATR of IntelSecurity, Rafal Wojtczuk of Bromium <strong>and</strong> LegbaCoreIt’s also used in Thunderstrike 2 by LegbaCore & Trammell Hudson


NORMAL BOOTS3 RESUMEWaking the system from S3 “sleep” stateVirtual MachineApps / OSBDSVMM / HypervisorU/EFI System <strong>Firmware</strong>DXEUEFI core& driversS3 BootScript TableRestoreshardware configScript EnginePlatform InitPlatform Init


What is S3 boot script table?A table of opcodes in physical memory which restoresplatform configurationS3_BOOTSCRIPT_MEM_WRITE opcode writes some value tospecified memory location on behalf of firmwareS3_BOOTSCRIPT_DISPATCH/2S3_BOOTSCRIPT_PCI_CONFIG_WRITES3_BOOTSCRIPT_IO_WRITE…


NORMAL BOOTMODIFYS3 RESUMEXen exposes S3 boot script table to Dom0Privileged PV guest (Dom0)ExploitVM modifies S3 bootscript table in memoryUpon resume, firmwareexecutes rogue S3 scriptXen HypervisorU/EFI System <strong>Firmware</strong>BDSDXEUEFI core& driversS3 BootScript TableRestoreshardware configScript EnginePlatform PEI0xDBAA4000Platform PEI


Xen attack <strong>via</strong> S3 boot scriptFound S3 boot scripttable in memoryaccessible to Dom0Changing the bootscript to access Xenhypervisor pages


Dumping Dom0VMCS from memoryprotected by EPT


Image sourceDEMO<strong>Attacking</strong> Xenin its sleep


Déjà vu?Xen 0wning Trilogy (Part 3) by Invisible Things Lab


So these firmware vulnerabilities areexploitable from privileged guest (e.g. rootpartition, Dom0 ..)What about use cases where guests mustbe strongly isolated from the rootpartition?


Image sciencenews.orgTools <strong>and</strong> Mitigations


First things first - fix that firmware!<strong>Firmware</strong> can be tested for vulnerabilities!common.uefi.s3bootscript(tests S3 boot script protections)tools.smm.smm_ptr(tests for SMI pointer issues)Protect the firmware in system flash memorycommon.bios_wpcommon.spi_lock...(tests firmware protections in system flash memory)


Testing hypervisors…Simple hardware emulation fuzzingmodules for open source CHIPSECtools.vmm.*_fuzzI/O, MSR, PCIe device, MMIO overlap, more soon …Tools to explore VMM hardware configchipsec_util iommu (IOMMU)chipsec_util vm (CPU VM extensions)


Dealing with system firmware attacks..A number of interfaces through whichfirmware can be attacked or relay attack ontoVMM• UEFI variables, SMI h<strong>and</strong>lers, S3 boot script, SPI flashMMIO, FW update..• FW doesn’t know memory VMM needs to protectVMM need to be careful with which of these itexposes to VMs including to administrative(privileged) guests• Some need not be exposed (e.g. S3 boot script), somemay be emulated <strong>and</strong> monitored


Conclusions• Compromised firmware is bad news for VMM.Test your system’s firmware for security issues• Windows 10 enables path for firmwaredeployment <strong>via</strong> Windows Update• Secure privileged/administrative guests; attacksfrom such guests are important• Vulnerabilities in device <strong>and</strong> CPU emulation arevery common. Fuzz all HW interfaces• <strong>Firmware</strong> interfaces/features may affecthypervisor security if exposed to VMs. Both needto be designed to be aware of each other


References1. CHIPSEC: https://github.com/chipsec/chipsec2. Intel’s ATR Security of System <strong>Firmware</strong>3. <strong>Attacking</strong> <strong>and</strong> Defending BIOS in 2015 by Intel ATR4. <strong>Hardware</strong> Involved Software Attacks by Jeff Forristal5. Xen 0wning Trilogy by Invisible Things Lab6. http://www.legbacore.com/Research.html7. Low level PC attack papers by Xeno Kovah


Thank You!

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!