Course / 10 Crypto and files / Lesson 10 of 19

binwalk and carving

Estimated time: 15 min reading · 15 min activity

A larger byte sequence can contain another file or something that resembles one. Binwalk looks for signatures associated with embedded data and can optionally extract ranges. An offset is a zero-based byte position; carving means copying a selected range into a separate artifact for inspection.

The supplied combined.bin was authored from NOTE followed by a line feed and a small PNG. Its known construction places the PNG start after five bytes. The card describes that placement. It is not a newly run Binwalk scan, and copying a range would not itself establish that a reader accepts a complete image.

Before you begin

Estimated time
15 min reading, 15 min activity. Setup and optional practice may take longer.
Where you work
Read the supplied byte tables and authored records in any browser, with paper or a text editor. Preserve original files; inspect copies in any later lab. No scanner, image decoder, capture, memory acquisition or installation is required. Practical tool work remains separate from this reading activity.
Without a lab
All evidence needed for the activity appears on this page. Copy it into notes if downloads are unavailable. Read the labeled model and predict each result; a paper trace practises the reasoning while tool operation waits for a lab. Reading needs no JavaScript. Answer checking needs JavaScript and a secure context; saving progress also needs usable browser storage.

After this lesson you can:

  • Name offset 5 as the start of the PNG signature in combined.bin.
  • Separate that author placement from a binwalk transcript.
  • State that a signature match still needs a bounded slice and a parser.

01Example

Fresh placement model for counting from zero; it does not alter the supplied binary.

Hypothetical prefix: 41 42 0a — three bytes
Next byte starts at offset 3
A matched signature there proposes a start
A complete file range and reader check are still needed.

02A hit is a place to look

A scanner match points to a place worth inspecting. It can be a fragment or an accidental pattern and may not show where a valid object ends. A complete-format reader checks more structure. Extraction can also invoke helper programs, so finding a signature and enabling extraction are separate decisions.

The historical course record reports Binwalk v2.3.3 classifying a PNG at offset 5 and zlib-compressed data at 46. zlib is a compression format that can occur inside PNG data; another signature does not automatically mean another independent complete file. The recorded scan remains separate from scan.txt’s author-placement explanation.

Use an offset to locate a possible embedded format and keep a signature hit separate from a complete parse.Model. A teaching model drawn by hand. It shows the idea, not real tool output.

Read the full explanation below.

Supplied bytes only · no file is parsed, decoded or executed

Source hex: 41 42 0a

Supplied prefix: offset 0, length 3. Exactly three bytes are supplied; the next byte starts at offset 3.

Filename claim: not traced yet

Byte evidence: Exactly three bytes are supplied; the next byte starts at offset 3.

Reader acceptance: A signature at offset 3 proposes a start. No byte at offset 3, full range or reader acceptance is supplied.

Offsets count from zero. Exactly 3 bytes are supplied; next offset 3 is outside this excerpt. Absent bytes and ranges cannot be inferred from a filename or signature.

The three-byte prefix occupies offsets 0, 1 and 2.

Follow the explanation

  1. The three-byte prefix occupies offsets 0, 1 and 2.
  2. The next offset is 3; a hypothetical hit there does not establish a complete embedded file.

Complete supplied bytes and evidence limits

Zero-based offsetHexASCII display
041A
142B
20A.
Supplied prefix · offset 0, length 3
Exactly three bytes are supplied; the next byte starts at offset 3.

Filename claim: Hypothetical prefix only. A signature at offset 3 proposes a start. No byte at offset 3, full range or reader acceptance is supplied.

Display row width: 3. Non-printable ASCII is represented by a dot, not an invented byte. Next offset 3 lies outside the 3-byte excerpt.

A hit tells where to inspect; it does not establish a complete extractable file.

03Read the author offset

Trace the five supplied prefix bytes without running a scanner or carving source.

Label: author offset card. Not a binwalk transcript.
Historical 2026-10-12 QA separately reports PNG at offset 5 and zlib data at offset 46. The placement card below remains authored evidence, not scanner output.

File: combined.bin
Prefix: the five bytes 4e 4f 54 45 0a, which are the letters NOTE and a line feed.
PNG signature starts at offset 5: 89 50 4E 47 0D 0A 1A 0A
The bytes from offset 5 are the same small PNG as benign-note.txt, placed there for this lesson.
A signature at a known offset is a candidate range. It is not a parser's verdict.
The author card and that signature scan name the same PNG offset. This card does not decode the image.

Download the author offset card

"""Print the first eight bytes at offset 5. Authoring did not run this file.

Default action: print hex. It does not write a carved file.
A later run, if separately authorized, uses a copy of combined.bin in a new directory.
"""
from pathlib import Path


def main():
    data = Path("combined.bin").read_bytes()
    piece = data[5:13]
    print(piece.hex())


if __name__ == "__main__":
    main()

Download the slice script

  1. Number 4e 4f 54 45 0a as positions 0,1,2,3,4. The final 0a is a line feed.
  2. Locate the next position, 5, and compare its eight bytes with the PNG reference.
  3. Read data[5:13] in carve.py: Python slicing includes position 5 and stops before 13, giving eight bytes. The script prints that range as hex and does not write a carved file.
  4. Stop with the candidate-start note. A later appropriate reader would need the complete object, not only these eight bytes.

04Optional challenge

For about ten optional minutes, list the byte positions covered by the slice 5:13 and copy the eight displayed bytes. Your note should say that a header-sized slice can support a signature observation but cannot establish the rest of the image.

05Fresh cases for the checks

Use these fictional cases for the checks below. They have different inputs from the worked examples. Read them here or make notes; no installation or external service is needed.

Placement card A: independent authored bytesOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

File: packet.bin. Byte offsets start at zero.
Prefix bytes: 50 41 43 4b 45 54 0a. Each pair is one byte.
Immediately after the prefix comes the eight-byte signature 89 50 4e 47 0d 0a 1a 0a.
This card records author placement, not scanner output. Only a candidate start is established.

Evidence card B: separate provenance descriptionsOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

B1: an author describes placing a header after a prefix.
B2: a saved scanner result reports a matching signature at an offset.
B3: a suitable full reader accepts a bounded copied object’s complete structure.
These are different kinds of evidence. No new scan or reader run occurs here.

Slice card C: independent copy-inspection planOwned fixture. An original file made for this course. Follow the activity's instructions in your own lab.

A signature starts at zero-based offset 9. The inspection needs exactly its 8 bytes, no more.
Python slice notation start:stop includes start and excludes stop.
This is a paper plan for reading a copied buffer, not carving or execution.

06Explain the evidence and its limit

Optional self-check: write source, zero-based offset, proposed range and a missing full-reader check for an embedded signature.

Review it: count bytes rather than hex characters, distinguish author placement from a scanner transcript, and do not infer completeness or automatic extraction permission from a hit.

07Common mistakes

If you count the prefix from one and place the next byte at six, rewrite positions starting at zero.

If a matched pattern becomes a complete-file claim, identify what establishes the range’s end and a suitable reader’s acceptance.

If extraction seems automatic after identification, separate those actions; this activity asks for reading and stops before extraction.

References