-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashcracker.py
More file actions
78 lines (63 loc) · 2.23 KB
/
Copy pathhashcracker.py
File metadata and controls
78 lines (63 loc) · 2.23 KB
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
import string, itertools, time
from utils.textStyle import C as c
from utils.crypto import hash_str
target_hash = input("Paste your hash to crack: ")
# `int(input(...) or "N")` lets empty input actually fall back to the default;
# `int(input(...)) or N` used to raise ValueError on "".
minChars = int(input("Min length: ") or "1")
maxChars = int(input("Max length: ") or "10")
lc = string.ascii_lowercase
uc = string.ascii_uppercase
dc = string.digits
pc = string.punctuation
hc = string.hexdigits.lower()
charSet = lc+uc+dc
# maxChars = int(input("Max length to try: "))
md5_len = 32
sha1_len = 40
sha256_len = 64
sha512_len = 128
hashType = None
def bruteforce(charset, minlength, maxlength):
return (''.join(candidate)
for candidate in itertools.chain.from_iterable(itertools.product(charset, repeat=i)
for i in range(minlength, maxlength + 1)))
if len(target_hash) == md5_len:
hashType = "md5"
if len(target_hash) == sha1_len:
hashType = "sha1"
if len(target_hash) == sha256_len:
hashType = "sha256"
if len(target_hash) == sha512_len:
hashType = "sha512"
if hashType == None:
print("Unable to determine hash. Exiting.")
exit()
print(f"{c.OKBLUE}Hash looks like {hashType}, attempting to crack{c.ENDC}")
start = time.time()
i = 0
for attempt in bruteforce(charSet, minChars, maxChars):
# Iter add
i += 1
# Hash the current string attempt
hex = hash_str(hashType, attempt)
# If every nth, print iter and time
if (i % 100000 == 0 and i != 0):
now = int(time.time() - start)
print(f"{c.OKCYAN}[{now}s] Try #{i} : {attempt}{c.ENDC}")
# print(f"{attempt} => {hex}")
if hex == target_hash:
now = int(time.time() - start)
found = 1
print(f"""
{c.OKGREEN}
Found string after {i} tries! Took {now} seconds.
Original hash: {target_hash}
Hash of password found: {target_hash}
Found string: {attempt}
{c.ENDC}""")
break
else:
found = 0
if found == 0:
print(f"{c.FAIL}Unable to find your string using up to {maxChars} characters from the charset {charSet}. Last attempt: {attempt}{c.ENDC}")