Thunderbolts and Lightning / Very, Very Frightening

Snare (Assurance)

BruCON 0x06 · Day 2

Overview

This talk, "Thunderbolts and Lightning / Very, Very Frightening," delivered by Snare from Assurance, delves into the potent capabilities of Direct Memory Access (DMA) attacks over Thunderbolt. Snare presents groundbreaking research conducted with his collaborator "Resin," an FPGA expert, to demonstrate how a custom hardware setup can achieve arbitrary memory reads and writes on a target system by directly interacting with its PCI Express bus via a Thunderbolt port. The talk highlights the evolution of DMA attacks, moving beyond the limitations of older FireWire-based methods, and explores the technical intricacies of using Field-Programmable Gate Arrays (FPGAs) to emulate PCI Express devices.

Watch on YouTube

Visual summary for Thunderbolts and Lightning / Very, Very Frightening by Snare
Visual summary for Thunderbolts and Lightning / Very, Very Frightening by Snare

Key moments

  1. 0:50 Introduction: Why Thunderbolt DMA attack research was needed
  2. 5:40 FireWire DMA limitations: 32-bit addressing and secure mode
  3. 6:45 Thunderbolt: PCI Express and DisplayPort glued together
  4. 16:00 MicroBlaze and AXI PCI Express core for DMA
  5. 29:30 Live demo: Thunderbolt DMA screen unlock exploit
  6. 30:30 Intel's VTD: Hardware defense against DMA attacks
  7. 38:40 Q&A: How the authentication code was located

Thunderbolts and Lightning / Very, Very Frightening

Speakers: Snare (Assurance)

Conference: BruCON

YouTube: https://www.youtube.com/watch?v=epeZYO9qFbs

Overview

This talk, "Thunderbolts and Lightning / Very, Very Frightening," delivered by Snare from Assurance, delves into the potent capabilities of Direct Memory Access (DMA) attacks over Thunderbolt. Snare presents groundbreaking research conducted with his collaborator "Resin," an FPGA expert, to demonstrate how a custom hardware setup can achieve arbitrary memory reads and writes on a target system by directly interacting with its PCI Express bus via a Thunderbolt port. The talk highlights the evolution of DMA attacks, moving beyond the limitations of older FireWire-based methods, and explores the technical intricacies of using Field-Programmable Gate Arrays (FPGAs) to emulate PCI Express devices.

The significance of this research lies in its practical demonstration of a powerful, hardware-based attack vector that leverages the fundamental architecture of modern computing systems. By circumventing software-level restrictions and addressing the limitations of prior DMA attack methodologies, Snare and Resin expose a critical vulnerability inherent in external high-speed bus interfaces like Thunderbolt. This work serves as a stark reminder that physical access can lead to complete system compromise, even on seemingly secure, updated systems, and underscores the ongoing challenge of securing powerful I/O channels.

Background

▶ Watch: Introduction: Why Thunderbolt DMA attack research was needed (0:50)

DMA attacks have long been a recognized threat in computer security, enabling an attacker with physical access to directly read from and write to system memory, bypassing operating system security controls. Early demonstrations include the Tribble board and Quinn "the Eskimo" at Apple in 2002, who famously connected two Macs via FireWire to draw a screensaver on the remote machine's framebuffer. Later, Metlstorm's Ruxcon talk and the attacks now commonly known as "Inception" demonstrated how FireWire DMA could be used to bypass Windows logon screens by patching authentication routines in memory.

These early FireWire DMA attacks relied on the SBP-2 protocol, which allowed connected devices to request arbitrary memory reads and writes over the FireWire bus. While effective, this approach faced several limitations. Primarily, FireWire utilizes 32-bit addressing, restricting access to only the first 4 gigabytes of system memory. With modern systems routinely equipped with 8GB, 16GB, or more RAM, critical operating system code or user data might reside outside this accessible region, rendering the attack ineffective for specific targets like screen unlock routines. Furthermore, on macOS, a "secure mode" feature, enabled when FileVault 2 (full disk encryption) is active and the screen is locked, disables FireWire DMA, preventing these attacks on protected systems from macOS 10.7 onwards.

The advent of Thunderbolt presented a new opportunity for DMA attacks. Thunderbolt is essentially a high-speed serial interconnect that multiplexes PCI Express and DisplayPort signals over a single cable, effectively extending the internal PCI Express bus outside the computer chassis. Initial Thunderbolt DMA attacks were merely "cheating" by connecting a FireWire adapter to a Thunderbolt port, thus re-introducing the same FireWire limitations. The core challenge for Snare and Resin was to achieve direct PCI Express DMA over Thunderbolt, bypassing these restrictions entirely.

To understand this direct approach, a brief overview of PCI Express (PCIe) is necessary. PCIe is the primary system bus in modern computers, functioning as a serial, point-to-point interconnect. Communication occurs via Transaction Layer Packets (TLPs) across three layers: physical, data link, and transaction. Devices connect to a root complex (often integrated into the CPU or PCH), and can request bus master capabilities to perform DMA operations directly on system memory. PCIe supports 64-bit addressing, overcoming the 4GB limitation of FireWire.

The chosen method to implement a custom PCIe device was an FPGA (Field-Programmable Gate Array). FPGAs are reconfigurable integrated circuits composed of a matrix of programmable logic blocks (slices containing lookup tables, flip-flops, etc.). Unlike fixed-function chips, FPGAs can be programmed to implement virtually any digital circuit. For this research, a key feature was the availability of a PCI Express transceiver in silicon on the FPGA, enabling it to communicate directly on the PCIe bus at full speed. To simplify control logic, the researchers utilized a MicroBlaze soft microcontroller, which can be implemented within the FPGA's logic. The MicroBlaze runs C/C++ code and communicates with other FPGA components via an AXI bus. A critical component for the attack was the AXI PCI Express core, which acts as a bridge, mapping the AXI bus to the PCI Express bus, allowing the MicroBlaze to craft and send arbitrary PCIe TLPs.

Key Findings

▶ Watch: Thunderbolt: PCI Express and DisplayPort glued together (6:45)

The central finding of this research is the successful demonstration of direct PCI Express DMA attacks over Thunderbolt, effectively bypassing the inherent limitations of previous FireWire-based methods. Snare and Resin proved that with a custom FPGA-based hardware setup, arbitrary memory reads and writes can be achieved on a target system via its Thunderbolt port.

Key findings include:

  • Overcoming FireWire Limitations: The FPGA-based approach leverages PCI Express's 64-bit addressing, enabling access to the entire physical memory space, unlike FireWire's 32-bit (4GB) limit. This also bypasses macOS's "secure mode" (FileVault 2 + screen lock) which specifically disables FireWire DMA, as the attack operates directly on the PCIe layer.
  • Hardware-Based Device Emulation: The researchers successfully configured an FPGA to emulate a legitimate PCI Express device — specifically, the Apple SDXC slot. This emulation included replicating the device's vendor ID, device ID, class code, and revision ID within the PCIe configuration space. Crucially, the emulated device also presented the IOPCITunnelCompatible flag, which macOS's I/O Kit framework uses to identify devices connected over Thunderbolt and allow them to load drivers and interact with the PCI Express bus.
  • Arbitrary Memory Access: By successfully emulating a recognized device and gaining bus master capabilities, the FPGA was able to send arbitrary Memory Read (MRd) and Memory Write (MWr) TLPs directly to system RAM. This granted the attacker full control over the target's memory.
  • Proof of Concept: Screen Unlock Bypass: A practical demonstration of the attack involved bypassing the macOS screen lock. The FPGA scanned system memory for a specific byte signature corresponding to the authentication routine's return instruction. Once found, a DMA write operation patched this code to always return "success," allowing any input (e.g., a single space) to unlock the machine.
  • Identification of VTD as a Defense: The research identified Intel's Virtualization Technology for Directed I/O (VTD) as the primary hardware-based defense against such direct DMA attacks. VTD, implemented in Ivy Bridge processors and later, provides DMA remapping capabilities within the Platform Controller Hub (PCH), allowing the operating system to establish access control lists for specific devices and memory regions.
  • VTD Configuration and Vulnerability: While VTD offers robust protection, its effectiveness is contingent on proper operating system configuration. macOS configures VTD from version 10.8.2 onwards, and Windows from version 8. Linux also configures VTD. This means that systems with older hardware (pre-Ivy Bridge) or older operating system versions (e.g., macOS < 10.8.2, Windows 7) remain vulnerable to these direct DMA attacks, even if they have Thunderbolt ports.

