• Aucun résultat trouvé

via Firmware and Hardware

N/A
N/A
Protected

Academic year: 2022

Partager "via Firmware and Hardware"

Copied!
44
0
0

Texte intégral

(1)

Alex Matrosov (@matrosov),

Mikhail Gorobets,

Oleksandr Bazhaniuk (@ABazhaniuk), Andrew Furtak,

Yuriy Bulygin (@c7zero)

Attacking Hypervisors

via Firmware and Hardware

Advanced Threat Research

(2)

Agenda

Hypervisor based isolation

Firmware rootkit vs hypervisor

Attacking hypervisors through system firmware Tools and mitigations

Conclusions

(3)

Hypervisor Based Isolation

Image source

(4)

Hypervisor Based Isolation

Hardware

I/O Memory

Network

Graphics

VMM / Hypervisor

System Firmware

(BIOS, U/EFI firmware, SMI handlers, Coreboot…)

CPU

Privilege

Virtual Machine

Operating System

App App

Virtual Machine

App App

Operating System

(5)

Hypervisor Based Isolation

Hardware

I/O Memory

Network

Graphics

VMM / Hypervisor

System Firmware

(BIOS, U/EFI firmware, SMI handlers, Coreboot…)

CPU

Privilege

Virtual Machine

Operating System

App App

Virtual Machine

App Attack

Operating System

(6)

Hypervisor Protections

Software Isolation

CPU / 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 tables Devices Isolation

CPU / SoC: interrupt remapping

Memory / MMIO: IOMMU, No-DMA ranges

(7)

CPU Virtualization (simplified)

VMM Host VM Guest OS

VM Exit Handler

VM Control

Structure (VMCS) MSR Bitmaps I/O Bitmaps

Instructions, exceptions, interrupts…

Extended Page Tables

Access to I/O ports (e.g. 0xB2) Access to CPU

MSRs

(e.g. DEBUGCTL)

Access to memory (EPT violations)

Hypervisor Traps (VM Exits)

(8)

Protecting Memory with HW Assisted Paging

VA0 VA1 VA2 VA3 VA4

VM Guest OS

GPA0 GPA1 GPA2 GPA3 GPA4 GPA5 GPA6

GPA0  HPA3

VMM Host

GPA2  HPA5 GPA4  HPA4

(1:1 mapping) GPA6  block

HPA0 HPA1 HPA2 HPA3 HPA4 HPA5 HPA6

Process Virtual Memory

Guest Page Tables

Guest Physical Memory

EPT

Host Physical Memory VMCS

CR3 EPTP

(9)

Hypervisor Protections

System Firmware Isolation

(10)

Firmware Rootkit vs Hypervisor

Image source

(11)

What is firmware rootkit?

Hardware

I/O Memory

Network

Graphics

VMM / Hypervisor

System Firmware

CPU

Privilege

Virtual Machine

Operating System

App App

Virtual Machine

App App

Operating System

Rootkit

(e.g. DXE driver)

(12)

Firmware rootkit can open a backdoor for an attacker VM to access all other VMs

System Firmware Rootkit

VMM / Hypervisor

Backdoor

2. During each boot rootkit installs a backdoor for an attacker controlled VM Virtual Machine

Operating System

App App

Attacker VM

App App

Operating System

1. At some point system firmware got infected with a rootkit

staying persistent 3. Now using this backdoor, attacker VM

can access all of memory of victim VMs

(13)

“Backdoor” for attacker’s VM

2. Rootkit added page table entries to attacker VM which expose entire

physical memory 1. Firmware rootkit

searches & modifies VM’s VMCS(B), VMM page tables

Now attacker VM has full access to physical memory

of VMM and other VMs

(14)

So how would one install a rootkit in

the firmware?

(15)

Using hardware SPI flash programmer…

(16)

USB & exploiting weak firmware protections...

(17)

From privileged guest (e.g. Dom0). Requires

privesc from normal guest (e.g. DomU) or remote From the host OS before/in parallel to VMM

From normal guest if firmware is exposed to the guest by VMM

For example, if firmware is not adequately write protected in system flash memory Software access and exploiting some

vulnerability in firmware …

(18)

