Script to read from CSV file and write to Syslog in CEF Format
Sample Python script that opens a CSV file and writes the values in CEF format to the local Syslog file on a Linux server. Designed to be used with this post.
#!/usr/bin/python
## Simple Python script designed to read a CSV file and write the values to the local Syslog file in CEF format.
## Frank Cardinale, April 2020
## Importing the libraries used in the script
import syslog
import csv
with open('sample_malicious_IPs.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter=',')
for row in readCSV:
#Creating a value that will be used to write to the Syslog file. Rows added to applicable CEF fields.
syslog_message = "CEF:0|" + row[0] + "|" + row[1] + "|1.0|1000|ThreatIntelFeed|10|src=" + row[2]
#Writing the event to the Syslog file.
syslog.openlog(facility=syslog.LOG_LOCAL7)
syslog.syslog(syslog.LOG_NOTICE, syslog_message)