-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathklv.py
243 lines (209 loc) · 10.8 KB
/
klv.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/usr/bin/python
############################################################################
# #
# Name: Kismet Log Viewer (KLV) v2 #
# #
# Description: KLV accepts one or more Kismet .netxml files, summarizes #
# & de-duplicatesthe data, and creates a readable summary #
# in either html or csv format. #
# #
# Usage: ./klv.py -h #
# ./klv.py /root/kismet-logs/ #
# ./klv.py -t csv /root/kismet-logs/ #
# #
# Requirements: Python #
# one or more Kismet .netxml log files #
# #
# Website: http://klv.professionallyevil.com #
# Author: Nathan Sweaney - [email protected] #
# Date: July 9, 2013 #
# #
# #
############################################################################
import os
import sys
import datetime
import xml.etree.ElementTree as ET
import argparse
# variables
oui_file = open('oui.txt')
network_matrix = []
bssid_list = []
log_file_list = []
now = datetime.datetime.now()
# used on the HTML page output
timestamp = now.strftime("%Y-%m-%d %H:%M:%S")
# process command-line arguments
parser = argparse.ArgumentParser(description='Kismet Log Viewer v2.01 creates a readable summary of Kismet .netxml log files.')
parser.add_argument('log_file_path', metavar='LogFilePath',
help='A directory containing one or more Kismet .netxml log files. KLV will process all .netxml files in the directory but will ignore all other files.')
parser.add_argument('-o', default="html", choices=['html', 'csv'],
help='Output format (default: html)')
parser.add_argument('-s', default="essid", choices=['essid', 'security', 'bssid', 'manufacturer', 'clients', 'packets'],
help='Sort output (default: essid) (***unfinished***)')
parser.add_argument('-g', default="no", choices=['yes', 'no'],
help='Group by essid (default: no) (***unfinished***)')
parser.add_argument('-t', default="beacon", nargs=1, choices=['beacon', 'request', 'response'],
help='Show network types (default: beacon only) (***unfinished***)')
args = parser.parse_args()
output_format = args.o
# add the ending slash in case it was left off
if args.log_file_path[-1:] <> "/":
args.log_file_path = args.log_file_path + "/"
def main():
# cycle through each file in the directory
files_in_dir = os.listdir(args.log_file_path)
for file_in_dir in files_in_dir:
if file_in_dir[-7:] == ".netxml":
print "Adding file: ", file_in_dir
log_file_list.append(file_in_dir)
xml_tree = ET.parse(args.log_file_path + file_in_dir)
xml_root = xml_tree.getroot()
# loop through each XML node of type "wireless-network"
for network in xml_root.findall('wireless-network'):
network_type = network.get('type')
# ignoring probes right now
if network_type <> 'probe':
network_essid = ""
network_encryption = ""
network_bssid = ""
network_manufacturer = ""
network_oui = ""
for network_detail in network:
if network_detail.tag == 'SSID':
for child_network in network_detail:
if child_network.tag == 'essid':
if child_network.attrib.get("cloaked") == "true":
cloaked = " <cloaked>"
else:
cloaked = ""
if child_network.text is None:
network_essid = "" + cloaked
else:
network_essid = child_network.text + cloaked
if child_network.tag == 'encryption':
network_encryption += child_network.text + "<br />"
if network_detail.tag == 'BSSID':
network_bssid = network_detail.text
network_oui = network_bssid[0:2] + "-" + network_bssid[3:5] + "-" + network_bssid[6:8]
oui_file.seek(0)
for line in oui_file:
if network_oui in line:
network_manufacturer = line[20:]
break
if network_bssid not in bssid_list:
bssid_list.append(network_bssid)
network_matrix.append([network_essid, network_encryption, network_bssid, network_manufacturer])
if output_format == 'html':
create_html_file(network_matrix)
elif output_format == 'csv':
create_csv_file(network_matrix)
#output to CSV
def create_csv_file(network_matrix):
summary_file = open('kismet-log-summary.csv','w')
for network in network_matrix:
summary_file.write(network[0] + ',' +network[1] + ',' +network[2] + ',' +network[3] + '\n')
summary_file.close()
# output to HTML
def create_html_file(network_matrix):
summary_file = open('kismet-log-summary.html','w')
# print header
summary_file.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n')
summary_file.write('<html>\n')
summary_file.write(' <head>\n')
summary_file.write(' <title>Kismet Log Summary</title>\n')
summary_file.write(' </head>\n')
summary_file.write(' <body>\n')
summary_file.write(' <table width="760" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#efefef">\n')
summary_file.write(' <tr>\n')
summary_file.write(' <td colspan=5 align="left">Kismet Log Summary</td>\n')
summary_file.write(' <td colspan=2 align="right"><font size="1">Created: ' + timestamp + '</font></td>\n')
summary_file.write(' </tr>\n')
summary_file.write(' <tr bgcolor="#cecece">\n')
summary_file.write(' <th></th>\n')
summary_file.write(' <th align=left><font size="1">Name (ESSID)</font></th>\n')
summary_file.write(' <th><font size="1">Security</font></th>\n')
summary_file.write(' <th><font size="1">BSSID</font></th>\n')
summary_file.write(' <th><font size="1">Manufacturer</font></th>\n')
summary_file.write(' <th><font size="1"><Clients></font></th>\n')
summary_file.write(' <th><font size="1"><Packets></font></th>\n')
summary_file.write(' </tr>\n')
row_toggle = 1
row = 1
for network in network_matrix:
# this flip-flops the background color for each row
if row_toggle == 1:
summary_file.write(' <tr>\n')
row_toggle = 0
else:
summary_file.write(' <tr bgcolor="#FFFFFF">\n')
row_toggle = 1
summary_file.write(' <td align="center"><font size="1">' + str(row) + '</font></td>\n')
summary_file.write(' <td><font size="1">' + network[0] + '</font></td>\n')
summary_file.write(' <td align="center"><font size="1">' + network[1] + '</font></td>\n')
summary_file.write(' <td align="center"><font size="1">' + network[2] + '</font></td>\n')
summary_file.write(' <td align="center"><font size="1">' + network[3] + '</font></td>\n')
summary_file.write(' <td align="center"><font size="1">' + '</font></td>\n')
summary_file.write(' <td align="center"><font size="1">' + '</font></td>\n')
summary_file.write(' </tr>\n')
row += 1
summary_file.write(' </table>\n')
summary_file.write('<br />\n')
# print list of log files
summary_file.write(' <table width="760" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#efefef">\n')
summary_file.write(' <tr bgcolor="#cecece">\n')
summary_file.write(' <td align="center">Log files included:</td>\n')
summary_file.write(' </tr>\n')
row_toggle = 1
for log_file in log_file_list:
# this flip-flops the background color for each row
if row_toggle == 1:
summary_file.write(' <tr>\n')
row_toggle = 0
else:
summary_file.write(' <tr bgcolor="#FFFFFF">\n')
row_toggle = 1
summary_file.write(' <td align="center"><font size="1">' + log_file + '</font></td>\n')
summary_file.write(' </tr>\n')
summary_file.write(' </table>\n')
# print footer
summary_file.write('<br />\n')
summary_file.write(' <table width="760" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#efefef">\n')
summary_file.write(' <tr>\n')
summary_file.write(' <td></td>\n')
summary_file.write(' </tr>\n')
summary_file.write(' <tr bgcolor="#FFFFFF">\n')
summary_file.write(' <td align="center"><font size="1">Kismet Log Viewer v2.01 - written by <a href="mailto:[email protected]">Nathan Sweaney</a></font></td>\n')
summary_file.write(' </tr>\n')
summary_file.write(' <tr>\n')
summary_file.write(' <td></td>\n')
summary_file.write(' </tr>\n')
summary_file.write(' </table>\n')
summary_file.write(' </body>\n')
summary_file.write('</html>\n')
summary_file.close()
main()
"""
Todo:
* add client data
- To start, just summarize the number of clients for each network.
* add packet data
- Count of packets seen on each network
* better handling of wireless security - currently only works well for html
- Maybe use bit counting to keep track of types, then handle output in the output functions.
* add options for sorting
* add option to group BSSIDs
- effectively de-duplicating SSIDs with all BSSIDs in one table.
- not sure how this looks in CSV format
* add option to show only specific network types
- do probe requests & responses need additional information?
* check to see if summary file exists before creating
* name summary file with timestamp
* allow input of specific files, not just a folder
* cool stylesheets
* gracefully handle missing oui.txt file
* gracefully handle no .netxml files
* download updated oui.txt file?
* Support GPS info
* create variable for version number instead of spreading it through code
"""