-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhashCrack.py
155 lines (112 loc) · 5.24 KB
/
hashCrack.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/python3
# THIS SCRIPT USES AN ONLINE RESOURCE OF A LARGE LIST OF PASSWORDS
# AND ENCRYPTS THEM WITH SPECIFIED HASHING ALGORITHMS
# AND THEN MATCHES THE RESULT WITH THE HASH GIVEN BY THE USER
# IT RETURNS THE CORRESPONDING PASSWORD IN PLAIN TEXT FROM THE DICTIONARY
# WHOSE HASH VALUE MATCHES WITH THE USER INPUT
# IF THE USER DOESN'T KNOW THE TYPE OF HASH,
# THE SCRIPT RUNS THROUGH ALL THE HASHING ALGORITHMS
# MD5, SHA1, SHA224, SHA256 AND SHA512
# AND RETURNS IF ANY HASH VALUE MATCHES ALONG WITH ITS TYPE
import hashlib
from urllib.request import urlopen
import sys # sys (system) module is used to handle the command line arguments
from termcolor import colored # use colored text output on the terminal
# crackAll() FUNCTION IS INVOKED WHEN THE USER
# DOESN'T KNOW THE TYPE OF HASH TO CRACK
# IT GOES THROUGH ALL THE TYPES OF HASHES
# FOR EACH WORD IN THE DICTIONARY
# AND SEARCHES FOR A MATCH WITH THE USER INPUT
def crackAll(val):
# passList is the dictionary of possible passwords read from the online location
passList = urlopen("https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt").read().decode()
for password in passList.split('\n'):
hashguess = hashlib.md5(bytes(password, 'utf-8')).hexdigest()
if hashguess == val:
print(colored("[!] Hash type : MD5", "yellow"))
print(colored("[+] Password found : " + password, "green"))
quit()
hashguess = hashlib.sha1(bytes(password, 'utf-8')).hexdigest()
if hashguess == val:
print(colored("[!] Hash type : SHA1", "yellow"))
print(colored("[+] Password found : " + password, "green"))
quit()
hashguess = hashlib.sha224(bytes(password, 'utf-8')).hexdigest()
if hashguess == val:
print(colored("[!] Hash type : SHA224", "yellow"))
print(colored("[+] Password found : " + password, "green"))
quit()
hashguess = hashlib.sha256(bytes(password, 'utf-8')).hexdigest()
if hashguess == val:
print(colored("[!] Hash type : SHA256", "yellow"))
print(colored("[+] Password found : " + password, "green"))
quit()
hashguess = hashlib.sha512(bytes(password, 'utf-8')).hexdigest()
if hashguess == val:
print(colored("[!] Hash type : SHA512", "yellow"))
print(colored("[+] Password found : " + password, "green"))
quit()
print(colored("[-!] Password not found in password list!", "red"))
quit()
# cracker() FUNCTION IS INVOKED WITH THE HASH VALUE TO BE CRACKED
# ALONG WITH ITS HASH TYPE (NEEDS TO BE KNOWN)
# IT ENCRYPTS THE DICTIONARY KEYS ACCORDING TO THE GIVEN HASH TYPE
# AND SEARCHES FOR A MATCH WITH THE HASH GIVEN BY THE USER
# IF HASH TYPE IS NOT KNOWN [htype = 0]
# THE FUNCTION CALLS THE crackAll() FUNCTION
# TO BRUTE FORCE THROUGH ALL THE HASH TYPES
# AND SEARCH FOR A MATCHING RESULT
# ARGS :-
# (int <type_of_hash> , str <HASH_VAL>) # <type_of_hash> values are defined as in main()
def cracker (htype, hval):
if htype == 0: # hash type not known by the user - call crackAll() function
crackAll (hval)
passList = urlopen("https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Common-Credentials/10-million-password-list-top-1000000.txt").read().decode()
if htype == 1: # md5 hashtype
for password in passList.split('\n'):
hashguess = hashlib.md5(bytes(password, 'utf-8')).hexdigest()
if hashguess == hval:
print(colored("[+] Password found : " + password, "green"))
quit()
elif htype == 2: # sha1 hashtype
for password in passList.split('\n'):
hashguess = hashlib.sha1(bytes(password, 'utf-8')).hexdigest()
if hashguess == hval:
print(colored("[+] Password found : " + password, "green"))
quit()
elif htype == 3: # sha224 hashtype
for password in passList.split('\n'):
hashguess = hashlib.sha224(bytes(password, 'utf-8')).hexdigest()
if hashguess == hval:
print(colored("[+] Password found : " + password, "green"))
quit()
elif htype == 4: # sha256 hashtype
for password in passList.split('\n'):
hashguess = hashlib.sha256(bytes(password, 'utf-8')).hexdigest()
if hashguess == hval:
print(colored("[+] Password found : " + password, "green"))
quit()
elif htype == 5: # sha512 hashtype
for password in passList.split('\n'):
hashguess = hashlib.sha512(bytes(password, 'utf-8')).hexdigest()
if hashguess == hval:
print(colored("[+] Password found : " + password, "green"))
quit()
print(colored("[-!] Password not found in password list!", "red")) # the hash value match is not found after all the iterations
quit()
def main():
hashtype = int(input("[*] Enter the type of hash (if known) :-\n(0) Unknown\t(1) MD5\n(2) SHA1\t(3) SHA224\n(4) SHA256\t(5) SHA512\nYour choice here: "))
if hashtype == 0:
hashVal = input("[*] Enter the hash value : ")
elif hashtype == 1:
hashVal = input("[*] Enter the MD5 hash value : ")
elif hashtype == 2:
hashVal = input("[*] Enter the SHA1 hash value : ")
elif hashtype == 3:
hashVal = input("[*] Enter the SHA224 hash value : ")
elif hashtype == 4:
hashVal = input("[*] Enter the SHA256 hash value : ")
elif hashtype == 5:
hashVal = input("[*] Enter the SHA512 hash value : ")
cracker(hashtype, hashVal)
main()