Hacking the Extensible Hacking the Extensible Firmware Interface - - PowerPoint PPT Presentation

hacking the extensible hacking the extensible firmware
SMART_READER_LITE
LIVE PREVIEW

Hacking the Extensible Hacking the Extensible Firmware Interface - - PowerPoint PPT Presentation

Hacking the Extensible Hacking the Extensible Firmware Interface Firmware Interface John Heasman, Director of Research John Heasman, Director of Research Agenda The role of the BIOS The role of the BIOS Attacking a


slide-1
SLIDE 1

Hacking the Extensible Hacking the Extensible Firmware Interface Firmware Interface

John Heasman, Director of Research John Heasman, Director of Research

slide-2
SLIDE 2
  • The role of the BIOS

The role of the BIOS

  • Attacking a legacy BIOS

Attacking a legacy BIOS

  • Limitations of the legacy BIOS

Limitations of the legacy BIOS

  • Introduction to the EFI environment

Introduction to the EFI environment

  • Attacking the EFI environment

Attacking the EFI environment

  • UEFI, summary and conclusions

UEFI, summary and conclusions

Agenda

slide-3
SLIDE 3
  • This talk is about rootkit persistence

This talk is about rootkit persistence

  • i.e. how to deploy a rootkit from the BIOS/EFI

i.e. how to deploy a rootkit from the BIOS/EFI

  • This talk is not about Trusted Computing

This talk is not about Trusted Computing

  • Some attacks may require physical access

Some attacks may require physical access

  • And most require root access

And most require root access

  • Could be deployed as a blended attack

Could be deployed as a blended attack

  • e.g. browser bug

e.g. browser bug -

  • > escalation to kernel

> escalation to kernel -

  • >

> deploy rootkit deploy rootkit

  • Parts of this research are still work in progress

Parts of this research are still work in progress… …

Some Caveats…

slide-4
SLIDE 4
  • Test and initialise the hardware

Test and initialise the hardware

  • Configure Northbridge and Southbridge

Configure Northbridge and Southbridge

  • Locate and execute options ROMs

Locate and execute options ROMs

  • Scan PCI buses

Scan PCI buses

  • Copy option ROMs to RAM

Copy option ROMs to RAM

  • Scan RAM for options ROMs and execute

Scan RAM for options ROMs and execute

  • Provide means of user configuration

Provide means of user configuration

  • User can select boot device priority and configure hw

User can select boot device priority and configure hw

  • Persists settings to CMOS

Persists settings to CMOS

  • Launch

Launch bootloader bootloader

The Role of the BIOS

slide-5
SLIDE 5
  • #1

#1 -

  • Modify BIOS code and

Modify BIOS code and reflash reflash firmware firmware

  • #2

#2 -

  • Modify PCI Option ROM and

Modify PCI Option ROM and reflash reflash device device

  • #3

#3 -

  • Modify ACPI tables and

Modify ACPI tables and reflash reflash firmware firmware

  • #4

#4 -

  • Non

Non-

  • persistent warm reboot attacks

persistent warm reboot attacks

Attacking a Legacy BIOS

slide-6
SLIDE 6
  • Many places that we can insert code

Many places that we can insert code

  • Ultimately we want to subvert the

Ultimately we want to subvert the bootloader bootloader

  • The

The bootloader bootloader relies on the Interrupt Vector Table relies on the Interrupt Vector Table

  • The IVT is created dynamically

The IVT is created dynamically

  • BIOS calls

BIOS calls int int 19h ( 19h (“ “the bootstrap loader the bootstrap loader” ” vector) vector)

  • Append code before this call after IVT is built

Append code before this call after IVT is built

  • Rewrite IVT to hook desired interrupt

Rewrite IVT to hook desired interrupt

  • Caveats:

Caveats:

  • May require physical access (write protect jumper)

May require physical access (write protect jumper)

  • Secure Flash may prevent unsigned updates

Secure Flash may prevent unsigned updates

  • 1. Patching the BIOS
slide-7
SLIDE 7
  • ROM on PCI card holding initialisation code

ROM on PCI card holding initialisation code

  • Can be for any platform but typically holds x86 code

Can be for any platform but typically holds x86 code

  • Copied to RAM and executed by BIOS

Copied to RAM and executed by BIOS

  • Stored in EPROM or EEPROM

