mcpField
P
performing-firmware-extraction-with-binwalk

performing-firmware-extraction-with-binwalk

github.com/mukul975安全35.2k68 次安装8 周前更新
代码仓库

关于 performing-firmware-extraction-with-binwalk

这是一份面向嵌入式设备安全研究人员的固件提取与检查流程,使用 binwalk 识别文件系统和数据区域,并指导提取内容、分析熵及查找敏感信息。

主要功能

  1. 01扫描固件中的文件签名
  2. 02分析熵以定位压缩或加密区域
  3. 03递归提取嵌入文件
  4. 04检查提取出的文件系统
  5. 05搜索凭据、密钥和配置
  6. 06汇总固件分析结果

适用场景

  1. 01分析路由器或 IoT 固件
  2. 02检查固件中的嵌入式文件系统
  3. 03定位可能加密的数据区域
  4. 04审计固件内的硬编码凭据

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill performing-firmware-extraction-with-binwalk

安装后在 Claude Code 中输入/performing-firmware-extraction-with-binwalk确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
references/
api-reference.md
scripts/
agent.py

详细介绍

使用 Binwalk 进行固件提取

何时使用

  • 分析从厂商网站下载或从闪存芯片中提取的 IoT 设备固件
  • 为漏洞研究而对路由器、摄像头或嵌入式设备固件进行逆向工程
  • 识别固件镜像中嵌入的文件系统(SquashFS、CramFS、JFFS2、UBIFS)
  • 使用熵分析检测加密或压缩区域
  • 从固件中提取硬编码凭据、API 密钥、证书或配置文件
  • 在授权渗透测试中对嵌入式设备进行安全评估

请勿使用于分析非固件镜像的标准桌面应用二进制文件或恶意软件样本;请改用专用的恶意软件分析工具。

前置条件

  • 已安装 binwalk v3.x(pip install binwalk3 或通过系统包管理器安装)
  • Python 3.8+ 及标准库(struct、math、hashlib、subprocess)
  • SquashFS 工具(unsquashfs),用于挂载提取出的 SquashFS 文件系统
  • Jefferson,用于提取 JFFS2 文件系统(pip install jefferson)
  • Sasquatch,用于处理 TP-Link 和 D-Link 等厂商使用的非标准 SquashFS 变体
  • strings 工具(GNU binutils),用于提取字符串
  • 可选:firmware-mod-kit,用于重新打包修改过的固件镜像

工作流

第 1 步:固件初步侦察

执行签名扫描以识别嵌入的文件类型及其偏移量:

# Basic signature scan - identify all recognized file types
binwalk firmware.bin

# Scan with verbose output showing confidence levels
binwalk -v firmware.bin

# Scan for specific file types only
binwalk -y "squashfs" firmware.bin
binwalk -y "gzip\|lzma\|xz" firmware.bin

# Opcode scan to identify CPU architecture
binwalk -A firmware.bin

# Scan for raw strings to find version info, URLs, credentials
binwalk -R "password" firmware.bin
binwalk -R "http://" firmware.bin
第 2 步:熵分析

分析熵以识别加密、压缩和明文区域:

# Generate entropy plot
binwalk -E firmware.bin

# Entropy with specific block size for higher resolution
binwalk -E -K 256 firmware.bin

# Combined entropy and signature scan
binwalk -BE firmware.bin

解读熵值:

  • 0.0 - 1.0:空白或填充区域(空字节、0xFF 填充)
  • 1.0 - 5.0:明文数据、代码、ASCII 字符串、配置
  • 5.0 - 7.0:压缩数据(gzip、LZMA、zlib)
  • 7.0 - 7.99:强压缩或加密数据
  • ~8.0:最大熵,很可能是加密或随机数据
第 3 步:提取嵌入文件

从固件镜像中提取所有已识别的组件:

# Automatic extraction of known file types
binwalk -e firmware.bin

# Recursive extraction (matryoshka mode) for nested archives
binwalk -Me firmware.bin

# Recursive extraction with depth limit
binwalk -Me -d 5 firmware.bin

# Extract specific file type with custom handler
binwalk -D "squashfs filesystem:squashfs:unsquashfs %e" firmware.bin

# Manual extraction of data at a known offset
dd if=firmware.bin of=extracted.squashfs bs=1 skip=327680 count=4194304
第 4 步:挂载并检查提取出的文件系统

挂载提取出的文件系统以进行深入检查:

# Mount SquashFS filesystem
mkdir /tmp/squashfs_root
unsquashfs -d /tmp/squashfs_root extracted.squashfs

# Mount CramFS filesystem
mkdir /tmp/cramfs_root
mount -t cramfs -o loop extracted.cramfs /tmp/cramfs_root

# Extract JFFS2 filesystem
jefferson extracted.jffs2 -d /tmp/jffs2_root

# Inspect the extracted filesystem
ls -la /tmp/squashfs_root/
find /tmp/squashfs_root -name "*.conf" -o -name "*.cfg" -o -name "*.key"
find /tmp/squashfs_root -name "passwd" -o -name "shadow"
第 5 步:字符串分析与凭据发现

在提取出的文件系统和原始固件中搜索敏感数据:

# Extract all printable strings
strings -a firmware.bin > all_strings.txt
strings -n 12 firmware.bin | sort -u > long_strings.txt

# Search for credentials and secrets
grep -rni "password\|passwd\|secret\|api_key\|token" /tmp/squashfs_root/etc/
grep -rni "BEGIN.*PRIVATE KEY" /tmp/squashfs_root/

