The Lightning and USB Attack Surface: TOCTOU Storage, WebUSB and Accessory Signaling

Working draft. See About ‘WIP’. A survey drawn from three of my repositories: badusb (USB mass-storage TOCTOU, 2019), lightning_strike (Lightning USB captures and a WebUSB proof of concept, 2019 and 2021) and lightning_dfu (accessory-ID DFU signaling, 2021). The connector-specific parts are from 2021; the storage work is from 2019. It builds on the posts PlugNPwn: Connect to Jailbreak and ACE Controller Secrets.

Abstract

The physical connector is the part of a phone’s trust boundary the user is least able to reason about. A cable or a dock looks inert, and a browser tab looks sandboxed, yet both can reach device interfaces that firmware treats as trusted. This survey collects three small studies of that surface. First, a FUSE harness that sits under USB mass storage, logs every read and write with content hashes, and serves different bytes on a later read than it served on the first, giving any verify-then-use consumer a time-of-check/time-of-use (TOCTOU) split. Second, a WebUSB page that opens an Apple device by vendor ID and selects a non-default USB configuration from an ordinary browser, with no driver and only a single click as the gate. Third, a microcontroller that drives the Lightning accessory-ID line to force a device into DFU. Together they argue that “it was signed” and “it is only a web page” are both weaker guarantees than they appear at the connector.

1. Mass storage is a promise, not a fact

A consumer that reads data from removable storage, verifies it, and then reads it again to use it has assumed the storage returns the same bytes both times. Removable storage is free to lie.

The harness. badusb is a FUSE filesystem that passes reads and writes through to a backing image while instrumenting them. Every read and write is recorded to SQLite with its path, offset, length and a SHA-256 of the buffer, and read counts are kept per region. This alone is a useful forensic lens on exactly what a restore or verification process touches and in what order.

The attack. On top of the log sits an injector. A modifier watches for a trigger, such as “the STATE partition has now been read N times”, and from that point rewrites the bytes served for a region, sourcing the replacement from a file, another partition, or a copy-on-write overlay. A PartitionReplaceInject tracks the GPT it has seen, locates the targeted partition, counts reads of its first byte, and swaps in a prepared bad image once the count passes a threshold. A verifier that reads a partition once to hash it and later reads it again to use it sees clean data at check time and attacker data at use time.

Why it matters. Restore and update flows read images from storage, check a signature or hash, and then consume them. If the check and the use are two separate reads of mutable storage, the signature was never a guarantee about the bytes that were used, only about the bytes that were checked. The defense is to verify the exact buffer that is consumed, from a single read into memory, rather than trusting that a second read matches the first.

2. A browser can reach the device

The proof of concept. lightning_strike’s bad_web_usb.html is a plain page. On a click, it calls navigator.usb.requestDevice filtered to an Apple vendor ID (0x05ac) and a specific product, opens the device, enumerates its configurations and interfaces, and calls selectConfiguration to switch it to a configuration that is not the default (configuration 5 in the code), then claims an interface.

Why it matters. WebUSB’s gate is a single user gesture and the browser’s device picker. Past that, a web page is talking to a physical USB device at the configuration and interface level, with no installed driver and no native code. Apple devices expose several USB configurations and alternate interfaces, some of them diagnostic; reaching one of those from a web page collapses the distance between “visited a link” and “spoke to a privileged device interface”. The USB captures in the same repository (Total Phase traces of DFU entry, backup, personal hotspot and ordinary connection) are the raw material for working out which configurations and interfaces appear in which states.

3. The accessory can command the port

The sketch. lightning_dfu is an early Tiva-C (TM4C123) microcontroller prototype aimed at triggering DFU or a reset through the Lightning accessory-identification path, the ACC_ID line, rather than the usual button chord.

Why it matters. DFU is a powerful state: it is where bootrom-level tooling and exploits such as checkm8 and PlugNPwn operate. If a cable or dock, which the user treats as passive, can push the device into DFU by itself through accessory signaling, then entering that state is no longer something only the device’s owner can do with a deliberate button sequence. This is the hardware counterpart to the PlugNPwn work: the connector is not just a data path, it is a control path.

4. The common thread

Each study removes an assumption the connector quietly relies on:

None of these is an exploit on its own. They are the preconditions an exploit chain draws on, and the reason the connector deserves the same scrutiny as the network stack.

5. Limitations and open work

References