Stupid PCIe Tricks Joe FitzPatrick Breakpoint 2014 whoami - - PowerPoint PPT Presentation

stupid pcie tricks
SMART_READER_LITE
LIVE PREVIEW

Stupid PCIe Tricks Joe FitzPatrick Breakpoint 2014 whoami - - PowerPoint PPT Presentation

Stupid PCIe Tricks Joe FitzPatrick Breakpoint 2014 whoami Electrical Engineering education with focus on CS and Infosec 8 years doing security research, speed debug, and tool development for CPUs Hardware Pen Testing of CPUs


slide-1
SLIDE 1

Joe FitzPatrick Breakpoint 2014

Stupid PCIe Tricks

slide-2
SLIDE 2
  • Electrical Engineering education with

focus on CS and Infosec

  • 8 years doing security research, speed

debug, and tool development for CPUs

  • Hardware Pen Testing of CPUs
  • Security training for functional validators

worldwide

  • Software Exploitation via Hardware

Exploits, AKA SExViaHEx

whoami

Joe FitzPatrick @securelyfitz

joefitz@securinghardware.com

slide-3
SLIDE 3

If Joe Fitz... Joe Sitz

slide-4
SLIDE 4

This is not academic-caliber research. Lots of this stuff has been done before. The difference is that I aim to show that PCIe attacks can be easier and cheaper than previously thought

Disclaimer

slide-5
SLIDE 5

What is PCIe?

slide-6
SLIDE 6

PCIe is PCI!

slide-7
SLIDE 7

PCIe is NOT PCI!

Foto tomada por Jorge González http://es.wikipedia.org Photo by snikerdo http://en.wikipedia.org

slide-8
SLIDE 8

Links and Lanes

Diagram: PCIe 2.1 specification

slide-9
SLIDE 9

Hierarchy

Diagram: PCIe 2.1 specification

slide-10
SLIDE 10

Switching and Routing

Diagram: PCIe 2.1 specification

slide-11
SLIDE 11

Layers

Diagram: PCIe 2.1 specification

slide-12
SLIDE 12

Configuration Space

Diagram: PCIe 2.1 specification

slide-13
SLIDE 13

Configuration Space

Diagram: PCIe 2.1 specification

slide-14
SLIDE 14

Configuration Space

Diagram: PCIe 2.1 specification

slide-15
SLIDE 15

Configuration Space

Diagram: PCIe 2.1 specification

slide-16
SLIDE 16

Configuration Space

Diagram: PCIe 2.1 specification

slide-17
SLIDE 17

Enumeration

Diagram: PCIe 2.1 specification

slide-18
SLIDE 18

Routing PCIe

slide-19
SLIDE 19

The Step-By-Step, Complicated, Mandatory, Inflexible Rules of Routing PCIe:

slide-20
SLIDE 20
  • 1. route pairs adjacent and equal length

The Step-By-Step, Complicated, Mandatory, Inflexible Rules of Routing PCIe:

slide-21
SLIDE 21
  • 1. route pairs adjacent and equal length

… that’s mostly it

The Step-By-Step, Complicated, Mandatory, Inflexible Rules of Routing PCIe:

slide-22
SLIDE 22

Routing PCIe

System Board Traces 12 Inches Add-in Card Traces 3.5 inches Chip-to-Chip Routes 15 inches

Follow these rules and your board might work. Break them and it might not.

slide-23
SLIDE 23

Routing PCIe

Minimum PCIe:

  • 2.5GHz TX
  • 2.5GHz RX
  • 100MHz Clock (optional)
slide-24
SLIDE 24
slide-25
SLIDE 25

$ $ $ $ $

slide-26
SLIDE 26

Routing PCIe

Cross-section of a USB 3.0 cable. Image courtesy of USB Implementers Forum

slide-27
SLIDE 27

PEXternalizer

  • n github
slide-28
SLIDE 28

PEXternalizer

  • n github
slide-29
SLIDE 29

PEXternalizer

  • n github
slide-30
SLIDE 30

PEXternalizer

  • n github
