forked from CyberKnight00/RainbowHash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RainbowHash.py
361 lines (316 loc) · 14.3 KB
/
RainbowHash.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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#!/usr/bin/python3
# importing required modules
import os
import hashlib
import sqlite3
import string
import argparse
import sys
import binascii
# used argparse module for creating help menu
parser = argparse.ArgumentParser(description="RainbowHash is Great Tool for recover Hashe.It Supports Hash such as md5, sha1, sha256, sha512, and many more. It is alsocapable of genrate Rainbow Table with Wordlist file as input.")
parser.add_argument('-f', '--file', help = 'File To Create Rainbow Table', nargs = 1)
parser.add_argument('-p', '--pre', help = 'Prepend Salt Value', nargs = 1)
parser.add_argument('-a', '--app', help = 'Append Salt Value', nargs = 1)
parser.add_argument('-H', '--hash', help = 'Hash to recover', nargs = 1)
parser.add_argument('-v', '--verbose', help = 'Verbose = True', action='store_true')
parser.add_argument('-w', '--word', help = 'Generate Hashe For A single string')
parser.add_argument('-c', '--check', help = 'Ignore repeated words in Wordlist, slow but effective', action='store_true')
# created argparse object to take command line argument
arg = parser.parse_args()
# used os module for checking directory exists or not, Create rainbow_Database directory if directory not exists
if os.path.isdir('.rainbow_Database'):
os.chdir('.rainbow_Database/')
else:
os.mkdir('.rainbow_Database')
os.chdir('.rainbow_Database/')
# used sqlite3 module for creating database of Hashes
sql = sqlite3.connect('Database.db')
sql.execute('create table if not exists Hashes_Table(name text, md5 hash, sha1 hash, sha224 hash, blake2s hash, blake2b hash, sha3_384 hash, sha384 hash, sha3_512 hash, sha3_224 hash, sha512 hash, sha256 hash, sha3_256 hash, ntlm hash)')
sql.commit()
# Function fetch_from_database takes one argument 'ha_sh' to recover hash
def fetch_from_database(ha_sh):
cursor = sql.execute('select * from Hashes_Table')
sql.commit()
for row in cursor:
if ha_sh == row[1]: # Is it in md5
print('Detected ALGORITHM (md5) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[2]: # Is it in sha1
print('Detected ALGORITHM (sha1) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[3]: # Is it in sha224
print('Detected ALGORITHM (sha224) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[4]: # Is it in blake2s
print('Detected ALGORITHM (blake2s) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[5]: # Is it in blake2b
print('Detected ALGORITHM (blake2b) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[6]: # Is it in sha3_384
print('Detected ALGORITHM (sha3_384) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[7]: # Is it in sha384
print('Detected ALGORITHM (sha384) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[8]: # Is it in sha3_512
print('Detected ALGORITHM (sha3_512) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[9]: # Is it in sha3_224
print('Detected ALGORITHM (sha3_224) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[10]: # Is it in sha512
print('Detected ALGORITHM (sha512) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[11]: # Is it in sha256
print('Detected ALGORITHM( (sha256) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[12]: # Is it in sha3_256
print('Detected ALGORITHM (sha3_256) : ', ha_sh, '\nword : ', row[0], )
return
elif ha_sh == row[13]: #Is it in ntlm
print('Detected ALGORITHM ntlm : ', ha_sh, '\nword : ', row[0], )
return
else:
print('Hash Not Found : Check your Hash String or update Database')
def check_me(ck_word):
cursor = sql.execute('select name from Hashes_Table')
sql.commit()
for row in cursor:
if ck_word == row[0]: # Is it in Database
return True
else : return False
def add_data(word_file, salt_value=None, post_value=None, rep = 0):
n = 0
# it will create rainbow table with given file
fp = open(word_file, '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 # Prepend the salt value
if post_value is not None:
word += post_value # append the salt value
if arg.verbose:
print(word)
if rep == 1:
chk = check_me(word)
if rep == 0 :
chk = False
if chk is False:
# 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()
ntlm = (binascii.hexlify(hashlib.new('md4', word.encode('utf-16le')).digest())).decode()
sql.execute('insert into Hashes_Table(name, md5 , sha1, sha224 , blake2s , blake2b , sha3_384 , sha384 , sha3_512, '
'sha3_224, sha512, sha256, sha3_256, ntlm ) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)', (word, md5, sha1,
sha224, blake2s,
blake2b, sha3_384,
sha384, sha3_512,
sha3_224, sha512,
sha256, sha3_256, ntlm))
except Exception:
print(Exception)
sql.commit()
print('WORD: ', n)
# stored user arguments to variable
if arg.file is not None:
file_name = ''.join(arg.file)
chk = 0
if arg.check:
chk = 1
if os.path.isfile(file_name):
if arg.pre is not None:
salt = ''.join(arg.pre)
add_data(file_name, salt_value = salt, rep = chk)
elif arg.app is not None:
post = ''.join(arg.ap)
add_data(file_name, post_value = post, rep = chk)
else:
add_data(file_name, rep = chk)
else:
print("file doesn't exist")
# stored user arguments to variable
if arg.hash is not None:
hash1 = arg.hash
hash1 = ''.join(hash1)
fetch_from_database(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()
ntlm = (binascii.hexlify(hashlib.new('md4', word.encode('utf-16le')).digest())).decode()
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()
print('ntlm :', ntlm)
print()
# check if word alrady exists into database
chk = check_me(word)
if chk is False :
# Store all hashes into database
choice = input ("Enter y to store word in database : ")
if choice == 'y':
sql.execute('insert into Hashes_Table(name, md5 , sha1, sha224 , blake2s , blake2b , sha3_384 , sha384 , sha3_512, sha3_224, sha512, sha256, sha3_256, ntlm) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)', ( word, md5, sha1, sha224, blake2s, blake2b, sha3_384, sha384, sha3_512, sha3_224, sha512, sha256, sha3_256, ntlm))
sql.commit()
print ("word : "+word)
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 a CLI
if len(sys.argv) < 2:
post = None
salt = None
file = None
hash_opt = None
print("RainbowHash is a Great Tool For Cracking Hashes one at a time.\nIt Supports Hash such as md5, sha1, sha223, sha3_384, sha384, sha3_224, sha512, sha256, sha3_256, blake2s, blake2b, ntlm \n")
# wile loop condition always true
while True:
inp = input('Rhash > ')
inp = inp.strip(string.whitespace)
if (inp == 'help') or (inp == '?'):
print(' help : Show all Command')
print(' file : Add Wordlist To Create Rainbow Table')
print(' hash : Recover Hash')
print(' exit : Exit CLI')
print(' clear: Clear the Screen')
print(' word : Single word to genrate Rainbow Table')
print(' Example : File /root/RainbowHash/pass')
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 Hash_String')
continue
elif inp == 'word':
print(' example : word RainbowMe')
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('Rhash > 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':
# chk = 1 to avoide dublicity
chk = 1
if os.path.isfile(file):
if post is not None:
add_data(file, post_value=post, rep = chk)
continue
if salt is not None:
add_data(file, salt_value=salt, rep = chk)
continue
else:
add_data(file, rep = chk)
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 To Rainbow Table')
print(' app: Append Salt Value To Rainbow Table')
print(' back : Back To Initial')
print(' run : Execute')
print(' clear : Clear The Screen')
continue
elif inp1 == 'back': # break this loop
break
elif inp1 == 'clear': # clear screen
clear()
continue
elif inp1 == 'app':
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] == 'app':
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_from_database(inp[1])
continue
elif inp[0] == 'word':
word_hash(inp[1])
continue
else:
print('Unknown Command')
elif inp == '':
continue
else:
print('Unknown Command')