90
$\begingroup$

Is there an example of two known strings which have the same MD5 hash value (representing a so-called "MD5 collision")?

$\endgroup$

migrated from stackoverflow.com Dec 11 '11 at 14:22

This question came from our site for professional and enthusiast programmers.

  • $\begingroup$ Example in Wikipedia. $\endgroup$ – Tomasz Nurkiewicz Dec 11 '11 at 9:04
  • $\begingroup$ mscs.dal.ca/~selinger/md5collision $\endgroup$ – Nicolas Thery Mar 19 '14 at 11:24
  • $\begingroup$ Once wrote two bash script that got the same MD5 value, and did two different things none-the-less. Pretty easy to do, but McAfee ate the .zip as a proto-virus was stored in it as well (you can create a .zip scanner but not one that can delete the files from the .zip, pretty lame). $\endgroup$ – Maarten Bodewes May 6 '14 at 23:43
64
$\begingroup$

Yes you can, see at the MD5 Collision Demo, the two blocks:

d131dd02c5e6eec4693d9a0698aff95c 2fcab58712467eab4004583eb8fb7f89 
55ad340609f4b30283e488832571415a 085125e8f7cdc99fd91dbdf280373c5b 
d8823e3156348f5bae6dacd436c919c6 dd53e2b487da03fd02396306d248cda0 
e99f33420f577ee8ce54b67080a80d1e c69821bcb6a8839396f9652b6ff72a70

and

d131dd02c5e6eec4693d9a0698aff95c 2fcab50712467eab4004583eb8fb7f89 
55ad340609f4b30283e4888325f1415a 085125e8f7cdc99fd91dbd7280373c5b 
d8823e3156348f5bae6dacd436c919c6 dd53e23487da03fd02396306d248cda0 
e99f33420f577ee8ce54b67080280d1e c69821bcb6a8839396f965ab6ff72a70

produce an MD5 collision.

Each of these blocks has MD5 hash 79054025255fb1a26e4bc422aef54eb4.

$\endgroup$
  • $\begingroup$ Are there any 2 email addresses that you know, that will produce the same MD5 hash? I ask this because I know that Gravatar website uses MD5 as an identifier of accounts (here: en.gravatar.com/site/implement/images/java ) , which is done on email addresses. Since email addresses aren't bound by length, any function that operates on it and returns a limited string must have collisions. $\endgroup$ – android developer Jul 25 at 19:41
33
$\begingroup$

A new result shows how to generate single block MD5 collisions, including an example collision:

Message 1

Message 2

> md5sum message1.bin message2.bin
> 008ee33a9d58b51cfeb425b0959121c9 message1.bin
> 008ee33a9d58b51cfeb425b0959121c9 message2.bin

There is an earlier example of a single block collision but not technique for generating it was published.

$\endgroup$
  • 2
    $\begingroup$ I just saw it too on eprint and was about to post this one, but you beat me to that :) $\endgroup$ – Jalaj Jan 30 '12 at 18:26
30
$\begingroup$

MD5 was intended to be a cryptographic hash function, and one of the useful properties for such a function is its collision-resistance. Ideally, it should take work comparable to around $2^{64}$ tries (as the output size is $128$ bits, i.e. there are $2^{128}$ different possible values) to find a collision (two different inputs hashing to the same output). (Actually, brute-forcing this is today almost in the range of possible, so this alone would be a reason not to use any small-output hash function like MD5.)

It showed that MD5 is not that resistant as intended, and nowadays it is relatively easy to produce more collisions, even with an arbitrary common prefix and suffix.

There was a spectacular example, when someone used an MD5 collision to get a fake SSL certificate from a certification agency. The agency signed a certificate for a domain which belonged to the attacker, and the attacker produced a different certificate (for another domain) with the same hash, i.e. for which the same signature was valid.

Don't use MD5 for any application which relies on collision-resistance (like signatures) ... or for any new application at all. Use SHA-2 (or SHA-3) now.