slide-31
SLIDE 31
slide-32
SLIDE 32

mPEXternalizer

  • n github
slide-33
SLIDE 33

POC || GTFO 0x05

slide-34
SLIDE 34

POC || GTFO 0x05

slide-35
SLIDE 35

POC || GTFO 0x05

slide-36
SLIDE 36

A brief history of DMA attacks

slide-37
SLIDE 37

Tribble

slide-38
SLIDE 38

Firewire Attacks

slide-39
SLIDE 39
slide-40
SLIDE 40

Video Demo Slides SysCan ‘14

slide-41
SLIDE 41

PLX Technologies Buy one

slide-42
SLIDE 42

Thunderbolt

slide-43
SLIDE 43

Thunderbolt

slide-44
SLIDE 44

USB3380 Firmware

slide-45
SLIDE 45

USB3380 Firmware

> xxd SLOTSCREAMER.bin 0000000: 5a00 0c00 2310 4970 0000 0000 e414 bc16 Z...#.Ip........

slide-46
SLIDE 46

USB3380 Firmware

> xxd SLOTSCREAMER.bin 0000000: 5a00 0c00 2310 4970 0000 0000 e414 bc16 Z...#.Ip........

slide-47
SLIDE 47

USB3380 Firmware

> xxd SLOTSCREAMER.bin 0000000: 5a00 0c00 2310 4970 0000 0000 e414 bc16 Z...#.Ip........

That’s all!

slide-48
SLIDE 48
slide-49
SLIDE 49

Hardware

http://www.hwtools.net/PLX.html

slide-50
SLIDE 50

Software

tools used in preparing this presentation:

  • plx’s flashing

software

  • pyusb + scripts
  • inception_pci
  • volatility for

memory analysis

slide-51
SLIDE 51

Attack-side Software

Quick ‘n’ dirty PCIe memory read/write with PyUSB

slide-52
SLIDE 52

More attack-side Software

slide-53
SLIDE 53

More attack-side Software

# EQUALS: # # |-- Offset 0x00 # / # /\ |-patchoffset--------------->[b0 01] # 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f .. (byte offset) # ----------------------------------------------- # c6 0f 85 a0 b8 00 00 b8 ab 05 03 ff ef 01 00 00 .. (chunk of memory data) # ----------------------------------------------- # \______/ \___/ \______/ # \ \ \ # \ \ |-- Chunk 2 at internaloffset 0x05 # \ |-- Some data (ignore, don't match this) # |-- Chunk 1 at internaloffset 0x00 # \_____________________/ # \ # |-- Entire signature #

slide-54
SLIDE 54

More attack-side Software