Stored in EPROM or EEPROM

  • Example: EEPROM on your PCIe graphics card:

Example: EEPROM on your PCIe graphics card:

  • Hooks

Hooks int int 10h in real mode IVT 10h in real mode IVT

  • Implements VGA/VBE BIOS functions

Implements VGA/VBE BIOS functions

  • 2. PCI Option ROMs
slide-8
SLIDE 8
  • Obtain option ROM and flash tool

Obtain option ROM and flash tool

  • Patch option ROM

Patch option ROM

  • Add code to hook interrupt of choice

Add code to hook interrupt of choice

  • Gain control when

Gain control when bootloader bootloader calls interrupt calls interrupt

  • Patch kernel itself or kernel modules

Patch kernel itself or kernel modules

  • Which interrupt to hook?

Which interrupt to hook?

  • eEye

eEye’ ’s s BootRoot BootRoot hooked hooked int int 13h (disk) 13h (disk)

  • Can also hook

Can also hook int int 10h (video) on Windows 10h (video) on Windows

  • There are likely other candidates

There are likely other candidates

Attacking Option ROMs

slide-9
SLIDE 9
  • Typically no jumper on PCI card

Typically no jumper on PCI card

  • Flashing is easy

Flashing is easy – – typically just I/O to the card typically just I/O to the card

  • Almost all standalone graphics card can be flashed

Almost all standalone graphics card can be flashed

  • Network cards with PXE are useful

Network cards with PXE are useful

  • Space is typically limited to a few kilobytes

Space is typically limited to a few kilobytes

  • Could distribute over multiple PCI devices

Could distribute over multiple PCI devices

  • Detection is fairly easy

Detection is fairly easy

  • Dump ROM from card and analyse

Dump ROM from card and analyse

  • Give

Give aways aways e.g. presence of protected mode code e.g. presence of protected mode code

  • Detection process could be subverted though

Detection process could be subverted though

Pros and Cons of Option ROM Attacks

slide-10
SLIDE 10
  • 3. Typical ACPI Implementation

ACPI Registers ACPI BIOS ACPI Tables ACPI Drivers/ AML Interpreter Device Driver Kernel OSPM System Code Applications BIOS Hardware

slide-11
SLIDE 11
  • BIOS holds tables containing AML instructions

BIOS holds tables containing AML instructions

  • ACPI device driver contains AML interpreter

ACPI device driver contains AML interpreter

  • AML instruction set allows us to modify system memory

AML instruction set allows us to modify system memory

  • Re

Re-

  • flash BIOS to contain patched ACPI tables

flash BIOS to contain patched ACPI tables

  • AML methods now deploy rootkit from BIOS

AML methods now deploy rootkit from BIOS

ACPI BIOS Rootkits

slide-12
SLIDE 12
  • Independent of OS!

Independent of OS!

  • AML is platform and OS independent

AML is platform and OS independent

  • ASL is a high level language

ASL is a high level language

  • Easy to disassemble AML to ASL and recompile

Easy to disassemble AML to ASL and recompile

  • Kernel is already loaded when AML is interpreted

Kernel is already loaded when AML is interpreted

  • Modify kernel data structures directly

Modify kernel data structures directly

  • Make

Make “ “smart smart” ” decisions before deploying rootkit decisions before deploying rootkit

  • Future

Future-

  • proof rootkit against service packs/

proof rootkit against service packs/hotfixes hotfixes

Benefits of ACPI Rootkits

slide-13
SLIDE 13
  • Must be able to update system BIOS

Must be able to update system BIOS

  • Signed updates prevent attack (Secure Flash)

Signed updates prevent attack (Secure Flash)

  • OS must have ACPI device driver

OS must have ACPI device driver

  • Stop it loading for cross

Stop it loading for cross-

  • view detection

view detection

  • OS must not sandbox AML interpreter

OS must not sandbox AML interpreter

  • Prevent mapping of kernel address space

Prevent mapping of kernel address space

Limitations of ACPI Rootkits

slide-14
SLIDE 14
  • Previous attacks make persistent modifications

Previous attacks make persistent modifications

  • Makes detection easier

Makes detection easier

  • Systems with

Systems with SLAs SLAs are not cold booted regularly are not cold booted regularly

  • But might be warm rebooted (to install updates)

