-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathHashExploit.py
331 lines (285 loc) · 12.3 KB
/
HashExploit.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/usr/bin/python3
# import modules
# Author Farid Luhar
# you can follow me on twitter @faridpy
import os, hashlib, sqlite3, string, argparse, sys
# used argparse module for creating help menu
parser = argparse.ArgumentParser(description="HashExploit CLI. HashExpoit is Great Tool For Cracking Hash.It Supports 11 Hash Such as md5, sha1, sha223, sha3_384, blake2s, blake2b, sha384, sha3_224, sha512, sha256, sha3_256 etc. It Generates Rainbow Table. It Creates Sqlite Database in Current Directory and Mactch Hash With Rainbow Table. It Also Supports Prepend and Append Salt ")
parser.add_argument('-f', '--file', help = 'Add Wordlist To Create Rainbow Table', nargs = 1)
parser.add_argument('-p', '--pre', help = 'Prepend Salt Value Into the Words Of Wordlist', nargs = 1)
parser.add_argument('-a', '--ap', help = 'Append Salt Value Into the Words Of Wordlist', nargs = 1)
parser.add_argument('-H', '--hash', help = 'Crack Hash', nargs = 1)
parser.add_argument('-v', '--verbose', help = 'Verbose Mode', action='store_true')
parser.add_argument('-w', '--word', help = 'Generate Hashes For A Particular Word')
# created argparse object
arg = parser.parse_args()
# used os module for checking directory
if os.path.isdir('rainbow_hash'):
os.chdir('rainbow_hash/')
else:
os.mkdir('rainbow_hash')
os.chdir('rainbow_hash/')
# used sqlite3 module for creating database
sql = sqlite3.connect('hashing.db')
sql.execute('create table if not exists hashes(name text, md5 text, sha1 text, sha224 text, blake2s text, '
'blake2b text, sha3_384 text, sha384 text, sha3_512 text, sha3_224 text, sha512 text, sha256 text, '
'sha3_256 text)')
sql.commit()
# OKGREEN = '\033[92m'
# FAIL = '\033[91m'
# UNDERLINE = '\033[4m'
# created function fetch_data and it takes one argument 'user_hash'
def fetch_data(user_hash):
cursor = sql.execute('select *from hashes')
sql.commit()
for row in cursor:
if user_hash == row[1]: # md5 check
print('word => "', row[0], '" hash ALGORITHM md5 ', user_hash)
return
elif user_hash == row[2]: # sha1
print('word => "', row[0], '" hash ALGORITHM sha1 ', user_hash)
return
elif user_hash == row[3]: # sha224
print('word => "', row[0], '" hash ALGORITHM sha224 ', user_hash)
return
elif user_hash == row[4]: # blake2s
print('word => "', row[0], '" hash ALGORITHM blake2s ', user_hash)
return
elif user_hash == row[5]: # blake2b
print('word => "', row[0], '" hash ALGORITHM blake2b ', user_hash)
return
elif user_hash == row[6]: # sha3_384
print('word => "', row[0], '" hash ALGORITHM sha3_384 ', user_hash)
return
elif user_hash == row[7]: # sha384
print('word => "', row[0], '" hash ALGORITHM sha384 ', user_hash)
return
elif user_hash == row[8]: # sha3_512
print('word => "', row[0], '" hash ALGORITHM sha3_512 ', user_hash)
return
elif user_hash == row[9]: # sha3_224
print('word => "', row[0], '" hash ALGORITHM sha3_224 ', user_hash)
return
elif user_hash == row[10]: # sha512
print('word => "', row[0], '" hash ALGORITHM sha512 ', user_hash)
return
elif user_hash == row[11]: # sha256
print('word => "', row[0], '" hash ALGORITHM sha256 ', user_hash)
return
elif user_hash == row[12]: # sha3_256
print('word => "', row[0], '" hash ALGORITHM sha3_256 ', user_hash)
return
else:
print('Not Found')
# created function add_data it takes three arguments file1 is mandatory remainings are optional
def add_data(file1, salt_value=None, post_value=None):
n = 0
# it will create rainbow table with given file
fp = open(file1, 'r',encoding="Latin-1")
for word in fp:
try:
n += 1
word = word.strip(string.whitespace)
if salt_value is not None:
word = salt_value + word
if post_value is not None:
word += post_value
if arg.verbose:
print(word)
# this function will create hashes
md5 = hashlib.md5(word.encode()).hexdigest()
sha1 = hashlib.sha1(word.encode()).hexdigest()
sha224 = hashlib.sha224(word.encode()).hexdigest()
blake2s = hashlib.blake2s(word.encode()).hexdigest()
blake2b = hashlib.blake2b(word.encode()).hexdigest()
sha3_384 = hashlib.sha3_384(word.encode()).hexdigest()
sha384 = hashlib.sha384(word.encode()).hexdigest()
sha3_512 = hashlib.sha3_512(word.encode()).hexdigest()
sha3_224 = hashlib.sha3_224(word.encode()).hexdigest()
sha512 = hashlib.sha512(word.encode()).hexdigest()
sha256 = hashlib.sha256(word.encode()).hexdigest()
sha3_256 = hashlib.sha3_224(word.encode()).hexdigest()
sql.execute('insert into hashes(name, md5 , sha1, sha224 , blake2s , blake2b , sha3_384 , sha384 , sha3_512, '
'sha3_224, sha512, sha256, sha3_256) values(?,?,?,?,?,?,?,?,?,?,?,?,?)', (word, md5, sha1,
sha224, blake2s,
blake2b, sha3_384,
sha384, sha3_512,
sha3_224, sha512,
sha256, sha3_256))
except Exception:
print(Exception)
sql.commit()
print('TOTAL WORD:', n)
# stored user arguments to variable
if arg.file is not None:
file_name = ''.join(arg.file)
if os.path.isfile(file_name):
if arg.pre is not None:
salt = ''.join(arg.pre)
add_data(file_name, salt_value = salt)
elif arg.ap is not None:
post = ''.join(arg.ap)
add_data(file_name, post_value = post)
else:
add_data(file_name)
else:
print("file doesn't exist")
# stored user arguments to variable
if arg.hash is not None:
hash1 = arg.hash
hash1 = ''.join(hash1)
fetch_data(hash1)
def word_hash(word):
# it takes one argument word and will create hash """
md5 = hashlib.md5(word.encode()).hexdigest()
sha1 = hashlib.sha1(word.encode()).hexdigest()
sha224 = hashlib.sha224(word.encode()).hexdigest()
blake2s = hashlib.blake2s(word.encode()).hexdigest()
blake2b = hashlib.blake2b(word.encode()).hexdigest()
sha3_384 = hashlib.sha3_384(word.encode()).hexdigest()
sha384 = hashlib.sha384(word.encode()).hexdigest()
sha3_512 = hashlib.sha3_512(word.encode()).hexdigest()
sha3_224 = hashlib.sha3_224(word.encode()).hexdigest()
sha512 = hashlib.sha512(word.encode()).hexdigest()
sha256 = hashlib.sha256(word.encode()).hexdigest()
sha3_256 = hashlib.sha3_224(word.encode()).hexdigest()
print('md5 :' , md5)
print()
print('sha1 :' , sha1)
print()
print('sha224 :', sha224)
print()
print('blake2s :', blake2s)
print()
print('blake2b :', blake2b)
print()
print('sha3_384:', sha3_384)
print()
print('sha384 :', sha384)
print()
print('sha3_512:', sha3_512)
print()
print('sha3_224:', sha3_224)
print()
print('sha512 :', sha512)
print()
print('sha256 :', sha256)
print()
print('sha3_256:', sha3_256)
print()
return
# will check word and strip word
if arg.word is not None:
word = arg.word.strip()
word = ''.join(word)
word_hash(word)
# create lambda function for clear screen
clear = lambda: os.system('clear')
# will check command line arguments if arguments are lessthan 2 then it will give user to CLI
if len(sys.argv) < 2:
post = None
salt = None
file = None
hash_opt = None
print()
# it is always true and user will run commands
while True:
inp = input('hash > ')
inp = inp.strip(string.whitespace)
if (inp == 'help') or (inp == '?'):
print(' help : Show This Help Message And Exit')
print(' file : Add Wordlist To Create Rainbow Table')
print(' hash : Crack Hash')
print(' exit : Exit')
print(' clear: Clear Screen')
print(' word : Word Of Hash')
print(' Example : File /root/file')
print(' Example : Hash Crack ')
continue
elif 'clear' == inp:
clear()
continue
elif inp == 'exit':
exit()
elif inp == 'file':
print(' file : Add Wordlist To Create Rainbow Table')
continue
elif inp == 'hash':
print(' Example : hash Crack')
continue
elif inp == 'word':
print(' example : word Hello')
continue
if inp is not '':
inp = inp.split()
if inp[0] == 'file':
file = inp[1]
# another while loop is true because of file option
while True:
inp1 = input('hash (file) > ')
inp1 = inp1.strip(string.whitespace)
if inp1 == 'show option':
print(' OPTION VALUE')
print(' file ', file)
print(' prepend ', salt)
print(' append ', post)
continue
elif inp1 == 'run':
if os.path.isfile(file):
if post is not None:
add_data(file, post_value=post)
continue
if salt is not None:
add_data(file, salt_value=salt)
continue
else:
add_data(file)
continue
else:
print(file, 'is not file')
continue
# help options of CLI
elif inp1 == 'help' or inp1 == '?':
print(' help : Show This Help Message And Exit')
print(' file : Add Wordlist To Create Rainbow Table')
print(' pre : Prepend Salt Value')
print(' append: Append Salt Value')
print(' back : back')
print(' run : Execute')
print(' clear : Clear Screen')
continue
elif inp1 == 'back': # break this loop
break
elif inp1 == 'clear': # clear screen
clear()
continue
elif inp1 == 'append':
#print(' example : Append Hash Value')
continue
elif inp1 == 'pre':
#print(' example : salt hash value')
continue
if inp1 is not '':
inp1 = inp1.split()
if inp1[0] == 'append':
post = inp1[1]
elif inp1[0] == 'pre':
salt = inp1[1]
else:
print('Unknown Command')
elif inp1 is '':
continue
else:
print('Unknown Command')
elif inp[0] == 'hash':
fetch_data(inp[1])
continue
elif inp[0] == 'word':
word_hash(inp[1])
continue
else:
print('Unknown Command')
elif inp == '':
continue
else:
print('Unknown Command')