Last active
April 18, 2019 01:55
-
-
Save tjnel/8834536167a30047aa02d41f46d94b22 to your computer and use it in GitHub Desktop.
This script converts a Suricata fast.log file to a csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def line2csv(line): | |
print(line) | |
a = re.compile(r"([0-9]{2}\/[0-9]{2}\/20[0-9]{2})-([0-9]+\:[0-9]+\:[0-9]+\.[0-9]+)\s+\[\*\*\]\s+\[([0-9]+)\:([" | |
r"0-9]+)\:([0-9]+)\]\s+(.*)\[\*\*\]\s+\[Classification\:\s+([aA-zZ 0-9]+)\]\s+\[Priority\:\s+([" | |
r"0-9]+)\]\s+\{([aA-zZ 0-9]+)\}\s+(.*)\s+->\s(.*)") | |
results = a.match(line) | |
return results.groups(0) | |
with open('out_file.csv', 'w') as outFile: | |
outFile.write('date,time,group,sid,sev,rule_name,classification,priority,protocol,from_addr,to_addr\n') | |
with open('fast.log', 'r') as inFile: | |
for line in inFile: | |
outFile.write(','.join(str(i) for i in line2csv(line))+'\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment