This repository has been archived by the owner on Aug 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cth.py
executable file
·416 lines (388 loc) · 16.8 KB
/
cth.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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
#!/usr/bin/env python3
####################################################
# #
# Code made by @0xblackbird #
# (40e219a80dfa2239c096e18bca46fd15) :) #
# #
####################################################
from concurrent.futures import wait, FIRST_COMPLETED
from pebble import ProcessPool
from Crypto.Hash import MD2
from Crypto.Hash import MD4
from random import uniform
from datetime import date
import urllib.request
import fileinput
import argparse
import binascii
import os.path
import hashlib
import time
import json
import sys
import os
version = "2.5.7"
rows, columns = os.popen("stty size", "r").read().split()
parser = argparse.ArgumentParser(prog="cth.py", usage="./%(prog)s -H <HASH> [OPTIONS] -T <NUM> -w <WORDLIST>", description="Ultra fast hashcracking tool written in Python3", epilog="Thank you for using this tool! Please take a moment and give some feedback on the tool: @0xblackbird or be1807v@pm.me")
parser.add_argument("-H", "-hash", metavar="hash", default="", help="Your hash that you want to crack")
parser.add_argument("-w", "-wordlist", metavar="wordlist", default="/usr/share/wordlists/rockyou.txt", help="The wordlist that is going to do the job (default: \"/usr/share/wordlists/rockyou.txt\")")
parser.add_argument("-T", "-type", metavar="type", type=int, default=0, help="Specify the hash type, use \"-L/-list\" for more info (default: \"0\" (md-5))")
parser.add_argument("-o", "-output", action="store_true", default=False, help="Output the result in a text file (default: \"False\")")
parser.add_argument("-oJ", "-output-json", action="store_true", default=False, help="Output the result in JSON format (default: \"False\")")
parser.add_argument("-I", "-interactive", action="store_true", default=False, help="Go through steps instead of typing all the flags manually")
parser.add_argument("-v", "-verbose", action="store_true", default=False, help="Turn on verbosity mode (default: \"False\")")
parser.add_argument("-L", "-list", action="store_true", default=False, help="Display all the hash types and exit")
parser.add_argument("-u", "-update", action="store_true", default=False, help="Update the script to the latest version")
parser.add_argument("-V", "-version", action="version", version="%(prog)s " + version)
args = parser.parse_args()
user_hash = args.H
wordlist = args.w
hash_type = args.T
verbose = args.v
output = args.o
output_json = args.oJ
list_types = args.L
update = args.u
interactive = args.I
line = "-" * int(columns)
startTime = time.time()
class color:
PURPLE = '\033[1;35;48m'
CYAN = '\033[1;36;48m'
BLUE = '\033[1;34;48m'
ORANGE = '\033[1;38;48m'
GREEN = '\033[1;32;48m'
YELLOW = '\033[1;33;48m'
RED = '\033[1;31;48m'
BLACK = '\033[1;30;48m'
BLINK = '\033[1;6;48m'
END = '\033[1;37;0m'
def typeText(text, delay):
for i in text:
print(i, end = "")
sys.stdout.flush()
time.sleep(uniform(0, delay))
print("")
print(color.RED + """
_____ _______ _ _
/ ____|__ __| | | |
| | | | | |__| |
| | | | | __ |
| |____ | | | | | |
\_____| |_| |_| |_|
""")
sys.stdout.write("\033[F")
typeText("CRACK THE HASH", 0.035)
print(color.CYAN)
sys.stdout.write("\033[F")
typeText("@0xblackbird", 0.035)
if update == True:
file = os.path.abspath("cth.py")
url = "https://github.com/0xblackbird/cth/releases/download/v" + version + "/cth.py"
jsonFile = "https://0xblackbird.github.io/data.json"
if os.path.isfile(file) == False:
print(color.RED + "[-] Error! I could not find the script to update! Please provide the installation path:" + color.END)
file = str(input(color.BLUE + ">>> " + color.RED))
get_data = urllib.request.urlopen(jsonFile)
if get_data.getcode() == 200:
jsonData = json.loads(get_data.read())
current_version = jsonData['tools']['tool0']['version']
if current_version == version:
print(color.GREEN + "[+] You already have the latest version of CTH! v" + current_version + color.END)
sys.exit()
elif current_version != version:
with urllib.request.urlopen(url) as response, open(file, "wb") as out_file:
data = response.read()
out_file.write(data)
print(color.GREEN + "[+] CTH is successfully updated! v" + current_version + color.END)
sys.exit()
else:
print(color.RED + "[-] An error has occurred. Exiting..." + color.END)
sys.exit()
else:
print(color.RED + "[-] An error has occurred while trying to reach a JSON file. Status code: " + str(get_status.getcode()) + color.END)
if interactive == True:
question = "Please provide the hash that you want to crack: \n"
print(color.BLUE)
for i in question:
print(i, end = "")
sys.stdout.flush()
time.sleep(0.025)
user_hash = str(input(color.BLUE + ">>> " + color.RED))
if user_hash == "":
print(color.RED + "[-] No hash provided! Goodbye." + color.END)
sys.exit()
sys.stdout.write("\033[F")
question = "What type is the hash you provided? \n"
print(color.BLUE)
for i in question:
print(i, end = "")
sys.stdout.flush()
time.sleep(0.025)
hash_type = int(input(color.BLUE + ">>> " + color.RED))
sys.stdout.write("\033[F")
if hash_type == "":
hash_type = 0
question = "What wordlist do you want to use? Leave blank to use the default wordlist: \n"
print(color.BLUE)
for i in question:
print(i, end = "")
sys.stdout.flush()
time.sleep(0.025)
wordlist = str(input(color.BLUE + ">>> " + color.RED))
sys.stdout.write("\033[F")
list_menu = color.ORANGE + """Usage: ./cth.py -H <HASH> [OPTIONS] -T <NUM> -w <WORDLIST>
Hash types:
_____________________________
| | |
| 0 | MD5 |
| 1 | MD4 |
| 2 | MD2 |
| 3 | SHA1 |
| 4 | SHA-224 |
| 5 | SHA-256 |
| 6 | SHA-384 |
| 7 | SHA-512 |
| 8 | SHA3-224 |
| 9 | SHA3-256 |
| 10 | SHA3-384 |
| 11 | SHA3-512 |
| 12 | BLAKE2s256 |
| 13 | BLAKE2b512 |
| 14 | NTLM |
| 15 | Whirlpool |
| 16 | SM3 |
| 17 | RIPEMD-160 |
|______________|______________|
More comming soon! ;)""" + color.END
if len(sys.argv) == 0:
print(color.RED + "[-] Incorrect syntax!" + color.END)
sys.exit()
if list_types == True:
print(list_menu)
sys.exit()
if user_hash == "":
print(color.BLINK + color.RED + "[-] No hash provided to crack! Use \"-h\" or \"--help\" to display the help menu!" + color.END)
sys.exit()
else:
print(color.BLACK + line + color.END)
print(color.CYAN + "Hash: " + color.RED + "\"" + str(user_hash) + "\"" + color.END)
if hash_type < 0:
print(color.RED + "[-] Invalid hash-type! Use \"-list\" to display the all the hash types!" + color.END)
sys.exit()
else:
if hash_type == 0:
print(color.CYAN + "Hash type: " + color.RED + "\"MD5\"" + color.END)
elif hash_type == 1:
print(color.CYAN + "Hash type: " + color.RED + "\"MD4\"" + color.END)
elif hash_type == 2:
print(color.CYAN + "Hash type: " + color.RED + "\"MD2\"" + color.END)
elif hash_type == 3:
print(color.CYAN + "Hash type: " + color.RED + "\"SHA-1\"" + color.END)
elif hash_type == 4:
print(color.CYAN + "Hash type: " + color.RED + "\"SHA-224\"" + color.END)
elif hash_type == 5:
print(color.CYAN + "Hash type: " + color.RED + "\"SHA-256\"" + color.END)
elif hash_type == 6:
print(color.CYAN + "Hash type: " + color.RED + "\"SHA-384\"" + color.END)
elif hash_type == 7:
print(color.CYAN + "Hash type: " + color.RED + "\"SHA-512\"" + color.END)
elif hash_type == 8:
print(color.CYAN + "Hash type: " + color.RED + "\"SHA3-224\"" + color.END)
elif hash_type == 9:
print(color.CYAN + "Hash type: " + color.RED + "\"SHA3-256\"" + color.END)
elif hash_type == 10:
print(color.CYAN + "Hash type: " + color.RED + "\"SHA3-384\"" + color.END)
elif hash_type == 11:
print(color.CYAN + "Hash type: " + color.RED + "\"SHA3-512\"" + color.END)
elif hash_type == 12:
print(color.CYAN + "Hash type: " + color.RED + "\"BLAKE2s256\"" + color.END)
elif hash_type == 13:
print(color.CYAN + "Hash type: " + color.RED + "\"BLAKE2b512\"" + color.END)
elif hash_type == 14:
print(color.CYAN + "Hash type: " + color.RED + "\"NTLM\"" + color.END)
elif hash_type == 15:
print(color.CYAN + "Hash type: " + color.RED + "\"Whirlpool\"" + color.END)
elif hash_type == 16:
print(color.CYAN + "Hash type: " + color.RED + "\"SM3\"" + color.END)
elif hash_type == 17:
print(color.CYAN + "Hash type: " + color.RED + "\"RIPEMD-160\"" + color.END)
else:
print(color.RED + "[-] Invalid hash-type! Use \"-list\" to display the all the hash types!" + color.END)
sys.exit()
if wordlist == "":
wordlist = "/usr/share/wordlists/rockyou.txt"
print(color.CYAN + "Wordlist: " + color.RED + "\"" + str(wordlist) + "\"" + color.END)
print(color.BLACK + line + color.END)
else:
print(color.CYAN + "Wordlist: " + color.RED + "\"" + str(wordlist) + "\"" + color.END)
print(color.BLACK + line + color.END)
def checkwordlist():
if os.path.isfile(wordlist) == True:
print(color.ORANGE + "[+] Starting password cracking!" + color.END)
elif os.path.isfile(wordlist) == False:
print(color.RED + "[-] \"{}\" does not exist! If you think that it really exists, try checking your spelling!" .format(str(wordlist)) + color.END)
sys.exit()
else:
print(color.RED + "[-] Error!" + color.END)
sys.exit()
def readBackwards():
for line in reversed(list(open(wordlist, "r", encoding="ISO-8859-1"))):
passwd1 = line.rstrip()
if hash_type == 0: #MD5
passwd_hash = hashlib.md5(passwd1.encode()).hexdigest()
elif hash_type == 1: #MD4
passwd_hash = MD4.new(passwd1.encode()).hexdigest()
elif hash_type == 2: #MD2
passwd_hash = MD2.new(passwd1.encode()).hexdigest()
elif hash_type == 3: #SHA1
passwd_hash = hashlib.sha1(passwd1.encode()).hexdigest()
elif hash_type == 4: #SHA-224
passwd_hash = hashlib.sha224(passwd1.encode()).hexdigest()
elif hash_type == 5: #SHA-256
passwd_hash = hashlib.sha256(passwd1.encode()).hexdigest()
elif hash_type == 6: #SHA-384
passwd_hash = hashlib.sha384(passwd1.encode()).hexdigest()
elif hash_type == 7: #SHA-512
passwd_hash = hashlib.sha512(passwd1.encode()).hexdigest()
elif hash_type == 8: #SHA3-224
passwd_hash = hashlib.sha3_224(passwd1.encode()).hexdigest()
elif hash_type == 9: #SHA3-256
passwd_hash = hashlib.sha3_256(passwd1.encode()).hexdigest()
elif hash_type == 10: #SHA3-384
passwd_hash = hashlib.sha3_384(passwd1.encode()).hexdigest()
elif hash_type == 11: #SHA3-512
passwd_hash = hashlib.sha3_512(passwd1.encode()).hexdigest()
elif hash_type == 12: #BLAKE2s256
passwd_hash = hashlib.new('blake2s256', passwd1.encode()).hexdigest()
elif hash_type == 13: #BLAKE2b512
passwd_hash = hashlib.new('blake2b512', passwd1.encode()).hexdigest()
elif hash_type == 14: #NTLM
passwd_hash = hashlib.new('md4', passwd1.encode('utf-16le')).hexdigest()
elif hash_type == 15: #Whirlpool
passwd_hash = hashlib.new('whirlpool', passwd1.encode()).hexdigest()
elif hash_type == 16: #SM3
passwd_hash = hashlib.new('sm3', passwd1.encode()).hexdigest()
elif hash_type == 17: #RIPEMD-160
passwd_hash = hashlib.new('ripemd160', passwd1.encode()).hexdigest()
else:
print(color.RED + "[-] Invalid hash type...Exiting!" + color.END)
sys.exit()
if verbose == True:
print(color.BLACK + "Trying {}" .format(str(repr(passwd1))) + color.END)
if user_hash == passwd_hash:
print(color.GREEN + "[+] Hash cracked! Results: " + color.RED + str(line) + color.END)
endTime = time.time()
deltaTime = endTime - startTime
sys.stdout.write("\033[F")
print(color.GREEN + "[+] Cracking finished in " + color.RED + str(format(deltaTime, ".3f")) + color.END + color.GREEN + "s" + color.END)
if output == True:
output_text = "\nDate: {0}\nHash: {1}\nCracked hash: {2}\nCracking time: {3}\nWordlist: {4}" .format(str(today.strftime("%d/%m/%Y")), str(user_hash), str(line).replace("\n", ""), format(deltaTime, ".3f"), str(wordlist))
print(output_text, file=open("results.txt", "a"))
print(color.ORANGE + "Results saved successfully in ./results.txt!" + color.END)
if output_json == True:
results = {
"date": str(today.strftime("%d/%m/%Y")),
"hash": str(user_hash),
"crackedHash": str(line).replace("\n",""),
"crackingTime": format(deltaTime, ".3f"),
"wordlist": str(wordlist)
}
results_json = json.dumps(results, indent=2)
print(results_json, file=open("results.json", "a"))
print(color.ORANGE + "Results saved successfully in ./results.json!" + color.END)
sys.exit()
print(color.RED + "[-] Hash not found! Maybe another wordlist would help." + color.END)
sys.exit()
def readNormal():
with open(wordlist, "r", encoding="ISO-8859-1") as FileObj:
for line in FileObj:
passwd1 = line.replace("\n", "")
if hash_type == 0: #MD5
passwd_hash = hashlib.md5(passwd1.encode()).hexdigest()
elif hash_type == 1: #MD4
passwd_hash = MD4.new(passwd1.encode()).hexdigest()
elif hash_type == 2: #MD2
passwd_hash = MD2.new(passwd1.encode()).hexdigest()
elif hash_type == 3: #SHA1
passwd_hash = hashlib.sha1(passwd1.encode()).hexdigest()
elif hash_type == 4: #SHA-224
passwd_hash = hashlib.sha224(passwd1.encode()).hexdigest()
elif hash_type == 5: #SHA-256
passwd_hash = hashlib.sha256(passwd1.encode()).hexdigest()
elif hash_type == 6: #SHA-384
passwd_hash = hashlib.sha384(passwd1.encode()).hexdigest()
elif hash_type == 7: #SHA-512
passwd_hash = hashlib.sha512(passwd1.encode()).hexdigest()
elif hash_type == 8: #SHA3-224
passwd_hash = hashlib.sha3_224(passwd1.encode()).hexdigest()
elif hash_type == 9: #SHA3-256
passwd_hash = hashlib.sha3_256(passwd1.encode()).hexdigest()
elif hash_type == 10: #SHA3-384
passwd_hash = hashlib.sha3_384(passwd1.encode()).hexdigest()
elif hash_type == 11: #SHA3-512
passwd_hash = hashlib.sha3_512(passwd1.encode()).hexdigest()
elif hash_type == 12: #BLAKE2s256
passwd_hash = hashlib.new('blake2s256', passwd1.encode()).hexdigest()
elif hash_type == 13: #BLAKE2b512
passwd_hash = hashlib.new('blake2b512', passwd1.encode()).hexdigest()
elif hash_type == 14: #NTLM
passwd_hash = hashlib.new('md4', passwd1.encode('utf-16le')).hexdigest()
elif hash_type == 15: #Whirlpool
passwd_hash = hashlib.new('whirlpool', passwd1.encode()).hexdigest()
elif hash_type == 16: #SM3
passwd_hash = hashlib.new('sm3', passwd1.encode()).hexdigest()
elif hash_type == 17: #RIPEMD-160
passwd_hash = hashlib.new('ripemd160', passwd1.encode()).hexdigest()
else:
print(color.RED + "[-] Invalid hash type...Exiting!" + color.END)
sys.exit()
if verbose == True:
print(color.BLACK + "Trying {}" .format(str(repr(passwd1))) + color.END)
if user_hash == passwd_hash:
print(color.GREEN + "[+] Hash cracked! Results: " + color.RED + str(line) + color.END)
endTime = time.time()
deltaTime = endTime - startTime
sys.stdout.write("\033[F")
print(color.GREEN + "[+] Cracking finished in " + color.RED + str(format(deltaTime, ".3f")) + color.END + color.GREEN + "s" + color.END)
if output == True:
output_text = "\nDate: {0}\nHash: {1}\nCracked hash: {2}\nCracking time: {3}\nWordlist: {4}" .format(str(today.strftime("%d/%m/%Y")), str(user_hash), str(line).replace("\n", ""), format(deltaTime, ".3f"), str(wordlist))
print(output_text, file=open("results.txt", "a"))
print(color.ORANGE + "Results saved successfully in ./results.txt!" + color.END)
if output_json == True:
results = {
"Date": str(today.strftime("%d/%m/%Y")),
"hash": str(user_hash),
"crackedHash": str(line).replace("\n", ""),
"crackingTime": format(deltaTime, ".3f"),
"wordlist": str(wordlist)
}
results_json = json.dumps(results, indent=2)
print(results_json, file=open("results.json", "a"))
print(color.ORANGE + "Results saved successfully in ./results.json!" + color.END)
sys.exit()
print(color.RED + "[-] Hash not found! Maybe another wordlist would help." + color.END)
sys.exit()
try:
if __name__ == "__main__":
startTime = time.time()
today = date.today()
checkwordlist()
with ProcessPool(max_workers=2) as pool:
f1 = pool.schedule(readNormal)
f2 = pool.schedule(readBackwards)
done, not_done = wait((f1, f2), return_when=FIRST_COMPLETED)
for f in not_done:
f.cancel()
except KeyboardInterrupt:
print(color.RED + "\n[-] \"Ctrl+^C\" detected! Exiting..." + color.END)
sys.exit()
except IndexError:
print(color.RED + "\n[-] Index Error: syntax does not make sens to me! Please check that out!" + color.END)
sys.exit()
except SyntaxError:
print(color.RED + "\n[-] Syntax error! Please kindly check what you executed." + color.END)
sys.exit()
except TypeError:
print(color.RED + "\n[-] Wrong value type given! Please kindly check what values you gave in." + color.END)
sys.exit()