# Find hardcoded URLs and endpoints
grep -rnoE "https?://[a-zA-Z0-9./?=_-]+" /tmp/squashfs_root/

# Search for certificate files
find /tmp/squashfs_root -name "*.pem" -o -name "*.crt" -o -name "*.key" -o -name "*.p12"

# Identify busybox and service versions
strings /tmp/squashfs_root/bin/busybox | grep "BusyBox v"
cat /tmp/squashfs_root/etc/banner 2>/dev/null
第 6 步:生成固件分析报告

汇总全面的提取与分析结果:

Report should include:
- Firmware metadata (vendor, model, version, build date)
- Identified components with offsets and sizes (bootloader, kernel, filesystem, config)
- Entropy analysis summary with regions of interest
- Extracted filesystem structure and key contents
- Discovered credentials, keys, certificates
- Identified services, daemons, and their versions
- Known CVEs applicable to identified component versions
- Recommendations for hardening or vulnerability remediation

关键概念

术语定义
固件嵌入硬件设备中的软件,提供底层控制;通常包含引导加载程序、内核、根文件系统和配置数据
熵分析对二进制数据随机性的统计测量;高熵表示加密或压缩,低熵表示明文或结构化数据
SquashFS嵌入式 Linux 设备中常用的只读压缩文件系统;支持 LZMA、gzip、LZO 和 zstd 压缩
魔数字节位于固定偏移处的已知字节序列,用于识别文件类型;binwalk 使用魔数签名数据库来检测嵌入文件
套娃式提取一种递归提取模式,binwalk 会重新扫描已提取的文件以查找更多嵌入内容,从而处理深层嵌套的归档文件
CramFS专为闪存存储有限的嵌入式系统设计的压缩 ROM 文件系统;仅支持 zlib 压缩
JFFS2日志闪存文件系统第 2 版,专为嵌入式设备中的 NOR 和 NAND 闪存设计

工具与系统

  • binwalk:主要的固件分析工具,用于特征扫描、熵分析和嵌入式文件的自动提取
  • unsquashfs:SquashFS 提取工具,用于挂载路由器和 IoT 固件中常见的只读压缩文件系统
  • jefferson:用于提取嵌入式设备中常见的 JFFS2 闪存文件系统镜像的 Python 工具
  • sasquatch:经过修补的 SquashFS 工具,支持非标准的厂商修改版 SquashFS 变体
  • firmware-mod-kit:用于提取、修改和重新打包固件镜像以进行安全测试的工具包

常见场景

场景:提取并审计路由器固件中的硬编码凭据

背景:一名安全研究员正在对一台消费级路由器进行授权评估。固件更新文件是从厂商的支持页面下载的。目标是识别硬编码凭据、不安全的默认配置以及已知存在漏洞的组件。

方法:

  1. 运行 binwalk -e firmware.bin 执行初步提取
  2. 使用 binwalk -E firmware.bin 检查熵并识别加密区域
  3. 在提取输出中定位 SquashFS 根文件系统
  4. 使用 unsquashfs 挂载并检查 /etc/passwd、/etc/shadow 和 Web 服务器配置
  5. 使用 grep -rni "password" /tmp/root/etc/ 搜索硬编码凭据
  6. 识别服务版本并与 CVE 数据库交叉比对
  7. 检查启动脚本中的调试接口(telnet、UART、JTAG 相关引用)
  8. 检查 Web 应用程序代码中的认证绕过或命令注入

陷阱:

  • 一些厂商使用带有自定义压缩的非标准 SquashFS;应使用 sasquatch 而非 unsquashfs
  • 加密固件需要解密密钥,这些密钥通常位于引导加载程序或此前的未加密版本中
  • 在 binwalk 能够识别嵌入式文件系统之前,可能需要剥离固件头
  • 经过混淆的字符串可能会躲过简单的 grep 搜索;使用熵分析来定位数据块

输出格式

FIRMWARE EXTRACTION REPORT
====================================
Firmware:         TP-Link TL-WR841N v14
File:             wr841nv14_en_3_16_9_up.bin
Size:             3,932,160 bytes (3.75 MB)
SHA-256:          a1b2c3d4e5f6...

SIGNATURE SCAN RESULTS
Offset       Type                          Size
------       ----                          ----
0x00000000   U-Boot bootloader header      64 bytes
0x00020000   LZMA compressed data          1,048,576 bytes
0x00120000   SquashFS filesystem v4.0      2,752,512 bytes
0x003B0000   Configuration partition       131,072 bytes

ENTROPY ANALYSIS
Region 0x000000-0x020000: 4.21 (bootloader - plaintext code)
Region 0x020000-0x120000: 7.89 (kernel - LZMA compressed)
Region 0x120000-0x3B0000: 7.45 (filesystem - SquashFS compressed)
Region 0x3B0000-0x3C0000: 1.12 (config - mostly empty)

EXTRACTED FILESYSTEM
Root filesystem: SquashFS v4.0, LZMA compression
Total files: 847
Total dirs: 112
BusyBox version: 1.19.4

SECURITY FINDINGS
[CRITICAL] Hardcoded root password in /etc/shadow (hash: $1$...)
[HIGH]     Telnet daemon enabled by default in /etc/init.d/rcS
[HIGH]     Private RSA key at /etc/ssl/private/server.key
[MEDIUM]   BusyBox 1.19.4 (CVE-2021-42373, CVE-2021-42374)
[MEDIUM]   Dropbear SSH 2014.63 (CVE-2016-3116)
[LOW]      UPnP service enabled by default

评论

支持 Markdown