I have the string that was used in a webapp with md5 hashing to come up with a hash. I also have the hash. But the md5 of the string doesn't match the hash, so I'm guessing there's a salt involved. Is there any software that can help me determine the salt?
In standard hashing functions (e.g., UNIX passwords in /etc/shadow) the salt is stored as part of the hash.
Pass the stored hash value as the salt and you should get the correct result.
The hashed password value in /etc/shadow is actually a $ delimited record. For example, we have this hash of the password 'blarg':
There are three fields separated by $'s which are
- The hash function (in this case '1', representing MD5)
- The salt (which is 'KfcI/JTQ')
- The hash value (which is 'b5VTf4i9Mnf6QFgLuVZNM0')
If you use mkpasswd several times the hash will change.
$ mkpasswd -m md5 blarg $1$Gst52IWk$8ARVeSlpkcZOlyKV10Slu/ $ mkpasswd -m md5 blarg $1$JeqRviA/$GnH/AvGnZEG9wLfJjiaAt1
However, by passing in the salt (i.e., the second field) from the hash value above we can match it against the original hash:
$ mkpasswd -m md5 -S KfcI/JTQ blarg $1$KfcI/JTQ$b5VTf4i9Mnf6QFgLuVZNM0
You can also pass in the whole password hash (although omitting the hash function).
$ mkpasswd -m md5 -S KfcI/JTQ$b5VTf4i9Mnf6QFgLuVZNM0 blarg $1$KfcI/JTQ$b5VTf4i9Mnf6QFgLuVZNM0
On Linux the hash type can be controlled in /etc/login.defs. Be very careful when changing this, you can completely lock yourself out of the system. I suggest reading the man page carefully specifically looking at the headings MD5_CRYPT_ENAB and ENCRYPT_METHOD.