Skip to main content
Be Bitwise

Firmware Forensics

Binary Forensics & Crash Analysis · Defense & Forensics track

6 min read

In this module

Investigating the Invisible Layer

Firmware sits below the operating system and is often the last place defenders look — which is precisely why sophisticated attackers hide there. Firmware forensics examines images to detect modifications, identify backdoors, and understand what's actually running on embedded hardware. As firmware attacks grow more common, this skill has moved from niche to necessary.

Extracting Firmware Images

Before you can analyse firmware, you need to obtain it. There are several acquisition methods, ranging from simple to requiring physical access:

Vendor downloads: Many manufacturers provide firmware update files on their websites. These are the easiest to obtain and serve as baseline images for comparison.

UART shell access: Many embedded devices expose a UART (serial) console on the PCB. Connecting to it with a USB-to-UART adapter often provides a root shell, from which you can dump the flash:

bash
# From a root shell on the device
dd if=/dev/mtd0 of=/tmp/firmware.bin bs=1M
# Transfer via network or serial

JTAG/SWD extraction: Debug interfaces allow direct access to the flash memory through tools like OpenOCD.

SPI flash dumping: Many devices store firmware on external SPI flash chips. With physical access, you can clip directly onto the chip and read its contents:

bash
# Read SPI flash with flashrom
flashrom -p ch341a_spi -r firmware.bin

Chip-off: For devices where the flash is integrated into the SoC, the chip can be physically desoldered and read with a chip reader. This is destructive but works when all other methods are blocked.

Firmware Analysis with Binwalk

Binwalk is the essential tool for initial firmware analysis. It scans a binary image for embedded file signatures, compressed archives, filesystem headers, and other recognisable patterns:

bash
# Scan for embedded files and filesystems
binwalk firmware.bin
# Extract all recognised components
binwalk -e firmware.bin
# Entropy analysis to find encrypted/compressed regions
binwalk -E firmware.bin

