Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 36 ยท Principles and Evidence Handling

Hashing and Evidence Integrity

Learn how cryptographic hashes (MD5, SHA-1, SHA-256) prove that evidence has not changed, how hash sets filter known files, and what hashes can and cannot tell you.

How can you prove that the copy of a hard disk you examine is identical to the original, down to the last bit, years after you made it? You cannot compare billions of bytes by eye. Instead you compute a cryptographic hash: a fixed-length fingerprint of the data. If even one bit differs, the fingerprint changes completely. Hashes are the foundation of integrity in digital forensics.

What a hash function does

A hash function takes any amount of data and returns a short string of fixed length. Good cryptographic hashes have these properties:

  • Deterministic: the same input always gives the same output.
  • Avalanche effect: a tiny change to the input changes the output beyond recognition.
  • One-way: you cannot reconstruct the input from the hash.
  • Collision resistant: it should be practically impossible to find two different inputs with the same hash.
Algorithm Output size Status for forensics
MD5 128 bits (32 hex chars) Collisions can be made on purpose; still common for quick identification, not for security
SHA-1 160 bits (40 hex chars) Practical collisions demonstrated; legacy use
SHA-256 256 bits (64 hex chars) Recommended default

Many labs record two hashes (for instance MD5 and SHA-256) of every image: a mismatch in either shows a change, and legacy databases still use MD5.

Python Hash a message and watch the avalanche

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.

Changing a single letter produces a totally different digest. That is why one matching hash is strong proof of an identical copy.

Hashing big files in chunks

An image can be hundreds of gigabytes, so tools read it in blocks and feed each block to the hash. The result equals hashing the whole file at once. You can see this with a small made-up buffer.

Python Chunked hashing equals whole-file hashing

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.

Verifying an image

The standard acquisition procedure is:

  1. Hash the source (through a write blocker).
  2. Create the image.
  3. Hash the image.
  4. Compare. Match means a faithful copy; record both values in the case notes.

Later, whenever you open the image, you can re-hash and compare to the recorded value to show nothing changed in storage.

TEXT
$ sha256sum suspect-disk.dd
9f2b8c1d4e...e7a0   suspect-disk.dd       (sample output, shortened)

If you ever see a mismatch, stop. Find out whether the image was damaged (a bad sector, a failed copy) or altered, and document what you learn.

Hash sets: finding the known and the unknown

Because hashes identify files regardless of name, labs compare every file on a drive against hash sets:

  • Known-good sets (for example, the NIST National Software Reference Library, NSRL) list hashes of standard operating-system and application files. Matching files can be ignored, which removes tens of thousands of files from review.
  • Known-bad sets list hashes of files that are illegal or are known malware. A match is a quick alert (child-safety organisations distribute such sets to police labs, so examiners never need to view the files to find them).

Renaming a file does not change its hash; changing even one byte does. So hash sets are fast and exact, but easy to dodge by editing the file. For images there are also perceptual hashes that tolerate resizing, outside our scope here.

Python Filter a file list with a known-good hash set

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.

Notice that renamed-calc.txt is skipped even though its name is different, because its content matches. A partial match would need fuzzy methods, not plain hashes.

Limits of hashes

  • A hash proves a file is identical, not that it is genuine. A forged document has its own valid hash.
  • A hash must be recorded separately from the thing it protects, or an attacker can change both.
  • MD5 collisions mean an adversary could craft two different files with the same MD5, so use SHA-256 when someone may be trying to fool you.
  • Hashes of a whole disk say nothing about where a difference is. For that, compare block hashes.

Piecewise hashing and finding differences

If a whole-image hash mismatches, you can hash each fixed-size block to find which part differs. This is also how some tools show that an image is mostly unchanged after a live capture.

Python Find the block that changed

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.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What happens to a hash if one bit of the input changes?

    The avalanche effect means even a tiny change gives an unrecognisably different hash.
  2. 2. Which algorithm is the recommended default today for evidence hashing?

    SHA-256 has no known practical collisions; MD5 and SHA-1 are weak against deliberate attacks.
  3. 3. A suspect renames a known-good system file. What happens when you hash-match it?

    Hashes are computed from content, not from names.
  4. 4. What does a matching hash NOT prove?

    A hash shows sameness of bytes, not that the content is authentic or true.

Summary

  • A cryptographic hash is a fixed-length fingerprint; any change in the data changes it entirely.
  • Hash the source and the image, compare, and record both values; use SHA-256 (optionally with MD5 for legacy databases).
  • Large files are hashed in chunks with identical results.
  • Hash sets filter known-good files and flag known-bad ones, independent of file names.
  • A hash proves sameness, not authenticity, and must be stored separately from what it protects.

Next: Forensic imaging and write blockers