performing-firmware-malware-analysis について
IoT機器、ルーター、UEFI/BIOSのイメージを調査し、悪意ある改変を探すファームウェア分析スキルです。ファイルシステムの抽出、バイナリのリバースエンジニアリング、エミュレーションを扱います。
主な機能
- 01ファームウェア構成要素の特定と抽出
- 02組み込みファイルシステムの検査
- 03不審なバイナリの解析
- 04UEFI/BIOSファームウェアの分析
- 05QEMUによるファームウェアのエミュレーション
- 06分析結果の記録
活用シーン
- 01ルーターに残るバックドアの調査
- 02IoTファームウェア更新の改ざん確認
- 03UEFI/BIOSのブートレベルマルウェアの調査
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ mukul975/ anthropic-cybersecurity-skills --skill performing-firmware-malware-analysisインストール後、Claude Code で/performing-firmware-malware-analysisを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
LICENSEreferences/api-reference.mdscripts/agent.py詳細
ファームウェアのマルウェア解析
使用する場面
- IoT デバイスやルーターが侵害され、埋め込まれたバックドアを特定するためにファームウェア解析が必要な場合
- OS を再インストールしても残存する UEFI/BIOS ルートキットを調査する場合
- サプライチェーンの侵害や悪意のある改変がないか、ファームウェアのアップデートを解析する場合
- IoT デバイスのファームウェアイメージから、組み込み Linux ファイルシステムを抽出して調査する場合
- ハードウェアまたはファームウェアレベルで侵害された疑いがある場合に、ファームウェアの完全性を検証する場合
使用しないでください。標準的なオペレーティングシステムのマルウェアには使用しないでください。一般的なシステム上の OS レベルのマルウェアには、PE/ELF 解析ツールを使用してください。
前提条件
- ファームウェアイメージの解析と抽出用に binwalk をインストールしておきます(
pip install binwalk) - 組み込みバイナリのリバースエンジニアリング用に、ARM/MIPS アーキテクチャをサポートする Ghidra を用意します
- UEFI ファームウェアの解析用に UEFI Tool(UEFITool)を用意します
- 自動ファームウェア解析用に Firmware Analysis Toolkit(FAT)または EMBA を用意します
- 抽出したファームウェアのファイルシステムをエミュレートするために QEMU を用意します
- ARM、MIPS などの組み込みアーキテクチャ用のクロスコンパイルツールチェーンを用意します
ワークフロー
ステップ 1:ファームウェアのコンポーネントを抽出して特定する
ファームウェアイメージの構造を解析し、ファイルシステムを抽出します。
# Identify embedded filesystems and compressed data
binwalk firmware.bin
# Extract all identified components
binwalk -e firmware.bin
# Recursive extraction with signature scanning
binwalk -eM firmware.bin
# Output typically includes:
# - Bootloader (U-Boot, GRUB, custom)
# - Kernel image (Linux, RTOS)
# - Root filesystem (SquashFS, JFFS2, CramFS, ext4)
# - Configuration data
# - Digital signatures or checksums
# Entropy analysis to find encrypted or compressed regions
binwalk -E firmware.bin
# Identify specific filesystem types
file _firmware.bin.extracted/*
# For SquashFS filesystems
unsquashfs _firmware.bin.extracted/squashfs-root.img
ls squashfs-root/
ステップ 2:抽出したファイルシステムを解析する
ファームウェアのファイルシステム内に悪意のある改変がないか検索します。
# Directory structure analysis
find squashfs-root/ -type f | head -50
# Search for suspicious files
find squashfs-root/ -name "*.sh" -exec ls -la {} \;
find squashfs-root/ -perm -4000 -type f # SUID binaries
find squashfs-root/ -name "*.so" -newer squashfs-root/bin/busybox # Modified libraries
# Check startup scripts for backdoors
cat squashfs-root/etc/init.d/rcS
cat squashfs-root/etc/inittab
ls -la squashfs-root/etc/rc.d/
# Search for hardcoded credentials
grep -rn "password\|passwd\|secret\|key\|token" squashfs-root/etc/ 2>/dev/null
grep -rn "root:" squashfs-root/etc/shadow 2>/dev/null
# Check for unauthorized SSH keys
find squashfs-root/ -name "authorized_keys" -exec cat {} \;
# Network configuration backdoors
cat squashfs-root/etc/hosts
grep -rn "iptables\|nc\|netcat\|ncat" squashfs-root/etc/ squashfs-root/usr/bin/
# Check for reverse shells in cron
find squashfs-root/ -name "crontab" -o -name "cron*" | xargs cat 2>/dev/null
# Identify all ELF binaries for analysis
find squashfs-root/ -type f -exec file {} \; | grep ELF
ステップ 3:不審なバイナリをリバースエンジニアリングする
バックドアの可能性がある、抽出したバイナリを解析します。
# Identify architecture and format
file squashfs-root/usr/bin/suspicious_binary
# Extract strings for IOC discovery
strings squashfs-root/usr/bin/suspicious_binary | grep -iE "http|ip|port|shell|connect|exec"
# Cross-reference against known firmware binaries
# Compare SHA-256 hashes with known-good firmware
sha256sum squashfs-root/usr/bin/* > current_hashes.txt
# diff against baseline: diff baseline_hashes.txt current_hashes.txt
# Import into Ghidra for disassembly (select correct architecture)
# ARM: ARM/AARCH64 (Little Endian for most IoT devices)
# MIPS: MIPS/MIPS64 (Big or Little Endian depending on device)
# x86: For UEFI modules
# Analyze with radare2 for quick triage
r2 -A squashfs-root/usr/bin/suspicious_binary
# Commands: afl (function list), pdf @main (disassemble main), iz (strings)
ステップ 4:UEFI/BIOS ファームウェアを解析する
ブートキットやインプラントがないか、システムファームウェアを解析します。
# Extract UEFI firmware volumes with UEFITool
# GUI: UEFITool -> File -> Open -> Select firmware.rom
# CLI: UEFIExtract firmware.rom
# Analyze UEFI firmware with chipsec (requires hardware access)
python chipsec_main.py -m common.bios_wp # BIOS write protection
python chipsec_main.py -m common.spi_lock # SPI flash lock
python chipsec_main.py -m common.secureboot # Secure Boot status
python chipsec_main.py -m common.uefi.s3bootscript # S3 resume script
# Dump UEFI firmware from live system
python chipsec_util.py spi dump firmware_dump.rom
# Compare with known-good firmware
sha256sum firmware_dump.rom
# Compare against vendor-provided firmware hash
# Scan for known UEFI malware signatures
yara -r uefi_malware_rules.yar firmware_dump.rom
Known UEFI Malware Families:
━━━━━━━━━━━━━━━━━━━━━━━━━━
LoJax: First in-the-wild UEFI rootkit (APT28/Fancy Bear)
Modifies SPI flash to drop persistence agent
MosaicRegressor: Modular UEFI framework dropping multiple payloads
CosmicStrand: UEFI firmware rootkit modifying kernel during boot
BlackLotus: UEFI bootkit bypassing Secure Boot on Windows 11
ESPecter: ESP (EFI System Partition) bootkit modifying boot manager
MoonBounce: SPI flash implant modifying CORE_DXE module
FinSpy UEFI: Surveillance software with UEFI persistence
ステップ 5:動的解析用にファームウェアをエミュレートする
エミュレート環境で、抽出したファームウェアを実行します。
# Emulate ARM-based IoT firmware with QEMU
# Mount the extracted filesystem
sudo mount -o loop squashfs-root.img /mnt/firmware
# Chroot into the firmware with QEMU user-mode emulation
sudo cp /usr/bin/qemu-arm-static /mnt/firmware/usr/bin/
sudo chroot /mnt/firmware /bin/sh
# Or use firmadyne for automated firmware emulation
# https://github.com/firmadyne/firmadyne
python3 fat.py firmware.bin
# Network service analysis within emulated firmware
# Scan for open ports and services
nmap -sV localhost -p 1-65535
# Monitor network traffic from emulated firmware
tcpdump -i tap0 -w firmware_traffic.pcap
ステップ 6:ファームウェア解析を記録する
ファームウェア解析の結果を包括的にまとめます。
Analysis documentation should cover:
- Firmware image metadata (vendor, model, version, build date)
- Extraction results (filesystem type, kernel version, architecture)
- Modified files compared to known-good baseline
- Backdoor binaries discovered with reverse engineering findings
- Hardcoded credentials and unauthorized access mechanisms
- Network services and their security posture
- UEFI/BIOS integrity verification results
- Extracted IOCs (IPs, domains, file hashes, SSH keys)
- Remediation recommendations (reflash, replace, update)
主要な概念
| 用語 | 定義 |
|---|---|
| ファームウェア | デバイスハードウェア(フラッシュメモリ、EEPROM)に恒久的に保存され、デバイスの低レベルの動作と起動プロセスを制御するソフトウェア |
| UEFI(Unified Extensible Firmware Interface) | 従来の BIOS に代わる最新のシステムファームウェアです。起動サービス、ランタイムサービス、モジュール式ドライバーアーキテクチャを提供します |
| SPI フラッシュ | UEFI/BIOS ファームウェアを保存するシリアル・ペリフェラル・インターフェースのフラッシュメモリチップです。永続化のために読み取りや改変が可能です |
| セキュアブート | 起動時に不正なコードが実行されないよう、ブートコンポーネントのデジタル署名を検証する UEFI の機能です |
| SquashFS | 組み込み Linux ファームウェアで、効率的な省スペース保存のために一般的に使用される読み取り専用の圧縮ファイルシステムです |
| ブートキット | オペレーティングシステムより前に読み込まれて OS レベルのセキュリティを回避するよう、起動プロセス(MBR、VBR、UEFI)に感染するマルウェアです |
| ファームウェアエミュレーション | 抽出したファームウェアを仮想環境(QEMU、firmadyne)で実行し、物理ハードウェアなしで動作を解析することです |
ツールとシステム
- binwalk:ファームウェアイメージ内の組み込みファイルシステムや圧縮データをスキャン、抽出、解析するファームウェア解析ツール
- UEFITool:UEFI ボリューム、モジュール、ドライバーを解析するための、オープンソースの UEFI ファームウェアイメージ解析・抽出ツール
- chipsec:SPI フラッシュ、セキュアブート、UEFI の解析など、プラットフォームのセキュリティ評価を行う Intel のオープンソースフレームワーク
- firmadyne:Linux ベースの組み込みデバイス向け、自動ファームウェア解析・エミュレーションプラットフォーム
- Ghidra:ファームウェアバイナリの解析に向けて、ARM、MIPS などの組み込みアーキテクチャをサポートする NSA のリバースエンジニアリングツール
一般的なシナリオ
シナリオ:永続的なバックドアに侵害されたルーターの調査
コンテキスト:ルーターが工場出荷時の状態にリセットした後も、不審な動作(予期しない DNS 名前解決、不明な IP への通信)を続けています。ファームウェアレベルでの侵害が疑われます。
アプローチ:
- JTAG/UART デバッグインターフェースまたはベンダーの管理ツールを使用して、ルーターからファームウェアをダンプします
- binwalk でファイルシステムを展開し、Linux ディストリビューションとカーネルのバージョンを特定します
- ファイルハッシュを、ベンダー提供の既知の正常なファームウェアイメージと照合します
- 起動スクリプト(rcS、inittab、crontab)を検索し、バックドアのエントリを探します
- 変更または新規追加されたバイナリを Ghidra で解析します(ARM/MIPS アーキテクチャ)
- ハードコードされた認証情報、不正な SSH キー、リバースシェルスクリプトを確認します
- ファームウェアをエミュレートしてネットワーク動作を観察し、C2 通信を特定します
注意点:
- 実際のデバイスからファームウェアをダンプしない(ベンダーサイトからダウンロードすると、侵害されていないバージョンが入手されます)
- システム関数をフックする可能性のある、変更された共有ライブラリ(.so ファイル)を見落とす
- メインのファイルシステム外(ブートローダー、設定パーティション)に保存されたファームウェアの変更を見落とす
- プライマリとバックアップの両方のファームウェアパーティションを確認しない(デュアルバンクフラッシュを搭載したデバイスもあります)
出力形式
FIRMWARE MALWARE ANALYSIS REPORT
===================================
Device: NetGear R7000 Router
Firmware Version: V1.0.11.116 (modified)
Architecture: ARM (Little Endian)
Filesystem: SquashFS (Linux 3.4.103)
Dump Method: UART debug console
INTEGRITY CHECK
Vendor Firmware Hash: aaa111bbb222... (clean V1.0.11.116)
Analyzed Firmware Hash: ccc333ddd444... (MISMATCH)
Modified Files: 14 files differ from vendor baseline
BACKDOOR FINDINGS
[!] /usr/bin/httpd_backdoor (new binary, not in vendor firmware)
Architecture: ARM 32-bit
Function: Reverse shell to 185.220.101[.]42:4444
Persistence: Added to /etc/init.d/rcS
[!] /etc/shadow modified
Root password changed to known hash
New user 'admin2' added with UID 0
[!] /etc/crontab modified
Added: */5 * * * * /usr/bin/httpd_backdoor
[!] /root/.ssh/authorized_keys (new file)
Contains attacker's SSH public key
EXTRACTED IOCs
C2 IP: 185.220.101[.]42
C2 Port: 4444
SSH Key: ssh-rsa AAAA... attacker@control
Backdoor Hash: eee555fff666...
REMEDIATION
1. Flash clean vendor firmware via TFTP recovery mode
2. Change all device credentials
3. Update to latest firmware version
4. Enable firmware integrity checking if available
5. Monitor for re-compromise indicators
コメント
Markdown 対応