βœ“
Field Note Β· Nov 23, 2026 Β· 17 min read

Hardware Security Assessment 101: Extracting & Emulating IoT Firmware from SPI Flash

A hands-on guide to IoT hardware security assessment. Learn how to dump SOIC-8 SPI flash chips with a CH341A programmer and emulate MIPS/ARM firmware with QEMU for authorized security audits.

Hardware Security Assessment 101: Extracting & Emulating IoT Firmware from SPI Flash
Authorized Security Research & Defensive Notice This technical guide is strictly intended for authorized security testing, QA debugging, and defensive engineering on systems, devices, and applications you own or have explicit, written authorization to audit. ToolWar strictly prohibits the use of these techniques or utilities for unauthorized access or destructive activities.

Bridging the Hardware-Software Divide: The Physical Security Assessment of IoT

In modern cybersecurity research, embedded Internet of Things (IoT) devices: ranging from enterprise Wi-Fi routers and IP security cameras to industrial smart switches: remain notoriously insecure. While enterprise software development has widely adopted memory-safe languages, stack canaries, and automated code analysis, IoT original equipment manufacturers (OEMs) continue to ship Linux firmware containing hardcoded root credentials, unauthenticated CGI command injection scripts, and decades-old vulnerable software daemons.

However, security researchers auditing these devices are frequently blocked at the perimeter: device management interfaces are locked down, SSH is disabled, and vendor support websites provide encrypted or partial update packages. To conduct an exhaustive security assessment, the researcher must interface directly with the physical silicon. By extracting firmware from non-volatile SPI Flash memory chips using inexpensive hardware tools and emulating the target binaries inside QEMU, analysts can uncover zero-day vulnerabilities without needing permanent physical access to the device.

Hardware Security Assessment Workflow: SPI Flash Extraction to QEMU Emulation

Figure 14.1: The physical hardware security assessment pipeline: SOIC-8 clip extraction, Binwalk unpacking, and user-mode QEMU emulation.

1. Identifying and Pinning the SPI Flash Chip

Almost all embedded consumer and enterprise networking equipment stores its bootloader (U-Boot), Linux kernel, and root filesystem inside a Serial Peripheral Interface (SPI) NOR Flash chip. These chips commonly adhere to the standard 8-pin Small Outline Integrated Circuit (SOIC-8) package (such as the Winbond 25Q64 or 25Q128).

