Reverse Engineering Firmware
Analyzes embedded firmware images and hardware interfaces to understand functionality, identify vulnerabilities, and document system architecture. Use when examining IoT devices, extracting firmware for security research, analyzing bootloaders, or auditing embedded systems that are owned or authorized for testing.
Analyzes embedded firmware binaries and hardware debug interfaces to recover architecture, extract filesystems, locate authentication/crypto logic, and document attack surface — for security research on owned or explicitly authorized hardware.
Bash# Identify container format and embedded signatures file firmware.bin binwalk firmware.bin # Extract everything binwalk recognizes binwalk -e firmware.bin # Entropy scan — flags compressed vs encrypted regions binwalk -E firmware.bin # Pull human-readable artifacts (version strings, URLs, debug banners) strings -n 8 firmware.bin | grep -iE "version|login|passwd|http|debug"
If binwalk -e yields a clean squashfs/jffs2 tree under _firmware.bin.extracted/, skip to filesystem analysis. If it yields high-entropy noise with no recognizable headers, go to the encrypted-firmware workflow below.
Progress:
- [ ] Step 1: Identify format and container structure
- [ ] Step 2: Extract or carve the filesystem
- [ ] Step 3: Map the boot chain
- [ ] Step 4: Static analysis of key binaries in Ghidra
- [ ] Step 5: Identify auth/crypto routines specifically
- [ ] Step 6: Cross-reference against known CVEs and SDK fingerprints
- [ ] Step 7: Document architecture and attack surface
Step 1: Identify format and container structure
Run binwalk -B firmware.bin for signature scanning. Typical output:
DECIMAL HEX DESCRIPTION
--------------------------------------------------------------------
0 0x0 uImage header, header size: 64 bytes, ...
64 0x40 LZMA compressed data
1245184 0x130000 Squashfs filesystem, little endian, version 4.0
Reading this: offset 0 is a U-Boot uImage wrapper — strip the 64-byte header to get the raw kernel. The LZMA blob starting at 0x40 is almost certainly the compressed Linux kernel. The squashfs at 0x130000 is the root filesystem — this is your primary extraction target.
If instead you see no recognizable headers and binwalk -E shows flat entropy ~7.9-8.0 across the whole file, treat it as encrypted or whitened (XOR'd) — see Edge Cases.
Step 2: Extract or carve the filesystem
Bashbinwalk -e firmware.bin cd _firmware.bin.extracted ls -la squashfs-root/
If binwalk -e fails to auto-extract (common with nonstandard squashfs block sizes or vendor-modified magic bytes), carve manually:
Bashdd if=firmware.bin of=rootfs.sqsh bs=1 skip=1245184 unsquashfs rootfs.sqsh
If unsquashfs errors on compression type, check for LZMA/XZ variants vendors patch in (common on Realtek/MediaTek SDKs) — use sasquatch (a binwalk-maintained fork of unsquashfs) which handles these nonstandard variants.
Once extracted, prioritize:
/etc/passwd,/etc/shadow— static credentials, often weak/default/etc/init.d/or/etc/rcS— boot-time service startup, reveals what's listening/www/cgi-bin/or/usr/bin/— web-facing binaries, highest-value targets/lib/— shared libs, check for custom crypto/auth libs vs stock OpenSSL
Step 3: Map the boot chain
Look for U-Boot environment strings in the raw image:
Bashstrings firmware.bin | grep -E "bootcmd|bootargs|baudrate"
This reveals the boot command sequence and often the memory layout (load addresses for kernel/rootfs), which tells you where in flash to find things if the image is a full flash dump rather than an OTA update package.
If you have physical access and a UART breakout, interrupt autoboot (usually send any key within the 1-3 second countdown) to get a U-Boot shell. From there:
=> printenv # dumps bootargs, bootcmd, flash partition map
=> md.b 0x0 0x100 # memory dump, confirm addressing
Step 4: Static analysis of key binaries in Ghidra
Import target binaries (prioritize anything network-facing or setuid). For MIPS/ARM embedded targets:
- Set the correct processor variant in Ghidra's import dialog (MIPS big vs little endian is a common misconfiguration that produces garbage disassembly — verify against
fileoutput first). - Run auto-analysis with "Decompiler Parameter ID" and "Shared Return Calls" enabled — embedded toolchains frequently produce tail-call patterns that confuse default analysis.
- Use the Symbol Tree to search for suspicious imports:
strcpy,system,popen,sprintf— classic command-injection and buffer-overflow sinks in web-facing CGI binaries. - Use Ghidra's string search (Search → For Strings) cross-referenced against the decompiled callers to find where hardcoded banners, URLs, or credential checks live.
Step 5: Identify auth/crypto routines specifically
Auth bypass research centers on finding the comparison logic. Search decompiled output for:
strcmp/memcmpcalls immediately following a buffer read from a network socket or HTTP parameter — classic password-check pattern.- Constant-looking byte arrays passed to
memcmp— likely hardcoded backdoor credentials or magic bypass strings. - Calls into
libcrypto/mbedtls/custom crypto blobs — check whether keys are embedded as string constants in.rodata(very common vendor failure) via Ghidra's Defined Strings view.
For firmware with signature verification on updates, locate the RSA/ECDSA verify call (search for _verify symbol names or constant-time comparison patterns) and check whether the public key is stored in NVRAM/flash where it could be swapped, versus burned into OTP/eFuse (unmodifiable).
Step 6: Cross-reference against known CVEs and SDK fingerprints
Fingerprint vendor SDK reuse — many IoT vendors ship the same Realtek/Broadcom/MediaTek reference SDK with minor branding changes. Search extracted /etc/, kernel version strings, and busybox --help banner output against CVE databases; a huge fraction of IoT vulnerabilities are unpatched SDK-level bugs (e.g., miniigd UPnP stack overflows, dnsmasq versions with known CVEs) rather than vendor-custom code.
Step 7: Document architecture and attack surface
Produce a findings doc with: boot chain diagram, partition map, list of network-facing services with binary paths, identified auth mechanisms and their weaknesses, crypto key storage location and exposure, and a prioritized vulnerability list mapped to CVSS or a simple High/Med/Low with exploitability notes.
Example 1: Reading a binwalk signature scan
Input:
$ binwalk firmware.bin
DECIMAL HEX DESCRIPTION
0 0x0 TRX firmware header, little endian, image size: 3932160
28 0x1C LZMA compressed data, properties: 0x5D
1310744 0x1400D8 Squashfs filesystem, little endian, version 4.0, size: 2621440
Output/Conclusion: This is a Broadcom TRX-wrapped image (common on older Linksys/Netgear routers). The TRX header at offset 0 contains partition offsets in its own header fields — parse those (first 32 bytes: magic, length, CRC32, flags/version, then three partition offsets) rather than trusting binwalk's single LZMA/squashfs hits blindly, since TRX often holds a second kernel partition binwalk may not flag separately.
Example 2: Carving a nonstandard squashfs
Input: unsquashfs fails with "unsquashfs: failed to read squashfs_super_block" despite binwalk identifying a squashfs signature.
Output/Conclusion: Vendor likely altered the magic bytes or uses a nonstandard block size/compression (LZMA instead of gzip, which stock unsquashfs often can't handle). Fix: use sasquatch or patch the magic bytes back to standard 0x73717368 before retrying, then confirm compression type via the superblock's compression field (byte offset 0x8-0x9 in the squashfs superblock).
- Encrypted firmware (flat entropy, no headers): Check for a bootloader-stage decryption routine instead — the encryption key/algorithm is often in an unencrypted first-stage bootloader. Dump that via JTAG/SPI flash read and reverse it before attempting to decrypt the main image. AES-CBC with a static key embedded in bootloader
.rodatais extremely common. - XOR-obfuscated (not真 encrypted) images: Flat-looking entropy that's slightly below true random (7.5-7.8 rather than 7.95+) often indicates simple XOR whitening rather than real encryption. Try single-byte and repeating-key XOR brute force against known-plaintext (e.g., expected ELF header
\x7fELFat offset 0). - Proprietary/custom compression: If
binwalkidentifies "unknown compression" or garbage after a recognized header, check the vendor's GPL compliance source drops (required for Linux-based firmware) — they often contain the exact mkfs/compression tool needed to reverse the format. - Secure boot chains: Unencrypted flash does not imply unsigned flash. Check for signature verification before claiming a full compromise — look for RSA/ECDSA verify calls in the first-stage bootloader before assuming a patched image will boot.
- SPI flash dumps with locked chip-select: If a logic analyzer shows no traffic on expected SPI lines, confirm the flash isn't routed through a secondary mux/CPLD — common on devices with multiple boot banks (A/B firmware slots).
- Confirm ownership or written authorization before extracting from or interfacing with physical hardware.
- Verify architecture/endianness (via
fileand ELF header bytes) before disassembling — wrong settings silently produce plausible-looking but wrong disassembly. - Keep raw dumps, extracted artifacts, and analysis notes in separate directories with hashes recorded, so findings are reproducible.
- Follow a responsible disclosure timeline (commonly 90 days) when reporting vendor vulnerabilities; document the report submission date and vendor response.
- Don't assume
binwalk's auto-extraction caught everything — always cross-check offsets manually against the hex dump for multi-partition images (TRX, vendor-custom containers). - Don't skip entropy analysis before diving into disassembly — hours get wasted treating encrypted blobs as corrupted compressed data.
- Don't trust default Ghidra auto-analysis on MIPS firmware without verifying endianness first; silent misconfiguration produces confidently wrong decompilation.
- Don't conflate "flash is readable" with "device is compromised" — secure boot and OTP-stored keys can block modified firmware from ever executing even with full flash read/write access.