DEMO

Rootkit in System Firmware Exposes Secrets from Virtual Machines

https://youtu.be/sJnIiPN0104

Image source

(19)

We flashed rootkited part of firmware image from within a root partition to install the rootkit The system doesn’t properly protect firmware in SPI flash memory so we could bypass

write-protection

Finally more systems protect firmware on the flash memory

common.bios_wp

CHIPSEC module to test write-protection

Malware can exploit vulnerabilities in firmware to install a rootkit on such systems

Attacking and Defending BIOS in 2015

(20)

VMM “forensics”

With the help of a rootkit in firmware any VM guest can extract all information about hypervisor and other VMs … and just from memory

 VMCS structures, MSR and I/O bitmaps for each VM guest

 EPT for each VM guest

 Regular page tables for hypervisor and each VM guest

 IOMMU pages tables for each IOMMU device

 Full hypervisor memory map, VM exit handler…

 Real hardware configuration (registers for real PCIe devices,

MMIO contents…)

(21)

VMM Hardware Page Tables…

(22)

Attacking Hypervisors through System Firmware

(with OS kernel access)

Image source

(23)

Pointer Vulnerabilities in SMI Handlers

Phys Memory

SMI Handlers in SMRAM

OS Memory

Exploit tricks SMI handler to write to an address inside SMRAM Attacking and Defending BIOS in 2015

RAX (code) RBX (pointer) RCX (function)

RDX RSI RDI

Fake structure inside SMRAM

SMI

(24)

Exploiting firmware SMI handler to attack VMM

Hardware

I/O Memory

Network

Graphics

Hypervisor

SMI Handlers System Firmware

CPU

Virtual Machine (child partition)

Operating System

App App

Root partition

App

Operating System Attack

SMI Pointer Compromised VM injects SMM payload

through the input pointer vulnerability in

SMI handler SMM firmware payload modifies hypervisor code or VMCS/EPT to install

a backdoor

VMM allows VM to invoke SMI handlers (grants access to SW

SMI I/O port 0xB2)

(25)

DEMO

Attacking Hypervisor via

Poisonous Pointers in Firmware SMI handlers

https://youtu.be/zUJEL9cGSE8

(26)

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

(27)

So this is firmware issue, right? What

if firmware validates pointers?

(28)

Still exploitable…

Phys Memory

SMI Handlers in SMRAM

Hypervisor Memory (Protected by EPT)

Firmware SMI handler validates input pointers to ensure they are outside of SMRAM preventing overwrite of SMI code/data

RAX (code) RBX (pointer) RCX (function)

RDX RSI RDI

SMI

(29)

Point SMI handler to overwrite VMM page!

Phys Memory

SMI Handlers in SMRAM

Hypervisor Memory (Protected by EPT)

• VT state and EPT protections are OFF in SMM (without STM)

• SMI handler writes to a protected page via supplied pointer

RAX (code) RBX (pointer) RCX (function)

RDX RSI RDI

VMM Protected Page

SMI

VMM

Protections

are OFF

(30)

Attacking VMM by proxying through SMI handler

Hardware

I/O Memory

Network

Graphics

VMM / Hypervisor

SMI Handlers System Firmware

CPU

VM with direct access to SMIs invokes SMI handler and supplies a

pointer to some VMM page

Virtual Machine (child partition)

Operating System

App App

Root partition

App

Operating System Attack

SMI handler writes to the supplied pointer overwriting contents of

protected VMM page

(31)

Do Hypervisors Dream of Electric Sheep?

Vulnerability used in this section is VU#976132 a.k.a. S3 Resume Boot Script Vulnerability independently discovered by ATR of Intel Security, Rafal Wojtczuk of Bromium and LegbaCore

It’s also used in Thunderstrike 2 by LegbaCore & Trammell Hudson

(32)

Waking the system from S3 “sleep” state

VMM / Hypervisor U/EFI System Firmware Virtual Machine

Platform Init DXE

UEFI core

& drivers BDS

Platform Init S3 Boot

Script Table

Restores hardware config

Script Engine

NORMAL BOOT S3 RESUME

Apps / OS

(33)

What is S3 boot script table?