But might be warm rebooted (to install updates)

  • Persist across reboot by modifying code at reset vector

Persist across reboot by modifying code at reset vector

  • This is copied to shadow RAM during cold boot

This is copied to shadow RAM during cold boot

  • We must remove write protection then modify

We must remove write protection then modify

  • Removing write protection is chipset specific

Removing write protection is chipset specific

  • Intel: Programmable Attribute Map Registers (

Intel: Programmable Attribute Map Registers (PAMs PAMs) )

  • AMD: Memory Type Range Registers (

AMD: Memory Type Range Registers (MTRRs MTRRs) )

  • 4. Warm Reboot Attacks
slide-15
SLIDE 15
  • BIOS typically written in Assembler

BIOS typically written in Assembler

  • Who writes 16

Who writes 16-

  • bit real mode assembler?

bit real mode assembler?

  • Rooted in x86 Interrupt model

Rooted in x86 Interrupt model

  • Few cleanly defined interfaces exposed by vendors

Few cleanly defined interfaces exposed by vendors

  • int

int 15h is the 15h is the “ “miscellaneous miscellaneous” ” interrupt interrupt

  • Subfunctions

Subfunctions vary from vendor to vendor vary from vendor to vendor

  • Interfaces that are defined are clunky

Interfaces that are defined are clunky e.g. the Post Memory Manager (PMM) spec: e.g. the Post Memory Manager (PMM) spec:

Legacy BIOS Limitations

slide-16
SLIDE 16

“ “A client follows this procedure to locate and access PMM Service A client follows this procedure to locate and access PMM Services: s:

  • 1. Search for the four
  • 1. Search for the four-
  • byte

byte “ “$PMM $PMM” ” string on paragraph boundaries starting string on paragraph boundaries starting at E000h, and ending, if not found, at at E000h, and ending, if not found, at FFFFh FFFFh. .

  • 2. Verify that the PMM Structure data is valid by performing a c
  • 2. Verify that the PMM Structure data is valid by performing a checksum.

hecksum. The checksum is calculated by doing a byte The checksum is calculated by doing a byte-

  • wise sum of the entire

wise sum of the entire PMM Structure and comparing this sum with zero. If the checksum PMM Structure and comparing this sum with zero. If the checksum is is not zero, then the PMM Structure data is not valid and the not zero, then the PMM Structure data is not valid and the EntryPoint EntryPoint field should not be called. field should not be called.

  • 3. Optionally inspect the
  • 3. Optionally inspect the StructureRevision

StructureRevision field to determine the field to determine the appropriate structure map. The appropriate structure map. The StructureRevision StructureRevision field changes if field changes if previously reserved fields in the PMM Structure are redefined to previously reserved fields in the PMM Structure are redefined to be be valid fields. valid fields.

  • 4. Make calls to the
  • 4. Make calls to the EntryPoint

EntryPoint field in the PMM Structure to allocate and field in the PMM Structure to allocate and free memory as desired. free memory as desired.” ”

Legacy BIOS Limitations Cont.

slide-17
SLIDE 17

Introduction Introduction to EFI to EFI

slide-18
SLIDE 18
  • Re

Re-

  • use existing technologies:

use existing technologies:

  • EFI system partition

EFI system partition filesystem filesystem is FAT is FAT

  • Executables are PE/PE32+

Executables are PE/PE32+

  • ACPI, SMBIOS

ACPI, SMBIOS

  • Extensibility and modularity

Extensibility and modularity

  • Core EFI implementation is in firmware

Core EFI implementation is in firmware

  • Third party drivers can exist on disk or firmware

Third party drivers can exist on disk or firmware

  • Development in high level language

Development in high level language

  • Bootloaders

Bootloaders/drivers typically written in C /drivers typically written in C

  • Platform agnostic, spec simply defines interfaces

Platform agnostic, spec simply defines interfaces

  • EFI Byte Code (EBC) is interpreted instruction set

EFI Byte Code (EBC) is interpreted instruction set

EFI Design Principles

slide-19
SLIDE 19

A Typical EFI Environment

slide-20
SLIDE 20
  • Protocol

Protocol – – “ “drivers drivers” ” that expose interfaces that expose interfaces

  • Each protocol has a GUID

Each protocol has a GUID

  • A single driver can implement multiple protocols

