JSON Fields with Filebeat for Snort

zuccin-some-logs

Premise

There are some scenarios where there are simply no premade ingest pipelines for some log formats, even log formats that one would think have something perfectly simple premade for them. It’s incredibly easy to tell a tool, such as Snort, to output logs in JSON format and then have filebeat automatically decode those logs using a built in JSON decoder.

This came up for me when I was trying to pull out some meaningful fields from snort with a simple Filebeat and Elastic index setup in my GNS3 lab, which doesn’t have access to fancy enterprise things like Elastic Agent.

This post makes some assumptions that Snort’s already installed and configuring it basically is already understood.

⛬

Parse snort logs as json

The folks who create Snort having written a bit about this on their blog, but I’d argue it’s a bit too general to get a good idea how it might be applied in practice.

alert_json =
{file = true,
fields = 'timestamp pkt_num proto pkt_gen pkt_len dir src_addr src_port dst_addr dst_port service rule priority class action b64_data',
}
filebeat.inputs:
- type: filestream

  id: filebeat-firewall
  enabled: true
  paths:
    - /var/log/snort/alert_json.txt
{ "timestamp" : "05/10-12:59:30.263657", 
"pkt_num" : 30, 
"proto" : "ICMP", 
"pkt_gen" : "raw", 
"pkt_len" : 84, 
"dir" : "C2S", 
"src_addr" : "10.10.30.2", 
"dst_addr" : "172.16.30.2", 
"service" : "unknown", 
"rule" : "1:384:8", 
"priority" : 3, 
"class" : "Misc activity", 
"action" : 
"allow", 
"b64_data" : "SomeB64StringHereForTheLogLines" }

The important step

 processors:
    - decode_json_fields:
        fields: ["message"]
        max_depth: 1
        target: "decoded"
        overwrite_keys: false
        add_error_key: true
    # Set paths for the log files when file input is used.
    var.paths: ["/var/log/snort/alert_json.txt"]

    # Toggle output of non-ECS fields (default true).

Result

zuccin-some-logs

Cheers ~

-N

References for this post