Reputation: 93
I am very interested in python and cryptography and I would like to know what would be the most simple method in python to crack a hash.
I would like to build a small python script that can crack this hash:21232f297a57a5a743894a0e4a801fc3 which is simply 'admin'.
What process would I need to go through to guess what this hash represents?
I have read up about md5 and at this point in time I have only just started learning the methods behind cryptography, but they also go into deep computer science which is something I don't understand as of yet.
I did some research here: http://nsfsecurity.pr.erau.edu/crypto/md5.html
Upvotes: 1
Views: 2665
Reputation: 11
You can use a dictionary attack to crack the given hash, which is the MD5 hash of the word "admin." Additionally, since MD5 has lost its reliability, you can find pre-cracked hashes on websites that contain thousands of passwords cracked using rainbow tables.
MD5 is a commonly used hash function that produces a hash value as a 32-character hexadecimal number. It is important to understand that MD5 is hashing, not encryption, meaning it is a one-way function that cannot be reversed. However, some MD5 hashes can be reversed using brute force or lookup tables, and MD5 has now lost its reliability. There are also many ways to crack hashes, including:
Brute Force: This method involves trying all possible character combinations until the hash that matches the given hash is found. For simple passwords, this can be done relatively quickly, but I think it's a waste of time to use this method.
Dictionary Attack: Instead of trying all possible combinations, a dictionary attack uses a predefined list of potential passwords (dictionary) and hashes each one to check if it matches the given hash. If the password is common, this method is faster than brute force and, in my opinion, the most reasonable approach at present.
Using Python, you can experiment with these attacks on a small scale, but it is almost impossible to crack passwords with a bit length of 256 and above. You can only perform attacks like rainbow attacks. If the password is a commonly used simple password, you might be able to crack it. Additionally, attempting these kinds of attacks takes time, but you improve over time, and I recommend researching a method called salting. Also, in the article below, I have discussed hashing and salting in more detail: Why We Should Use Hashing and Salting for Security.
Upvotes: 1
Reputation: 75
import hashlib
def md5_encryption(string: str) -> str:
return hashlib.md5(string.encode()).hexdigest()
print(md5_encryption("admin"))
'21232f297a57a5a743894a0e4a801fc3'
Upvotes: 0
Reputation: 369444
http://www.google.com/search?q=md5+lookup
>>> import requests
>>> import lxml.html
>>>
>>> def reverse_md5(digest):
... r = requests.get('http://www.md5-lookup.com/index.php?q={}'.format(digest))
... root = lxml.html.fromstring(r.content)
... for x in root.cssselect('#LSResult table tr')[4:-3]:
... return x.find('td').text_content()
... # fallback to brute force.
... # ...
...
>>> reverse_md5('21232f297a57a5a743894a0e4a801fc3')
'admin'
>>> reverse_md5('21232f297a57a5a743894a0e4a801fc4') # lookup fail
>>>
Upvotes: 3
Reputation: 8945
You can output a hex md5 like so:
>>> from hashlib import md5
>>> md5('admin').hexdigest()
'21232f297a57a5a743894a0e4a801fc3'
If you have a list of words, you could try them one by one and output if their md5 matches your desired one. (This is known as a dictionary attack)
>>> words = 'test', 'alex', 'steve', 'admin'
>>> for word in words:
... if md5(word).hexdigest() == '21232f297a57a5a743894a0e4a801fc3':
... print word
... break
...
admin
If you were serious about cracking an MD5 you'd have much better results on the GPU - try a tool like OCLHashCat
Upvotes: 6