Technical Deep Dive

▶ Watch: MicroBlaze and AXI PCI Express core for DMA (16:00)

The technical core of this research revolves around the intricate interaction between Thunderbolt, PCI Express, and a custom FPGA-based hardware setup. Thunderbolt, at its essence, provides a high-speed serial tunnel for PCI Express and DisplayPort. A Thunderbolt controller on the host side aggregates internal PCIe lanes and DisplayPort signals, sending them over a 10 or 20 Gigabit per second serial link to an external Thunderbolt device. This device, in turn, contains another Thunderbolt controller that de-multiplexes these signals back into standard PCI Express and DisplayPort. This architecture effectively extends the internal PCI Express bus to external ports, making it a prime target for direct memory access attacks.

The attack platform comprised a Xilinx SP605 FPGA development board, chosen for its PCI Express capabilities and relative affordability. The FPGA itself contains a hardware-level PCI Express transceiver, necessary for high-speed serial communication. To bridge the Thunderbolt connection to the FPGA, a B+TH E05 Thunderbolt-to-PCI Express board was used. This specific board was later recalled by its manufacturer, likely due to licensing issues with Intel, but similar Thunderbolt enclosures or adapters exist.

Within the FPGA, the researchers implemented a MicroBlaze soft microcontroller. This allowed them to write control logic in C/C++ rather than the more complex hardware description languages like VHDL or Verilog, significantly streamlining development. The MicroBlaze communicated with a Xilinx AXI PCI Express core, which served as the crucial interface between the FPGA's internal AXI bus and the external PCI Express bus. This core maps PCI Express registers and memory spaces into the MicroBlaze's address space, enabling the MicroBlaze to construct and send arbitrary Transaction Layer Packets (TLPs). This direct TLP generation was key, offering fine-grained control over PCIe transactions that might not be available through higher-level APIs.

The attack methodology involved device emulation. For a Thunderbolt-connected PCI Express device to be recognized and have a driver loaded by macOS, it must present a valid PCIe Configuration Space. This configuration space contains critical information such as the vendor ID, device ID, class code, revision ID, subsystem ID, and base address registers (BARs) which define memory-mapped I/O regions. The researchers chose to emulate the Apple SDXC slot because its driver (part of the AppleSDXC.kext) is designed to load for Thunderbolt-tunneled PCI Express devices and has a straightforward vendor/device ID combination. Crucially, the info.plist file for this driver contains the IOPCITunnelCompatible flag, which signals to macOS's I/O Kit framework that the device is allowed to operate over a tunneled PCI Express connection like Thunderbolt. By emulating these specific attributes, the FPGA could masquerade as a legitimate internal device, causing macOS to load the appropriate driver and grant it bus master capabilities—a legacy PCI flag that still dictates a device's ability to initiate DMA.

Once the FPGA successfully emulated the Apple SDXC slot and its driver was loaded, it gained the ability to perform arbitrary DMA operations. The proof of concept for bypassing the macOS screen lock involved:

  1. Memory Scanning (DMA Reads): The MicroBlaze, via the AXI PCIe core, initiated Memory Read (MRd) TLPs across the target system's memory. It searched for a specific 9-byte byte signature corresponding to the assembly instruction sequence responsible for returning the authentication result (e.g., move result into AX; return). To account for Address Space Layout Randomization (ASLR), the search was performed at specific offsets within memory pages, as ASLR typically randomizes page base addresses but not internal offsets.
  2. Code Patching (DMA Writes): Upon locating the signature, the FPGA sent Memory Write (MWr) TLPs to overwrite the identified 9-byte sequence. The malicious payload replaced the original instructions with move 1 into AX; return, effectively forcing the authentication function to always return "success" regardless of the input password.

The entire setup demonstrated the power of extending the PCI Express bus externally. The physical connection was: Target Host (Thunderbolt port) -> B+TH E05 board -> Xilinx SP605 FPGA board (via PCIe slot). The FPGA board was also connected via JTAG and UART to an attacker's host for debugging and issuing commands.

Demo / Proof of Concept

▶ Watch: Intel's VTD: Hardware defense against DMA attacks (30:30)

Snare presented a video demonstration of the attack, humorously dubbed the "sweet sonic demo," as he could not carry the full hardware rig while traveling. The video clearly illustrated the real-world impact of the direct Thunderbolt DMA attack:

The demonstration begins with a macOS target machine displaying the locked screen. An attempt to log in with a single space as the password predictably fails, confirming the machine is secured. The attacker then connects the FPGA-based hardware rig to the target machine's Thunderbolt port. Via a serial console connected to the FPGA, the attacker issues the command "unlock please."

The FPGA then actively engages in the DMA attack:

  1. It begins scanning the target's memory (performing DMA reads) to locate the specific 9-byte signature corresponding to the authentication routine.
  2. Once the signature is found, the FPGA performs a DMA write operation, patching the identified code in memory to force a "success" return. The speaker notes that in some cases, multiple instances of the code might be found, requiring the FPGA to continue scanning and patching until it reaches the end of memory.
  3. With the patch applied, the attacker returns to the target machine's locked screen. This time, entering a single space as the password and pressing Enter immediately unlocks the screen, bypassing the authentication mechanism entirely.

The demonstration vividly illustrates the complete compromise achieved through direct Thunderbolt DMA, highlighting the ability to manipulate core operating system functions with physical access. A humorous movie clip featuring "Goth" further underscores the concept of remote, precise control over a system.

Defensive Implications

▶ Watch: Q&A: How the authentication code was located (38:40)

The research by Snare and Resin highlights a critical vulnerability in systems with externally exposed PCI Express buses, such as those using Thunderbolt. However, it also points to the primary hardware-based mitigation: Intel's Virtualization Technology for Directed I/O (VTD), also known as VT-d.

VTD is a feature integrated into Intel's Platform Controller Hub (PCH) since the Ivy Bridge microarchitecture. Its core function is to provide DMA remapping capabilities, acting as a hardware-level access control system for DMA requests. When a PCI Express device attempts a DMA read or write, the request first hits the VTD unit in the PCH. VTD then consults access control tables configured by the operating system to determine if the device is permitted to access the requested memory region. If access is denied, the DMA request is blocked, and an error is logged.

Originally designed for I/O virtualization (e.g., allowing a virtual machine to directly access a physical device like a network card or GPU via "VM Direct Path"), VTD is leveraged by modern operating systems to protect against malicious DMA. The OS configures domains, typically one for the host OS and potentially others for virtualized guests. When kernel drivers allocate DMA buffers for devices, the allocator informs the VTD unit, specifying which device is allowed to access that buffer and with what permissions (read-only, write-only, or read/write). This creates a granular Access Control List (ACL) at the hardware level.

The effectiveness of VTD, however, depends entirely on the operating system's configuration:

  • Operating System Support: macOS configures VTD from version 10.8.2 onwards. Windows supports VTD configuration from Windows 8 and later. Linux distributions generally configure VTD, often setting up a domain per device, which also facilitates KVM-based device passthrough.
  • Hardware and Software Combinations:
  • Pre-Ivy Bridge machines: These systems lack VTD hardware and are inherently vulnerable to direct DMA attacks, regardless of the OS version.
  • Ivy Bridge or later machines running older OS versions: If the OS is older than macOS 10.8.2 or Windows 8 (e.g., Windows 7), it will not configure VTD, leaving the system vulnerable even if the hardware supports it.
  • Current OS on current hardware: Systems running a modern OS (macOS 10.8.2+, Windows 8+, Linux) on Ivy Bridge or later hardware are generally protected by VTD against arbitrary DMA attacks.

