URL: http://www.madsekci.net/md5.html
This small report was written to inform in most cases PHP developers of the fact that MD5 offers a false secure feeling. Not because of the algorithm, but because of its use.
MD5 is a one-way hash algorithm that provides a 128 bits length hash whatever the original text length might have been. The resulting hash is often used to sign documents thus giving a way to verify that the original content of the document wasn't altered neither by software/hardware nor by a third party.
Today, many applications (most of them network-oriented) use MD5 as their authentication algorithm to avoid that plain text passwords are sent over the network. (or in many cases, the internet)
Here's an example of how MD5 is used (faulty) today: A client sends an MD5 password hash over the network to the server. The server makes his own MD5 password hash and then compares the two hashes. If they match, the ser- ver assumes that the client (or whoever sent the hash) knows the password and therefor the authentication will be successful. But the server might be totally wrong.
Theoretically, MD5 cannot be reversed. That means that nobody can guess or compute from the hash back what the original text might have been. (even with small strings, like most passwords). But do attackers really need to know the original string? No, the number of a resulting hash is fixed (2128) and a lot of strings will give the same MD5 hash.
So MD5 is a faulty algorithm? No, but it's used for a wrong purpose. As stated above, it offers some form of verification to see if a file is altered (or string) but the designers never intended that it should be used as an authentication algorithm.
The problem is that many authentication methods make use of MD5 in a wrong way. Let's take MSN Messenger as an example. The common way to use MD5 as authentication is MD5(challenge + MD5(password + challenge)) but Messenger uses a simplified version, MD5(challenge + password). Using MD5 as authentication was a weak choice in the first place, but making a simplified authentication algorithm was even worse.
How is MD5 cracked then? There are two ways it can be easily broken. First, most would try a dictionary attack. A file with commonly used passwords is used. Each string (or in this case password) is MD5'd and the resulting hash is compared with the existing MD5 hash. Once the two hashes match, the authentication is broken (which in no way means that the string from the dictionary file is identical to the original string of the cracked hash).
A second method is a brute force attack. BF just tries every possible combination of characters. So in the end, it will always come up with a hash matching the one that had to be cracked. Though, both methods might be time consuming. But as most people use weak or short passwords (easy to remember ones) the cracking shouldn't take that long. As most people use existing words, the dictionary attack comes obviously in the first place of the attacker.
How to prevent this from happening? Well, use MD5 as it was intended (as signature for file checking) and use real authentication algorithms to provide a strong security for the information that requires secrecy.
In the end, weak authentication systems are not weak because of the used algorithm, but because the designers / developers have chosen a wrong algorithm which wasn't created for such purpose in the first way.
To improve security, you can use md5 in a more "sophisticated way".
Example:
function str_encode($str) {
$strMD5feed = sha1("y8Vyica9aspPHs9H9X6Z"); // random key added to md5
$str = base64_encode($str);
$str = str_rot13($str);
$str = bin2hex($str);
$str = md5($str + md5($strMD5feed + $str));
return $str;
}
To get a good $strMD5feed value, I suggest for those who are not that creative in picking random letters, use my phpPPG tool (check the link in my signature)