Matryoshka Extraction
Add -M and extraction stops being one level
deep. Everything binwalk extracts is scanned
again, anything found inside is extracted and
scanned in turn, until nothing new appears or
the depth limit — 8 levels by default,
adjustable with -d — stops the descent.
Real firmware needs this: a filesystem inside
an update archive, a compressed kernel inside
the filesystem, configuration archives inside
that.
The specimen's nested member was built to
prove the chain: image → gzip → tar → text
file. Here is the -Me run, trimmed to its
skeleton — note that it is not one scan but
four, one per generation:
$ binwalk -Me --run-as=root specimen.bin
Target File: .../specimen.bin
Signatures: 411
65536 0x10000 Squashfs filesystem, ...
69632 0x11000 gzip compressed data, ...
69776 0x11090 gzip compressed data, ...
Target File: .../_specimen.bin.extracted/11000
(no results — the release notes are plain text)
Target File: .../_specimen.bin.extracted/11090
0 0x0 POSIX tar archive, owner user name: "ker.txt"
Target File: .../_specimen.bin.extracted/_11090.extracted/deep/marker.txt
(no results — a text file, the bottom of the nest)
And the tree it leaves:
_specimen.bin.extracted/11090
_specimen.bin.extracted/_11090.extracted
_specimen.bin.extracted/_11090.extracted/0.tar
_specimen.bin.extracted/_11090.extracted/deep
_specimen.bin.extracted/_11090.extracted/deep/marker.txt
Three things to learn from this one run:
Recursion scans everything, including the
dead ends. The extracted release notes
(11000) were scanned and produced an empty
table; so was marker.txt itself. Those empty
tables are not noise — they are the audit
trail showing the descent actually reached the
bottom and found nothing more. When you read
someone else's -Me output, the empty scans
are how you know the nest was fully opened.
Each generation gets its own extracted
folder. The tar was found inside the file
carved from 0x11090, so its output lives in
_11090.extracted, and the tar's own carve is
0.tar — offset 0, because inside its parent
file the tar starts at the beginning. Read the
folder nesting as a family tree and you can
always answer "where did this file come from"
by walking up.
Descriptions stay mechanical at every
level. The tar row claims its owner user
name is "ker.txt". A tar header has a field
for the owner's name at a fixed position;
binwalk's signature reads those bytes and
prints them. In the specimen's tar, that
position happens to hold the tail of the first
member's name (deep/marker.txt), so the
description confidently prints a fragment of a
filename as a user name. Nothing is broken —
the signature did exactly what signatures do.
It is the smallest possible demonstration of
why descriptions are field readings, not
findings. (The worked specimen chapter puts
this beside the other misleading rows from
this same image.)
The recovered bottom of the nest, for the record:
$ cat .../_11090.extracted/deep/marker.txt
Nested marker, carried inside a tar inside a gzip.
Nested marker: WOMBAT-2210-CANDLE.
Keeping recursion on a leash
Matryoshka extraction on a hostile or merely enthusiastic image can fill a disk: archives that contain archives that contain copies of themselves are a classic prank and a real accident (firmware that bundles a full backup of itself exists). Binwalk ships the leashes; use them before you need them:
| Guard | Flag | What it caps |
|---|---|---|
| Depth | -d <n> |
how many generations down (default 8) |
| Count | -n <n> |
total number of extracted files |
| Size | -j <bytes> |
size of each extracted file |
And the standing rule from the extraction chapter applies at every depth: all of this unpacking runs third-party parsers on untrusted bytes, so recursive extraction belongs on a throwaway machine or VM, and the disk you give it should be one you can watch fill without pain.
Check: a matryoshka run is complete when
you can walk the extracted tree from the image
to the innermost file, naming the container at
every step — here, image → gzip (11090) →
tar (0.tar) → deep/marker.txt — and the
output shows the scan of that innermost file
coming back empty.