-
Notifications
You must be signed in to change notification settings - Fork 1.8k
conf: parser: add Mikrotik firewall parser #11199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hlein
wants to merge
1
commit into
fluent:master
Choose a base branch
from
hlein:parsers-add-mikrotik
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) | ||
|
|
||
| (?<ident>firewall) ,info \s | ||
|
|
||
| # labels are optional, and user-defined | ||
| (?: catchall \s )? | ||
| (?: | ||
| (?<fw_action> | ||
| (?: | ||
| accept (?:keepalive) ? | ||
| | allow (?: \s [-A-Za-z]+ )? | ||
| | (?: [-A-Za-z]+ \s ) ? drop (?: \s invalid ) ? | ||
| | [a-z0-9]+_scanhost | ||
| | masq | ||
| ) | ||
| ) | ||
| \s | ||
| )? | ||
|
|
||
| (?<fw_direction> (?: forward | input | output | srcnat ) ) :\s | ||
| (?: in: (?: \(unknown\s [0-9]\) | (?<in_interface>[^ ]+) ) ) \s | ||
| (?: out: (?: \(unknown\s [0-9]\) | (?<out_interface>[^ ,]+) ) ) ,\s | ||
|
|
||
| (?: connection-state: (?<conn_state>[^\s]+) \s )? | ||
|
|
||
| (?: src-mac\s (?<macsrc>[A-Fa-f0-9]{2} (?: :[A-Fa-f0-9]{2}){5} ) ,\s )? | ||
|
|
||
| proto\s | ||
|
|
||
| (?: | ||
| (?<proto>TCP) | ||
| \s\( | ||
| (?: (?<tcp_syn>SYN) ,? )? | ||
| (?: (?<tcp_ack>ACK) ,? )? | ||
| (?: (?<tcp_rst>RST) ,? )? | ||
| (?: (?<tcp_fin>FIN) ,? )? | ||
| (?: (?<tcp_psh>PSH) ,? )? | ||
| (?: (?<tcp_urg>URG) ,? )? | ||
| \) | ||
| | | ||
| (?<proto>UDP) | ||
| | | ||
| (?<proto>ICMP) | ||
| \s \( | ||
| type\s (?<icmp_type>\d+),\s | ||
| code\s (?<icmp_code>\d+) \) | ||
| | | ||
| (?<proto>[^\s,]+) | ||
| ) | ||
| ,\s | ||
| (?<source>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| (?: : (?<src_port>\d+) )? | ||
| -> | ||
| (?<dest>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| (?: : (?<dst_port>\d+) )? | ||
| ,\s | ||
|
|
||
| # NAT logs: | ||
| # - parens-tuple for source or dest | ||
| # - apparently *both* could be rewritten | ||
| # - NAT IPs are not necessarily 1:1 | ||
| (?: | ||
| NAT\s | ||
| (?: | ||
| \( | ||
| (?<nat_source_orig>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| (?: : \k<src_port> )? | ||
| -> | ||
| (?<nat_source>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| (?: : (?<nat_src_port>\d+) )? | ||
| \) | ||
| -> | ||
| \k<dest> | ||
| (?: : \k<dst_port> )? | ||
| | | ||
| (?: \k<source> | (?<nat_source_orig>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) ) | ||
| (?: : \k<src_port> )? | ||
| -> | ||
| \( | ||
| (?<nat_dest_orig>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| (?: : (?<nat_dst_port>\d+) )? | ||
| -> | ||
| (?<nat_dest>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| (?: : \k<dst_port> )? | ||
| \) | ||
| ) | ||
| , \s | ||
| )? | ||
hlein marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| len\s (?<pkt_len>\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) | ||
|
|
||
| (?<ident>web-proxy) ,account \s | ||
|
|
||
| (?<host>[^\s]+) \s | ||
| (?<method>[^\s]+) \s | ||
| (?<url>\S+) \s+ | ||
|
|
||
| action=(?<proxy_action>\S+) | ||
|
|
||
| # Only permitted requests will show a cache status | ||
| (?: | ||
| \s cache=(?<cache_status>\S+) | ||
| (?: \s \([^)]*\) )? | ||
| )? | ||
| $ | ||
|
|
||
| - name: mikrotik-dhcp | ||
| # DHCP logs from Mikrotiks | ||
| # https://regex101.com/r/jBqBIg/1 | ||
| format: regex | ||
| regex: | | ||
| (?x) | ||
|
|
||
| (?<ident>dhcp) ,info \s | ||
|
|
||
| (?: | ||
| dhcp-client\s on\s | ||
| (?<fw_netname>[-_.A-Za-z0-9]+) \s | ||
| (?<dhcp_action>(?: got | lost ) )\s | ||
| IP\s address\s | ||
| (?<src_ip>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| (?: \s - \s .*) ? | ||
| | | ||
| (?<fw_netname>[-_.A-Za-z0-9]+) \s | ||
| (?<dhcp_action> (?: de )? assigned ) \s | ||
| (?<src_ip>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) \s | ||
| (?: for | from | to ) \s | ||
| (?<macsrc>[A-Fa-f0-9]{2} (?: :[A-Fa-f0-9]{2}){5} ) | ||
| (?: \s (?<hostname>\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 | ||
| (?<src_ip>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| ,\s port: \s | ||
| (?<src_port>\d+) | ||
| \s to \s | ||
| (?<dst_ip>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| | | ||
| < (?<src_ip>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) >:\s | ||
| disconnected | ||
| (?: \s <[^>]+>)? | ||
| | | ||
| (?<vpn_name>[^ :]+) :\s | ||
| (?: | ||
| initializing\.\.\. | ||
| | | ||
| connect (?: ed | ing\.\.\. ) | ||
| | | ||
| disconnected | ||
| (?: \s <[^>]+>)? | ||
| | | ||
| terminating\.\.\. .* | ||
| | | ||
| using\s encoding\s -\s | ||
| (?<cipher>[-_/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 | ||
| (?<user>[^\s]+) | ||
| \s logged\s (?: in | out ) \s | ||
|
|
||
| (?: | ||
| from \s | ||
| (?: | ||
| (?<source>(?:[0-9]{1,3}\.){3}[0-9]{1,3}) | ||
| | | ||
| (?<srcmac>[A-Fa-f0-9]{2} (?: :[A-Fa-f0-9]{2}){5} ) | ||
| ) | ||
| \s | ||
| )? | ||
|
|
||
| # remote protocol or local | ||
| via \s | ||
| (?<access_method>.*) | ||
|
|
||
| - 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=<tab> | ||
| # include the whole list; as long as this is the last Mikrotik parser, | ||
| # more specific ones that matched will have already consumed the message. | ||
| (?<ident> | ||
| (?: | ||
| 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 | ||
| (?<mikrotik_remainder>.*) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Verification inconclusive
IP address pattern accepts invalid addresses; consider stricter validation.
Lines 61, 64 (and repeated at 76, 79, 90, 93) use the pattern
(?:[0-9]{1,3}\.){3}[0-9]{1,3}, which matches any sequence of 1–3 digits separated by dots. This allows invalid IPv4 addresses such as999.999.999.999,00.00.00.00, or192.168.256.1. While this may be acceptable for log parsing if Mikrotik's output is known to be well-formed, consider using proper IPv4 validation for robustness:This pattern strictly validates each octet to the range 0–255.
If tighter validation is desired, apply this diff to the firewall parser (and repeat for DHCP, OpenVPN, and login parsers):
I'll verify the regex patterns by testing them against various IPv4 addresses to confirm the claims in the review comment.
IP pattern is permissive but validates correctly in practice; consider stricter validation if defense-in-depth is desired.
Lines 61, 64, 76, 79, 90, 93 use the pattern
(?:[0-9]{1,3}\.){3}[0-9]{1,3}, which theoretically accepts invalid IPv4 addresses such as999.999.999.999or192.168.256.1. However, the parser has been validated against 620 million real Mikrotik logs with a 100% match rate, indicating the current pattern works correctly for the actual log format produced by Mikrotik.If stricter validation is desired for defense-in-depth, apply the stricter pattern:
Otherwise, the current approach is sufficient given real-world validation results.
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See other comment - standardized on
(?:[0-9]{1,3}\.){3}[0-9]{1,3}which is used by other, existing parsers likeiptablesinparsers_extra.conf.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 7290
@hlein, thank you for the clarification! I've verified that the iptables parser in
parsers_extra.confdoes indeed use the same(?:[0-9]{1,3}\.){3}[0-9]{1,3}pattern. Standardizing on this pattern across all parsers makes perfect sense for consistency and maintainability.Given that your firewall parser has been validated against 620 million real log lines with 100% match rate, and you're following established conventions in the codebase, the current pattern is clearly the right choice here.
🐰💭
✏️ Learnings added
🧠 Learnings used