Skip to content

Commit cd00e57

Browse files
authored
Merge pull request #223 from cglewis/master
more parsing for snort output
2 parents 4f87365 + 995ad0c commit cd00e57

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

snort/snort.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,44 @@ def get_path():
4848
print("No path provided: {0}, quitting".format(str(e)))
4949
return path
5050

51+
def parse_snort(output):
52+
lines = output.split('\n')
53+
keep_lines = False
54+
good_lines = []
55+
for line in lines:
56+
if line.startswith('Commencing packet processing'):
57+
keep_lines = True
58+
continue
59+
if keep_lines:
60+
good_lines.append(line)
61+
62+
groups = {}
63+
i = 0
64+
title = None
65+
# remove last two lines for 'snort exiting'
66+
while i < len(good_lines)-2:
67+
if good_lines[i].startswith('==='):
68+
if (good_lines[i+1].startswith('===') or
69+
good_lines[i+1].startswith('Snort exiting') or
70+
good_lines[i+1].startswith('Run time for packet') or
71+
good_lines[i+1].startswith('Memory usage summary') or
72+
good_lines[i+1].startswith('Packet I/O Totals')):
73+
i += 1
74+
continue
75+
title = good_lines[i+1].strip()
76+
groups[title] = []
77+
i += 2
78+
continue
79+
if title:
80+
groups[title].append(good_lines[i])
81+
i += 1
82+
83+
return groups
84+
85+
def parse_alerts(alerts):
86+
alerts = alerts.split('\n\n')
87+
return {'Alerts': alerts}
88+
5189
def run_tool(path):
5290
output = ''
5391
alerts = ''
@@ -58,6 +96,8 @@ def run_tool(path):
5896
except Exception as e:
5997
print(str(e))
6098

99+
output = parse_snort(output)
100+
alerts = parse_alerts(alerts)
61101
print(output)
62102
print(alerts)
63103
return output, alerts

0 commit comments

Comments
 (0)