$\endgroup$
  • $\begingroup$ Or use Blake2b. Faster and more secure. $\endgroup$ – Demi Mar 24 '16 at 2:21
  • 4
    $\begingroup$ @Demetri while faster can be easily proven (on specific hardware), is there a proof of it being more secure (if it's twice as fast it might be twice as insecure from a brute-force attack)? The most analysis goes into the most-widely used crypto functions trying to break them, so it doesn't always seem a fair comparison. $\endgroup$ – Nick T Jul 25 '16 at 22:12
30
$\begingroup$

Just to show you how easy it is today to create collisions on MD5:

One could create collisions using Marc Steven's HashClash on AWS and estimated the the cost of around $0.65 per collision.

These 2 images have the same md5 hash: 253dd04e87492e4fc3471de5e776bc3d

Ship image

Plane image

If you want to test it yourself and the images below do not give you the MD5 hash displayed above then you may need to take images from the original link below:

Reference: http://natmchugh.blogspot.com/2015/02/create-your-own-md5-collisions.html

$\endgroup$
  • 5
    $\begingroup$ Same hash and theme... $\endgroup$ – Matas Vaitkevicius May 11 '16 at 11:37
  • $\begingroup$ when i used the basic hash of mac's terminal, i get different results !! MD5 (image1.jpg) = d37ca5b7a8e39f810bc341616005fd0f MD5 (image2.jpg) = 6dbe9c815f73327fd10c3a5b0b3a7498 $\endgroup$ – DeyaEldeen Jul 23 '17 at 16:18
  • 14
    $\begingroup$ @DeyaEldeen probably the images have been altered by stackexchange. Btw only looking at the pictures clearly shows there is a collision somewhere… ;-) $\endgroup$ – Flavien Volken Aug 16 '17 at 9:45
20
$\begingroup$
  1. Two different strings in hex format:

    4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa200a8284bf36e8e4b55b35f427593d849676da0d1555d8360fb5f07fea2
    4dc968ff0ee35c209572d4777b721587d36fa7b21bdc56b74a3dc0783e7b9518afbfa202a8284bf36e8e4b55b35f427593d849676da0d1d55d8360fb5f07fea2
    

    both have MD5 hash:

    008ee33a9d58b51cfeb425b0959121c9
    

    Example:

    > md5sum message1.bin message2.bin
    008ee33a9d58b51cfeb425b0959121c9 message1.bin
    008ee33a9d58b51cfeb425b0959121c9 message2.bin
    > sha1sum message1.bin message2.bin
    c6b384c4968b28812b676b49d40c09f8af4ed4cc message1.bin
    c728d8d93091e9c7b87b43d9e33829379231d7ca message2.bin
    
  2. Another example (in hex):

    0e306561559aa787d00bc6f70bbdfe3404cf03659e704f8534c00ffb659c4c8740cc942feb2da115a3f4155cbb8607497386656d7d1f34a42059d78f5a8dd1ef
    0e306561559aa787d00bc6f70bbdfe3404cf03659e744f8534c00ffb659c4c8740cc942feb2da115a3f415dcbb8607497386656d7d1f34a42059d78f5a8dd1ef
    

    both have MD5 hash:

    cee9a457e790cf20d4bdaa6d69f01e41
    

Example 1. is straight from Marc Stevens: Single-block collision for MD5, 2012; he explains his method, with source code (alternate link to the paper).

Example 2. is adapted from Tao Xie and Dengguo Feng: Construct MD5 Collisions Using Just A Single Block Of Message, 2010.

Please note that above examples are hexadecimal representation of the strings. So to test it, you've to write these hex values into the binary files and then compare them as shown above.

To make simple test in shell, please check the commands provided in: Can two different strings generate the same MD5 hash code?

See also: What is the MD5 collision with the smallest input values?

$\endgroup$
  • 14
    $\begingroup$ For those who can't squint: The 18th-to-last character in 1 is different 555 and d55 and in 2 it's somewhere in the middle of first row 659e744 and 659e704 $\endgroup$ – rath Apr 29 '14 at 14:49
  • $\begingroup$ whe I try it here I don't get the same hash: md5.cz $\endgroup$ – RicardoE May 6 '14 at 3:52
  • 4
    $\begingroup$ In response to others saying they're not getting the same MD5 hash, the data is in hex format and must be converted to binary format. Here's an example in PHP: ideone.com/UyP22Z $\endgroup$ – ub3rst4r Mar 7 '16 at 21:24
  • 2
    $\begingroup$ @ub3rst4r If you've got python, just type this: hashlib.md5(bytearray.from_hex("STRING HERE")).digest() $\endgroup$ – Zizouz212 Aug 22 '16 at 21:47
  • 1
    $\begingroup$ Or this tool supports also HEX input: decrane.io/md5 $\endgroup$ – malejpavouk Jan 31 '17 at 19:47
17
$\begingroup$

Here are some other interesting examples. One of them is, two downloadable executables that have the same MD5 hash, but are actually different, and produce different (safe) results when run!

So much for using MD5 hashes to ensure download file integrity :-(

http://www.mscs.dal.ca/~selinger/md5collision/

$\endgroup$
6
$\begingroup$

From "Schneier on Security", March 10, 2005…

More Hash Function Attacks

Here's(1) a pair of valid X.509 certificates that have identical signatures. The hash function used is MD5.

And here's a paper(2) demonstrating a technique for finding MD5 collisions quickly: eight hours on 1.6 GHz computer.

Links:

  1. http://www.win.tue.nl/~bdeweger/CollidingCertificates/
  2. http://cryptography.hyperlink.cz/md5/MD5_collisions.pdf
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy