Hi Doug,
Thank you for your answer!
Actually, I'm trying to get the information in realtime, the best one possible, that's why I was trying to get the alert directly from Snort into my program so nothing else is running between both.
I finally got to decrypt the binary alert to get the information I want, using a Python Script:
#! /usr/bin/env python
import os
import socket
import struct
# from src/decode.h
ALERTMSG_LENGTH = 256
SNAPLEN = 1500
def main():
s = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
# This format does NOT include the 'Event' struct which is the last element
# of the _AlertPkt struct in src/output-plugins/spo_alert_unixsock.h
# Thus, we must truncate the messages ('datain[:fmt_size]') before passing
# them to struct.unpacket()
fmt = "%ds9I%ds" % (ALERTMSG_LENGTH, SNAPLEN)
fmt_size = struct.calcsize(fmt)
try:
os.remove("logs/snort_alert")
except OSError:
pass
s.bind("logs/snort_alert")
while True:
try:
(datain, addr) = s.recvfrom(4096)
(msg, ts_sec, ts_usec, caplen, pktlen, dlthdr, nethdr, transhdr, data, val, pkt) = struct.unpack(fmt, datain[:fmt_size])
# to print the message
print(msg);
# optionally, do something with the pcap pkthdr (ts_sec + ts_usec +
# caplen + pktlen) and packet body (pkt)
# to print the ip address of the origin packet: nethdr is the offset of the network information in the packet pkt, so you need to offset in pkt to the network information + offset to the desire information and convert it.
print(struct.unpack(">I",pkt[nethdr+12:nethdr+16])[0]);
# and so on for others information
except(struct.error) as e:
print ("bad message? (msglen=%d): %s" % (len(datain), e.message))
if __name__ == '__main__':
main()