S3_BOOTSCRIPT_DISPATCH/2

S3_BOOTSCRIPT_PCI_CONFIG_WRITE S3_BOOTSCRIPT_IO_WRITE

A table of opcodes in physical memory which restores platform configuration

S3_BOOTSCRIPT_MEM_WRITE opcode writes some value to

specified memory location on behalf of firmware

(34)

Xen exposes S3 boot script table to Dom0

Xen Hypervisor

U/EFI System Firmware Privileged PV guest (Dom0)

Exploit

VM modifies S3 boot script table in memory

Upon resume, firmware executes rogue S3 script

Platform PEI DXE

UEFI core

& drivers BDS

Platform PEI S3 Boot

Script Table

Restores hardware config

Script Engine

NORMAL BOOT S3 RESUME

MODIFY

0xDBAA4000

(35)

DEMO

Attacking Xen in its sleep

https://youtu.be/Dsu-scEJyJg

Image source

(36)

Déjà vu?

Xen 0wning Trilogy (Part 3) by Invisible Things Lab

(37)

So these firmware vulnerabilities are

exploitable from privileged guest (e.g. root partition, Dom0 ..)

What about use cases where guests must be

strongly isolated from the root partition?

(38)

Tools and Mitigations

Image sciencenews.org

(39)

First things first - fix that firmware!

Firmware 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 memory

common.bios_wp common.spi_lock

...

(tests firmware protections in system flash memory)

(40)

Testing hypervisors…

Simple hardware emulation fuzzing modules for open source CHIPSEC

tools.vmm.*_fuzz

I/O, MSR, PCIe device, MMIO overlap, more soon …

Tools to explore VMM hardware config

chipsec_util iommu (IOMMU)

chipsec_util vm (CPU VM extensions)

(41)

Dealing with system firmware attacks..

A number of interfaces through which

firmware can be attacked or relay attack onto VMM

 UEFI variables, SMI handlers, S3 boot script, SPI flash MMIO, FW update..

 FW doesn’t know memory VMM needs to protect

VMM need to be careful with which of these it exposes to VMs including to administrative

(privileged) guests

 Some need not be exposed (e.g. S3 boot script), some

may be emulated and monitored

(42)

Conclusions

• Compromised firmware is bad news for VMM.

Test your system’s firmware for security issues

• Windows 10 enables path for firmware deployment via Windows Update

• Secure privileged/administrative guests; attacks from such guests are important

• Vulnerabilities in device and CPU emulation are very common. Fuzz all HW interfaces

• Firmware interfaces/features may affect

hypervisor security if exposed to VMs. Both need

to be designed to be aware of each other

(43)

References

1. CHIPSEC: https://github.com/chipsec/chipsec 2. Intel’s ATR Security of System Firmware

3. Attacking and Defending BIOS in 2015 by Intel ATR 4. Hardware Involved Software Attacks by Jeff Forristal 5. Xen 0wning Trilogy by Invisible Things Lab

6. http://www.legbacore.com/Research.html

7. Low level PC attack papers by Xeno Kovah

(44)

Thank you!

Références

Documents relatifs

The bootstrap loader MUST reject a firmware package if the list of supported hardware module type identifiers within the firmware package does not include the object identifier

Press the two buttons above the power button at the same time and the monitor starts updating firmware..

• We present P RETENDER , a proof-of-concept system able to automatically build hardware models, through a mix of novel hardware and interrupt recording techniques, machine

Firmware for embedded devices frequently contains security critical bugs, which can be uncovered using well established dynamic program analysis and testing techniques.. However,

The HP 13256A is made up of a 9-track magnetic tape containing HP 2645A terminal source code, an HP 8080 Cross Assembler program, and various data files and utility programs..

Your wheel should appear under the name “Thrustmaster Advanced Mode Racer”. Thrustmaster Advanced Mode Racer OK.. 4) Your wheel’s firmware version is displayed in the

When there’s newer version of firmware available on ASUS website, follow the procedures below to update your monitor.. Make sure that the power supply is stable and the USB drive

Utiliser un flasher : NODEMCU Firmware programmer pour moi ici : Configurer la laision comme suit :. Choisir un .bin pour mettre le firmware