Skip to content

binwalk - Firmware Analysis Tool ​

binwalk is a fast, easy to use tool for analyzing, reverse engineering, and extracting firmware images. It's designed to identify embedded files and executable code within firmware images and other binary files.

🎯 Purpose ​

  • Firmware Analysis: Extract and analyze firmware images
  • File Carving: Identify and extract embedded files
  • Reverse Engineering: Analyze binary file structures
  • CTF Challenges: Solve steganography and binary analysis challenges

πŸš€ Basic Usage ​

Basic Scanning ​

bash
# Basic file analysis
binwalk firmware.bin

# Verbose output
binwalk -v firmware.bin

# Scan for specific signatures
binwalk -B firmware.bin

# Show entropy analysis
binwalk -E firmware.bin

File Extraction ​

bash
# Extract all identified files
binwalk -e firmware.bin

# Extract and recursively scan
binwalk -Me firmware.bin

# Extract to specific directory
binwalk -e --directory=/tmp/extracted firmware.bin

πŸ”§ Analysis Options ​

Signature Scanning ​

bash
# Scan for specific file types
binwalk --include="filesystem" firmware.bin

# Exclude certain signatures
binwalk --exclude="compressed" firmware.bin

# Custom signature file
binwalk --signature=custom.sig firmware.bin

# List available signatures
binwalk --list-signatures

Entropy Analysis ​

bash
# Generate entropy graph
binwalk -E firmware.bin

# Save entropy data
binwalk -E --save firmware.bin

# Entropy analysis with custom block size
binwalk -E -K 1024 firmware.bin

String Analysis ​

bash
# Extract strings
binwalk -S firmware.bin

# Minimum string length
binwalk -S --length=10 firmware.bin

# ASCII strings only
binwalk -S --ascii firmware.bin

🎯 Common Use Cases ​

Firmware Reverse Engineering ​

bash
# Complete firmware analysis
binwalk -Me firmware.bin

# Identify bootloader and filesystem
binwalk -B firmware.bin

# Extract configuration files
binwalk -e --include="config" firmware.bin

CTF Challenges ​

bash
# Find hidden files in images
binwalk -e image.jpg

# Analyze suspicious executables
binwalk -A suspicious.exe

# Look for embedded archives
binwalk --include="archive" challenge.bin

IoT Device Analysis ​

bash
# Router firmware analysis
binwalk -Me router_firmware.bin

# Extract root filesystem
binwalk -e --include="squashfs,cramfs,jffs2" iot_firmware.bin

# Identify encryption signatures
binwalk --include="encrypted" device_firmware.bin

πŸ“ Installation ​

Debian/Ubuntu ​

bash
sudo apt update
sudo apt install binwalk

# Install additional dependencies
sudo apt install python3-pip
pip3 install pycryptodome

From Source ​

bash
git clone https://github.com/ReFirmLabs/binwalk.git
cd binwalk
sudo python setup.py install

# Install optional dependencies
sudo apt install mtd-utils gzip bzip2 tar arj lzma xz-utils cabextract

Additional Tools ​

bash
# For better extraction support
sudo apt install unrar p7zip-full

# For filesystem mounting
sudo apt install fuse-utils

# For encryption analysis
pip3 install python-lzo

βš™οΈ Advanced Features ​

Custom Signatures ​

Create custom signature file:

python
# custom.sig
0x00 string CUSTOM Custom file header
0x10 string MAGIC Magic signature

Scripting Integration ​

python
#!/usr/bin/env python3
import binwalk

# Scan file programmatically
for module in binwalk.scan('firmware.bin', signature=True, quiet=True):
    print(f"File: {module.name}")
    for result in module.results:
        print(f"  {result.offset}: {result.description}")

Entropy Visualization ​

bash
# Generate entropy plot
binwalk -E --save --png firmware.bin

# Analyze high entropy regions
binwalk -E --threshold=0.8 firmware.bin

πŸ’‘ Pro Tips ​

Effective Firmware Analysis ​

bash
# Multi-step analysis workflow
binwalk firmware.bin                    # Initial scan
binwalk -E firmware.bin                 # Entropy analysis
binwalk -Me firmware.bin               # Extract everything
file _firmware.bin.extracted/*          # Identify extracted files

Working with Compressed Files ​

bash
# Handle compressed firmware
binwalk -Me compressed_firmware.gz

# Extract nested archives
binwalk -r extracted_files/

File System Analysis ​

bash
# Mount extracted filesystems
sudo mount -o loop extracted_filesystem.img /mnt/analysis

# Analyze extracted binaries
find /mnt/analysis -name "*.bin" -exec binwalk {} \;

πŸ”§ Output Interpretation ​

Understanding Results ​

bash
# Sample output interpretation
DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             U-Boot uImage, Linux kernel
64            0x40            gzip compressed data
131072        0x20000         Squashfs filesystem

Common Signatures ​

  • U-Boot: Bootloader images
  • LZMA/gzip: Compressed data
  • SquashFS/JFFS2: Linux filesystems
  • Certificate: SSL/TLS certificates
  • AES/DES: Encrypted data

🚨 Important Notes ​

  • Legal Compliance: Only analyze firmware you own or have permission to examine
  • Backup Original: Always keep backups of original firmware files
  • Extraction Dependencies: Some file types require additional tools for extraction
  • False Positives: Verify extracted files are legitimate
  • Nested Analysis: Extracted files may contain additional embedded content

Combine binwalk with:

  • hexdump: Raw binary analysis
  • strings: Text extraction
  • file: File type identification
  • dd: Binary extraction and manipulation
  • ghidra: Advanced reverse engineering

Part of the HackerHub.me tool documentation series