Android Hardware Reverse Engineering

Exploiting Android Peripherals: Identifying and Leveraging SPI Bus Vulnerabilities

Google AdSense Native Placement - Horizontal Top-Post banner

Introduction to SPI in Android Devices

The Serial Peripheral Interface (SPI) is a synchronous serial communication interface specification used for short-distance communication, primarily in embedded systems. In Android devices, SPI is ubiquitous, connecting the System-on-Chip (SoC) to a myriad of critical peripherals such as touchscreens, camera sensors, NFC controllers, secure elements, accelerometers, gyroscopes, and even external flash memory for firmware storage. Understanding and exploiting SPI vulnerabilities can provide a powerful avenue for hardware-level attacks, ranging from data exfiltration to unauthorized control over device functionality or even persistent root access.

Unlike more complex interfaces like USB or PCIe, SPI is relatively simple, often lacking built-in security features. This simplicity, combined with direct hardware access, makes it an attractive target for security researchers and attackers looking to bypass software-level protections. An insecurely implemented or accessible SPI bus can expose critical components to eavesdropping, data injection, or even firmware manipulation.

Identifying SPI Bus Connections

Datasheet Analysis

The most straightforward method to identify SPI connections is through datasheets. Begin by locating the datasheet for the device’s SoC. These often detail the pinout, including dedicated SPI masters and their respective pins (MOSI, MISO, SCLK, CS). Subsequently, look for datasheets of major peripherals (e.g., touchscreen controller IC, camera module IC) that might communicate via SPI. Cross-referencing these datasheets helps map the connections.

Physical Inspection and Board Analysis

When datasheets are unavailable, physical inspection is crucial. Disassemble the Android device carefully. Key areas to focus on include:

  • SoC Proximity: SPI peripherals are typically located close to the main SoC to minimize trace lengths and signal integrity issues.
  • Flex Cables: Components like displays often connect via flex cables, which may carry SPI lines.
  • Component Markings: Identify common SPI chips like NOR flash, EEPROMs, or sensor controllers.
  • Test Points: Many PCBs include unpopulated test points (TP) that break out important signals, including SPI. Look for groups of four adjacent TPs or pads near potential SPI devices.

Use a high-resolution camera or microscope to examine the traces. SPI connections typically consist of four main lines: MOSI (Master Out, Slave In), MISO (Master In, Slave Out), SCLK (Serial Clock), and CS (Chip Select, often active-low). A multimeter in continuity mode can help trace identified pins from a known SoC SPI interface to a peripheral.

Software-Based Identification (Rooted Devices)

For rooted Android devices, the kernel provides insights into hardware. You can often identify active SPI devices and their configurations:

adb shell
dmesg | grep spi
ls -l /dev/spi*
cat /sys/kernel/debug/spi/spi*/*

Analyzing the device tree blob (`.dtb`) files (usually located in `/proc/device-tree` or extracted from the boot image) can reveal SPI controller definitions, associated peripherals, and their chip select lines. Tools like `dtc` (Device Tree Compiler) can decompile `.dtb` files into human-readable `.dts` format.

Accessing the SPI Bus Physically

Physical access is paramount for hardware exploitation. Tools required include a soldering iron with fine tips, flux, thin enamel-coated magnet wire (30-36 AWG), a microscope, a logic analyzer (e.g., Saleae Logic, Open Bench Logic Sniffer), and a multimeter.

Connection Methods:

  1. Soldering Wires: The most common method involves soldering thin wires directly to identified SPI test points or component pins. Patience and a steady hand are essential.
  2. Probes: Fine-tipped probes can temporarily connect to test points or IC pins, suitable for quick analysis without permanent modification.
  3. Desoldering: In advanced scenarios, an entire peripheral might be desoldered and replaced with a custom interposer board to facilitate direct interaction or bypass device authentication.

Sniffing SPI Traffic with a Logic Analyzer

Once wires are soldered or probes are attached, a logic analyzer is used to capture and decode SPI traffic. Connect the logic analyzer probes to SCLK, MOSI, MISO, and the relevant CS line. Ensure the logic analyzer’s ground is connected to the device’s ground.

Configuring the Logic Analyzer:

  • Sample Rate: Set a high enough sample rate (e.g., 24MHz or higher) to capture clock transitions accurately, typically at least 4x the SPI clock frequency.
  • Trigger: Configure a trigger on the Chip Select (CS) line going active (e.g., falling edge for active-low CS) to capture a complete transaction.
  • Protocol Decoder: Use the built-in SPI decoder, specifying clock polarity (CPOL) and clock phase (CPHA) (0/0, 0/1, 1/0, 1/1), bit order (MSB/LSB first), and bits per transfer (usually 8).

Here’s a conceptual example of a capture on a Saleae Logic analyzer showing decoded SPI data:

Channel 0 (SCLK): Clock signal
Channel 1 (MOSI): Master Out, Slave In data
Channel 2 (MISO): Master In, Slave Out data
Channel 3 (CS): Chip Select (active low)

--- Logic Analyzer Output Snippet ---
Time       | CS | SCLK | MOSI (Hex) | MISO (Hex)
-----------|----|------|------------|------------
0.000000ms | L  |      |            |
0.000010ms | L  |      | 0x9F       | 0x00       (Master sends READ_ID, Slave replies 0x00 initial)
0.000025ms | L  |      | 0x00       | 0xEF       (Master sends dummy, Slave replies ID byte 1)
0.000040ms | L  |      | 0x00       | 0x40       (Master sends dummy, Slave replies ID byte 2)
0.000055ms | L  |      | 0x00       | 0x18       (Master sends dummy, Slave replies ID byte 3)
0.000070ms | H  |      |            |            (Transaction ends)
------------------------------------

Interpreting the raw data requires understanding the peripheral’s communication protocol, often found in its datasheet. Common patterns include an opcode followed by addresses and then data for read/write operations.

Leveraging SPI Vulnerabilities

Firmware Extraction via SPI

Many peripherals store their firmware in external SPI NOR flash chips. If such a chip is connected via SPI directly to the SoC or a dedicated microcontroller, and its read commands are not authenticated or restricted, you can extract the firmware. This often involves:

  1. Identifying the SPI flash chip (e.g., Winbond W25Q series).
  2. Sniffing the boot-up sequence to observe how the SoC interacts with the flash.
  3. Using a custom SPI master (e.g., an MCU like an ESP32 or a dedicated SPI programmer) to send read commands and dump the entire flash content.

Example (hypothetical) using a custom SPI tool to dump a 16MB flash:

# Assuming device /dev/spidev0.0 exists and is configured
# This sends a 'READ' command (0x03) followed by a 24-bit address
# and continuously reads data.

python3 -c '
import spidev
import sys

bus = 0
device = 0
spi = spidev.SpiDev()
spi.open(bus, device)
spi.max_speed_hz = 1000000 # 1 MHz
spi.mode = 0b00 # SPI mode 0

# Assuming a 24-bit address flash, 0x03 is Read Data command
# For a 16MB flash, address range is 0x000000 to 0xFFFFFF

output_file =

Android Mobile Specs & Compare Directory

Are you researching mobile hardware properties, processor SoCs, GPU chipsets, or RAM configurations? Access our complete specs catalog to compare up to 5 devices side-by-side!

Compare Devices Specs →
Google AdSense Inline Placement - Content Footer banner