bh- us 08 winning the race to bare metal - don bailey ......winning the race to bare metalwinning...

27
Winning the Race to Bare Metal Winning the Race to Bare Metal ~ UEFI H i UEFI Hypervisors He who gets there fastest with the mostest winsHe who gets there fastest with the mostest wins 1

Upload: others

Post on 28-Jul-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

Winning the Race to Bare MetalWinning the Race to Bare Metal~

UEFI H iUEFI Hypervisors

“He who gets there fastest with the mostest wins”He who gets there fastest with the mostest wins

1

Page 2: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

Summary

• There is a race to bare metal between black hats and white hatsThere is a race to bare metal between black hats and white hats

• UEFI pre-OS capabilities provide the ability to launch tools BEFORE the OS bootloader is called

• Bare metal hypervisor technology is powerful, well understood and maturing

• Commodity support for UEFI 2.0 is emerging

• The combination of bare metal hypervisors and UEFI has greatThe combination of bare metal hypervisors and UEFI has great potential and implications for system exploitation and security

2

Page 3: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

O C t B M t l H iOur Custom Bare Metal Hypervisor

• Lightweight and pluggable by design

C t i t h i ti d b• Contains a custom hypervisor runtime debugger

• Capable of hosting x64 line of Windows Operating Systems

• Implements Intel® VMX (VT-x)

3

Page 4: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI

• Unified Extensible Firmware Interface

• UEFI describes a programmatic interface between the platform fi d th OSfirmware and the OS

• UEFI replaces and extends the functionality of legacy BIOS

• UEFI 2.0 is supported in Microsoft Windows Vista x64 SP1 and Linux distributions

• Commodity motherboards are beginning to support UEFI 2.0

• Some of the more interesting an powerful features of UEFI are the OS biliti

4

pre-OS capabilities

Page 5: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI GoalsUEFI Goals

• OS neutralityOS neutrality

• Well defined, clean, and extensible interfaces

• Modularity

• HLL friendly• HLL friendly

• Scalability

• Revolutionary Boot Manager

Ki k A OS biliti

5

• Kick-Ass pre-OS capabilities

Page 6: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI F kUEFI Framework

Operating System

Legac OS Loader UEFI OS LoaderLegacy OS Loader UEFI OS Loader

UEFI Boot Services

Me T

DrivBoot Devices

UEFIRuntime

Compatibility

emory

Timer

vers

Protocols and Handlers

RuntimeServices

Platform FirmwareOther

Platform Hardware

Other

SMBIOS

ACPI EFI SystemPartition OS

MotherboardROM/Flash Option

Rom

6

OSPartition

EFI OSLoader

EFI Drivers

EFI Drivers

EFI Drivers

Rom

Page 7: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

E dPreVerifier

CPUInit

OS-AbsentApplication

Transient OS

ExposedAPI Previously exposed

Framework APIs now limited

ExitBootServices()Init

ChipsetInit

Device,Bus, orServiceDriver

Transient OSEnvironment

Transient OS

VE

RIFY

MotherboardInit

DXEDispatcher

BootDispatcher

a s e t OSBoot Loader

OS-PresentApplicationDispatcher Dispatcher

Boot ServicesRuntime Services

DXE Services

Final OSBoot Loader Final OS

Environment

Application

?

Security(SEC)

Pre-EFIInitialization

(PEI)

Driver ExecutionEnvironment

(DXE)

Boot DeviceSelection

(BDS)

Transient SystemLoad(TSL)

Run Time(RT)

AfterLife(AL)

7

( ) ( ) ( ) ( ) ( )

Power On [..Platform Initialization ..] [..OS Boot ..] Shutdown

Page 8: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

E dPreVerifier

CPUInit

OS-AbsentApplication

Transient OS

ExposedAPI Previously exposed

Framework APIs now limited

ExitBootServices()Init

ChipsetInit

Device,Bus, orServiceDriver

Transient OSEnvironment

Transient OS

VE

RIFY

MotherboardInit

DXEDispatcher

BootDispatcher

a s e t OSBoot Loader

OS-PresentApplicationDispatcher Dispatcher

Boot ServicesRuntime Services

DXE Services

Final OSBoot Loader Final OS

Environment

Application

?

Security(SEC)

Pre-EFIInitialization

(PEI)

Driver ExecutionEnvironment

(DXE)

Boot DeviceSelection

(BDS)

Transient SystemLoad(TSL)

Run Time(RT)

