The Python code attached receives the hash function of an input string (for example, the user's password) and generates a 156-bit Hash using MD5.What vulnerabilities that make password hashing unsuitable can exist in this code.
#
from Crypto.Hash import MD5
import binascii
def hash(msg):
# pad message to 16 bytes
if len(msg) < 16:
msg = msg + (16 - len(msg)) * 'A'
# pick first 16 bytes
msg = msg[:16]
# converts message to upper case
msg = msg.upper()
# create MD5 objects
h1 = MD5.new()
h2 = MD5.new()
# hash two parts of message separately
h1.update(msg[:8])
h2.update(msg[8:16])
# concatenate the two hashes
h = h1.digest() + h2.digest()
return h
# print message
print(binascii.hexlify(hash("Hello, this is a great passphrase, and I am
wondering if anyone can crack it")))
There has been a password handling protocol in Windows called LM (LAN Manager) that had similar flaws to what we see here. I kind of feel like solving a quiz question you were supposed to do yourself... but since I enjoy it, who cares.
Going from the top:
I think this is it.