You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Zeek Conn data to calculate bandwidth totals per host per hour
A SIEM is a very expensive calculator - perform calculations upstream and send the results to the reporting layer.
Create a Stream from the Zeek Conn topic
CREATE STREAM conn_stream (
ts DOUBLE(16,6),
uid STRING,
"id.orig_h"VARCHAR,
"id.orig_p"INTEGER,
"id.resp_h"VARCHAR,
"id.resp_p"INTEGER,
proto STRING,
service STRING,
conn_state STRING,
local_orig BOOLEAN,
local_resp BOOLEAN,
missed_bytes INTEGER,
history STRING,
orig_packets INTEGER,
orig_ip_bytes INTEGER,
resp_pkts INTEGER,
resp_ip_bytes INTEGER)
WITH (KAFKA_TOPIC='conn', VALUE_FORMAT='JSON');
Create a table to hold aggregate byte counts
CREATETABLEHOURLY_BYTE_COUNT_TABLE WITH (KAFKA_TOPIC='BYTE_TABLE', VALUE_FORMAT='JSON') ASSELECT"id.orig_h"AS SRC_IP,
sum(orig_ip_bytes + resp_ip_bytes) AS TOTAL_BYTES
FROM CONN_STREAM
WINDOW TUMBLING(SIZE 1 HOUR)
GROUP BY"id.orig_h";
Run a SELECT * query for a single host as a sanity check
SELECT*FROM HOURLY_BYTE_COUNT_TABLE WHERE SRC_IP='192.168.1.15';
SELECT
SRC_IP, TOTAL_BYTES, WINDOWSTART, WINDOWEND,
UNIX_TIMESTAMP() AS NOW_EPOCH,
FORMAT_TIMESTAMP(FROM_UNIXTIME(WINDOWSTART), 'yyyy-MM-dd HH:mm:ss') AS TIME_START,
FORMAT_TIMESTAMP(FROM_UNIXTIME(WINDOWEND), 'yyyy-MM-dd HH:mm:ss') AS TIME_END,
FORMAT_TIMESTAMP(FROM_UNIXTIME(UNIX_TIMESTAMP()), 'yyyy-MM-dd HH:mm:ss.SSS') AS NOW,
TOTAL_BYTES/1000000.00AS TOTAL_MB
FROM HOURLY_BYTE_COUNT_TABLE
WHERE SRC_IP='192.168.1.15' ;