Skip to content

Commit 038dfa4

Browse files
committed
conf: parser: iptables: Handle many more message types, more fields
Address prefixes added by different tools, parse payloads in ICMP errors, support --log-uid logs, etc. Note that this _does_ change or rename a few fields, it is not strictly additive. Also switch regex reference to one that matches fluent-bit behavior. Signed-off-by: Hank Leininger <hlein@korelogic.com>
1 parent ee47dcf commit 038dfa4

File tree

1 file changed

+127
-29
lines changed

1 file changed

+127
-29
lines changed

conf/parsers_extra.yaml

Lines changed: 127 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,68 @@ parsers:
7272
- name: iptables
7373
# Parse IP Tables rules
7474
# N.B. ipv4 only
75-
# https://rubular.com/r/VEqBcImT3lav1K
75+
# https://regex101.com/r/DujdAl/1
7676
format: regex
7777
regex: |
7878
(?x)
7979
80+
# kernel timestamp - optional, and may have already been consumed
81+
(?: \[\s* (?<kernel_uptime>[0-9]+\.[0-9]+) \]\s )?
82+
8083
# Log prefix - depends on the rule-building tools
81-
\[ (?<rule_chain>\w*) - (?<rule_name>\w*) - (?<accept_or_drop>\w*) \]
84+
(?:
85+
86+
# Original Fluent-Bit PR #3108
87+
\[
88+
(?<rule_chain>\w*) -
89+
(?<rule_name>\w*) -
90+
(?<accept_or_drop>\w*)
91+
\]
92+
|
93+
94+
# UFW
95+
\[ UFW\s (?<accept_or_drop> (?: ALLOW | AUDIT | BLOCK ) ) \] \s
96+
|
97+
98+
# firewalld
99+
(?<rule_chain>[^_]+)_
100+
(?<fw_direction> (?: FWD | IN | OUT ) )_
101+
(?: (?<fw_zone>[a-z0-9]+) _ )?
102+
(?<accept_or_drop>[A-Z]+) : \s
103+
|
104+
105+
# Calico
106+
calico-
107+
(?<accept_or_drop>\w*)
108+
: \s
109+
|
110+
111+
# other
112+
FW:\s (?<fw_direction>[a-z]+) \s
113+
(?<accept_or_drop>[A-Z]+) \s
114+
|
115+
116+
# Conntrack error
117+
nf_ct_proto_6:\s
118+
(?:
119+
(?<nf_ct_err>bad\s checksum)
120+
|
121+
(?<nf_ct_err>challenge-ack\s ignored)
122+
|
123+
(?<nf_ct_err>invalid \s
124+
(?: new | rst | tcp\s flag\s combination | truncated\s packet )
125+
)
126+
|
127+
packet\s \( index\s [0-3] \) \s
128+
in\s dir\s [01]\s
129+
(?<nf_ct_err>ignored) ,\s
130+
state\s (?<tcp_state>[A-Z0-9_]+)
131+
) \s
132+
|
133+
134+
# support arbitrary unknown prefixes rather than fail to match
135+
(?<fw_unknown_prefix>.{1,64}?)
136+
)
82137
83138
IN=(?<in_interface>[\w.]+)?\s
84139
OUT=(?<out_interface>[\w.]+)?\s
@@ -100,40 +155,83 @@ parsers:
100155
SRC=(?<source>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s
101156
DST=(?<dest>(?:[0-9]{1,3}\.){3}[0-9]{1,3})\s
102157
LEN=(?<pkt_len>\d+)\s
103-
TOS=(?<pkt_tos>[\w\d]+)\s
104-
PREC=(?<pkt_prec>[\w\d]+)\s
158+
# kernel nf_log_syslog.c mixes 0x%x and 0x%X for various hex outputs,
159+
# be defensive in case someone decides to standardize some day
160+
TOS=(?<pkt_tos>0x[A-Fa-f0-9]+)\s
161+
PREC=(?<pkt_prec>0x[A-Fa-f0-9]+)\s
105162
TTL=(?<pkt_ttl>\d+)\s
106-
ID=(?<pkt_id>\d+)\s?
107-
(?<pkt_frg>[A-Z\s].?)\s?
108-
109-
# TCP and UDP have some next fields in common
110-
PROTO=(?<protocol>[\w\d]+)\s
111-
(
112-
SPT=(?<source_port>\d+)\s
113-
DPT=(?<dest_port>\d+)\s
114-
( LEN=(?<proto_pkt_len>\w+)? \s )?
115-
(
163+
ID=(?<pkt_id>\d+)\s
164+
(?: (?<ip_df>DF) \s )?
165+
166+
# Get what we can out of each protocol
167+
PROTO=
168+
(?:
169+
(?<proto>TCP) \s
170+
SPT=(?<src_port>\d+) \s
171+
DPT=(?<dst_port>\d+) \s
172+
# Some logs are missing SEQ= and ACK=
173+
(?:
174+
SEQ=\d+ \s
175+
ACK=\d+ \s
176+
)?
177+
WINDOW=(?<tcp_win>[0-9]+) \s
178+
RES=0x[A-Fa-f0-9]{2} \s
179+
(?: (?<tcp_flag_cwr>CWR) \s )?
180+
(?: (?<tcp_ewe>EWE) \s )?
181+
(?: (?<tcp_urg>URG) \s )?
182+
(?: (?<tcp_ack>ACK) \s )?
183+
(?: (?<tcp_psh>PSH) \s )?
184+
(?: (?<tcp_rst>RST) \s )?
185+
(?: (?<tcp_syn>SYN) \s )?
186+
(?: (?<tcp_fin>FIN) \s )?
187+
URGP=\d+ \s
188+
(?: OPT \s \( [^)\s]+ \) \s )?
189+
|
190+
(?<proto>UDP) \s
191+
SPT=(?<src_port>\d+) \s
192+
DPT=(?<dst_port>\d+) \s
193+
LEN=(?<udp_len>\d+) \s
194+
|
195+
(?<proto>ICMP) \s
196+
TYPE=(?<icmp_type>\d+) \s
197+
CODE=(?<icmp_code>\d) \s
198+
# Some ICMP errors have an embedded packet header inside
199+
(?:
200+
ID=(?<icmp_id>\d+) \s
201+
SEQ=(?<icmp_seq>\d+) \s
202+
|
203+
\[
204+
SRC= (?<icmp_err_src_ip>[0-9.]{7,15}) \s
205+
DST= (?<icmp_err_dst_ip>[0-9.]{7,15}) \s
206+
.*
207+
PROTO=(?<icmp_err_proto>[^ ]+) \s
116208
(?:
117-
SEQ=(?<tcp_seq>\d+)\s
118-
ACK=(?<tcp_ack>\d+)\s
209+
SPT=(?<icmp_err_src_port>\d+) \s
210+
DPT=(?<icmp_err_dst_port>\d+) \s
119211
)?
120-
WINDOW=(?<proto_window_size>\d+)\s
121-
RES=(?<pkt_res>\w+)?\s
122-
(?<pkt_type>\w+)\s
123-
(?<pkt_flag> (?:[A-Z]+\s)* )
124-
URGP=(?<pkg_urgency>\d)\s
212+
[^\]]*
213+
\] .*
125214
)?
126-
)?
215+
|
216+
(?<proto>ESP) \s
217+
SPI=(?<esp_spi>0x[A-Fa-f0-9]+) \s
218+
|
219+
(?<proto>[^ ]+) \s
220+
(?: (?<proto_extra>[^\s].*) \s )?
221+
)
127222
128-
# ICMP is the next most likely protocol
129-
(
130-
TYPE=(?<pkt_icmp_type>\d+)\s
131-
CODE=(?<pkt_icmp_code>\d+)\s
132-
ID=(?<pkt_icmp_id>\d+)\s
133-
SEQ=(?<pkt_icmp_seq>\d+)\s
223+
# Output rules might have --log-uid applied
224+
(?:
225+
UID=(?<uid>[0-9]+) \s
226+
GID=(?<gid>[0-9]+) \s
134227
)?
228+
# Packet markings
229+
(?: MARK=(?<pkt_mark>0x[A-Fa-f0-9]+) \s )?
230+
231+
# support arbitrary unknown suffixes rather than fail to match
232+
(?<fw_unknown_suffix>.*)
135233
$
136-
types: 'source_port:integer,dest_port:integer,pkt_ttl:integer,pkt_tos:integer,pkt_len:integer'
234+
types: 'src_port:integer,dst_port:integer,pkt_ttl:integer,pkt_tos:integer,pkt_len:integer'
137235

138236
- name: couchbase_json_log_nanoseconds
139237
# Various parsers for Couchbase Server logs

0 commit comments

Comments
 (0)