A typical firmware image might contain: a bootloader (U-Boot), a Linux kernel (compressed with gzip or lzma), a root filesystem (SquashFS or CramFS), and configuration data. Binwalk identifies each component, but for extraction it hands off to external tools, and it can only extract what those tools are installed for. SquashFS needs sasquatch (a patched unsquashfs that copes with vendors' non-standard SquashFS variants), and JFFS2, UBI and CramFS each need their own extractor. If binwalk -e finds a filesystem but leaves no squashfs-root behind, a missing extractor is the usual reason.

Entropy as a Map

Running binwalk -E on a firmware image produces an entropy plot that serves as a map of the image. Padding and erased flash sit near 0 bits per byte, text and structured data around 4 to 5, and machine code usually around 5.5 to 6.5. Compressed or encrypted data sits close to 8. (binwalk scales its plot from 0 to 1, so divide these figures by 8.) Sudden transitions between entropy levels indicate boundaries between different components. A completely flat high-entropy region across the entire image suggests the firmware is fully encrypted.

Here's a binwalk -E style plot of an illustrative 4 MiB router image. Before you check, mark every block you'd call compressed or encrypted and guess where the bootloader, the LZMA kernel, the SquashFS root filesystem and the encrypted config blob begin and end. Look hard at the small dip between the two long plateaus.

Router firmware image (4 MiB, illustrative)

Illustrative data

binwalk -E style view: one entropy reading per 64 KiB block of a 4 MiB SPI flash dump.

Mode

Entropy of 64 blocks of 64 KiB across 4 MiB. 57 blocks are at or above the 7.2 threshold.024680x000000: 6.16 bits per byte0x010000: 3.79 bits per byte0x020000: 0.61 bits per byte0x030000: 7.96 bits per byte0x040000: 7.95 bits per byte0x050000: 7.95 bits per byte0x060000: 7.96 bits per byte0x070000: 7.95 bits per byte0x080000: 7.95 bits per byte0x090000: 7.96 bits per byte0x0A0000: 7.94 bits per byte0x0B0000: 7.96 bits per byte0x0C0000: 7.95 bits per byte0x0D0000: 7.95 bits per byte0x0E0000: 7.96 bits per byte0x0F0000: 7.96 bits per byte0x100000: 7.95 bits per byte0x110000: 7.96 bits per byte0x120000: 4.93 bits per byte0x130000: 7.95 bits per byte0x140000: 7.96 bits per byte0x150000: 7.95 bits per byte0x160000: 7.95 bits per byte0x170000: 7.96 bits per byte0x180000: 7.96 bits per byte0x190000: 7.95 bits per byte0x1A0000: 7.96 bits per byte0x1B0000: 7.95 bits per byte0x1C0000: 7.95 bits per byte0x1D0000: 7.95 bits per byte0x1E0000: 7.95 bits per byte0x1F0000: 7.95 bits per byte0x200000: 7.96 bits per byte0x210000: 7.95 bits per byte0x220000: 7.95 bits per byte0x230000: 7.96 bits per byte0x240000: 7.95 bits per byte0x250000: 7.95 bits per byte0x260000: 7.96 bits per byte0x270000: 7.95 bits per byte0x280000: 7.95 bits per byte0x290000: 7.95 bits per byte0x2A0000: 7.96 bits per byte0x2B0000: 7.96 bits per byte0x2C0000: 7.95 bits per byte0x2D0000: 7.95 bits per byte0x2E0000: 7.95 bits per byte0x2F0000: 7.95 bits per byte0x300000: 7.95 bits per byte0x310000: 7.95 bits per byte0x320000: 7.96 bits per byte0x330000: 7.96 bits per byte0x340000: 7.96 bits per byte0x350000: 7.95 bits per byte0x360000: 7.95 bits per byte0x370000: 7.95 bits per byte0x380000: 7.95 bits per byte0x390000: 7.95 bits per byte0x3A0000: 7.47 bits per byte0x3B0000: 0.00 bits per byte0x3C0000: 7.95 bits per byte0x3D0000: 7.96 bits per byte0x3E0000: 0.00 bits per byte0x3F0000: 1.21 bits per bytethreshold 7.20x0000000x0800000x1000000x1800000x2000000x2800000x3000000x3800000x400000offset in file

Click the cells under the chart to mark blocks you think are compressed or encrypted (arrow keys move between cells). Then check, and the region boundaries appear.

  • Low, below 3
    Zeros, 0xFF padding, sparse tables
  • Medium, 3 to 7.2
    Machine code, text, structured data
  • High, 7.2 and up
    Compressed or encrypted data

Entropy here is Shannon entropy in bits per byte, from 0 (one byte value repeated) to 8 (all 256 values equally likely). The values are computed from synthetic bytes that mimic each kind of content, so the shapes are realistic but the exact numbers are illustrative.

Filesystem Identification and Extraction

Once the filesystem is extracted, you can analyse it like any Linux filesystem:

bash
# After binwalk extraction, examine the filesystem
ls -la _firmware.bin.extracted/squashfs-root/
cat _firmware.bin.extracted/squashfs-root/etc/passwd
cat _firmware.bin.extracted/squashfs-root/etc/shadow
find _firmware.bin.extracted/squashfs-root/ -name "*.conf" -exec grep -l "password" {} \;

Common findings in firmware filesystems: hardcoded credentials buried in /etc/passwd, /etc/shadow, or config files; SSH/SSL private keys left in the image by someone who forgot to clean up; debug binaries with verbose logging that never ship in production software; web server files with admin interfaces that haven't seen a security review in years.

Identifying the Base Address

For disassembly of bare-metal firmware (without an OS), you need to determine the base address - the memory address where the firmware expects to be loaded. Incorrect base address means all cross-references and function pointers in the disassembly are wrong.

Techniques for finding the base address:

  • Vector table: ARM Cortex-M firmware starts with a vector table whose first entry is the initial stack pointer and second is the reset handler address. These addresses reveal the memory map.
  • String references: Find a string in the binary, then search for instructions that reference that string's offset. The difference reveals the base address.
  • Known hardware addresses: Peripheral register addresses (from the SoC datasheet) appear as constants in the firmware. Finding these constants helps determine the memory map.

Detecting Firmware Modifications

Comparing a suspect firmware image against a known-good version reveals unauthorised modifications:

bash
# Binary diff between firmware versions
vbindiff firmware_good.bin firmware_suspect.bin
# Compare extracted filesystems
diff -rq good_squashfs/ suspect_squashfs/
# Hash every file in both extractions and compare
# (cd into each tree so both lists use the same relative paths, then sort by path)
(cd good_squashfs && find . -type f -exec sha256sum {} + | sort -k2) > good_hashes.txt
(cd suspect_squashfs && find . -type f -exec sha256sum {} + | sort -k2) > suspect_hashes.txt
diff good_hashes.txt suspect_hashes.txt

Backdoor indicators include: new executable files, modified system binaries (especially busybox, dropbear, or the web server), additional startup scripts, modified iptables rules, and new cron jobs.

Firmware Backdoor Detection

Backdoors in firmware take several forms:

Hardcoded accounts: Hidden user accounts with fixed passwords. The classic example is default admin credentials that persist after the user changes the visible admin password — the backdoor account lives in a separate authentication path and is never touched.

Undocumented services: Network services (telnet, SSH, custom protocols) that appear in the firmware but aren't documented and can't be disabled through any normal interface.

Magic packets: The firmware listens for a specific byte pattern on a network port. Receive the magic packet, and a hidden interface opens or a command runs.

Modified system utilities: The busybox binary or other core tools patched to include extra commands or to skip authentication under specific conditions.

Supply Chain Firmware Attacks

Firmware is a prime target for supply chain attacks because it is rarely inspected by end users, persists across OS reinstallations, and runs with the highest privileges. Verifying firmware integrity requires either comparing against a known-good image from the vendor or validating cryptographic signatures (if the device supports secure boot). Without these checks, a compromised firmware image can persist indefinitely.