uefi firmware rootkits: myths and reality · legacy bios vs. uefi legacy bios uefi firmware...

82
UEFI Firmware Rootkits: Myths and Reality Alex Matrosov @matrosov Eugene Rodionov @vxradius

Upload: others

Post on 10-Jul-2020

177 views

Category:

Documents


9 download

TRANSCRIPT

Page 1: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

UEFI Firmware Rootkits: Myths and Reality

Alex Matrosov@matrosov

Eugene Rodionov@vxradius

Page 2: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Agenda

Historical overview of BIOS rootkits

Threat Model for UEFI Rootkits

BIOS Rootkits In-The-Wild HackingTeam Rootkit BIOS Implants Computrace/LoJack

BIOS Update Issues

Secure Boot Issues

Forensic Approaches

Page 3: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

History of BIOS rootkits

Page 4: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 5: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

2006200620082008 20092009 20112011 20122012 20132013 2014201419981998

20152015

Com

putr

ace

Meb

rom

i/BI

OSk

it

Rakshasa

DEI

TYBO

UN

CE

Move to UEFI world with Secure Boot

In the Wild

Proof of Concept

Win

CIH

ACPI Rootkit

SMM

Rootkit

Dream Boot

1 st SecureBoot Bypass

20162016

BadB

IOS

Hys

teri

a

Darth Venamis

Thunderstrike

HT

rklo

ader

Thunderstrike2

SMM

backdoor

MS Win10: Virtualization Based Security Era

SMM

->VMM

PEIbackdoor

BAN

AN

ABA

LLO

T

20072007

PCI OptRom Rootkit

BIOS Patching

LightEater

IceLord Rootkit

Mem

ory Sinkhole

ThinkPwn

History of BIOS rootkits

Page 6: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

2006200620082008 20092009 20112011 20122012 20132013 2014201419981998

20152015

Com

putr

ace

Meb

rom

i/BI

OSk

it

Rakshasa

DEI

TYBO

UN

CE

Move to UEFI world with Secure Boot

In the Wild

Proof of Concept

Win

CIH

ACPI Rootkit

SMM

Rootkit

Dream Boot

1 st SecureBoot Bypass

20162016

BadB

IOS

Hys

teri

a

Darth Venamis

Thunderstrike

HT

rklo

ader

Thunderstrike2

SMM

backdoor

MS Win10: Virtualization Based Security Era

SMM

->VMM

PEIbackdoor

BAN

AN

ABA

LLO

T

20072007

PCI OptRom Rootkit

BIOS Patching

LightEater

IceLord Rootkit

Mem

ory Sinkhole

ThinkPwn

History of BIOS rootkits

Page 7: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

2006200620082008 20092009 20112011 20122012 20132013 2014201419981998

20152015

Com

putr

ace

Meb

rom

i/BI

OSk

it

Rakshasa

DEI

TYBO

UN

CE

Move to UEFI world with Secure Boot

In the Wild

Proof of Concept

Win

CIH

ACPI Rootkit

SMM

Rootkit

Dream Boot

1 st SecureBoot Bypass

20162016

BadB

IOS

Hys

teri

a

Darth Venamis

Thunderstrike

HT

rklo

ader

Thunderstrike2

SMM

backdoor

MS Win10: Virtualization Based Security Era

SMM

->VMM

PEIbackdoor

BAN

AN

ABA

LLO

T

20072007

PCI OptRom Rootkit

BIOS Patching

LightEater

IceLord Rootkit

Mem

ory Sinkhole

ThinkPwn

History of BIOS rootkits

Page 8: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

In The Beginning…

In 1998-99 CIH (Chernobyl) viruswritten by a student of Taipei Tatung Institute of Technology in Taiwan infected ~60 million PCs

CIH (Chernobyl) erased BIOS ‘ROM’ boot block and boot sectors on a hard drive causing ~1B US dollars in damage

Bootkits: past, present & future (VB2014)

Page 9: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

• Mebromi malware includes BIOS infector & MBR bootkit components

