-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconverthound.py
More file actions
169 lines (130 loc) · 6.59 KB
/
converthound.py
File metadata and controls
169 lines (130 loc) · 6.59 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
#!/usr/bin/python3
import sys
import os
import argparse
import json
from zipfile import ZipFile
dashline = "-" * 75
def color(text):
if text.startswith('[+]'):
return "\033[%d;3%dm%s\033[0m" % (0, 2, text)
if text.startswith('[-]'):
return "\033[%d;3%dm%s\033[0m" % (0, 1, text)
if text.startswith('[*]'):
return "\033[%d;3%dm%s\033[0m" % (0, 3, text)
def banner():
print(r"""
_____ __ __ __ __
/ ___/__ ___ _ _____ ____/ /_/ // /__ __ _____ ___/ /
/ /__/ _ \/ _ \ |/ / -_) __/ __/ _ / _ \/ // / _ \/ _ /
\___/\___/_//_/___/\__/_/ \__/_//_/\___/\_,_/_//_/\_,_/
author: Cory Wolff <OGloki aka visnet
aka iwaslokibeforeallofthesemovies
aka the '84 kid>
company: Layer 8 <layer8security.com>
""")
print(dashline + "\n")
def python_check():
if sys.version_info.major != 3:
print(color("[-] Please run with Python 3. Python 2 is ded."))
exit()
def create_computers_xml(filename_prefix, raw_json):
data = json.loads(raw_json)
new_file_name = './converthound/' + filename_prefix + '_computers.xml'
new_file = open(new_file_name, "w")
xml_header = ['<?xml version="1.0"?><?xml-stylesheet href="file:///usr/local/bin/../share/nmap/nmap.xsl" type="text/xsl"?><!-- Nmap 5.59BETA3 scan initiated Fri Sep 9 18:33:41 2011 as:nmap -T4 -A -p 1-1000 -oX - scanme.nmap.org --><nmaprun scanner="nmap" args="nmap -T4 -A -p 1-1000 -oX - scanme.nmap.org" start="1315618421" startstr="Fri Sep 9 18:33:41 2011" version="5.59BETA3" xmloutputversion="1.03"><scaninfo type="syn" protocol="tcp" numservices="1000" services="1-1000"/><verbose level="0"/><debugging level="0"/>']
new_file.writelines(xml_header)
for c in data['computers']:
hostname = c['Properties']['name']
os = c['Properties']['operatingsystem'] or "n/a"
new_host = ['<host starttime="1315618421" endtime="1315618434">',
'<status state="up" reason="echo-reply"/>',
'<address addr="' + hostname +'" addrtype="ipv4"/>',
'<hostnames>',
'<hostname name="' + hostname + '" type="FQDN"/>',
'</hostnames>',
'<ports>',
'<extraports state="closed" count="997">',
'<extrareasons reason="resets" count="997"/>',
'</extraports>',
'</ports>',
'<os>',
'<portused state="closed" proto="tcp" portid="1"/>',
'<portused state="closed" proto="udp" portid="31289"/>',
'<osclass type="general purpose" vendor="Microsoft" osfamily="Windows" accuracy="100">',
'</osclass>',
'<osmatch name="' + os + '" accuracy="100" line="39278"/>',
'</os>',
'<uptime seconds="23450" lastboot="Fri Sep 9 12:03:04 2011"/>',
'<distance value="11"/>',
'<times srtt="26517" rttvar="19989" to="106473"/>',
'</host>']
new_file.writelines(new_host)
xml_footer = ['<runstats><finished time="1315618434" timestr="Fri Sep 9 18:33:54 2011" elapsed="13.66" summary="Nmap done at Fri Sep 9 18:33:54 2011; 1 IP address (1 host up) scanned in 13.66 seconds" exit="success"/><hosts up="1" down="0" total="1"/></runstats></nmaprun>']
new_file.writelines(xml_footer)
def create_users_file(filename_prefix, raw_json):
data = json.loads(raw_json)
new_file_name = './converthound/' + filename_prefix + '_users.csv'
new_file = open(new_file_name, "w")
new_file.writelines(['display_name, user_name, domain, email, title, home_directory\n'])
for u in data['users']:
new_user = str( u['Properties']['displayname'] or "none") + ',' + \
str( u['Properties']['name'] or "none" ) + ',' + \
str( u['Properties']['domain'] or "none" ) + ',' + \
str( u['Properties']['email'] or "none" ) + ',' + \
str( u['Properties']['title'] or "none" ) + ',' + \
str( u['Properties']['homedirectory'] or "none" ) + '\n'
new_file.writelines(new_user)
#
#
# Start of class
#
#
class ConvertHound(object):
def __init__(self):
parser = argparse.ArgumentParser(usage='''converthound.py <command> [<args>]
Possible Commands:
<convert> // Convert a Bloodhound computers.json to nmap XML
Try converthound.py <command> -h for help with a particular command.
''')
parser.add_argument('command', help='Command to run')
args = parser.parse_args(sys.argv[1:2])
if not hasattr(self, args.command):
print (color('[-] Unrecognized command'))
parser.print_help()
exit(1)
# use dispatch pattern to invoke method with same name
getattr(self, args.command)()
def convert(self):
parser = argparse.ArgumentParser(description='Convert a Bloodhound zip file to multiple output files.')
parser.add_argument('zipfile', type=str)
args = parser.parse_args(sys.argv[2:])
filename_prefix = args.zipfile.split("_")[0]
if not (args.zipfile.endswith('.zip')):
print(color('[-] You sure this is a zip file?'))
exit()
if not os.path.isdir('./converthound'):
os.mkdir('converthound')
try:
print(color("[+] Reading zip file..."))
with ZipFile(args.zipfile) as bloodzip:
files = bloodzip.namelist()
for f in files:
if "computers" in f:
print(color('[+] Creating computers file...'))
computers_file = bloodzip.read(f)
create_computers_xml(filename_prefix, computers_file)
elif "users" in f:
print(color('[+] Creating users file...'))
users_file = bloodzip.read(f)
create_users_file(filename_prefix, users_file)
except IOError as e:
errno, strerror = e.args
print(color("[-] I/O error({0}): {1}".format(errno,strerror)))
except: #handle other exceptions such as attribute errors
print(color("[-] Unexpected error:" + sys.exc_info()[0]))
pass
if __name__ == '__main__':
banner()
python_check()
ConvertHound()