-
Notifications
You must be signed in to change notification settings - Fork 15
/
Convert-Invoke-Kerberoast.py
66 lines (59 loc) · 2.06 KB
/
Convert-Invoke-Kerberoast.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
#!/usr/bin/python
import argparse
import os
import io
import re
def format_Data(fHandle):
fh = io.open(fHandle, 'r')
SamAccountName = ''
DistinguishedName = ''
Hash = ''
Hashes = []
try:
for line in fh:
#Grab the SamAccountName
if "SamAccountName" in line:
stuff = line.split(':')
SamAccountName = stuff[1].strip()
#Grab the DistinguishedName
if "DistinguishedName" in line:
stuff = line.split(':')
stuff = line.split(',')
DistinguishedName = "{0}.{1}".format(stuff[-2].strip().replace('DC=',''),stuff[-1].strip().replace('DC=',''))
#Grab Hash Line
if "Hash" in line:
stuff = line.split(' :')
Hash += stuff[1].strip()
#Grab Hash Line
if " " in line:
Hash += line.strip()
if line == '\n':
Hashes.append(re.sub(r'\*.*\*',"*{0}${1}$spn*$".format(SamAccountName,DistinguishedName), Hash))
SamAccountName = ''
DistinguishedName = ''
Hash = ''
pass
except:
pass
return Hashes
parser = argparse.ArgumentParser(description='Parser of Kerberoast output from Invoke-Kerberoast')
parser.add_argument('-f', action="store", dest="inputHandle", required=True)
parser.add_argument('-w', action="store", dest="outputHandle")
parsed = parser.parse_args()
if(os.path.isfile(parsed.inputHandle)):
print("Opening file: {0}").format(parsed.inputHandle)
output = format_Data(parsed.inputHandle)
if parsed.outputHandle:
fOutput = open(parsed.outputHandle, 'w')
for element in output:
fOutput.write(element)
fOutput.write('\n')
fOutput.close()
print("Hashes written to: {0}".format(parsed.outputHandle))
else:
for element in output:
print(element)
print('\n')
else:
print("Error opening file: {0}").format(parsed.inputHandle)
exit()