binary-analysis について
バイナリファイル、ファームウェア、不明データの調査とリバースエンジニアリングを支援するスキルです。セキュリティ分析担当者や開発者向けに、形式判定、文字列抽出、16進数表示、埋め込みファイルの検出を扱います。
主な機能
- 01不明なファイル形式の特定
- 02文字列とシンボルの抽出
- 03ファームウェア内の埋め込みファイル検出
- 04生の16進レイアウトの確認
- 05エントロピーと隠しデータの分析
活用シーン
- 01未知のバイナリの初期調査
- 02ファームウェア内容の確認
- 03埋め込みアーカイブや追加データの特定
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ laurigates/ claude-plugins --skill binary-analysisインストール後、Claude Code で/binary-analysisを入力して読み込まれたか確認します。
詳細
バイナリ解析
バイナリファイル、ファームウェア、不明なデータを調査し、リバースエンジニアリングするためのツールです。
このスキルを使う場面
| 次のような場合はこのスキルを使います… | 次のような場合は代わりに rg-code-search を使います… |
|---|---|
不明なファイル形式やテキスト以外のファイル形式を特定する(file、xxd) | トラッキング対象のソースファイルから正規表現で検索する |
| コンパイル済みバイナリ/ファームウェアから文字列やシンボルを抽出する | リポジトリ内のテキスト形式のファイルを監査し、ハードコードされたパターンを探す |
ELF、Mach-O、.bin のデータの生の 16 進数レイアウトを調べる | 入力が人間に読めるコードまたは Markdown である |
| 次のような場合はこのスキルを使います… | 次のような場合は代わりに jq-json-processing を使います… |
|---|---|
| 不透明なバイナリ形式をリバースエンジニアリングする | データがすでに構造化 JSON で、変換を待っている |
binwalk -e で埋め込みファイルを探す | 解析済みの JSON ペイロードからフィールドを抽出する |
クイックリファレンス
| ツール | 用途 | インストール |
|---|---|---|
strings | バイナリから印字可能なテキストを抽出 | 標準搭載(binutils) |
binwalk | ファームウェア解析、ファイル抽出 | pip install binwalk または cargo install binwalk |
hexdump | 16 進数/ASCII ダンプ | 標準搭載 |
xxd | 逆変換機能付き 16 進数ダンプ | 標準搭載(vim) |
file | ファイル形式を特定 | 標準搭載 |
strings - バイナリからテキストを抽出
バイナリファイルに埋め込まれた、人間に読める文字列を検索します。
# Basic usage - find all printable strings (min 4 chars)
strings binary_file
# Set minimum string length
strings -n 10 binary_file # Only strings >= 10 chars
# Show file offset of each string
strings -t x binary_file # Hex offset
strings -t d binary_file # Decimal offset
# Search for specific patterns
strings binary_file | grep -i password
strings binary_file | grep -E 'https?://'
strings binary_file | grep -i api_key
# Wide character strings (UTF-16)
strings -e l binary_file # Little-endian 16-bit
strings -e b binary_file # Big-endian 16-bit
strings -e L binary_file # Little-endian 32-bit
# Scan entire file (not just initialized data sections)
strings -a binary_file
strings でよく見つかるもの:
- ハードコードされた認証情報、API キー
- URL とエンドポイント
- エラーメッセージ(機能の手掛かりになります)
- ライブラリのバージョン
- デバッグシンボルと関数名
- 設定パス
binwalk - ファームウェア解析
埋め込みファイルを特定して抽出し、エントロピーを解析して、隠されたデータを見つけます。
# Signature scan - identify embedded files/data
binwalk firmware.bin
# Extract all identified files
binwalk -e firmware.bin # Extract to _firmware.bin.extracted/
binwalk --extract firmware.bin # Same as -e
# Recursive extraction (extract files within extracted files)
binwalk -Me firmware.bin
# Entropy analysis - find compressed/encrypted regions
binwalk -E firmware.bin # Generate entropy graph
binwalk --entropy firmware.bin
# Opcode analysis - identify CPU architecture
binwalk -A firmware.bin
binwalk --opcodes firmware.bin
# Raw byte extraction at offset
binwalk --dd='type:extension' firmware.bin
# Specific signature types
binwalk --signature firmware.bin # File signatures only
binwalk --raw='\\x1f\\x8b' firmware.bin # Search for gzip magic bytes
binwalk の出力の解釈:
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 TRX firmware header
28 0x1C LZMA compressed data
1835008 0x1C0000 Squashfs filesystem, little endian
hexdump / xxd - 生の 16 進数解析
# Hex + ASCII dump
hexdump -C binary_file
xxd binary_file
# Dump specific byte range
xxd -s 0x100 -l 256 binary_file # 256 bytes starting at offset 0x100
# Just hex, no ASCII
hexdump -v -e '/1 "%02x "' binary_file
# Create hex dump that can be reversed
xxd binary_file > hex.txt
xxd -r hex.txt > reconstructed_binary
# Find specific bytes
xxd binary_file | grep "504b" # Look for PK (ZIP signature)
file - ファイル形式の特定
# Basic identification
file unknown_file
file -i unknown_file # MIME type
# Check multiple files
file *
# Follow symlinks
file -L symlink
よく使われる解析ワークフロー
不明なバイナリの調査
# 1. Identify file type
file mystery_file
# 2. Check for embedded files
binwalk mystery_file
# 3. Extract strings
strings -n 8 mystery_file | head -100
# 4. Look at hex header
xxd mystery_file | head -20
# 5. Check entropy (compressed/encrypted?)
binwalk -E mystery_file
ファームウェア解析
# 1. Initial scan
binwalk firmware.bin
# 2. Extract everything
binwalk -Me firmware.bin
# 3. Explore extracted filesystem
find _firmware.bin.extracted -type f -name "*.conf"
find _firmware.bin.extracted -type f -name "passwd"
# 4. Search for secrets
grep -r "password" _firmware.bin.extracted/
strings -n 10 firmware.bin | grep -i -E "(pass|key|secret|token)"
隠されたデータの検索
# Check for data after end of file
binwalk -E file.jpg # Entropy spike at end = appended data
# Look for embedded archives
binwalk file.jpg | grep -E "(Zip|RAR|7z|gzip)"
# Extract with offset
dd if=file.jpg of=hidden.zip bs=1 skip=12345
ファイルシグネチャ(マジックバイト)
| シグネチャ | 16 進数 | ファイル形式 |
|---|---|---|
PK | 50 4B 03 04 | ZIP アーカイブ |
Rar! | 52 61 72 21 | RAR アーカイブ |
7z | 37 7A BC AF | 7-Zip |
ELF | 7F 45 4C 46 | Linux 実行ファイル |
MZ | 4D 5A | Windows 実行ファイル |
PNG | 89 50 4E 47 | PNG 画像 |
JFIF | FF D8 FF E0 | JPEG 画像 |
sqsh | 73 71 73 68 | SquashFS |
hsqs | 68 73 71 73 | SquashFS(LE) |
ヒント
- まずはエントロピーを確認します:エントロピーが高い場合は、圧縮または暗号化されている可能性があります
- 最初に文字列を探します:目的がすぐに分かることがよくあります
- ファイルヘッダーを確認します:先頭 16 バイトで形式を特定できることがよくあります
- 再帰的な抽出を使います:ファームウェアには入れ子になったアーカイブが含まれていることがよくあります
- オフセットを記録します:対象を絞った抽出に備えて、興味深い位置をメモします
コメント
Markdown 対応