AfterLife(AL)

8

( ) ( ) ( ) ( ) ( )

Power On [..Platform Initialization ..] [..OS Boot ..] Shutdown

Page 9: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI Driver UEFIApplication

UEFIBootcode

OSLoader

Failure

Platform Init UEFI ImageLoad

Boot ServicesTerminate

UEFI OS LoaderLoad

Standard Drivers and Boot from OperationStandard Firmware Platform Initialization

Drivers andApplicationsLoaded Iteratively

Boot fromOrdered List ofUEFI OS Loaders

Operation Handed OffTo OS Loader

KKey

Specified by API

Value Added Implementation

UEFI API

9

Boot Manager

UEFI Binaries

Page 10: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI F kUEFI Framework

Operating System

Legac OS Loader UEFI OS LoaderLegacy OS Loader UEFI OS Loader

UEFI Boot Services

Me T

DrivBoot Devices

UEFIRuntime

Compatibility

emory

Timer

vers

Protocols and Handlers

RuntimeServices

Platform FirmwareOther

Platform Hardware

Other

SMBIOS

ACPI EFI SystemPartition OS

MotherboardROM/Flash Option

Rom

10

OSPartition

EFI OSLoader

EFI Drivers

EFI Drivers

EFI Drivers

Rom

Page 11: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI F kUEFI Framework

Operating System

Legac OS Loader UEFI OS LoaderLegacy OS Loader UEFI OS Loader

UEFI Boot Services

Me T

DrivBoot Devices

UEFIRuntime

Compatibility

emory

Timer

vers

Protocols and Handlers

RuntimeServices

Platform FirmwareOther

Platform Hardware

Other

SMBIOS

ACPI EFI SystemPartition OS

MotherboardROM/Flash Option

Rom

11

OSPartition

EFI OSLoader

EFI Drivers

EFI Drivers

EFI Drivers

Rom

Page 12: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

OS L d FlOS Loader Flow

DetermineOS Loader

DetermineUEFI Hypervisor

LocationLoad and Execute

Location

DetermineOS Location

UEFI Hypervisor(Runtime Service)

Build SystemMemor MapMemory Map

Retrieve BootOptions from

NVRAM

CallExitBootServices()

Transition toKernel

12

Page 13: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI H i F kUEFI Hypervisor FrameworkOperating System

UEFI Hypervisor

Legac OS Loader UEFI OS LoaderLegacy OS Loader UEFI OS Loader

UEFI Boot Services

Me T

DrivBoot Devices

UEFIRuntime

Compatibility

emory

Timer

vers

Protocols and Handlers

RuntimeServices

Platform FirmwareOther

Platform Hardware

Other

SMBIOS

ACPI EFI SystemPartition

MotherboardROM/Flash Option

Rom

U

13

PartitionOS

PartitionUEFI OSLoaderUEFI

Drivers

UEFI Drivers

UEFI Drivers

Rom

UE

FI Hypervisor

Page 14: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI H i F kUEFI Hypervisor FrameworkOperating System

UEFI Hypervisor

Legac OS Loader UEFI OS LoaderLegacy OS Loader UEFI OS Loader

UEFI Boot Services

Me T

DrivBoot Devices

UEFIRuntime

Compatibility

emory

Timer

vers

Protocols and Handlers

RuntimeServices

Platform FirmwareOther

Platform Hardware

Other

SMBIOS

ACPI EFI SystemPartition

MotherboardROM/Flash Option

Rom

U

14

PartitionOS

PartitionUEFI OSLoaderUEFI

Drivers

UEFI Drivers

UEFI Drivers

Rom

UE

FI Hypervisor

Page 15: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

Key Concepts of the Architecture

• Objects managed by UEFI firmwareUEFI I• UEFI Images

• Handle Database and protocolsUEFI S t T bl• UEFI System Table

• Events• Device Paths• Device Paths• Capsules

15

Page 16: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

Key Concepts of the Architecture

• Objects managed by UEFI firmware• EFI Images• Handle Database and protocols• UEFI System Table• Events• Device Paths• Capsules

16

Page 17: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI Imageg• A class of files defined by the specification that contain

executable codeexecutable code

• UEFI images contain the old familiar PE/COFF header th t d fi th f t f th t bl dthat defines the format of the executable code– UEFI uses a subset of the PE32+ image format with a modified

image signature

• The header defines processor type AND the image type– UEFI Application– UEFI Boot Services Driver– UEFI Runtime Driver

