Skip to content
Tutorials Center
My learning

Topics

Lesson 34 of 36 ยท Projects and Practice

Project: Evidence Manifest and Hashing

Build an evidence manifest tool in Python: hash files with SHA-256 and MD5, record metadata, verify integrity later, detect changed, missing and added files, and export a report.

Before any analysis, an examiner needs to prove that the evidence is the same afterwards as it was at the start. The standard tool is a manifest: a list of every item with its size, time and cryptographic hash, signed off at collection and re-checked whenever the evidence moves. In this project you build one in Python. It is small, but it is the same idea as the hash lists used in real cases, and the same one behind the evidence handling described in legal frameworks.

The files here are simulated in memory so the project runs in your browser; the code that reads real files is shown as read-only.

Why hashes work

A cryptographic hash function turns any amount of data into a fixed-size fingerprint. Changing a single bit changes the fingerprint completely, and nobody can practically craft a different file with the same fingerprint (for strong algorithms such as SHA-256). Practice in the field:

  • Use SHA-256 (or stronger). MD5 and SHA-1 are broken against deliberate collisions, but many tools and hash lists still show them, so labs often record several.
  • Hash at the earliest moment, and again after every copy.
  • Store the manifest separately from the evidence, ideally signed or on write-once media.

Step 1: Hash and describe items

Python Step 1: build a manifest

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For real files you read in chunks so large images do not need to fit in memory. This is read-only code to adapt on evidence you are authorized to handle:

Python
import hashlib

def hash_file(path, chunk=1024 * 1024):
    h = hashlib.sha256()
    with open(path, "rb") as f:          # read-only
        while block := f.read(chunk):
            h.update(block)
    return h.hexdigest()

Opening with "rb" only reads; still, hash a copy or use a write blocker for original media.

Step 2: Verify later

Verification recomputes hashes and compares them with the manifest. Three kinds of discrepancy matter: changed (same name, different hash), missing (in the manifest, not found) and added (found, not in the manifest).

Python Step 2: verify against the manifest

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The result says what is wrong but not why. A failure is not necessarily tampering (a bad disk or a copy error can cause it), yet it must be investigated and written into the notes.

Step 3: Hash everything, including the manifest

If someone can edit the manifest, the check proves nothing. Protect it by hashing the manifest file itself and recording that hash in a separate place (a signed email, a printed case sheet, a timestamping service). You can also chain entries so editing one breaks all that follow.

Python Step 3: seal the manifest

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Sorting keys and fixing separators gives a canonical form, so equal data always produces the same seal.

Step 4: A readable report

Turn results into a short plain-text block for the case file.

Python Step 4: format a verification report

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Good practice checklist

  1. Hash before anything else, and write the hash on the custody form.
  2. Use SHA-256; add a second algorithm if tools demand it.
  3. Keep the manifest apart from the evidence; seal it.
  4. Re-verify after every transfer and before analysis and reporting.
  5. Record who ran the verification, when, with which tool and version.
  6. Never work on originals; hash the working copy too (timelines).

Extensions

  • Walk a directory with os.walk and include modification times.
  • Write the manifest in a CSV format compatible with common hash-list tools.
  • Add a signature step using a public-key library on a real system.
  • Compare against a known-good hash list to exclude standard files.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which hash algorithm should be preferred for new evidence manifests?

    SHA-256 is collision-resistant; MD5 and SHA-1 are broken against deliberate collisions and CRC32 is not cryptographic.
  2. 2. A file is in the manifest but not in the evidence store. How is it classified?

    Present in the manifest but not found now means missing.
  3. 3. Why seal (hash) the manifest itself?

    Without protecting the manifest, someone could change both evidence and manifest to match.
  4. 4. A verification fails. What is the right response?

    Failures may have innocent causes, but they must be examined and recorded.

Summary

  • A manifest lists every evidence item with size and cryptographic hashes.
  • Verify by recomputing: classify items as OK, changed, missing or added.
  • Protect the manifest by sealing it and storing the seal elsewhere.
  • Hash early, after each copy and before reporting; record who, when and which tool.

Next: Project: Incident Timeline Builder