Skip to main content
Be Bitwise

Firmware Analysis

Firmware Reverse Engineering · Embedded Systems & Firmware track

6 min read

In this module

Dissecting the Binary Blob

A raw firmware image arrives as an opaque blob. Inside might be a bootloader, a compressed kernel, a filesystem image, configuration data, and calibration tables — all jammed together with no signposts to mark the boundaries. Firmware analysis is the work of finding those boundaries, extracting each component, and figuring out what the whole thing looks like under the hood.

Binwalk: The Essential Tool

Binwalk scans a binary file looking for known file format signatures (magic bytes) and reports what it finds:

bash
# Scan firmware for embedded files
binwalk firmware.bin
# Output example:
# DECIMAL HEXADECIMAL DESCRIPTION
# 0 0x0 U-Boot bootloader
# 65536 0x10000 uImage header, Linux kernel
# 1048576 0x100000 Squashfs filesystem, little endian, version 4.0
# Extract all identified components
binwalk -e firmware.bin
# Recursive extraction (extract within extracted files)
binwalk -eM firmware.bin

These are the long-standing Python binwalk (v2) flags. binwalk v3 is a Rust rewrite that keeps -e, -M and -E but drops some v2 options, so check binwalk --help for the version you have.

Those matches are just magic numbers at known offsets. Here's what binwalk found at 0x10000 and 0x100000 in the example above (values illustrative, layouts exact). The bootloader at offset 0 has no fixed header like these; binwalk recognises U-Boot from signatures such as its version string.

uImage header at 0x10000 (all fields big-endian)

0000'..V^|.._<.@....
0010.. ...a...D.....
0020Linux Kernel Ima
0030ge..............

Click a coloured byte or a field name to decode it

SquashFS superblock at 0x100000 (little-endian)

0000hsqs....@.<_....
0010:...............

Click a coloured byte or a field name to decode it

Binwalk's extraction mode drops every identified component into a directory. A SquashFS filesystem comes out as a complete directory tree you can walk through file by file.

Entropy Analysis

Entropy analysis reveals the structure of a firmware image without relying on signature matching:

bash
binwalk -E firmware.bin

This produces an entropy plot where:

  • Low entropy: padding, ASCII text, tables and other structured data
  • Middling entropy (very roughly 5-7 bits/byte): machine code
  • Close to 8 bits/byte: compressed data (gzip, LZMA, zlib) and encrypted or random data

The entropy plot is a map. Sharp transitions between entropy levels mark the boundaries between firmware sections. What it can't do on its own is tell compressed data from encrypted data, since good compression and good encryption both look close to random. Look for the compression format's magic bytes and headers at the start of the region, or run a randomness test such as chi-square (ent reports it): compressed streams usually deviate from uniform more than ciphertext does. A firmware image that's near 8 bits/byte from start to finish with no recognisable headers is very likely encrypted.

Encrypted Firmware Strategy

If the firmware is encrypted, you need the decryption key. Common approaches: (1) Find an older, unencrypted firmware version and extract the decryption key from it. (2) Extract the key from a running device via UART or JTAG. (3) Use fault injection to bypass the decryption check in the bootloader. (4) Analyse the bootloader (which must be unencrypted to run) for the decryption routine and key.

Filesystem Identification

Common filesystems in firmware:

  • SquashFS: Read-only compressed filesystem, very common in Linux-based devices
  • JFFS2: Journaling flash filesystem, designed for raw NAND flash
  • CramFS: Compressed ROM filesystem, older alternative to SquashFS
  • ext2/ext4: Standard Linux filesystems, sometimes used on larger storage
  • UBIFS: Unsorted Block Image File System, modern NAND flash filesystem

After extraction, examine the filesystem for security-relevant artifacts:

bash
# Check for hardcoded credentials
cat etc/passwd etc/shadow
grep -r "password" etc/
grep -r "admin" etc/
# Check for SSH keys
find . -name "*.pem" -o -name "id_rsa" -o -name "authorized_keys"
# Check startup scripts for network services
cat etc/init.d/*
cat etc/rc.local
# Look for web server configuration
find . -name "*.conf" -path "*/httpd/*" -o -path "*/lighttpd/*" -o -path "*/nginx/*"

Identifying Base Addresses for Disassembly

For bare-metal firmware (without a Linux filesystem), you need to determine the correct base address for disassembly in tools like Ghidra or IDA Pro.

ARM Cortex-M vector table method: The first word is the initial SP, the second is the reset handler address. These reveal the memory map:

bash
# Read first 8 bytes of firmware
xxd -l 8 firmware.bin
# Output: 00000000: 0010 0020 c501 0008
# Initial SP = 0x20001000 (RAM)
# Reset handler = 0x080001c5 (Flash base 0x08000000)

The low bit of the reset handler address is the Thumb bit, which every Cortex-M vector must have set. The handler's code actually starts at 0x080001c4, so that's the address to disassemble from.

String reference method: Find a known string in the binary, find code that references it, and calculate the base address from the reference instruction's encoding and the string's file offset.

Automated Analysis Tools

Beyond binwalk, several tools automate firmware analysis:

  • FACT (Firmware Analysis and Comparison Tool): Web-based platform for automated firmware analysis with plugin support
  • Firmwalker: Shell script that searches extracted firmware filesystems for common security issues
  • EMBA: Automated firmware security analysis framework with hundreds of check modules
bash
# Firmwalker: quick security scan of extracted filesystem
firmwalker /path/to/extracted/filesystem/
# Checks for: hardcoded credentials, SSL certificates, private keys,
# config files, web server files, binary hardening, and more
Analysis Is Iterative

Firmware analysis is rarely a linear process. Initial binwalk extraction might reveal a bootloader with an encrypted kernel. Analysing the bootloader reveals the decryption routine. Extracting the key allows decrypting the kernel. The kernel contains device tree information that explains the memory map. This information enables correct disassembly of bare-metal components discovered in the initial scan. Each step reveals information needed for the next.