Skip to content

Instantly share code, notes, and snippets.

@FrankSpierings
Created September 16, 2017 16:05
Show Gist options
  • Save FrankSpierings/03ac03acfe829872d7f47a0bc522a8d6 to your computer and use it in GitHub Desktop.
Save FrankSpierings/03ac03acfe829872d7f47a0bc522a8d6 to your computer and use it in GitHub Desktop.
ELK indexing iptables messages (UFW)
### Add this specific input
- input_type: log
paths:
- /var/log/ufw.log
tags: ["iptables"]
filter {
if ("iptables" in [tags]) {
grok {
break_on_match => true
patterns_dir => "/etc/logstash/patterns/ufw"
match => { "message" => "%{IPTABLES}" }
}
}
}
IN IN=(?<nf_in>.*?)
OUT OUT=(?<nf_out>.*?)
SRC SRC=(?<nf_src>.*?)
DST DST=(?<nf_dst>.*?)
SPT SPT=(?<nf_spt>.*?)
DPT DPT=(?<nf_dpt>.*?)
MAC MAC=(?<nf_mac>.*?)
PROTO PROTO=(?<nf_proto>TCP|UDP|ICMP|[0-9]+)
HEADER (%{SYSLOGTIMESTAMP:nf_timestamp})\s*(%{HOSTNAME:nf_host})\skernel: \[%{INT}\.%{INT}\]
NFCOMMENT (?<nf_comment>.*)
IPTABLES_TCPUDP %{HEADER} %{NFCOMMENT}%{IN}\s%{OUT}\s%{SRC}\s%{DST}\s.*?%{PROTO}\s.*?%{SPT}.?%{DPT}\s.*?$
IPTABLES_OTHER %{HEADER} %{NFCOMMENT}%{IN}\s%{OUT}\s.*?%{SRC}%{DST}\s.*?%{PROTO}\s
IPTABLES (?:%{IPTABLES_TCPUDP}|%{IPTABLES_OTHER})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment