最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

regex - how to write wazuh syslog decoder correctly - Stack Overflow

programmeradmin3浏览0评论

Good afternoon, please tell me what am I doing wrong? my goal is to write a decoder for accepting logs wazuh I get these logs in the format:

Feb 17 10:08:43 2.2.2.2 %AAA-I-DISCONNECT: http connection for user admin, source 1.1.1.1 destination 2.2.2.2 TERMINATED

Feb 17 10:08:47 2.2.2.2 %AAA-I-CONNECT: New http connection for user admin, source 1.1.1.1 destination 2.2.2.2, local user table ACCEPTED.

I wrote a regular expression and checked it on the site rexeg101 and I saw my meanings there. "^(\w{3} \d{1,2} \d{2}:\d{2}:\d{2}) (\S+) %AAA-I-(CONNECT|DISCONNECT): New http connection for user (\S+), source (\S+) destination (\S+), (.*)$" Next I'm writing a decoder for wazuh:

"""

<decoder name="switch_log">
  <prematch>^\w{3} \d{1,2} \d{2}:\d{2}:\d{2}</prematch>
  <regex>^(\w{3} \d{1,2} \d{2}:\d{2}:\d{2}) (\S+) %AAA-I-(CONNECT|DISCONNECT): New http connection for user (\S+), source (\S+) destination (\S+), (.*)$</regex>
  <order>timestamp, hostname, action, user, source_ip, destination_ip, message</order>
</decoder>

""" and then I insert the data and it doesn’t work + it still doesn’t pass the decoder verification test. And when I try to save it says a syntax error. Help fix the problem. I don’t understand where to dig

screenshots for 1 answer

Good afternoon, please tell me what am I doing wrong? my goal is to write a decoder for accepting logs wazuh I get these logs in the format:

Feb 17 10:08:43 2.2.2.2 %AAA-I-DISCONNECT: http connection for user admin, source 1.1.1.1 destination 2.2.2.2 TERMINATED

Feb 17 10:08:47 2.2.2.2 %AAA-I-CONNECT: New http connection for user admin, source 1.1.1.1 destination 2.2.2.2, local user table ACCEPTED.

I wrote a regular expression and checked it on the site rexeg101 and I saw my meanings there. "^(\w{3} \d{1,2} \d{2}:\d{2}:\d{2}) (\S+) %AAA-I-(CONNECT|DISCONNECT): New http connection for user (\S+), source (\S+) destination (\S+), (.*)$" Next I'm writing a decoder for wazuh:

"""

<decoder name="switch_log">
  <prematch>^\w{3} \d{1,2} \d{2}:\d{2}:\d{2}</prematch>
  <regex>^(\w{3} \d{1,2} \d{2}:\d{2}:\d{2}) (\S+) %AAA-I-(CONNECT|DISCONNECT): New http connection for user (\S+), source (\S+) destination (\S+), (.*)$</regex>
  <order>timestamp, hostname, action, user, source_ip, destination_ip, message</order>
</decoder>

""" and then I insert the data and it doesn’t work + it still doesn’t pass the decoder verification test. And when I try to save it says a syntax error. Help fix the problem. I don’t understand where to dig

screenshots for 1 answer

Share Improve this question edited Feb 17 at 10:06 Alexey asked Feb 17 at 9:27 AlexeyAlexey 157 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Here is the regex to match both the DISCONNECT-TERMINATED and CONNECT-ACCEPTED log instances information see: new_pattern:


REGEX PATTERNS:

old_pattern = /^(\w{3} \d{1,2} \d{2}:\d{2}:\d{2}) (\S+) %AAA-I-(CONNECT|DISCONNECT): New http connection for user (\S+), source (\S+) destination (\S+), (.*)$/gm

new_pattern = /^(\w\w\w \d\d? \d\d:\d\d:\d\d) (\S+) %AAA-I-(CONNECT|DISCONNECT): (New )?http connection for user (\S+), source (\S+) destination (\S+),? (.*)$/gm

CHANGES TO old_pattern:

  • (New )? I placed New in parenthesis and made it optional ?.
  • ,? I made the comma , before the message optional ?

DEMO old_pattern: https://regex101/r/NaJhrN/3

DEMO new_pattern: https://regex101/r/NaJhrN/4


wazuh example (2025.02.18 edit):

I found this: The regex flavor can be enabled with type in the <regex> tag. I.e. PCRE can be enabled in rules and decoders using the type="pcre2" attribute. https://documentation.wazuh/current/user-manual/ruleset/ruleset-xml-syntax/pcre2.html#configuring-pcre

Below is a simple example of data extraction with PCRE. Here is a log message of a program called switch_log:

CODE (wazuh):

<decoder name="switch_log">
  <program_name>^switch_log$</program_name>
</decoder>

<decoder name="switch_log">
  <parent>switch_log</parent>
  <regex type="pcre2>^(\w{3} \d{1,2} \d{2}:\d{2}:\d{2}) (\S+) %AAA-I-(CONNECT|DISCONNECT): New http connection for user (\S+), source (\S+) destination (\S+), (.*)$</regex>
  <order>timestamp, hostname, action, user, source_ip, destination_ip, message</order>
</decoder>

发布评论

评论列表(0)

  1. 暂无评论