From 54e1900ae39d0a86b10974d46a1ff446b705dbdf Mon Sep 17 00:00:00 2001 From: Hank Leininger Date: Sat, 22 Nov 2025 13:32:56 -0700 Subject: [PATCH] conf: parser: add Mikrotik firewall parser Signed-off-by: Hank Leininger --- conf/parsers_mikrotik.yaml | 254 +++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 conf/parsers_mikrotik.yaml diff --git a/conf/parsers_mikrotik.yaml b/conf/parsers_mikrotik.yaml new file mode 100644 index 00000000000..0aa7455a193 --- /dev/null +++ b/conf/parsers_mikrotik.yaml @@ -0,0 +1,254 @@ +# parsing rules for Mikrotik firewalls +# https://forum.mikrotik.com/ + +parsers: + + - name: mikrotik-firewall + # Firewall logs from Mikrotiks + # https://regex101.com/r/k32H3p/1 + format: regex + regex: | + (?x) + + (?firewall) ,info \s + + # labels are optional, and user-defined + (?: catchall \s )? + (?: + (? + (?: + accept (?:keepalive) ? + | allow (?: \s [-A-Za-z]+ )? + | (?: [-A-Za-z]+ \s ) ? drop (?: \s invalid ) ? + | [a-z0-9]+_scanhost + | masq + ) + ) + \s + )? + + (? (?: forward | input | output | srcnat ) ) :\s + (?: in: (?: \(unknown\s [0-9]\) | (?[^ ]+) ) ) \s + (?: out: (?: \(unknown\s [0-9]\) | (?[^ ,]+) ) ) ,\s + + (?: connection-state: (?[^\s]+) \s )? + + (?: src-mac\s (?[A-Fa-f0-9]{2} (?: :[A-Fa-f0-9]{2}){5} ) ,\s )? + + proto\s + + (?: + (?TCP) + \s\( + (?: (?SYN) ,? )? + (?: (?ACK) ,? )? + (?: (?RST) ,? )? + (?: (?FIN) ,? )? + (?: (?PSH) ,? )? + (?: (?URG) ,? )? + \) + | + (?UDP) + | + (?ICMP) + \s \( + type\s (?\d+),\s + code\s (?\d+) \) + | + (?[^\s,]+) + ) + ,\s + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + (?: : (?\d+) )? + -> + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + (?: : (?\d+) )? + ,\s + + # NAT logs: + # - parens-tuple for source or dest + # - apparently *both* could be rewritten + # - NAT IPs are not necessarily 1:1 + (?: + NAT\s + (?: + \( + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + (?: : \k )? + -> + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + (?: : (?\d+) )? + \) + -> + \k + (?: : \k )? + | + (?: \k | (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) ) + (?: : \k )? + -> + \( + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + (?: : (?\d+) )? + -> + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + (?: : \k )? + \) + ) + , \s + )? + + len\s (?\d+) + types: 'src_port:integer,dst_port:integer,pkt_len:integer' + + - name: mikrotik-proxy + # Proxy logs from Mikrotiks + # https://regex101.com/r/C3Odc7/1 + format: regex + regex: | + (?x) + + (?web-proxy) ,account \s + + (?[^\s]+) \s + (?[^\s]+) \s + (?\S+) \s+ + + action=(?\S+) + + # Only permitted requests will show a cache status + (?: + \s cache=(?\S+) + (?: \s \([^)]*\) )? + )? + $ + + - name: mikrotik-dhcp + # DHCP logs from Mikrotiks + # https://regex101.com/r/jBqBIg/1 + format: regex + regex: | + (?x) + + (?dhcp) ,info \s + + (?: + dhcp-client\s on\s + (?[-_.A-Za-z0-9]+) \s + (?(?: got | lost ) )\s + IP\s address\s + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + (?: \s - \s .*) ? + | + (?[-_.A-Za-z0-9]+) \s + (? (?: de )? assigned ) \s + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) \s + (?: for | from | to ) \s + (?[A-Fa-f0-9]{2} (?: :[A-Fa-f0-9]{2}){5} ) + (?: \s (?\S+) )? + ) + \s? + $ + + - name: mikrotik-ovpn + # OpenVPN logs from Mikrotiks + # https://regex101.com/r/hoEBSE/1 + format: regex + regex: | + (?x) + + ovpn,info\s + + (?: + connection\s established\s from\s + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + ,\s port: \s + (?\d+) + \s to \s + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + | + < (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) >:\s + disconnected + (?: \s <[^>]+>)? + | + (?[^ :]+) :\s + (?: + initializing\.\.\. + | + connect (?: ed | ing\.\.\. ) + | + disconnected + (?: \s <[^>]+>)? + | + terminating\.\.\. .* + | + using\s encoding\s -\s + (?[-_/A-Z0-9]+) + ) + ) + + - name: mikrotik-logins + # Login/logout events from Mikrotiks + # https://regex101.com/r/LpmF15/1 + format: regex + regex: | + (?x) + + system,info,account\s + + user\s + (?[^\s]+) + \s logged\s (?: in | out ) \s + + (?: + from \s + (?: + (?(?:[0-9]{1,3}\.){3}[0-9]{1,3}) + | + (?[A-Fa-f0-9]{2} (?: :[A-Fa-f0-9]{2}){5} ) + ) + \s + )? + + # remote protocol or local + via \s + (?.*) + + - name: mikrotik-other + # Other logs from Mikrotiks + # https://regex101.com/r/kaPYeX/1 + format: regex + regex: | + (?x) + + # list of topics obtained from CLI: /system/logging/add topics= + # include the whole list; as long as this is the last Mikrotik parser, + # more specific ones that matched will have already consumed the message. + (? + (?: + account |dot1x |l2tp |pptp |store + |acme-client |dude |ldp |ptp |stp + |amt |e-mail |lora |queue |system + |async |error |lte |radius |telephony + |backup |event |manager |radvd |tftp + |bfd |evpn |mme |raw |timer + |bgp |fetch |mpls |read |tr069 + |bridge |firewall |mqtt |rip |update + |calc |gps |mvrp |route |upnp + |caps |gsm |natpmp |rpki |ups + |certificate |health |netinstall |rsvp |vpls + |clock |hotspot |netwatch |script |vrrp + |cmr |igmp-proxy |ntp |sertcp |warning + |container |info |ospf |simulator |watchdog + |critical |interface |ovpn |smb |web-proxy + |ddns |ipsec |packet |snmp |wireguard + |debug |iscsi |pim |socksify |wireless + |dhcp |isdn |poe-out |ssh |write + |disk |isis |ppp |sstp |zerotier + |dns |kvm |pppoe |state + ) + ) + , [^\s]+ + \s + + # remaining message contents + (?.*)