PL EN
WB-19755A85TLP:CLEARWazuh 4

Decoding BMC logs in Wazuh: from a syslog sample to a rule

Turn a management controller syslog sample into decoder fields, a rule and a logtest check, keeping the source format separate from the Wazuh logic.

Syslog from a management controller reaches Wazuh as plain text until a decoder extracts the fields that rules work on. On a sample event I build a decoder, a rule and a test in wazuh-logtest, and I take options and defaults from the Wazuh documentation.

Sample and fields

I start with one syslog line. All values are examples: agent-01, example-bmc, example-operator and an address from the 192.0.2.0/24 range.

Nov 17 12:00:00 agent-01 example-bmc: event=login_failed user=example-operator src=192.0.2.44

I assign a field to each fixed fragment before I write a pattern:

Sample fragmentFieldKind
example-bmcprogram_namesyslog header, pre-decoding phase
login_failedbmc_eventdynamic field
example-operatoruserstatic field, alias of dstuser
192.0.2.44srcipstatic field

The documentation splits the names in <order> into static and dynamic. A dynamic field is any string outside the static list. The user field is an alias of dstuser, and one decoder can use only one of these names.

Static fieldDescription in the documentation
srcusersource username
dstuserdestination username
useralias of dstuser
srcipsource IP address
dstipdestination IP address
srcportsource port
dstportdestination port
protocolprotocol
system_namesystem name
idevent identifier
urlevent URL
actionevent action (deny, drop, accept and so on)
statusevent status (success, failure and so on)
datadata
extra_dataany additional data

Four entries from the first table are enough for the sample. I do not create fields whose values I cannot see in the log.

Log collection by the agent

The <localfile> section configures log collection from files, Windows events and command output. Two options choose the file and the format: location points to the source (a file path, an event channel, macos or journald), and log_format is required. For most text files with one entry per line, the documentation points to the syslog format. Filters and conversion for the journald source are covered in the post on journald in localfile.

OptionDescription in the documentationValues
locationwhere the log data comes fromfile path, event channel, macos, journald
log_formatformat of the log being read, required fieldsee the table below
commandcommand output read as a logcommand
ageskips files not modified for the given timenumber with suffix s, m, h or d
excludeexcludes a group of files with a wildcardpath with a wildcard
ignore_binariesdiscards binary filesyes, no
log_format valueUse according to the documentation
syslogtext files in a syslog-like format, one entry per line
genericgeneral text files
jsonJSON files with one event per line
commandruns the command as root, each output line is a separate log
full_commandruns the command as root, the whole output is one log
journaldsystemd-journal events in syslog format
eventchannelWindows event channels

In file names I can use strftime markers or wildcards, but not both in one entry. The agent monitors at most 1000 files at the same time. The example from the documentation for a syslog file looks like this:

<localfile>
  <log_format>syslog</log_format>
  <location>/var/log/syslog</location>
</localfile>

The server keeps external logs in archives, which are disabled by default. The text archive is /var/ossec/logs/archives/archives.log, the JSON archive is /var/ossec/logs/archives/archives.json. Two options in the <global> section of the server’s /var/ossec/etc/ossec.conf enable them:

OptionEffectValues
logallwrites all logs in syslog formatyes, no
logall_jsonwrites events in JSON formatyes, no

Only logall_json provides the index for visualizing events on the dashboard. After the change, the documentation says to restart the manager.

<ossec_config>
  <global>
    <jsonout_output>yes</jsonout_output>
    <alerts_log>yes</alerts_log>
    <logall>yes</logall>
    <logall_json>yes</logall_json>
  </global>
</ossec_config>

The archives hold logs from all monitored endpoints, so over time they take up a lot of space on the server. The manager compresses logs daily and stores them in directories named after the source file, the year and the month. A file compressed on 13 April 2024 goes to /var/ossec/logs/archives/2024/Apr/ as ossec-archive-13.log.gz, with the checksum in ossec-archive-13.log.sum. The difference between an archive and an alert is covered in a separate guide.

Decoder

I keep custom decoders in /var/ossec/etc/decoders/local_decoder.xml, and for larger changes in separate files of that directory. The parent decoder recognizes the program, the child extracts the fields. The documentation describes these options:

OptionValuesDescription
<parent>decoder namethe decoder becomes a child and runs after the parent matches
<program_name>regex, sregex or pcre2the program from the syslog header must match the expression
<prematch>regex or pcre2condition on the log content without the syslog header
<regex>regex or pcre2extracts fields from parentheses
<order>list of field namesnames for consecutive regex groups

Three restrictions from the documentation apply. <regex> requires <order> next to it. <regex> also requires <prematch> or <program_name> in the decoder or in its parent. A child decoder cannot be a parent, but one parent can have many children, which gives sibling decoders for logs with a variable structure.

The expression type is set by the type attribute:

Tagtype valuesDefault
<program_name>osmatch, osregex, pcre2osmatch
<prematch>osregex, pcre2osregex
<regex>osregex, pcre2osregex

The decoder for the sample uses pcre2 in <regex>:

<decoder name="example-bmc">
  <program_name>^example-bmc</program_name>
</decoder>

<decoder name="example-bmc">
  <parent>example-bmc</parent>
  <regex type="pcre2">event=(\w+) user=([\w-]+) src=([0-9.]+)</regex>
  <order>bmc_event,user,srcip</order>