A single driver can implement multiple protocols

  • EFI System Table

EFI System Table

  • Key EFI data structure handed to every app/driver

Key EFI data structure handed to every app/driver

  • Provides means of accessing EFI services

Provides means of accessing EFI services

  • Boot Services

Boot Services – – Services Services available in EFI environment available in EFI environment

  • Event, Timer and Task Priority Services

Event, Timer and Task Priority Services

  • Memory Allocation Services

Memory Allocation Services

  • Protocol Handler Services

Protocol Handler Services

  • Images Services

Images Services

Key EFI Definitions

slide-21
SLIDE 21
  • Runtime Services

Runtime Services – – Services Services available post EFI available post EFI

  • Variable Services

Variable Services

  • Time Services

Time Services

  • Virtual Memory Services

Virtual Memory Services

“The Framework The Framework” ” – – Intel Intel’ ’s reference implementation s reference implementation

  • Used by OS X

Used by OS X

  • Partially open source as

Partially open source as “ “Tiano Tiano” ”

“ “Intel views the Framework as the implementation of choice Intel views the Framework as the implementation of choice” ”

Key EFI Definitions Cont.

slide-22
SLIDE 22
  • EFI 1.10 spec not focused on security

EFI 1.10 spec not focused on security

  • Framework docs elaborate on Security phase

Framework docs elaborate on Security phase

  • Security (SEC) is first phase in the Framework:

Security (SEC) is first phase in the Framework:

  • Handles all platform restart events
  • Creates a temporary memory store
  • Serves as the root of trust in the system
  • Passes handoff information to the PEI
  • PEI is the Pre

PEI is the Pre-

  • EFI phase:

EFI phase:

  • Loads modules specific to low level hardware

Loads modules specific to low level hardware

  • Maintains root of trust

Maintains root of trust

  • Invokes Driver Execution Environment (DXE) loader

Invokes Driver Execution Environment (DXE) loader

EFI Security

slide-23
SLIDE 23

EFI Security Cont.

slide-24
SLIDE 24

Abusing EFI Abusing EFI

slide-25
SLIDE 25
  • Get code into the EFI environment

Get code into the EFI environment

  • 1. Modify
  • 1. Modify bootloader

bootloader itself itself

  • 2. Modify NVRAM
  • 2. Modify NVRAM bootloader

bootloader variable variable

  • 3. Modify and
  • 3. Modify and reflash

reflash platform firmware platform firmware

  • 4. Exploit implementation flaw in driver
  • 4. Exploit implementation flaw in driver
  • Subvert loading of the operating system

Subvert loading of the operating system

  • 1. Shim a boot service/runtime service
  • 1. Shim a boot service/runtime service
  • 2. Modify the ACPI tables
  • 2. Modify the ACPI tables
  • 3. Load an SMM driver
  • 3. Load an SMM driver
  • 4. Hook interrupt handlers if CSM & legacy
  • 4. Hook interrupt handlers if CSM & legacy bootloader

bootloader

Objectives

slide-26
SLIDE 26
  • Modify the

Modify the bootloader bootloader binary itself binary itself

  • MacOS

MacOS X X: /System/Library/ /System/Library/CoreServices/boot.efi CoreServices/boot.efi

  • N.B. OS X does not use the EFI system partition

N.B. OS X does not use the EFI system partition

  • Not very stealthy

Not very stealthy

  • Easily detected with system integrity tools

Easily detected with system integrity tools

  • Why not just modify the kernel itself?

Why not just modify the kernel itself?

  • Won

Won’ ’t work if environment enforces driver signing t work if environment enforces driver signing

Modifying the Bootloader

slide-27
SLIDE 27
  • Global variables persisted in NVRAM

Global variables persisted in NVRAM

  • Specifies which

Specifies which bootloader bootloader to use to use

  • EFI provides interface for reading/writing

EFI provides interface for reading/writing

  • OS typically provides an

OS typically provides an ‘ ‘nvram nvram’ ’ tool tool

  • Create custom

Create custom bootloader bootloader

  • Can simply patch environment and call original

Can simply patch environment and call original

  • Modify

Modify “ “efi efi-

  • boot

boot-

  • device

device” ” variable variable

  • Stealthier than modifying original

Stealthier than modifying original bootloader bootloader? ?

  • Leaves original

