-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathhash_generator.py
More file actions
67 lines (59 loc) · 2.23 KB
/
hash_generator.py
File metadata and controls
67 lines (59 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
#!/usr/bin/env python3
__author__ = 'Jake Miller (@LaconicWolf)'
__date__ = '20190102'
__version__ = '0.01'
__description__ = """Reads a plain text file and hashes each line. The hashes are written
to a new file. The purpose of this tool is to generate sample hashes for testing password
cracking."""
import hashlib
import argparse
import os
def md5_hash(string_value):
"""Returns a md5 hash of the supplied string."""
return hashlib.md5(string_value.encode()).hexdigest()
def ntlm_hash(string_value):
"""Returns an ntlm hash of the supplied string."""
return hashlib.new('md4', string_value.encode('utf-16le')).hexdigest()
def main():
with open(filename, encoding="utf8", errors='ignore') as fh:
words = fh.read().splitlines()
if algo == 'md5':
hashes = [md5_hash(word) for word in words]
elif algo == 'ntlm':
hashes = [ntlm_hash(word) for word in words]
else:
hashes = ''
with open(outfile, 'w', encoding="utf8", errors='ignore') as fh:
for digest in hashes:
print(digest)
fh.write(digest + '\n')
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--filename",
help="Specify a file containing words.")
parser.add_argument("-o", "--outfile",
help="Writes the output to a specified file.")
parser.add_argument("-a", "--algorithm",
choices=('md5', 'ntlm'),
help="Selects an algorithm to generate hashes.")
args = parser.parse_args()
if not args.filename:
parser.print_help()
print("\n[-] Please specify an input file containing words (-f).\n")
exit()
else:
filename = args.filename
if not os.path.exists(filename):
print("\n[-] The file {} cannot be found or you do not have permission to open the file. Please check the path and try again\n".format(filename))
exit()
if not args.algorithm:
parser.print_help()
print("\n[-] Please specify an algorithm (-a ntlm).\n")
exit()
else:
algo = args.algorithm
if args.outfile:
outfile = args.outfile
else:
outfile = 'hashed_values.txt'
main()