Understanding Hash Collisions in the MD5 Algorithm

Hello everyone! In this first installment of our #ForensicFriday series, I want to talk to you about a crucial topic in the world of computer security and digital forensics: hash collisions in the MD5 algorithm.

As many of you know, MD5 has been one of the most widely used hash algorithms for verifying the integrity of files and data. However, with technological advancements and new analysis techniques, vulnerabilities have been discovered that mean MD5 is no longer considered secure for certain applications.

What is a Hash and What is it Used For?

A hash is a function that takes an input (or ‘message’) and returns a fixed-length string, which typically represents the “digital fingerprint” of the original content. Hashes are fundamental in:

  • Integrity verification: To ensure that a file has not been modified.
  • Password storage: Instead of storing passwords in plain text, their hashes are stored.
  • Digital signatures and certificates: To ensure the authenticity of documents and communications.

The MD5 Algorithm

MD5 (Message-Digest Algorithm 5) is a 128-bit hash function widely used since its creation in 1991. Although it has been popular for decades, weaknesses affecting its security were identified as early as 1996.

What is a Hash Collision?

A hash collision occurs when two different inputs produce the same hash. This is problematic because it compromises the integrity and reliability of the hash:

  • Compromised integrity: We cannot be certain that the content has not been altered.
  • Collision attacks: An attacker can replace a legitimate file with a malicious one that has the same hash.

Practical Experiment: MD5 Collision

In my free book and on my website, I have shared an experiment that demonstrates an MD5 collision. You can download the test files here:

🔗 http://jocsanlaguna.com/wp-content/uploads/2024/11/colisionmd52.jpg

🔗 http://jocsanlaguna.com/wp-content/uploads/2024/11/colisionmd51.jpg

The provided files are two different images that, surprisingly, generate the same MD5 hash.

Steps to Reproduce the Experiment

Below, I will show you how to calculate the MD5 hash of these files on Windows, Linux, and Mac.


How to Calculate the MD5 Hash

On Windows

Using CertUtil (included in Windows Vista and later):

  1. Open the Command Prompt (CMD).
  2. Navigate to the directory where you downloaded the files.
  3. Run the following command:
certutil -hashfile nombre_del_archivo MD5

Example:

certutil -hashfile imagen1.png MD5

Using PowerShell:

  1. Open PowerShell.
  2. Run:
Get-FileHash -Algorithm MD5 nombre_del_archivo

Example:

Get-FileHash -Algorithm MD5 imagen1.png

On Linux

Most distributions include the tool md5sum.

  1. Open the Terminal.
  2. Navigate to the directory containing the files.
  3. Run:
md5sum nombre_del_archivo

Example:

md5sum imagen1.png

On Mac

Like Linux, macOS has the tool available md5.

  1. Open the Terminal.
  2. Navigate to the directory containing the files.
  3. Run:
md5 nombre_del_archivo

Example:

md5 imagen1.png

Expected Results

When calculating the MD5 hash of both files, you will notice that, despite being different images, the resulting hash is exactly the same. This demonstrates a collision and proves why MD5 is no longer secure for certain critical applications.

  • If you have reached this point, I have a very valuable recommendation for you: It is useless for digital forensics and comes as the default in many applications; this could result in the loss of credibility for all your evidence—yes, all the evidence. Therefore, it is very important that you check which algorithm you are using.

Leave a comment