Skip to content

Lesson 5 of 14 · 15m

Binwalk, SquashFS, and the Filesystem Inside

Entropy first, signatures second, then per-filesystem extraction with unsquashfs, sasquatch, jefferson, and ubireader.

A firmware image is a concatenation of regions — bootloader, kernel, root filesystems, config — each with its own format. Your job is to find the boundaries and open each region with the tool that understands it. binwalk is the boundary-finder.

Read the entropy first

Before carving, run binwalk -E fw.bin. The entropy plot answers the question that saves you hours: is this encrypted? A plot that's uniformly high with no dips, where the signature scan returns nothing, is ciphertext or compressed container all the way down. Carving it produces nothing. Encrypted images mean the key lives in the updater — go get UART access or the updater binary instead of fighting math.

Normal firmware has visible structure: low-entropy bootloader regions, a signature-dense kernel header, the filesystem blocks.

Signature scan and carve

binwalk fw.bin          # list signatures and offsets
binwalk -e fw.bin       # extract at each signature
binwalk -Me fw.bin      # recursive extraction into nested containers

The output names formats and byte offsets: SquashFS filesystem, little-endian, version 4.0, compression:xz, U-Boot uImage headers, gzip streams, X.509 certificates, device tree blobs (the d00dfeed magic), CRC tables. Each one is a region boundary with a format attached.

Three more flags earn their keep: -A runs the architecture scan — opcode statistics that name MIPS, ARM, or x86 before you've carved anything; -B is the raw signature scan without extraction; -W hex-diffs a region or a whole image — the fast way to see what a silent vendor update actually changed.

Signature offsets can lie — false positives inside compressed data are routine — so verify each carve produced real files before trusting it. When binwalk finds an offset but the auto-extraction fails, dd if=fw.bin of=part.bin bs=1 skip=<offset> isolates the region manually, and --dd='.*' with a custom pattern does surgical carving when you know the magic. -Me (matryoshka mode) matters because vendors nest formats: tar inside gzip inside a signed wrapper.

The kernel regions deserve attention too: a legacy uImage wraps kernel + metadata in a U-Boot header with its own CRC; device tree blobs decode with dtc to the actual memory map and peripheral config the vendor compiled in.

Opening the filesystems

Each filesystem type has its own extractor:

  • SquashFS — the default read-only rootfs on routers and cameras. unsquashfs handles standard images; sasquatch handles the vendor-mangled variants — vendors modified SquashFS magic for years (the DD-WRT era) and sasquatch knows the nonstandard signatures stock unsquashfs rejects.
  • JFFS2 — flash-friendly journaling FS on NOR. jefferson extracts it.
  • UBIFS — NAND flash FS. Needs the UBI volume layer: ubireader_extract_images pulls volumes from a dump, ubireader_extract_files pulls files from a volume. Feeding ubireader a raw linear dump with OOB data still interleaved is the classic failure — strip spare areas first.
  • Cramfs — compressed read-only FS on older routers, extracted with cramfsck/fsck.cramfs; it shows up on firmware old enough to also carry JFFS2.
  • CPIO/gzip — kernel initramfs and older rootfs images.

Check cat /proc/mtd output from the live device against your carved layout — MTD names tell you which partition is which region.

What's inside

A successful extraction is a real root filesystem: /etc/passwd and /etc/shadow, init.d scripts, the web server's CGI tree, every binary, every config. file or readelf -h on a binary gives you the architecture — big-endian MIPS is the router classic, ARM dominates newer gear, and it decides which disassembler target you feed Ghidra later.

A firmware image can hold several filesystem partitions — check the MTD layout (cat /proc/mtd on the live device) against your carved offsets so partition names map to regions, and so a jffs2 config partition doesn't get mistaken for part of the rootfs.

The extraction step is mechanical; the findings live in what you extracted. That read is the next lesson.

Practice

The sequence is always: entropy → signatures → carve → per-filesystem extraction → inventory. When a step fails, it fails for a structural reason (encryption, OOB, vendor-mangled magic, false-positive offsets) — diagnose the structure, don't retry the command.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.