| name | binwalk |
| description | Build, extend, and operate Binwalk — a fast, easy-to-use tool for analyzing, reverse engineering, and extracting firmware images. Use when the user asks about firmware analysis, embedded file extraction, entropy analysis, IoT security research, or hardware hacking. Covers installation, signature scanning, file extraction, recursive extraction, entropy analysis, custom magic signatures, supported formats (squashfs, cramfs, jffs2, LZMA, gzip, and more), firmware modification workflow, filesystem extraction, and firmware version diffing.
|
| metadata | {"author":"redhoundinfosec","version":"1.0","repo":"https://github.com/ReFirmLabs/binwalk"} |
binwalk Agent Skill
When to Use This Skill
Use this skill when:
- The user needs to analyze, extract, or reverse engineer firmware images
- Working on IoT security assessments or hardware hacking engagements
- The user asks about identifying embedded file systems, compressed data, or executables in binary blobs
- Performing entropy analysis to identify encrypted or compressed regions
- Comparing firmware versions to identify changes or patches
- Building custom magic signatures for proprietary formats
What Binwalk Does
Binwalk is a firmware analysis tool designed to search binary images for embedded files and
executable code. It uses a library of magic byte signatures to identify file types within a
binary, then optionally extracts them to disk. Binwalk is the de facto standard for IoT
firmware reverse engineering, capable of handling everything from raw flash dumps to
vendor-supplied update packages. It supports entropy analysis to highlight encrypted regions,
recursive extraction to unpack nested archives, and side-by-side firmware diffing.
Installation
sudo apt install binwalk -y
pip3 install binwalk
git clone https://github.com/ReFirmLabs/binwalk.git
cd binwalk
sudo python3 setup.py install
sudo apt install squashfs-tools cramfsck jefferson sasquatch \
mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full cabextract \
sleuthkit default-jdk lzop cpio openjdk-11-jdk -y
git clone https://github.com/devttys0/sasquatch
cd sasquatch && ./build.sh
Core Concepts
Signature Scanning
Binwalk compares bytes at every offset against a database of magic signatures (stored in
/usr/lib/python3/dist-packages/binwalk/magic/). A match reports the offset, hex offset,
and description of the identified file type.
Extraction
When -e is used, binwalk calls external tools (7z, tar, dd, jefferson, unsquashfs, etc.)
mapped to each signature type to extract content. Extracted files land in _{firmware}_extracted/.
Entropy Analysis
The -E flag computes Shannon entropy across the file in sliding windows. High entropy (~1.0)
indicates encryption or compression; low entropy (~0.0) indicates sparse/null data;
mid-range entropy is typical of compressed but not encrypted data.
CLI Reference
Basic Scanning
binwalk firmware.bin
binwalk -v firmware.bin
binwalk firmware_v1.bin firmware_v2.bin
binwalk -q firmware.bin; echo "Exit: $?"
Extraction
binwalk -e firmware.bin
binwalk -e -C /tmp/extracted/ firmware.bin
binwalk -Me firmware.bin
binwalk -e --dd='.*' firmware.bin
binwalk -e --dd='squashfs' firmware.bin
Entropy Analysis
binwalk -E firmware.bin
binwalk -E -J entropy.png firmware.bin
binwalk -eE firmware.bin
binwalk --entropy firmware.bin
Firmware Diffing
binwalk -W firmware_v1.bin firmware_v2.bin
binwalk -W --block=512 firmware_v1.bin firmware_v2.bin
binwalk -W firmware_v1.bin firmware_v2.bin > diff.txt
Signature and Magic Options
binwalk --list-magic
binwalk -m /path/to/custom.magic firmware.bin
binwalk --magic=/path/to/extra.magic firmware.bin
binwalk --magic=/path/to/custom.magic --no-default-magic firmware.bin
Code/String Scanning
binwalk -A firmware.bin
binwalk -R "password" firmware.bin
binwalk -R "admin\x00password" firmware.bin
binwalk -r "root:.*:[0-9]+:" firmware.bin
Miscellaneous Options
binwalk -l 1048576 firmware.bin
binwalk -O 0x100000 firmware.bin
binwalk --exclude='jpeg' firmware.bin
binwalk --csv firmware.bin > scan.csv
binwalk firmware.bin --log=scan.json
Supported Formats
| Category | Formats |
|---|
| Filesystems | SquashFS, CramFS, JFFS2, YAFFS2, ext2/3/4, FAT, romfs, ubifs |
| Compression | gzip, bzip2, lzma, xz, lzop, zlib, lz4 |
| Archives | tar, zip, 7z, arj, lha, cpio, rar |
| Bootloaders | U-Boot, LILO, GRUB, CFE |
| Kernels | Linux kernel (zImage, uImage, bzImage) |
| Executables | ELF (ARM, MIPS, x86, PPC), PE, Java class |
| Certs/Keys | X.509, PEM, RSA private key |
| Misc | OpenWRT TRX, Broadcom CFE, D-Link DLOB |
Custom Magic Signatures
Binwalk uses a modified libmagic format. Custom signature file example:
# custom.magic
0 string MYRTR Custom Router Firmware Header
>4 lelong x version: %d
>8 lelong x payload length: %d bytes
0 string \x55\xAA\x00\x01 Proprietary bootloader image
>2 leshort x build: %d
binwalk -m custom.magic firmware.bin
binwalk --magic=custom.magic firmware.bin
Common Workflows
Full IoT Firmware Analysis
binwalk firmware.bin
binwalk -E firmware.bin
binwalk -Me firmware.bin
cd _firmware.bin.extracted/
ls -la
cd squashfs-root/
grep -r "password" . --include="*.conf" --include="*.cfg" -l
find . -name "*.pem" -o -name "*.key" -o -name "id_rsa"
cat etc/passwd etc/shadow 2>/dev/null
grep -r "admin\|root\|password\|secret" ./usr/bin/ --binary-files=text
binwalk -A firmware.bin | head -5
file _firmware.bin.extracted/squashfs-root/bin/busybox
Firmware Modification (Repack)
binwalk -Me firmware.bin
cd _firmware.bin.extracted/squashfs-root/
echo 'toor::0:0:root:/root:/bin/sh' >> etc/passwd
mksquashfs squashfs-root/ new_squashfs.bin -comp lzma -b 131072 -no-xattrs
dd if=firmware.bin of=new_firmware.bin bs=1 count=<squashfs_offset>
cat new_squashfs.bin >> new_firmware.bin
ORIG_SIZE=$(wc -c < firmware.bin)
SQUASH_OFFSET=<squashfs_offset>
SQUASH_SIZE=<original_squashfs_size>
TAIL_OFFSET=$((SQUASH_OFFSET + SQUASH_SIZE))
dd if=firmware.bin bs=1 skip=$TAIL_OFFSET >> new_firmware.bin
JFFS2 Filesystem Extraction
pip3 install jefferson
binwalk -e firmware.bin
jefferson jffs2_image.bin -d output_dir/
Comparing Two Firmware Versions
binwalk -W old_firmware.bin new_firmware.bin | head -100
binwalk -Me old_firmware.bin -C /tmp/old/
binwalk -Me new_firmware.bin -C /tmp/new/
diff -rq /tmp/old/ /tmp/new/ --exclude="*.pyc"
Advanced Techniques
Scripting with Binwalk's Python API
import binwalk
for module in binwalk.scan('firmware.bin', signature=True, quiet=True):
for result in module.results:
print(f"0x{result.offset:08X} {result.description}")
for module in binwalk.scan('firmware.bin', signature=True, extract=True,
matryoshka=True, quiet=True):
pass
Entropy-Guided Investigation
import binwalk
for module in binwalk.scan('firmware.bin', entropy=True, quiet=True):
for result in module.results:
if result.entropy > 0.9:
print(f"High entropy at 0x{result.offset:08X}: {result.entropy:.4f}")
Handling Non-Standard SquashFS (Router Firmware)
Many consumer routers use modified SquashFS with non-standard block sizes or endianness.
Use sasquatch (auto-invoked by binwalk if installed) or firmware-mod-kit:
git clone https://github.com/rampageX/firmware-mod-kit
cd firmware-mod-kit
./extract-firmware.sh firmware.bin
Integration with Other Tools
| Tool | Use Case |
|---|
| Ghidra / IDA Pro | Decompile extracted ELF/ARM binaries from firmware |
| firmwalker | Automated security scan of extracted filesystem |
| Emba | Comprehensive embedded Linux security analysis |
| QEMU | Emulate extracted firmware for dynamic analysis |
| strings | Quick string extraction from binary blobs |
| file | Identify file types for manual extraction |
git clone https://github.com/craigz28/firmwalker
sudo ./firmwalker.sh /tmp/_firmware.bin.extracted/squashfs-root/
Troubleshooting
Squashfs extraction fails:
git clone https://github.com/devttys0/sasquatch && cd sasquatch && ./build.sh
which sasquatch
-Me produces no filesystem:
- Check entropy — if entire file is high entropy, it may be encrypted
- Look for the decryption key in a bootloader region or a companion file
- Try
binwalk --dd='.*' firmware.bin to carve raw data
Binwalk misses embedded content:
- The file may use a proprietary header — add a custom magic signature
- Try
binwalk -v to see all candidate matches including low-confidence hits
Python API import errors:
pip3 install --upgrade binwalk
python3 -c "import binwalk; print(binwalk.__version__)"
Repack checksum mismatch on router:
- Dump the router's UART boot log to identify CRC algorithm
- Use
binwalk -Y to detect cryptographic hash functions in the bootloader binary
Built by Red Hound InfoSec — On-demand offensive security expertise for SMBs.
20+ years of Fortune 500 experience. Penetration testing, attack surface analysis, and security consulting.
redhound.us | GitHub | Book a consultation