| name | binwalk |
| description | Auth/lab ref: Firmware analysis and extraction tool for identifying and extracting embedded file systems, compressed archives, executable code, and crypto keys from binary blobs. |
| license | MIT |
| compatibility | Python 3; Linux/macOS/WSL. |
| metadata | {"author":"AeonDave","version":"1.1"} |
Binwalk
Firmware analysis and extraction — identify and extract embedded files from binary blobs.
Contents
Safe triage before extraction
Follow the firmware workflow before extraction. Binwalk-specific invariant: start with a signature/entropy scan; make -eM and --dd ".*" opt-in; use a fresh -C directory plus -d, -n, and -j; and enforce total output bytes with an external monitor/quota because Binwalk v2 has no total-output flag. -j limits each carved input region, but an external extractor may still decompress it into a larger tree.
On MCPwn, use firmware_analyze or binwalk_analyze with detach=True. firmware_analyze exposes the external aggregate tree budget; binwalk_analyze does so only when extract=true, because scan-only mode creates no extraction tree. unblob_analyze is also detached and session-owned. auto_malware_hunt defaults to scan-only, so request recursive extraction explicitly only after triage.
Installation
sudo apt install binwalk
pip install binwalk
git clone https://github.com/ReFirmLabs/binwalk && cd binwalk
sudo python setup.py install
sudo apt install mtd-utils gzip bzip2 tar arj lhasa p7zip p7zip-full \
cabextract cramfsswap squashfs-tools sleuthkit default-jdk lzop srecord
Quick Start
binwalk firmware.bin
binwalk -e -n 1000 -j 268435456 -C ./extracted firmware.bin
binwalk -eM -d 3 -n 5000 -j 268435456 -C ./extracted firmware.bin
Core Flags
| Flag | Purpose |
|---|
| (none) | Signature scan (default) |
-e | Extract found files |
-M | Recursive/matryoshka extraction |
-E | Entropy analysis |
-A | Disassemble CPU opcodes |
-W | Hexdiff between files |
-R STRING | Search for raw string |
-C DIR | Set output directory |
-q | Quiet mode |
-D TYPE:EXT:CMD | Custom extraction rule |
-d N | Limit recursive extraction depth |
-n N | Limit number of extracted files |
-j N | Limit each extracted file's size |
-l N | Limit input bytes scanned |
--dd ".*" | Carve every matching signature; high expansion risk |
-H N | Set the floating-point high entropy-edge threshold for entropy scans (-E) |
-m FILE | Custom magic/signature file |
Common Workflows
Full firmware analysis pipeline
binwalk firmware.bin
binwalk -E firmware.bin
binwalk -E --save firmware.bin
binwalk -eM -d 3 -n 5000 -j 268435456 firmware.bin -C ./extracted/
ls ./extracted/
Post-extraction analysis
find ./extracted/ -type f \( -name "*.conf" -o -name "*.cfg" -o -name "passwd" \
-o -name "shadow" -o -name "*.key" -o -name "*.pem" \) 2>/dev/null
grep -rn "password\|secret\|api_key\|token\|admin" ./extracted/ --include="*.conf" --include="*.sh" --include="*.lua"
find ./extracted/ -type f -executable | file -f - | grep "ELF"
find ./extracted/ -type f \( -name "*.html" -o -name "*.php" -o -name "*.cgi" \) 2>/dev/null
Compare firmware versions
binwalk -W firmware_v1.bin firmware_v2.bin
binwalk -W firmware_v1.bin firmware_v2.bin > diff_report.txt
Custom signature scanning
binwalk -R "\x7fELF" firmware.bin
binwalk -R "MZ" firmware.bin
binwalk -R "SSH-" firmware.bin
binwalk -m custom_signatures.magic firmware.bin
Manual extraction
dd if=firmware.bin of=extracted_blob.bin bs=1 skip=OFFSET count=SIZE
binwalk -D "gzip:gz:gunzip '{filename}'" firmware.bin
binwalk --dd ".*" --offset=0x10000 --length=0x50000 firmware.bin
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', entropy=True, quiet=True):
for result in module.results:
print(f" 0x{result.offset:08X}: entropy={result.description}")
binwalk.scan('firmware.bin', signature=True, extract=True, quiet=True,
directory='./output/')
Emulation after extraction
ls ./extracted/squashfs-root/
cp $(which qemu-arm-static) ./squashfs-root/usr/bin/
sudo chroot ./squashfs-root/ /usr/bin/qemu-arm-static /bin/sh
Resources