• Patches BIOS ROM binary injecting malicious ISA Option ROM with legitimate BIOS image mod utility

• Triggers SW SMI 0x29/0x2F to erase SPI flash then write patched BIOS binary

Signed BIOS Updates Are Rare

Bootkits: past, present & future (VB2014)

Page 10: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Threat Model for UEFI Rootkits

Page 11: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 12: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

• Mitigations: PatchGuard, Code Signing Policy

• Prevention: AV HIPS

OS Kernel-Mode (Ring 0)

• Mitigations: Secure/Measured Boot, Boot Guard

• Prevention: AV HIPS

Boot code (MBR/VBR)

• Mitigations: ??? (STM? but nobody used)

• Prevention: ???

BIOS/UEFI Firmware SMM (Ring -2)

Page 13: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Legacy BIOS vs. UEFI

No more MBR and VBR/IPL code

Different hard drive partitioning scheme: GPT (GUID Partition Table)

Secure Boot and Measured Boot

BIOS

BIOS boot code

Boot Manager (bootmgr.exe)

Load kernel and boot start drivers

OS Loader (winload.exe)

MBR (Master Boot Record)

VBR/IPL(Volume Boot Record/ Initial Program Loader)

Load kernel and boot start drivers

OS Loader (winload.efi)

UEFI boot loader (bootmgfw.efi)

UEFI boot code

UEFI

Page 14: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Legacy BIOS vs. UEFI

Legacy BIOS UEFI firmware

Architecture Unspecified firmware development process. All

BIOS vendors independently support their own code

base

Unified specification for firmware development and

Intel reference code (EDKI/EDKII)

Implementation Mostly on Assembly Language C/C++

Memory Model 16-bit Real-Mode 32/64-bit Protected-Mode

Bootstrap Code MBR and VBR none (firmware controls the boot process)

Partition Scheme MBR partition table GUID partition table (GPT)

Disk IO System Interrupts UEFI Services

Boot Loaders bootmgr and winload bootmgrfw.efi and winload.efi

OS Interaction BIOS Interrupts UEFI Services

Page 15: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

UEFI BIOS Firmware

SEC

Pre-EFI Init (PEI)

Driver Exec Env(DXE)

Boot Dev Select (BDS)

Runtime / OS

S-CRTM; Init caches/MTRRs; Cache-as-RAM (NEM); Recovery; TPM Init

S-CRTM: Measure DXE/BDSEarly CPU/PCH InitMemory (DIMMs, DRAM) Init, SMM Init

Continue initialization of platform & devicesEnum FV, dispatch drivers (network, I/O, service..)Produce Boot and Runtime Services

Boot Manager (Select Boot Device)EFI Shell/Apps; OS Boot Loader(s)

ExitBootServices. Minimal UEFI services (Variable)

ACPI, UEFI SystemTable, SMBIOS table

CPU Reset

Page 16: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

UEFI BIOS Firmware Rootkits

UEFI Binaries

Boot Manager

Platform Initialization(Firmware)

UEFI Driver

UEFI Image Load(DXE and Apps)

UEFI Application

UEFI OS Loader Load (Boot order select )

Boot Services (ExitBootServices)

UEFI Boot Code

Operating System Loader

Patching UEFI “Option ROM”UEFI DXE Driver in Add-On Card (Network, Storage ..)

Non-Embedded in FV in ROM

Adding/Replacing DXE DriverModified DriverOrder / Driver#### EFI variables

Replacing Windows Boot ManagerEFI System Partition (ESP) on Fixed Drive

ESP\EFI\Microsoft\Boot\bootmgfw.efi

Replacing Fallback Boot LoaderESP\EFI\Boot\bootx64.efi

Adding New Boot Loader (bootkit.efi)Modified BootOrder / Boot#### EFI variables

Page 17: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

EFI_RUNTIME_SERVICES and HAL

Pointers

EFI_SYSTEM_TABLE

EFI_RUNTIME_SERVICES