</decoder>

For <prematch>, the documentation recommends a pattern as specific as possible, to avoid matching unwanted events. I apply the same rule to <program_name> in the parent.

Rule

I keep custom rules in /var/ossec/etc/rules/local_rules.xml or in a separate file of the /var/ossec/etc/rules/ directory. The documentation assigns custom rule identifiers to the range 100000 to 120000, although the syntax allows numbers from 1 to 999999. Every rule must have at least one group, which the <group> element provides.

<rule> attributeDescriptionAllowed values
levelrule level used by alerts and responses0 to 16
idrule identifier1 to 999999
frequencynumber of matches before an alert2 to 9999
timeframetime window in seconds1 to 99999
ignoretime in seconds during which the rule does not fire after being triggered1 to 999999
noalertno alert despite a match0 (default) or 1

Conditions used in the rules below:

ConditionMeaning
decoded_asevent decoded by the given decoder
fieldcompares a field extracted by the decoder with a regular expression
if_sidthe rule matches when an earlier rule from the list matched
srcipcompares an address or CIDR block with the address decoded as srcip

The field element takes a name attribute with the field name, negate (yes or no, default no) and type (osregex by default, osmatch, pcre2). Several field elements in one rule work as a conjunction: all conditions must be met. The documentation shows decoded_as in a level 0 grouping rule from which the detailed rules inherit:

<rule id="53500" level="0">
  <decoded_as>smtpd</decoded_as>
  <description>OpenSMTPd grouping.</description>
</rule>

For the sample I write two rules. The first links the decoder with the value of the bmc_event field, the second narrows it to an address range:

<group name="example-bmc,">
  <rule id="100010" level="5">
    <decoded_as>example-bmc</decoded_as>
    <field name="bmc_event">login_failed</field>
    <description>Example BMC: login failure</description>
  </rule>

  <rule id="100011" level="8">
    <if_sid>100010</if_sid>
    <srcip>192.0.2.0/24</srcip>
    <description>Example BMC: login failure from the example range</description>
  </rule>
</group>

I pick levels 5 and 8 only to show the syntax. Separating extraction from detection shows, during a test, whether a missing alert comes from the decoder or from a rule condition. Rules that depend on the number of events are covered in the post on event correlation.

Testing in wazuh-logtest

/var/ossec/bin/wazuh-logtest runs on the Wazuh server and shares sessions: each one loads its own set of rules and decoders, and the firedtimes counter grows within it. In a cluster, the master node processes the events. Parameters of the <rule_test> section in /var/ossec/etc/ossec.conf:

ParameterDescriptionDefaultAllowed values
enabledenables and disables logtestyesyes, no
threadsnumber of threads11-128 or auto
max_sessionsnumber of open sessions641-500
session_timeoutminimum idle time that closes a session15mnumber with suffix s, m or h, at most 365d

The output has three phases: pre-decoding (syslog header), decoding (decoder and fields) and filtering (rule). For the first sample, phase 2 should show the example-bmc decoder and three fields, and phase 3 should show rule 100011 at level 8. These are values expected from the definitions, not a recorded result.

I change one element at a time and write down the expected result of each phase before running it:

InputExpected phase 2Expected phase 3
unchanged sampledecoder example-bmc, three fieldsrule 100011
src=198.51.100.7decoder example-bmc, three fieldsrule 100010, because the address is outside the range
event=login_okbmc_event equal to login_okno 100010 or 100011, because field does not match
program example-otherno example-bmc decoderno rule
example-bmc: heartbeat okno bmc_event, user or srcip fieldsno rule

The last row catches the assumption that every event of a program has the same layout. The phases are explained in the article on wazuh-logtest.

Saving the files is enough for a test in logtest. The manager must be restarted to generate alerts from changed definitions:

systemctl restart wazuh-manager
# or on SysV init
service wazuh-manager restart

Built-in decoder

When a default decoder parses a log badly, I do not edit the file in /var/ossec/ruleset/decoders/. The documentation describes another way: I copy the file to /var/ossec/etc/decoders/, set the owner and permissions, exclude the original from the load list and change the copy.

chown wazuh:wazuh /var/ossec/etc/decoders/0310-ssh_decoders.xml
chmod 660 /var/ossec/etc/decoders/0310-ssh_decoders.xml
<ruleset>
  <decoder_dir>ruleset/decoders</decoder_dir>
  <rule_dir>ruleset/rules</rule_dir>
  <decoder_dir>etc/decoders</decoder_dir>
  <rule_dir>etc/rules</rule_dir>
  <decoder_exclude>ruleset/decoders/0310-ssh_decoders.xml</decoder_exclude>
</ruleset>

The excluded file does not receive fixes from updates, and the copy stays unchanged, so I port the needed changes by hand. For the BMC format a custom decoder is enough. The syntax is covered in the guide to custom decoders, and the file order in the description of ruleset loading.

What the documentation does not define

The Wazuh documentation does not define the format of IPMI, Redfish or BMC events, common field names across vendors, controller configuration for sending syslog, or a universal rule level for such events. The sample and the field names are examples. Before deployment I replace them with values confirmed in the real log and in the documentation of the source vendor.

Sources

↑↓ select Enter open Esc close