Articles / Forensics

  • forensics
  • hashing
  • disk-imaging
  • chain-of-custody
  • digital-signatures
  • linux

Does a Matching Hash Prove a Disk Image Is the Original Evidence?

No. A matching hash proves that the bytes you hashed today agree with whatever produced the reference value. By itself, it says nothing about where that value came from, when it was made, or which disk was on the bench.

That can sound like pedantry, but it takes very little to get a clean "OK" from an altered image.

You can edit the image and still pass verification

The commands below make a stand-in for an image, hash it the usual way, then alter it. Use an empty scratch directory, because this overwrites evidence.img.

head -c 1M /dev/urandom > evidence.img
printf 'meet at 09:00' | dd of=evidence.img bs=1 seek=4096 conv=notrunc
sha256sum evidence.img > evidence.img.sha256

# Someone changes the time
printf 'meet at 17:00' | dd of=evidence.img bs=1 seek=4096 conv=notrunc
sha256sum -c evidence.img.sha256    # fails, as it should

# The same someone regenerates the hash file
sha256sum evidence.img > evidence.img.sha256
sha256sum -c evidence.img.sha256    # evidence.img: OK

SHA-256 did nothing wrong. It was asked whether two things match, and they do.

The weakness is that the reference value lived where the attacker could rewrite it. A hash stored beside its file catches accidents, such as a bad copy or a flaky cable. It does not stop anyone who can write to both.

The same question applies to forensic container formats that carry a hash inside the file. An internal checksum is handy for spotting corruption, but someone who can build a new container can compute a new checksum.

The claim you want is really four claims

"This is the original evidence" bundles several claims together:

  • Integrity: the image has not changed since the reference hash was taken.
  • Fidelity: the image matched the source when it was acquired.
  • Identity: the source was the device you say it was.
  • History: nothing relevant happened to that device before you imaged it.

A trustworthy reference hash gets you the first. It can support the second, depending on how it was computed. For the third and fourth you need records and people.

Matching the source depends on what you hashed

If you image a drive and then hash only the image, you have fingerprinted your output. A truncated read, the wrong partition or a block of substituted zeroes will all be faithfully preserved and will verify forever.

A stronger check reads the source separately and compares the results. Here /dev/sdX stands in for the evidence drive, attached through a write blocker:

lsblk -d -o NAME,MODEL,SERIAL,SIZE /dev/sdX
sudo sha256sum /dev/sdX
sha256sum evidence.img

Check that you imaged the whole device (/dev/sdX, not /dev/sdX1), that the sizes agree, and that the imaging log shows no read errors. Even then, both reads came through the same machine, cable and kernel. A compromised or broken acquisition system can lie consistently.

Quick detour: a mismatch need not mean tampering

I find this bit pleasingly awkward. An SSD is a small computer which manages its own flash, and what it returns for trimmed or failing areas is up to its firmware. A write blocker stops the host writing to it, but does not stop the drive's own housekeeping once powered.

So a second read of the source can differ from the first without anyone touching your files. A failing hard disk can do the same, returning a sector on one pass and an error on the next. Record the acquisition hash and any errors at the time, rather than assuming you can recreate them later.

Back to the image: it can remain perfectly stable against its acquisition hash even when the original no longer reads the same way.

Collisions are a separate, narrower problem

MD5 and SHA-1 are both broken for collision resistance; the SHAttered work published two different PDFs with one SHA-1 value in 2017. Someone who prepares both files in advance can exploit that.

Taking an arbitrary existing disk and forging a second one to match its hash is a different, much harder preimage problem. Still, there is little reason to choose either for new work. Use SHA-256, and notice that it would not have saved the example above.

Sign the record so it cannot be quietly replaced

Put the hash in an acquisition record along with the things it cannot express:

  • device make, model, serial number and capacity
  • exhibit reference, and who handed it to whom
  • tool names and versions, write blocker used, and read errors
  • start and finish times, plus how the clock was checked
  • the image hash and, where you took one, the separate source hash

Then sign that record. OpenSSH can do it with an Ed25519 key:

ssh-keygen -Y sign -f examiner_key -n evidence record.txt

# Later: allowed_signers holds "identity key-type public-key"
ssh-keygen -Y verify -f allowed_signers -I [email protected] \
  -n evidence -s record.txt.sig < record.txt

The verifier must get the public key by a route they trust. If allowed_signers travels in the same folder as the evidence, an attacker can replace the key, record and signature together. We have merely built a taller version of the first problem.

A signature also leaves a gap: the key holder can write a new record and sign that instead, with any date they like typed into it.

A timestamp pins down "no later than"

An RFC 3161 time-stamping authority signs a hash together with its own time. You send it the digest, not the record or the image.

openssl ts -query -data record.txt -sha256 -cert -out record.tsq

# Submit record.tsq to your chosen authority and save its reply
# as record.tsr, then verify against that authority's certificates
openssl ts -verify -data record.txt -in record.tsr \
  -CAfile tsa-ca.pem

Depending on the authority, you may also need to pass an intermediate or signing certificate with -untrusted.

A valid token shows that this exact record existed by the stated time, assuming you trust the authority. It does not show that the contents are true. A mistaken serial number, timestamped, is a very durable mistake.

Timestamp promptly. A token obtained a month after acquisition leaves a month in which the record could have been rewritten. Sending a copy of the hash to a second person or an append-only log at the time also helps, provided the examiner cannot edit it afterwards.

What you can honestly say

Compare these two statements:

  • Weak: "The hash matches, so this is the original evidence."
  • Better: "This image matches the SHA-256 value in a signed and timestamped acquisition record, which identifies the source device and notes how it was read."

The second is longer because it says what each piece of proof is doing. It also shows where to push: who controlled the device before acquisition, whether the acquisition system was sound, and whether the custody notes have holes.

None of those questions has a command that prints "OK". An image taken from a drive that was altered the previous evening will hash, sign and timestamp beautifully.