Standard SOIC-8 SPI Flash chips (such as the Winbond W25Q128 or Macronix MX25L64) adhere to a standardized 8-pin layout:

  • Pin 1 (CS# / Chip Select): Active LOW signal held HIGH during bus idle; connect to Programmer Pin 1.
  • Pin 2 (SO / Serial Output / MISO): Transmits raw memory data from flash to programmer; connect to Programmer Pin 2.
  • Pin 3 (WP# / Write Protect): Hardware write protection line; pull HIGH to VCC for safe read-only dumping.
  • Pin 4 (GND / Common Ground): System ground reference; connect directly to Programmer Ground.
  • Pin 5 (SI / Serial Input / MOSI): Receives command opcodes from programmer; connect to Programmer Pin 5.
  • Pin 6 (SCK / Serial Clock): Synchronous clock driven by programmer up to 50 MHz; connect to Programmer Pin 6.
  • Pin 7 (HOLD# / Reset): Suspends serial communication; pull HIGH to VCC to prevent bus floating.
  • Pin 8 (VCC / Power Rail): Regulated 3.3V power input; strict 3.3V rail required (never 5V!).

The standard SOIC-8 pinout conforms to the following electrical layout:

Pin # Signal Name Description Programmer Connection
Pin 1 /CS Chip Select (Active Low) CH341A CS Pin
Pin 2 DO (MISO) Data Output (Master In Slave Out) CH341A MISO Pin
Pin 4 GND Ground Reference CH341A Ground
Pin 5 DI (MOSI) Data Input (Master Out Slave In) CH341A MOSI Pin
Pin 6 CLK Serial Clock CH341A SCK Pin
Pin 8 VCC Power Supply (Strictly 3.3V!) CH341A 3.3V Rail

CRITICAL SAFETY WARNING: Many inexpensive black-PCB CH341A programmers output 5V logic on their data lines by default, which will permanently fry 3.3V SPI flash chips. Verify your programmer logic level with a multimeter or perform the standard 3.3V voltage pin 28 modification before attaching it to the target PCB.

HARDWARE SAFETY WARNING: Preventing 5V Overvoltage Damage

Many cheap black-PCB CH341A programmers supply 5V logic on data lines despite a 3.3V jumper setting. Always verify logic line voltages with a digital multimeter before attaching clip leads to an in-circuit SPI flash chip, or utilize a dedicated 1.8V/3.3V logic level-shifting adapter to prevent permanently frying the target SoC.

2. In-Circuit Firmware Dumping with flashrom

By using an 8-pin SOIC-8 test clip, you can clamp directly onto the surface-mount chip while it remains soldered to the PCB, eliminating the risk of lifting traces through hot-air desoldering.

Once clipped and connected via USB, execute flashrom to identify the chip and extract the full raw binary image:

# Step 1: Detect chip model over SPI bus
<strong>flashrom</strong> -p ch341a_spi

# Step 2: Extract binary image twice to verify zero read errors
<strong>flashrom</strong> -p ch341a_spi -r firmware_read1.bin
<strong>flashrom</strong> -p ch341a_spi -r firmware_read2.bin

# Step 3: Verify byte-for-byte cryptographic integrity
md5sum firmware_read1.bin firmware_read2.bin

If the MD5 hashes do not match, the test clip has poor physical contact with the pins or the host microcontroller is attempting to drive the SPI lines simultaneously (holding the SoC's reset pin to ground with a jumper wire will silence the CPU during the dump).

3. Decompiling and Carving Filesystems with Binwalk

The extracted raw .bin file contains raw flash memory: bootloader, NVRAM partition, kernel, and filesystems concatenated together. Use Binwalk to recursively scan headers and extract the root filesystem:

# Scan firmware for magic signatures and automatically extract partitions
<strong>binwalk</strong> -Me firmware.bin

# Inspect extracted <strong>squashfs</strong>-root directory
cd _firmware.bin.extracted/<strong>squashfs</strong>-root/
ls -la

Once extracted, the entire target operating system is exposed on your workstation. Immediate high-value triage targets include:

  • /etc/shadow: Look for hardcoded root password hashes. Many vendors deploy identical DES/MD5 crypt hashes across their entire hardware product line.
  • /etc/init.d/: Inspect startup rc scripts to discover hidden maintenance telnet daemons or undocumented debug backdoors listening on raw TCP sockets.
  • /usr/sbin/httpd: Locate web server binaries and CGI handlers for static reverse engineering in Ghidra or dynamic debugging with x64dbg and forensic inspection with Autopsy.

4. Dynamic Emulation in QEMU: Running Foreign MIPS/ARM Binaries

Auditing binaries statically is slow. To find command injection vulnerabilities dynamically, we can execute the device's web server directly on our x86 Linux workstation using QEMU user-mode emulation.

# Step 1: Copy static QEMU MIPS emulator into extracted root filesystem
cp $(which qemu-mips-static) ./<strong>squashfs</strong>-root/

# Step 2: Chroot into the embedded filesystem and launch the target web daemon
sudo chroot ./<strong>squashfs</strong>-root ./qemu-mips-static /usr/sbin/httpd -f /etc/httpd.conf

If the binary fails due to missing NVRAM environment variables (a common trait in router firmware), compile a lightweight shared library (libnvram.so) that intercepts nvram_get() calls and preload it using LD_PRELOAD. For full system-level emulation, platforms like Firmadyne automate the entire kernel bootstrapping and network bridging process, providing a live browser-accessible replica of the hardware.

Frequently Asked Questions

Q1: Why does flashrom sometimes fail to detect the chip while in-circuit?

In-circuit dumping powers the target chip from the programmer's 3.3V VCC pin. If the target PCB's power planes pull excessive current (powering adjacent SoCs, capacitors, and LEDs), the programmer's USB voltage rail may brown out. Mitigate this by grounding the main SoC's RESET pin to keep it in reset, or supply external 3.3V laboratory bench power to the PCB ground/VCC rails.

Q2: How do vendors protect firmware from SPI Flash extraction?

Advanced hardware designs implement SPI bus encryption, hardware secure boot (e.g., ARM TrustZone / cryptographic signature validation in ROM), or encapsulate flash memory inside the System-on-Chip (SoC) silicon die, preventing external bus sniffing or physical clamping.

Q3: What is the difference between QEMU user-mode and system-mode emulation?

QEMU user-mode (`qemu-mips-static`) emulates a single non-native application binary by translating target Linux syscalls to the host kernel's syscalls, making it lightweight for quick testing. QEMU system-mode emulates the full virtualized hardware platform (CPU, MMU, timers, and peripheral buses), requiring a target-specific Linux kernel image to boot the complete OS.

Q4: Can volatile memory be extracted from an IoT device during operation?

Yes, if a root shell is achieved over UART/JTAG serial pin headers or network exploitation. Analysts can compile a static memory acquisition binary like DumpIt or dump `/dev/mem` directly to netcat to capture RAM states for Volatility analysis.

KS

Kapil Soni

Updated test bio for ToolWar lead researcher

πŸ’¬ Discussion

0 comments
No comments yet. Have insights or questions regarding this article? Join the discussion!