Leaves original bootloader bootloader in tact in tact

  • But obviously requires extra file on disk

But obviously requires extra file on disk

  • Won

Won’ ’t work if environment enforces driver signing t work if environment enforces driver signing

Modifying NVRAM Variables

slide-28
SLIDE 28
  • Important when firmware verifies digital signatures

Important when firmware verifies digital signatures

  • Depends on implementation flaw in driver

Depends on implementation flaw in driver

  • Plenty of targets:

Plenty of targets:

  • File system drivers (e.g. FAT32, HFS+)

File system drivers (e.g. FAT32, HFS+)

  • PE parsing code

PE parsing code

  • Crypto code (Data in

Crypto code (Data in certs certs, ASN.1 decoding) , ASN.1 decoding)

  • Network interaction (PXE)

Network interaction (PXE)

Code Injection Attacks

slide-29
SLIDE 29
  • Bootloader

Bootloader must call must call ExitBootServices ExitBootServices() ()

  • This indicates it is ready to launch kernel

This indicates it is ready to launch kernel

  • Runtime drivers remain

Runtime drivers remain

  • Perfect place to hook as kernel is likely in memory

Perfect place to hook as kernel is likely in memory

  • Create runtime driver that hooks

Create runtime driver that hooks ExitBootServices ExitBootServices: :

  • Replace

Replace ExitBootServices ExitBootServices function pointer function pointer

  • Function pointer located in EFI System Table

Function pointer located in EFI System Table

  • Locate kernel, patch to deploy rootkit

Locate kernel, patch to deploy rootkit

  • Could alternatively shim a runtime service, if called

Could alternatively shim a runtime service, if called

Shimming Boot Services

slide-30
SLIDE 30

eLilo eLilo loading kernel: loading kernel:

1.

  • 1. kernel_load(image, kname, &kd, &imem, &mmem))

kernel_load(image, kname, &kd, &imem, &mmem)); ; /* free resources associated with file accesses /* free resources associated with file accesses (before ExitBootServices) */ (before ExitBootServices) */ 2.

  • 2. close_devices();

close_devices(); /* terminate bootservices */ /* terminate bootservices */ 3.

  • 3. status = BS

status = BS-

  • >ExitBootServices(image, cookie);

>ExitBootServices(image, cookie); 4.

  • 4. start_kernel(kd.kentry, bp);

start_kernel(kd.kentry, bp); /* NOT REACHED */ /* NOT REACHED */

Shimming Boot Services Cont.

slide-31
SLIDE 31
  • SMM first introduced in 386SL

SMM first introduced in 386SL

  • Entered via SMI

Entered via SMI

  • May be triggered via external event

May be triggered via external event

  • Or periodically

Or periodically

  • Or on I/O access

Or on I/O access

“Get out of jail free card Get out of jail free card” ” for platform designers for platform designers

  • Enable/disable ACPI mode

Enable/disable ACPI mode

  • Power button support while not in ACPI mode

Power button support while not in ACPI mode

  • Error logging for ECC/PERR/SERR in IA

Error logging for ECC/PERR/SERR in IA-

  • 32

32

  • Protected flash writes on some IA

Protected flash writes on some IA-

  • 32 platforms

32 platforms

  • Century rollover bug workaround

Century rollover bug workaround

System Management Mode

slide-32
SLIDE 32
  • Loic

Loic Duflot Duflot used SMM to bypass BSD used SMM to bypass BSD Securelevels Securelevels

  • Hinted at possibility of SMM

Hinted at possibility of SMM-

  • based malware

based malware

  • What does this mean for rootkits/rootkit detection?

What does this mean for rootkits/rootkit detection?

  • Hardware breakpoints do not fire in SMM

Hardware breakpoints do not fire in SMM

  • Access to SMM memory blocked if lock bit set

Access to SMM memory blocked if lock bit set

  • SMIs

SMIs cannot be interrupted, even by cannot be interrupted, even by NMIs NMIs

  • SMM can trap I/O reads/writes

SMM can trap I/O reads/writes

  • Why has there been no SMM malware yet?

Why has there been no SMM malware yet?

  • Bar for entry is high: debug with logic analyzer

Bar for entry is high: debug with logic analyzer

  • Limited opportunity with SMM lock bit

