forked from s0md3v/Hash-Buster
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.py
More file actions
178 lines (156 loc) · 6.4 KB
/
Copy pathhash.py
File metadata and controls
178 lines (156 loc) · 6.4 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
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
#!/usr/bin/env python3
import re
import urllib3
import os
import argparse
import concurrent.futures
from database import Database
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
parser = argparse.ArgumentParser()
parser.add_argument('-s', help='hash', dest='hash')
parser.add_argument('-f', help='file containing hashes', dest='file')
parser.add_argument('-d', help='directory containing hashes', dest='dir')
parser.add_argument('-t', help='number of threads', dest='threads', type=int)
parser.add_argument('-m', help='force hash type (md5, ntlm, sha1, sha256, sha384, sha512)',
dest='type', choices=['md5', 'ntlm', 'sha1', 'sha256', 'sha384', 'sha512'])
args = parser.parse_args()
#flag
found=0
hashv = ''
#Colors and shit like that
end = '\033[0m'
red = '\033[91m'
green = '\033[92m'
white = '\033[97m'
dgreen = '\033[32m'
yellow = '\033[93m'
back = '\033[7;91m'
run = '\033[97m[~]\033[0m'
que = '\033[94m[?]\033[0m'
bad = '\033[91m[-]\033[0m'
info = '\033[93m[!]\033[0m'
good = '\033[92m[+]\033[0m'
cwd = os.getcwd()
directory = args.dir
file = args.file
thread_count = args.threads or 4
if directory:
if directory[-1] == '/':
directory = directory[:-1]
print ('''\033[1;97m_ _ ____ ____ _ _ ___ _ _ ____ ___ ____ ____
|__| |__| [__ |__| |__] | | [__ | |___ |__/
| | | | ___] | | |__] |__| ___] | |___ | \\ %sv3.0\033[0m\n''' % red)
md5 = [Database.weakpass, Database.md5decrypt, Database.gromweb, Database.md5hashing, Database.crackcrypt]
ntlm = [Database.weakpass, Database.md5decrypt]
sha1 = [Database.weakpass, Database.md5decrypt, Database.gromweb, Database.md5hashing, Database.crackcrypt]
sha256 = [Database.weakpass, Database.md5decrypt, Database.md5hashing, Database.crackcrypt]
sha384 = [Database.md5decrypt, Database.md5hashing]
sha512 = [Database.md5decrypt, Database.md5hashing, Database.crackcrypt]
# Maps a forced hash type (-m) to its service list. NTLM and MD5 share the
# same 32-char length, so it cannot be auto-detected -- use -m ntlm to force it.
apis = {
'md5': md5, 'ntlm': ntlm, 'sha1': sha1,
'sha256': sha256, 'sha384': sha384, 'sha512': sha512,
}
LABELS = {'md5': 'MD5', 'ntlm': 'NTLM', 'sha1': 'SHA1',
'sha256': 'SHA-256', 'sha384': 'SHA-384', 'sha512': 'SHA-512'}
def lookup(api_list, hashvalue, hashtype):
"""Run each service for a hash type, returning the first plaintext found."""
for api in api_list:
r = api(hashvalue, hashtype)
if r:
return r
return False
def crack(hashvalue):
"""
Return a dict mapping a hash-type label -> cracked plaintext for every
match found, or False if nothing was cracked. A 32-char hash is looked up
as BOTH md5 and ntlm (same length, indistinguishable) so both results are
reported. -m forces a single type.
"""
# -m forces the hash type (e.g. ntlm, which is 32 chars like md5).
if args.type:
if not file:
print ('%s Hash function : %s (forced)' % (info, LABELS[args.type]))
r = lookup(apis[args.type], hashvalue, args.type)
return {LABELS[args.type]: r} if r else False
length = len(hashvalue)
if length == 32:
if not file:
print ('%s Hash function : MD5 / NTLM' % info)
# 32-char hashes are ambiguous (md5 vs ntlm) -- report both attempts.
results = {LABELS[ht]: lookup(apis[ht], hashvalue, ht) for ht in ('md5', 'ntlm')}
return results if any(results.values()) else False
elif length in (40, 64, 96, 128):
ht = {40: 'sha1', 64: 'sha256', 96: 'sha384', 128: 'sha512'}[length]
if not file:
print ('%s Hash function : %s' % (info, LABELS[ht]))
r = lookup(apis[ht], hashvalue, ht)
return {LABELS[ht]: r} if r else False
else:
if not file:
print ('%s This hash type is not supported.' % bad)
quit()
return False
def display_result(res):
"""Multi-line rendering for a single hash on screen (shows every attempt)."""
if len(res) == 1:
return next(iter(res.values()))
return '\n'.join('%s : %s' % (label, plain if plain else '(not found)')
for label, plain in res.items())
def inline_result(res):
"""One-line rendering for file output / multi-hash mode (found results only)."""
found = [(label, plain) for label, plain in res.items() if plain]
if len(res) == 1:
return found[0][1] if found else ''
return ', '.join('%s (%s)' % (plain, label) for label, plain in found)
result = {}
def threaded(hashvalue):
resp = crack(hashvalue)
if resp:
line = inline_result(resp)
print (hashvalue + ' : ' + line)
result[hashvalue] = line
def grepper(directory):
os.system('''grep -Pr "[a-f0-9]{128}|[a-f0-9]{96}|[a-f0-9]{64}|[a-f0-9]{40}|[a-f0-9]{32}" %s --exclude=\\*.{png,jpg,jpeg,mp3,mp4,zip,gz} |
grep -Po "[a-f0-9]{128}|[a-f0-9]{96}|[a-f0-9]{64}|[a-f0-9]{40}|[a-f0-9]{32}" >> %s/%s.txt''' % (directory, cwd, directory.split('/')[-1]))
print ('%s Results saved in %s.txt' % (info, directory.split('/')[-1]))
def miner(file):
lines = []
found = set()
with open(file, 'r') as f:
for line in f:
lines.append(line.strip('\n'))
for line in lines:
matches = re.findall(r'[a-f0-9]{128}|[a-f0-9]{96}|[a-f0-9]{64}|[a-f0-9]{40}|[a-f0-9]{32}', line)
if matches:
for match in matches:
found.add(match)
print ('%s Hashes found: %i' % (info, len(found)))
threadpool = concurrent.futures.ThreadPoolExecutor(max_workers=thread_count)
futures = (threadpool.submit(threaded, hashvalue) for hashvalue in found)
for i, _ in enumerate(concurrent.futures.as_completed(futures)):
if i + 1 == len(found) or (i + 1) % thread_count == 0:
print('%s Progress: %i/%i' % (info, i + 1, len(found)), end='\r')
def single(args):
result = crack(args.hash)
if result:
print (display_result(result))
else:
print ('%s Hash was not found in any database.' % bad)
if directory:
try:
grepper(directory)
except KeyboardInterrupt:
pass
elif file:
try:
miner(file)
except KeyboardInterrupt:
pass
with open('cracked-%s' % file.split('/')[-1], 'w+') as f:
for hashvalue, cracked in result.items():
f.write(hashvalue + ':' + cracked + '\n')
print ('%s Results saved in cracked-%s' % (info, file.split('/')[-1]))
elif args.hash:
single(args)