-
Notifications
You must be signed in to change notification settings - Fork 39
/
merge-hashcat.py
executable file
·71 lines (49 loc) · 1.74 KB
/
merge-hashcat.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
#!/usr/bin/env python
import sys
self_name = sys.argv[0].split('/')[-1]
usage = """
%(name)s
%(underline)s
Matches passwords cracked with hashcat to their usernames.
Usage: %(name)s <user:hash file> <hash:password file>
Notes: The "hash:password" file is created by hashcat's -o option.
The "user:hash" file is easy to create using your original hashdump and
the "cut" command. An example of creating this file from hashes dumped
from a Windows domain controller follows:
cat raw_dump.txt | cut -d ':' -f 1,4 > dumped-users_hashes.txt
""" % {'name': self_name,
'underline': ('-' * len(self_name)),
}
def file_to_dict(filename, reverse=0):
'''
Takes the filename of a colon-separated file and returns a dictionary
containing the keys and values from that file.
'''
f = open(filename, 'r')
lines = [line.rstrip() for line in f.readlines()]
f.close()
output_dict = {}
for line in lines:
if ":" in line:
key = line.split(":")[0]
value = line.split(":")[1]
output_dict[key] = value
return output_dict
def dict_to_string(d):
s = ""
for key in d.keys():
s += "%s:%s\n" % (key, d[key])
return s.rstrip()
if len(sys.argv) < 3 or "-h" in sys.argv or "--help" in sys.argv:
print usage
exit()
user_hash_filename = sys.argv[1]
hash_password_filename = sys.argv[2]
user_hash = file_to_dict(user_hash_filename)
hash_password = file_to_dict(hash_password_filename)
user_password = {}
for user in user_hash.keys():
password_hash = user_hash[user]
password = hash_password.get(password_hash)
if password != None: user_password[user]=password
print dict_to_string(user_password)