Limited opportunity with SMM lock bit

  • System dependencies make it less attractive

System dependencies make it less attractive

Abusing SMM

slide-33
SLIDE 33
  • EFI provides clean, easy to use SMM interfaces

EFI provides clean, easy to use SMM interfaces

  • Base Protocol for driver registration

Base Protocol for driver registration

  • Access Protocol for setting lock bit

Access Protocol for setting lock bit

  • Control Protocol for triggering SMI

Control Protocol for triggering SMI

  • Child Dispatch Protocol for types of SMM event

Child Dispatch Protocol for types of SMM event

  • System Management System Table (SMST)

System Management System Table (SMST)

  • Provides set of services to SMM drivers

Provides set of services to SMM drivers

  • Handles memory allocation/de

Handles memory allocation/de-

  • allocation

allocation

  • Abstracts access to CPU context, memory,

Abstracts access to CPU context, memory, and I/O space and I/O space

EFI and SMM

slide-34
SLIDE 34

EFI and SMM Cont.

“ “The SMM phase must preserve the chain of trust initiated in the The SMM phase must preserve the chain of trust initiated in the previous previous

  • phase. To do so, it must validate the modules that it loads for
  • phase. To do so, it must validate the modules that it loads for the

the subsequent dispatcher. subsequent dispatcher.” ”

slide-35
SLIDE 35
  • Provide backwards compatibility for legacy

Provide backwards compatibility for legacy bootloader bootloader

  • Implements IVT

Implements IVT

  • Execute

Execute bootloader bootloader in 16 in 16-

  • bit real mode

bit real mode

  • Interrupt handlers

Interrupt handlers thunk thunk to EFI (32 to EFI (32-

  • bit, protected)

bit, protected)

  • Examples:

Examples:

  • Xp

Xp On Mac (XOM) On Mac (XOM)

  • Apple

Apple Bootcamp Bootcamp

  • Hook IVT as per legacy BIOS attack

Hook IVT as per legacy BIOS attack

Compatibility Support Modules

slide-36
SLIDE 36

UEFI UEFI

slide-37
SLIDE 37

“Unified EFI Unified EFI” ” spec originally based on EFI 1.10 spec originally based on EFI 1.10

  • UEFI is a consortium of major hw/

UEFI is a consortium of major hw/sw sw vendors vendors

  • Current version is 2.1

Current version is 2.1

  • Provides further information on driver signing

Provides further information on driver signing

  • Trusted Computing Group specs:

Trusted Computing Group specs:

  • TCG EFI Platform Specification

TCG EFI Platform Specification

  • TCG EFI Protocol Specification

TCG EFI Protocol Specification

EFI and UEFI

slide-38
SLIDE 38

EFI and UEFI

slide-39
SLIDE 39
  • EFI offers a large attack surface

EFI offers a large attack surface

  • High level development tools make it more of a target

High level development tools make it more of a target

  • Third party driver model presents easier target

Third party driver model presents easier target

  • The EFI spec is vague on security

The EFI spec is vague on security

  • Blurred relationship between spec and Framework

Blurred relationship between spec and Framework

  • How is the Sec phase supposed to be implemented?

How is the Sec phase supposed to be implemented?

  • UEFI makes things clearer

UEFI makes things clearer

  • But plenty of surface for code injection attacks

But plenty of surface for code injection attacks

  • More to come on EFI attacks, stay tuned

More to come on EFI attacks, stay tuned ☺ ☺

Summary & Conclusions

slide-40
SLIDE 40
  • EFI

EFI -

  • http://

http://www.intel.com/technology/efi www.intel.com/technology/efi/ /

  • UEFI

UEFI -

  • http://

http://www.uefi.org www.uefi.org/specs/ /specs/

  • Tiano

Tiano -

  • https://

https://www.tianocore.org www.tianocore.org/ /

“Security Issues Relating to System Management Mode Security Issues Relating to System Management Mode” ”

  • http://www.cansecwest.com/slides06/csw06

http://www.cansecwest.com/slides06/csw06-

  • duflot.ppt

duflot.ppt

  • XP On Mac

XP On Mac -

  • http://

http://www.onmac.net www.onmac.net/ /

References

slide-41
SLIDE 41

Any Questions? Any Questions? Thanks! Thanks! john at john at ngssoftware ngssoftware dot com dot com