{'OS': 'Mac OS X 10.9', 'versions': ['10.9'], 'architectures': ['x64'], 'name': 'DirectoryService/OpenDirectory unlock/privilege escalation', 'notes': 'Overwrites the DoShadowHashAuth/ODRecordVerifyPassword return value. 'signatures': [{'offsets': [0x1e5], # 10.9 'chunks': [{'chunk': 0x4488e84883c4685b415c415d415e415f5d, 'internaloffset': 0x00, 'patch': 0x90b001, # nop; mov al,1; 'patchoffset': 0x00}]}]}]

slide-55
SLIDE 55

Attacking via PCIe

slide-56
SLIDE 56
slide-57
SLIDE 57

MRd

Find important values at known locations Take memory dumps for later analysis Example: Dump memory and use Volatility to analyze it

slide-58
SLIDE 58

Dump Analysis with Volatility

dmesg log of the attack recovered from the memory dump of the victim

slide-59
SLIDE 59

Dump Analysis with Volatility

names, pids, and uids for dumped processes

slide-60
SLIDE 60

Dump Analysis with Volatility

extracted machine info the perfect amount of memory to dump!

slide-61
SLIDE 61

MWr

Modify values at known locations Manipulate code!!! Example: Use Inception to modify lock screen checking, or drop a metasploit payload!

slide-62
SLIDE 62

Inception with Metasploit (W7sp1 POC only)

slide-63
SLIDE 63

IORd/IOWr

Only for legacy devices (legacy means not thoroughly tested recently)

slide-64
SLIDE 64

CfgRd/CfgWr

Interact with other PCI devices’ config spaces Yet another separate address space/different means of accessing hardware

slide-65
SLIDE 65

Msg/MsgD

Messages send things like interrupts and vendor- defined configuration Many message types are very rarely used Example: Invisible Things Labs SNB VT-D

slide-66
SLIDE 66

Mitigations

slide-67
SLIDE 67

Bus Master Enable

joefitz@linUX31a:~/Documents/pcie/SLOTSCREAMER/inception_pci$ lspci -vv | grep BusMaster Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+ Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+ Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+ Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+ Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+ Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx- Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+

slide-68
SLIDE 68

Access Control Services

slide-69
SLIDE 69

IOMMU

slide-70
SLIDE 70

Mitigating the Mitigations

slide-71
SLIDE 71
  • Identifies device to the OS
  • OS chooses which driver to load
  • OS configures ACS, BME, etc…
  • OS loads driver

VID:PID

slide-72
SLIDE 72

Default Drivers

  • Some drivers are ‘class’ drivers (think USB

MSC, etc...)

  • Some device specific drivers might be

installed by default (OSX)

  • Drivers contain bugs
  • Think facedancer for PCIE or Thunderbolt
slide-73
SLIDE 73

Early Boot

  • IOMMU is not configured yet
  • Neither is much else
  • Wishlist: Volatility support for EFI shell
slide-74
SLIDE 74

Option ROM/EFI drivers

  • Some devices have firmware that gets run at

early boot

  • Some systems block this (but usually for

anti-competitive reasons, not security)

slide-75
SLIDE 75

Breaking the rules

  • Spoof requesterID for posted transactions
  • Well-timed spoofed requesterID for non-

posted transactions

  • Setting the ‘translated request’ bit
slide-76
SLIDE 76

Misconfigurations

  • Everything is MMIO now - memory

protections are essential

  • Memory protections are not enough - need

Cfg and IO protections as well - don’t forget about them

  • Does installing a hypervisor change how

your OS uses its IOMMU?

slide-77
SLIDE 77

Putting it all together

slide-78
SLIDE 78

Thunderbolt

Diagram: Apple Thunderbolt Device Driver Programming Guide

slide-79
SLIDE 79

HALIBUTDUGOUT

slide-80
SLIDE 80

Sorry, Previous Speakers

ALLOYVIPER

slide-81
SLIDE 81

Building ALLOYVIPER

slide-82
SLIDE 82

Building ALLOYVIPER

slide-83
SLIDE 83

Building ALLOYVIPER

slide-84
SLIDE 84

Building ALLOYVIPER

slide-85
SLIDE 85

Building ALLOYVIPER

slide-86
SLIDE 86

Building ALLOYVIPER

slide-87
SLIDE 87

Building ALLOYVIPER

slide-88
SLIDE 88

Building ALLOYVIPER

slide-89
SLIDE 89

MITMing

slide-90
SLIDE 90

⇐ Thanks for the slides, snare & rzn

slide-91
SLIDE 91

⇐ Thanks for the slides, snare & rzn

slide-92
SLIDE 92

Bypassing VT-d on Macbooks?

  • VT-d is off at boot/reboot
  • Broadcom Ethernet drivers crash the system
  • System reboots - all the doors are open for a

few moments No POC yet (I’ll GTFO soon…)

slide-93
SLIDE 93

Can we do it without imitating a device?

  • Some PCIe switches have ‘transparent’

mode

  • Some PCIe switches have TLP injection

debug features

  • Can we build one into a genuine device?
  • Can we build one into a cable?

No POC yet here either

slide-94
SLIDE 94

Potential enhancements

  • 64-bit DMA (>4gb access!)
  • Full control over TLP Header

○ spoofing requester ID ○ testing ‘reserved’ bits

Enough unproven concepts… time to GTFO...

slide-95
SLIDE 95

Joe FitzPatrick @securelyfitz joefitz@securinghardware.com http://www.securinghardware.com

Questions?