EFI_BOOT_SERVICES

EFI_DXE_SERVICES

Page 18: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 19: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Firmware Rootkit Stage 1:

Client-Side Exploit drop installer (1) Installer Elevate Privileges to System

Stage 2: Bypass Code Signing Policies Install Kernel-Mode Payload (2)

Stage 3: Execute SMM exploit Elevate Privileges to SMM Execute Payload (3)

Stage 4: Bypass Flash Write Protection Install Rootkit into Firmware

Page 20: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Expose S3 boot script table (VU #976132) for BIOS Rootkits

U/EFI System Firmware

OS Kernel-Mode

Exploit

Platform PEI

DXE

UEFI core

& drivers

BDS

Platform PEI

S3 Boot

Script Table

Restores

hardware configScript EngineN

OR

MA

L B

OO

T

MO

DIF

Y

SPI Flash

http://blog.cr4.sh/2016/06/exploring-and-exploiting-lenovo.html

SMM

S3 R

ESU

ME

Page 21: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

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

Page 22: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Exploiting firmware SMI handler

Hardware

I/O

Memory

Network

Graphics

SMI Handlers

System Firmware

CPU

Injects SMM payload through the input

pointer vulnerability in SMI handler

SMM firmware payload install a persistent

rootkit

OS Kernel-Mode

Exploit

Exploit invoke SMI handlers (grants access

to SW SMI I/O port 0xB2)

SMI P

oin

ter

Page 23: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Hardware

I/O Memory Network Graphics

UEFI DXE Core / Dispatcher

UEFI OS Loaders (winload.efi, winresume.efi)

System Firmware (SEC/PEI)

UEFI

OROM

UEFI

Boot Loader

Bootx64.efi

Bootmgfw.efi

Signed BIOS

Update

UEFI

OROM

UEFI

App

UEFI

App

DXE

Driver

DXE

Driver

OS Kernel / Early Launch Anti-Malware (ELAM)

UEFI

Secure

Boot

OS Driver OS Driver

Windows 10

Secure

Boot

What about Secure Boot?

Hardware

I/O Memory Network Graphics TPM

Measured Boot

Page 24: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Firmware Rootkit Stage 1:

Client-Side Exploit drop installer (1) Installer Elevate Privileges to System

Stage 2: Bypass Code Signing Policies Install Kernel-Mode Payload (2)

Stage 3: Execute SMM exploit Elevate Privileges to SMM Execute Payload (3)

Stage 4: Bypass Flash Write Protection Install Rootkit into Firmware

Page 25: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Hardware

I/O Memory Network Graphics

UEFI DXE Core / Dispatcher

UEFI OS Loaders

System Firmware (SEC/PEI)

DXE

Driver

UEFI

Boot Loader

Bootx64.efi

Bootmgfw.efi

Signed BIOS

Update

DXE

Driver

OS Kernel

OS Driver OS Exploit

Modify Secure Boot FW or

config in ROM

Going deeper or bypass still possible?

Measured BootHardware

I/O Memory Network Graphics

Hardware

I/O Memory Network Graphics TPM

Windows 10

Secure

Boot

UEFI

Secure

Boot

Page 26: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

BIOS Rootkits In-The-Wild

Page 27: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 28: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

HakingTeam Vector-EDK

Page 29: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Hacking Team UEFI Implant

First* discovery of non-PoC UEFI Malware

Persistent copy of malicious agent inside BIOS

http://www.intelsecurity.com/advanced-threat-research/content/data/HT-UEFI-rootkit.html

Page 30: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Hacking Team UEFI Implant : Modules

rkloader

• DXE module

• bootkit trigger

fsbg

• UEFI application

• main bootkitfunctionality

ntfs

• DXE module

• NTFS driver

Page 31: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Hacking Team UEFI Implant: How It Works

RkLoader is executed at DXE

phase by Firmware

• Load and execute main bootkitmodule fsbg

Application fsbgis executed

• Initialize NTFS protocol by loading NTFS driver

Drop malware onto NTFS

volume

• Application fsbg installs malware onto NTFS volume

Page 32: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Hacking Team UEFI Implant: How It Works

Page 33: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 34: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 35: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Hacking Team UEFI Implant: How It Works

Page 36: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Hacking Team : Results

• Via exploitation of firmware vulnerability

Page 37: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 38: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

DEITYBOUNCE

Page 39: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Only Snowden-leaked documentation is available for analysis

Safe to assume that servers use legacy BIOS1

1. http://resources.infosecinstitute.com/nsa-bios-backdoor-god-mode-malware-deitybounce/

Page 40: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

DEITYBOUNCE Workflow

Computer Firmware (BIOS)

ARKSTREAM DEITYBOUNCE

SMRAM

Malicious SMI handler

System Initialization

Execute OS bootloader

OS Kernel is initialized

Patch OS kernel/Inject malicious module

Page 41: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

BANANABALLOT and JETPLOW (Equation Group)

Page 42: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 43: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 44: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 45: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

https://dsec.ru/ipm-research-center/research/architecture_jetplow/

Page 46: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Computrace/LoJack

Page 47: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Computrace/LoJack

Legitimate application that provides anti-theft protection.

Implements rootkit functionality to “persist” on the system

Contains UEFI BIOS components to perform its activities

Page 48: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 49: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Computrace/LoJack

Page 50: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Computrace/LoJack

Page 51: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Computrace/LoJackUEFI Environment

OS Environment

Computrace Configuration & Activation

LenovoComputraceLoaderDxe LenovoComputraceEnablerDxe

AbsoluteComputraceInstallerDxe LenovoComputraceSmiServices

OS NTFS Volume

Computrace C&C Servers

Ne

two

rk

Inte

rfac

e

OS

Pro

cess

Co

mp

utr

ace

A

gen

t

Inst

all C

om

pu

trac

e A

gen

t

OS

Pro

cess

OS

Pro

cess

...

Page 52: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

BIOS Update Issues

Page 53: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 54: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Lenovo BIOS Update on MS Win10 with Device Guard

Page 55: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Forensic Approaches

Page 56: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 57: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Firmware Forensics with CHIPSEC

Live system firmware analysis

chipsec_util spi info

chipsec_util spi dump rom.bin

chipsec_util spi read 0x700000 0x100000 bios.bin

chipsec_util uefi var-list

chipsec_util uefi var-read db

D719B2CB-3D3A-4596-A3BC-DAD00E67656F db.bin

Offline system firmware analysis

chipsec_util uefi keys PK.bin

chipsec_util uefi nvram vss bios.bin

chipsec_util uefi decode rom.bin

chipsec_util decode rom.bin

https://github.com/chipsec/chipsec

Page 58: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Firmware Forensics with CHIPSEChttps://github.com/chipsec/chipsec/blob/master/chipsec/modules/tools/uefi/blacklist.json

{

"HT_rkloader" : { "guid": "F50248A9-2F4D-4DE9-86AE-BDA84D07A41C" },

"HT_rkloader_name" : { "name": "rkloader" },

"HT_Ntfs" : { "guid": "F50258A9-2F4D-4DA9-861E-BDA84D07A44C" },

"HT_Ntfs_name" : { "name": "Ntfs" },

"HT_app" : { "guid": "EAEA9AEC-C9C1-46E2-9D52-432AD25A9B0B" },

"ThinkPwn_SmmRuntimeProtGuid" : { "regexp": "\\xA1\\x97\\x68\\xA5 ...\\x9A" },

"ThinkPwn_SystemSmmRuntimeRt_name" : { "name": "SystemSmmRuntimeRt.efi" },

"ThinkPwn_SystemSmmRuntimeRt" : { "guid": "7C79AC8C-5E6C-4E3D-BA6F-C260EE7C172E" },

"ThinkPwn_SmmRuntime_name" : { "name": "SmmRuntime" },

"ThinkPwn_SmmRuntime" : { "guid": "A56897A1-A77F-4600-84DB-22B0A801FA9A" }

}

https://github.com/chipsec/chipsec/blob/master/chipsec/modules/tools/uefi/blacklist.py

chipsec_main.py -i -m tools.uefi.blacklist [-a <fw_image>,<blacklist>]

chipsec_main.py -i --no_driver -m tools.uefi.blacklist -a uefi.rom,blacklist.json

https://github.com/chipsec/chipsec

Page 59: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

How to dump SPI Flash?

Page 60: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

SPI Flash Dump – Dumping from OS

• SPI Controller• Get SPI Base Address Register (refer to

ICH/PCH documentation) -- SPIBAR

• Memory-mapped SPI Registers• SPIBAR + 0x04: HSFS – Status Register

• SPIBAR + 0x06: HSFC – Control Register

• SPIBAR + 0x08: FADDR – Address Register

• SPIBAR + 0x10: FDATAX – Data Registers

Get platform

PCH/ICH configuration

Get Root Complex

Block Address

Get SPIBAR value

Page 61: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

SPI Flash Dump – Dumping from OS

Reader SPI ControllerWrite start address to FADDR

Write size of data to read to HSFC

Write read command to HSFC

Set FGO (0x0001) bit in HSFC

Read data from FDATAX registers

Wait for SPI read cycle completion

FDBC

FGOFCYCLE

FSMIE

FDBC

FGOFCYCLE

FSMIE

FDBC

FGOFCYCLE

FSMIE

Flash Linear AddressFADDR:

HSFC:

HSFC:

HSFC:

...

FDO

NE

FCERR

AEL

BER

ASE

SCIPHSFS:

DATAFDATAX:

Page 62: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

SPI Flash Dump – Attacker’s Possibilities

Flash SPI SMI# Enable (FSMIE) — R/W. When set to 1, the SPI asserts an SMI# request whenever the Flash Cycle Done (FDONE) bit is 1.

FDBC

FGOFCYCLE

FSMIEHSFC:

Page 63: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

SPI Flash Dump – Attacker’s Possibilities

Reader SPI Controller

Write start address to FADDR

Write size of data to read to HSFC

Write read command to HSFC

Set FGO (0x0001) bit in HSFC

Read data from FDATAX registers

Wait for SPI read cycle completion

Attacker

Once FDONE is set to 1 SMI is triggered

Write fake data to FDATAX registers

Set FSMIE bit to 1 in HSFC

Page 64: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 65: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

How to dump BIOS firmware directly from chip?

Page 66: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

How to dump BIOS firmware directly from chip?

Page 67: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

How to dump BIOS firmware directly from chip?

Page 68: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

How Debug UEFI Firmware?

http://wiki.bios.io/doku.php?id=ida_pro_tracing

Page 69: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

How Debug UEFI Firmware?

http://wiki.bios.io/doku.php?id=ida_pro_tracing

Page 70: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Intel Virtual Platform

• Perfect simulation of hardware

• Boot after power on, sleep and hibernate

• Dump SMRAM, memory map and other parameters

• Disassembling

• Dynamic check of accesses out of allowable memory regions and SMRAM call-outs

Page 71: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Minnowboard Max

http://wiki.minnowboard.org/

Page 72: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Minnowboard Max

http://wiki.minnowboard.org/

Page 73: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 74: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Intel XDP Hardware Debuggers

Page 75: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

SMM Debug with Intel System Debugger

Page 76: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Few words about UEFI Firmware Mitigations

Page 77: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 78: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Exploiting AMI Aptio firmware on example of Intel NUC

http://blog.cr4.sh/2016/10/exploiting-ami-aptio-firmware.html

Page 79: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 80: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 81: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support
Page 82: UEFI Firmware Rootkits: Myths and Reality · Legacy BIOS vs. UEFI Legacy BIOS UEFI firmware Architecture Unspecified firmware development process. All BIOS vendors independently support

Thank you for your attention!

Eugene Rodionov@vxradius

Alex Matrosov@matrosov