How to use Python for Hacking
Hacking is an attempt to exploit a computer system or a private network inside a computer. Simply put, it is the unauthorized access to or control over computer network security systems for some illicit purpose.
Ethical hacking is to scan vulnerabilities and to find potential threats on a computer or networks.
Python is a widely used general-purpose, high-level programming language. It has great libraries that can be used for hacking.
In this article, we will see an example of hacking passwords with Python. We are going to see how to hack a plain text password when you find a password that is in hashed(md5)
format. So we take the input_hash(hashed password in the database) and try to compare it with md5 hash of every plain text password which is in a password file(pass_doc) and when the hashes are matched we simply display the plain text password which is in the password file(pass_doc). If the password is not present in the input password file it will say password is not found. This type of attack can be considered as a dictionary attack.
Let’s suppose the text file containing list of password is password.txt
.
import hashlib print("******PASSWORD CRACKER******") pass_found = 0 input_hash = input("Enter the hashed password:") pass_doc = input("\nEnter passwords filename including path(root / home/):") try: # trying to open the password file. pass_file = open(pass_doc, 'r') except: print("Error:") print(pass_doc, "is not found.\nPlease give the path of file correctly.") quit() # comparing the input_hash with the hashes # of the words in password file, # and finding password. for word in pass_file: # encoding the word into utf-8 format enc_word = word.encode('utf-8') # Hasing a word into md5 hash hash_word = hashlib.md5(enc_word.strip()) # digesting that hash into a hexa decimal value digest = hash_word.hexdigest() if digest == input_hash: # comparing hashes print("Password found.\nThe password is:", word) pass_found = 1 break # if password is not found. if not pass_found: print("Password is not found in the", pass_doc, "file") print('\n') print("--Thank you--")
Input:
Enter the hashed password : 061a01a98f80f459b1431236b62bb10b Enter passwords filename including path(root/home/) : password.txt
Output:
Password found. The password is : anie