17

Page 18: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI Imageg• A class of files defined by the specification that contain

executable codeexecutable code

• UEFI images contain the old familiar PE/COFF header th t d fi th f t f th t bl dthat defines the format of the executable code– UEFI uses a subset of the PE32+ image format with a modified

image signature

• The header defines processor type AND the image type– UEFI Application– UEFI Boot Services Driver

– UEFI Runtime Driver

18

Page 19: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

Overview of Runtime ServicesOverview of Runtime Services• Available before, during and after the OS is booted; after

ExitBootService() is called

UEFI R ti D i l d d i k d• UEFI Runtime Drivers are loaded in memory marked as EfiRuntimeServiceCode

• UEFI Runtime data structuresare marked asEfiRuntimeServiceData

• UEFI Runtime Drivers coexist with and can be invoked by a UEFI-aware OS

19

a UEFI-aware OS

Page 20: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI Sample Codep

(Note the lack of 16-bit assembly language code!!)

20

Page 21: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

/*++/

Copyright (c) 1998 Intel Corporation

Module Name:

rtdriver.c

Abstract:Abstract:

Test runtime driver

Revision History

--*/

#include "efi h"#include efi.h

#include "efilib.h“

//

EFI_STATUS

l d (TestRtUnload (

IN EFI_HANDLE ImageHandle

);

//

CHAR16 *RtTestString1 = L"This is string #1";

CHAR16 *RtTestString2 = L"This is string #2";

CHAR16 *RtTestString3 = L"This is string #3";

EFI_GUID RtTestDriverId = { 0xcc2ac9d1, 0x14a9, 0x11d3, 0x8e, 0x77, 0x0, 0xa0,

21

0xc9, 0x69, 0x72, 0x3b };

Page 22: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

EFI_STATUS

InitializeTestRtDriver (

IN EFI_HANDLE ImageHandle,

* blIN EFI_SYSTEM_TABLE *SystemTable

)

{

EFI_LOADED_IMAGE *Image;

EFI STATUS Status;EFI_STATUS Status;

// Initialize the Library.

InitializeLib (ImageHandle SystemTable);InitializeLib (ImageHandle, SystemTable);

Print(L"Test RtDriver loaded\n");

// Add an unload handler

Status = BS->HandleProtocol (ImageHandle, &LoadedImageProtocol, (VOID*)&Image);

ASSERT (!EFI_ERROR(Status));

Image->Unload = TestRtUnload;

22

Page 23: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

// Add a protocol so someone can locate us

Status = LibInstallProtocolInterfaces (&ImageHandle, &RtTestDriverId, NULL, NULL);NULL);ASSERT (!EFI_ERROR(Status));

// Modify one pointer to verify fixups don't reset it

Print(L"Address of RtTestString3 is %x\n", RtTestString3);Print(L"Address of RtTestString3 pointer is %x\n", &RtTestString3);RtTestString3 = RtTestString2;return EFI_SUCCESS;

}}

EFI_STATUSTestRtUnload (

IN EFI_HANDLE ImageHandle))

{DEBUG ((D_INIT, "Test RtDriver unload being requested\n"));LibUninstallProtocolInterfaces (ImageHandle, &RtTestDriverId, NULL, NULL);

23

return EFI_SUCCESS;

Page 24: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

UEFI H iUEFI Hypervisor

• Our challenge was to convert our x64 Windows hypervisor device driver to a UEFI Runtime device driver

• We identified the MSI P45 Platinum motherboard as UEFI 2 0 li tUEFI 2.0 compliant

• We used the Tianocore UEFI 2 0 0 1 SDKWe used the Tianocore UEFI 2.0.0.1 SDK

24

Page 25: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

DEMO

25

Page 26: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

RResourcesUEFI 2 0 S ifi ti htt // fi• UEFI 2.0 Specification – http://www.uefi.org

• “Beyond BIOS – Implementing the Unified Extensible Firmware Interface with Intel’s Framework” by Zimmerman, Rothman, and Hale - Intel® Press -http://www.intel.com/intelpress/

26

Page 27: BH- US 08 Winning the Race to Bare Metal - Don Bailey ......Winning the Race to Bare MetalWinning the Race to Bare Metal ~ UEFI H iUEFI Hypervisors ... Framework APIs now limited ExitBootServices()

Q ti ?Questions ?

Email: don AT hypervista-tech.comEmail: don AT hypervista tech.com

27