Despite VTD, some attack surface remains:

  • Vulnerabilities in Drivers: Even with VTD enabled, a device is granted access to some memory regions. If a legitimate device driver has a vulnerability (e.g., a buffer overflow or logic flaw) that can be triggered by sending malicious data to its allocated DMA buffers, an attacker could still exploit this. The FPGA could emulate the device, send carefully crafted data to the driver's legitimate DMA region, and trigger the vulnerability.
  • Bypassing VTD Itself: While challenging, bypassing or subverting VTD's protections is an area of ongoing research. This could involve finding flaws in VTD's implementation or the OS's configuration of VTD.
  • Accessing Permitted Memory: An attacker might identify memory regions that a specific emulated device is legitimately allowed to read from or write to, and then leverage that access for malicious purposes, even if it's not arbitrary system memory.

For defenders, the key implications are:

  • Physical Security is Paramount: This research reinforces the fundamental principle that physical access to a machine can lead to complete compromise, especially when high-speed I/O ports like Thunderbolt are present.
  • Keep Systems Updated: Ensure both hardware (firmware/BIOS) and operating systems are running the latest versions to benefit from VTD's protections and other security enhancements.
  • Hardware Refresh Cycles: Older hardware (pre-Ivy Bridge) simply lacks the necessary VTD capabilities and will remain vulnerable. Organizations should consider hardware refresh cycles to address this.
  • Consider Thunderbolt Security Policies: For highly sensitive environments, policies regarding Thunderbolt port usage (e.g., disabling them if not needed, or using physical port locks) might be considered, though this can impact usability.

Key Takeaways

  • Direct Thunderbolt DMA is a Potent Attack Vector: This research demonstrates that Thunderbolt, by extending the PCI Express bus externally, enables powerful DMA attacks that bypass the 32-bit memory limitations and macOS "secure mode" defenses of older FireWire-based methods.
  • FPGAs Facilitate Advanced Hardware Attacks: Field-Programmable Gate Arrays (FPGAs) are highly effective tools for emulating PCI Express devices, allowing attackers to gain bus master capabilities and perform arbitrary memory reads and writes on target systems.
  • Device Emulation is Crucial for OS Interaction: Successfully imitating a legitimate PCI Express device, including its configuration space (vendor/device IDs, IOPCITunnelCompatible flag), is essential for the operating system to load a driver and grant the necessary bus access for DMA operations.
  • VTD Provides Hardware-Level DMA Protection: Intel's Virtualization Technology for Directed I/O (VTD) offers a robust, hardware-based defense against arbitrary DMA attacks by enforcing access controls on memory regions; however, its effectiveness relies on proper operating system configuration.
  • Older Systems Remain Vulnerable: Systems with pre-Ivy Bridge processors or running older operating system versions (e.g., macOS < 10.8.2, Windows 7) lack or do not configure VTD, leaving them susceptible to direct Thunderbolt DMA attacks.
  • Ongoing Attack Surface Exists: Even with VTD enabled, vulnerabilities in device drivers or the potential for bypassing VTD itself represent avenues for future research and attack, emphasizing the continuous need for vigilance and defense-in-depth strategies.

About the Speaker(s)

Snare is a security researcher from Melbourne, Australia, working at Assurance. He is known for his previous talks on EFI firmware persistence and macOS kernel security. In this presentation, Snare delivered the research on behalf of his colleague, Resin.

Resin is described as an "FPGA nerd" who performed "all the hard stuff" for this research. He was working on a PhD on FPGA topics involving ray tracing. His expertise in FPGAs and PCI Express was instrumental in developing the custom hardware and logic for the direct Thunderbolt DMA attack.

Reviews

  • Dr. Zero (Offensive Security Researcher) — MUST SEE ★★★★★

→ Top-rated talks at BruCON 0x06

All talks from BruCON 0x06