Skip to content

Latest commit

 

History

History
2335 lines (1759 loc) · 129 KB

File metadata and controls

2335 lines (1759 loc) · 129 KB

Rules Syntax

The Wazuh Ruleset combined with any customs rules is used to analyze incoming events and generate alerts when appropriate. The Ruleset is constant expansion and enhancement thanks to the collaborative effort of our developers and our growing community.

Our aim is to provide the best guidance possible for anyone who may be looking into developing their own custom rules and remember you can always contribute to our community.

Overview

The xml labels used to configure rules are listed here.

Option Values Description
rule See table below. Its starts a new rule and its defining options.
match Any regular expression. It will attempt to find a match in the log using sregex by default, deciding if the rule should be triggered.
regex_rules Any regular expression. It does the same as match, but with regex as default.
decoded_as Any decoder's name. It will match with logs that have been decoded by a specific decoder.
category Any type. It will match with logs whose decoder's type concur.
field Name and any regular expression. It will compare a field extracted by the decoder in order with a regular expression.
srcip Any IP address. It will compare the IP address with the IP decoded as srcip. Use "!" to negate it.
dstip Any IP address. It will compare the IP address with the IP decoded as dstip. Use "!" to negate it.
srcport Any regular expression. It will compare a regular expression representing a port with a value decoded as srcport.
dstport Any regular expression. It will compare a regular expression representing a port with a value decoded as dstport.
data Any regular expression. It will compare a regular expression representing a data with a value decoded as data.
extra_data Any regular expression. It will compare a regular expression representing a extra data with a value decoded as extra_data.
user Any regular expression. It will compare a regular expression representing a user with a value decoded as user.
system_name Any regular expression. It will compare a regular expression representing a system name with a value decoded as system_name.
program_name Any regular expression. It will compare a regular expression representing a program name with a value pre-decoded as program_name.
protocol Any regular expression. It will compare a regular expression representing a protocol with a value decoded as protocol.
hostname Any regular expression. It will compare a regular expression representing a hostname with a value pre-decoded as hostname.
time Any time range. e.g. (hh:mm-hh:mm) It checks if the event was generated during that time range.
weekday monday - sunday, weekdays, weekends It checks whether the event was generated during certain weekdays.
id Any regular expression. It will compare a regular expression representing an ID with a value decoded as id
url Any regular expression. It will compare a regular expression representing a URL with a value decoded as url
location Any regular expression. It will compare a regular expression representing a location with a value pre-decoded as location.
action Any String or regular expression. It will compare a string or regular expression representing an action with a value decoded as action.
status Any regular expression. It will compare a regular expression representing a status with a value decoded as status.
srcgeoip Any regular expression. It will compare a regular expression representing a GeoIP source with a value decoded as srcgeoip.
dstgeoip Any regular expression. It will compare a regular expression representing a GeoIP destination with a value decoded as dstgeoip.
if_sid A rule ID. It works similar to parent decoder. It will match if that rule ID has previously matched.
if_group Any group name. It will match if the indicated group has matched before.
if_level Any level from 1 to 16. It will match if that level has already been triggered by another rule.
if_matched_sid Any rule ID (Number). Similar to if_sid but it will only match if the ID has been triggered in a period of time.
if_matched_group Any group name. Similar to if_group but it will only match if the group has been triggered in a period of time.
same_id None. The decoded id must be the same.
not_same_id None. The decoded id must be different.
different_id None. The decoded id must be different.
same_source_ip None. The decoded srcip must be the same.
not_same_source_ip None. The decoded srcip must be different.
same_srcip None. The decoded srcip must be the same.
different_srcip None. The decoded srcip must be different.
same_dstip None. The decoded dstip must be the same.
different_dstip None. The decoded dstip must be different.
same_srcport None. The decoded srcport must be the same.
different_srcport None. The decoded srcport must be different.
same_dstport None. The decoded dstport must be the same.
different_dstport None. The decoded dstport must be different.
same_location None. The location must be the same.
different_location None. The location must be different.
same_srcuser None. The decoded srcuser must be the same.
different_srcuser None. The decoded srcuser must be different.
same_user None. The decoded user must be the same.
not_same_user None. The decoded user must be different.
different_user None. The decoded user must be different.
not_same_agent None. The decoded agent must be different.
same_field None. The decoded field must be the same as the previous ones.
not_same_field None. The decoded field must be different than the previous ones.
different_field None. The decoded field must be different than the previous ones.
same_protocol None. The decoded protocol must be the same.
different_protocol None. The decoded protocol must be different.
same_action None. The decoded action must be the same.
different_action None. The decoded action must be different.
same_data None. The decoded data must be the same.
different_data None. The decoded data must be different.
same_extra_data None. The decoded extra_data must be the same.
different_extra_data None. The decoded extra_data must be different.
same_status None. The decoded status must be the same.
different_status None. The decoded status must be different.
same_system_name None. The decoded system_name must be the same.
different_system_name None. The decoded system_name must be different.
same_url None. The decoded url must be the same.
different_url None. The decoded url must be different.
same_srcgeoip None. The decoded srcgeoip must the same.
different_srcgeoip None. The decoded srcgeoip must be different.
same_dstgeoip None. The decoded dstgeoip must the same.
different_dstgeoip None. The decoded dstgeoip must be different.
description Any String. Provides a human-readable description to explain what is the purpose of the rule. Please, use this field when creating custom rules.
list Path to the CDB file. Perform a CDB lookup using an ossec list.
info Any String. Extra information using certain attributes.
options See the table below. Additional rule options that can be used.
check_diff None. Determines when the output of a command changes.
group Any String. Add additional groups to the alert.
mitre See Mitre table below. Contains Mitre Technique IDs that fit the rule
var Name for the variable. Most used: BAD_WORDS Defines a variable that can be used anywhere inside the same file.

rule

<rule> is the label that starts the block that defines a rule. In this section, different options for this label are explained.

+---------------+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | level | Definition | Specifies the level of the rule. Alerts and responses use this value. | + +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | | Allowed values | 0 to 16 | +---------------+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | id | Definition | Specifies the ID of the rule. | + +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | | Allowed values | Any number from 1 to 999999 | +---------------+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | maxsize | Definition | Specifies the maximum size of the event. | + +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | | Allowed values | Any number from 1 to 9999 | +---------------+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | frequency | Definition | Number of times the rule must have matched before firing. | + +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | | Allowed values | Any number from 2 to 9999 | +---------------+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | timeframe | Definition | The timeframe in seconds. This option is intended to be used with the frequency option. | + +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | | Allowed values | Any number from 1 to 99999 | +---------------+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | ignore | Definition | The time (in seconds) to ignore this rule after firing it (to avoid floods). | + +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | | Allowed values | Any number from 1 to 999999 | +---------------+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | overwrite | Definition | Used to supersede a rule with local changes. | + +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | | Allowed values | yes, no | +---------------+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | noalert | Definition | Not trigger an alert if the rule matches. | + +----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+ | | Allowed values | 0 (alerts, value by default) or 1 (no alerts). If noalert is set to 1, the event continues analyzing other rules despite the rule matches. | +---------------+----------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------+

Example:

<rule id="3151" level="10" frequency="8" timeframe="120">
  <if_matched_sid>3102</if_matched_sid>
  <same_source_ip />
  <description>sendmail: Sender domain has bogus MX record. </description>
  <description>It should not be sending e-mail.</description>
  <group>multiple_spam,pci_dss_11.4,gdpr_IV_35.7.d,nist_800_53_SI.4,</group>
</rule>

The rule is created with ID: 3151 and it will trigger a level 10 alert if the rule 3102 has matched 8 times in the last 120 seconds.

match

Used as a requisite to trigger the rule, will search for a match in the log event.

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="100001" maxsize="300" level="3">
  <if_sid>100200</if_sid>
  <match>Queue flood!</match>
  <description>Flooded events queue.</description>
</rule>

If the rule matches the id 100200 and the log contains the Queue flood! phrase in it, rule activates and triggers a level 3 alert.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If match label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

regex

Used as a requisite to trigger the rule, will search for a match in the log event.

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="100001" level="3">
  <if_sid>100500</if_sid>
  <regex>\d+.\d+.\d+.\d+</regex>
  <description>Matches any valid IP</description>
</rule>

If the rule matches the ìd 100500 and the event contains any valid IP, the rule is triggered and generates a level 3 alert.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osregex

-------------+

osmatch

-------------+

pcre2

osregex

If regex label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

decoded_as

Used as a requisite to trigger the rule. It will be triggered if the event has been decoded by a certain decoder. Useful to group rules and have child rules inheriting from it.

Default Value n/a
Allowed values Any decoder name

Example:

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

The rule will be triggered if the event was decoded by the smtpd decoder. Now is possible to make more rules that will inherit from this one, specifically made for OpenSMTPd events.

category

Used as a requisite to trigger the rule. It will be triggered if the decoder included that log in said category.

Default Value n/a
Allowed values Any type

Example:

<rule id="01" level="0" noalert="1">
  <category>syslog</category>
  <description>Generic template for all syslog rules.</description>
</rule>

The rule will be triggered if the event has previously been cataloged syslog by the decoder, but it will not trigger an alert. Instead, it will be matched by other rules that might trigger alerts if needed.

field

Used as a requisite to trigger the rule. It will check for a match in the content of a field extracted by the decoder.

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Below is the list of attributes.

Attribute Description Value range Default value

name

specifies the name of the field extracted by the decoder.

n/a

n/a

negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osregex

-------------+

osmatch

-------------+

pcre2

osregex

Example:

<rule id="87100" level="0">
    <decoded_as>json</decoded_as>
    <field name="integration">virustotal</field>
    <description>VirusTotal integration messages.</description>
    <options>no_full_log</options>
</rule>

This rule, groups events decoded from json that belong to an integration called VirusTotal. It checks the field decoded as integration and if its content is virustotal the rule is triggered.

srcip

Used as a requisite to trigger the rule. It will compare any IP address or CIDR block to an IP decoded as srcip. Use "!" to negate it.

Default Value n/a
Allowed values Any srcip

Example:

<rule id="100105" level="8">
    <if_sid>100100</if_sid>
    <srcip>10.25.23.12</srcip>
    <description>Forbidden srcip has been detected.</description>
</rule>

This rule will trigger when that exact scrip has been decoded.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

If srcip label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

dstip

Used as a requisite to trigger the rule. It will compare any IP address or CIDR block to an IP decoded as dstip. Use "!" to negate it.

Default Value n/a
Allowed values Any dstip

Example:

<rule id="100110" level="5">
    <if_sid>100100</if_sid>
    <dstip>!198.168.41.30</dstip>
    <description>A different dstip has been detected.</description>
</rule>

This rule will trigger when an dstip different from 198.168.41.30 is detected.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

If dstip label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

srcport

Used as a requisite to trigger the rule. It will check the source port (decoded as srcport).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="100110" level="5">
    <if_sid>100100</if_sid>
    <srcport type="pcre2">^5000[0-7]$</srcport>
    <description>Source port $(srcport) is detected.</description>
</rule>

This rule will trigger when srcport is in the range of 50000 to 50007.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If srcport label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

dstport

Used as a requisite to trigger the rule. It will check the destination port (decoded as dstport).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If dstport label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

data

Used as a requisite to trigger the rule. It will check the data (decoded as data).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If data label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

extra_data

Used as a requisite to trigger the rule. It will compare any string with the one decoded into the extra_data field.

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="7301" level="0">
  <category>windows</category>
  <extra_data>^Symantec AntiVirus</extra_data>
  <description>Grouping of Symantec AV rules from eventlog.</description>
</rule>

This rule will trigger when the log belongs to windows category and the decoded field extra_data is: Symantec AntiVirus

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If extra_data label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

user

Used as a requisite to trigger the rule. It will check the username (decoded as user).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="140101" level="12">
  <if_group>authentication_success</if_group>
  <user negate="yes">wazuh|root</user>
  <description>Unexpected user successfully logged to the system.</description>
</rule>

This rule will trigger when a user different from root or wazuh successfully login into the system.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If user label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

system_name

Used as a requisite to trigger the rule. It will check the system name (decoded as system_name).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If system_name label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

program_name

Used as a requisite to trigger the rule. The program's name is decoded from syslog process name.

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="1005" level="5">
  <program_name>syslogd</program_name>
  <match>^restart</match>
  <description>Syslogd restarted.</description>
  <group>pci_dss_10.6.1,gpg13_10.1,gpg13_4.14,gdpr_IV_35.7.d,hipaa_164.312.b,nist_800_53_AU.6,</group>
</rule>

The rule will trigger when the program Syslogd restarted.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If program_name label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

protocol

Used as a requisite to trigger the rule. It will check the protocol (decoded as protocol).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If protocol label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

hostname

Used as a requisite to trigger the rule. Any hostname (decoded as the syslog hostname) or log file.

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="2931" level="0">
  <hostname>yum.log$</hostname>
  <match>^Installed|^Updated|^Erased</match>
  <description>Yum logs.</description>
</rule>

This rule will group rules for Yum logs when something is either being installed, updated or erased.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If hostname label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

time

Used as a requisite to trigger the rule. Used for checking the time that the event was generated.

Default Value n/a
Allowed values Any time range (hh:mm-hh:mm, hh:mm am-hh:mm pm, hh-hh, hh am-hh pm)

Example:

<rule id="17101" level="9">
  <if_group>authentication_success</if_group>
  <time>6 pm - 8:30 am</time>
  <description>Successful login during non-business hours.</description>
  <group>login_time,pci_dss_10.2.5,pci_dss_10.6.1,gpg13_7.1,gpg13_7.2,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7,nist_800_53_AU.6,</group>
</rule>

This rule will trigger when there is a successful login between 6 pm and 8 am.

weekday

Used as a requisite to trigger the rule. Checks the weekday that the event was generated.

Default Value n/a
Allowed values monday - sunday, weekdays, weekends

Example:

<rule id="17102" level="9">
  <if_group>authentication_success</if_group>
  <weekday>weekends</weekday>
  <description>Successful login during weekend.</description>
  <group>login_day,pci_dss_10.2.5,pci_dss_10.6.1,gpg13_7.1,gpg13_7.2,gdpr_IV_35.7.d,gdpr_IV_32.2,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7,nist_800_53_AU.6,</group>
</rule>

This rule will trigger when there is a successful login during the weekend.

id

Used as a requisite to trigger the rule. It will check any ID (decoded as the ID).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="81100" level="0">
    <decoded_as>kernel</decoded_as>
    <id>usb</id>
    <description>USB messages grouped.</description>
</rule>

This rule will group the logs whose decoded ID is usb.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If id label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

url

Used as a requisite to trigger the rule. It will check any URL (decoded as the URL).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="31102" level="0">
  <if_sid>31101</if_sid>
  <url>.jpg$|.gif$|favicon.ico$|.png$|robots.txt$|.css$|.js$|.jpeg$</url>
  <compiled_rule>is_simple_http_request</compiled_rule>
  <description>Ignored extensions on 400 error codes.</description>
</rule>

This rule is a child from a level 5 rule 31101 and becomes a level 0 rule when it confirms that the extensions are nothing to worry about.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If url label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

location

3.5.0

Used as a requisite to trigger the rule. It will check the content of the field location and trying to find a match.

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

The location identifies the origin of the input. If the event comes from an agent, its name and registered IP (as it was added) is appended to the location.

Example of a location for a log pulled from "/var/log/syslog" in an agent with name "dbserver" and registered with IP "any":

(dbserver) any->/var/log/syslog

The following components use a static location:

Component Location
Windows Eventchannel EventChannel
Windows Eventlog WinEvtLog
FIM (Syscheck) syscheck
Rootcheck rootcheck
Syscollector syscollector
Vuln Detector vulnerability-detector
Azure Logs azure-logs
AWS S3 integration aws-s3
Docker integration Wazuh-Docker
Osquery integration osquery
OpenSCAP integration open-scap
CIS-CAT integration wodle_cis-cat
SCA module sca

Example:

<rule id="24000" level="3">
  <location>osquery$</location>
  <description>osquery message</description>
</rule>

This rule, groups logs that come from osquery location. Triggering a level 3 alert for it.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If location label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

action

Used as a requisite to trigger the rule. It will check any action (decoded as the ACTION).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="4502" level="4">
  <if_sid>4500</if_sid>
  <action type="osregex">warning|WARN</action>
  <description>Netscreen warning message.</description>
</rule>

This rule will trigger a level 4 alert when the decoded action from Netscreen is warning or WARN.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

string

Note

Use type attribute only for regular expression match. It must be omitted if action field try to match a string.

If action label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

status

Checks the actual status of an event.

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

Example:

<rule id="213" level="7">
  <if_sid>210</if_sid>
  <status>aborted</status>
  <description>Remote upgrade could not be launched. Error: $(error).</description>
  <group>upgrade,upgrade_failure,</group>
</rule>

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If status label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

srcgeoip

Used as a requisite to trigger the rule. It will check the GeoIP source (decoded as srcgeoip).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If srcgeoip label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

dstgeoip

Used as a requisite to trigger the rule. It will check the GeoIP destination (decoded as dstgeoip).

Default Value n/a
Allowed values Any regex, sregex or pcre2 expression.

The attributes below are optional.

Attribute Description Value range Default value
negate
allows to negate the regular expression

no

-------------+

yes

no

type
allows to set regular expression type

osmatch

-------------+

osregex

-------------+

pcre2

osmatch

If dstgeoip label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.
  • The resulting value of an attribute corresponds to the one specified in the last label. If it is not specified, the default value will be used.

if_sid

Used as a requisite to trigger the rule. Matches if the ID has previously matched. It is similar to a child decoder, with the key difference that alerts can have as many descendants as necessary, whereas decoder cannot have "grandchildren".

Default Value n/a
Allowed values Any rule id

Example:

<rule id="100110" level="5">
  <if_sid>100100</if_sid>
  <match>Error</match>
  <description>There is an error in the log.</description>
</rule>

The rule will be triggered if the rule with id: 100100 has previously been triggered and the log contains the word "Error".

if_group

Used as a requisite to trigger the rule. Matches if the group has matched before.

Default Value n/a
Allowed values Any Group

Example:

<rule id="184676" level="12">
    <if_group>sysmon_event1</if_group>
    <field name="sysmon.image">lsm.exe</field>
    <description>Sysmon - Suspicious Process - lsm.exe</description>
    <group>pci_dss_10.6.1,pci_dss_11.4,gdpr_IV_35.7.d,hipaa_164.312.b,nist_800_53_AU.6,nist_800_53_SI.4,</group>
</rule>

The rule matches if the group sysmon_event1 has previously matched before and if the field decoded as sysmon.image is "lsm.exe".

if_level

Matches if the level has matched before.

Default Value n/a
Allowed values Any level from 1 to 16

if_matched_sid

Matches if an alert of the defined ID has been triggered in a set number of seconds.

This option is used in conjunction with frequency and timeframe.

Default Value n/a
Allowed values Any rule id

Note

Rules at level 0 are discarded immediately and will not be used with the if_matched_rules. The level must be at least 1, but the <no_log> option can be added to the rule to make sure it does not get logged.

Example:

<rule id="30316" level="10" frequency="10" timeframe="120">
  <if_matched_sid>30315</if_matched_sid>
  <same_srcip />
  <description>Apache: Multiple Invalid URI requests from same source.</description>
  <group>invalid_request,pci_dss_10.2.4,pci_dss_11.4,gdpr_IV_35.7.d,hipaa_164.312.b,nist_800_53_AU.14,nist_800_53_AC.7,nist_800_53_SI.4,</group>
</rule>

The rule is triggered when rule 30315 has been triggered 10 times in 120 seconds and if the requests were made by the same srcip.

if_matched_group

Matches if an alert of the defined group has been triggered in a set number of seconds.

This option is used in conjunction with frequency and timeframe.

Default Value n/a
Allowed values Any Group

Example:

<rule id="40113" level="12" frequency="8" timeframe="360">
  <if_matched_group>virus</if_matched_group>
  <description>Multiple viruses detected - Possible outbreak.</description>
  <group>virus,pci_dss_5.1,pci_dss_5.2,pci_dss_11.4,gpg13_4.2,gdpr_IV_35.7.d,nist_800_53_SI.3,nist_800_53_SI.4,</group>
</rule>

The rule will trigger when the group virus has been matched 8 times in the last 360 seconds.

if_fts

Makes the decoder that processed the event to take the fts line into consideration.

Example of use <if_fts />

Note

The dynamic filters same_field or not_same_field will not work with the static fields (user, srcip, dstip, etc.) and the specific ones have to be used instead.

same_id

Specifies that the decoded id must be the same. This option is used in conjunction with frequency and timeframe.

Example of use <same_id />

not_same_id

3.13.0 Use different_id instead.

Specifies that the decoded id must be different. This option is used in conjunction with frequency and timeframe.

Example of use <not_same_id />

different_id

Specifies that the decoded id must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_id />

same_source_ip

3.13.0 Use same_srcip instead.

Specifies that the decoded source ip must be the same. This option is used in conjunction with frequency and timeframe.

Example of use <same_source_ip />

not_same_source_ip

Specifies that the decoded source ip must be different. This option is used in conjunction with frequency and timeframe.

3.13.0 Use different_srcip instead.

Example of use <not_same_source_ip />

same_srcip

Specifies that the decoded source ip must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_srcip />

different_srcip

Specifies that the decoded source ip must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_srcip />

same_dstip

Specifies that the decoded destination ip must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_dstip />

different_dstip

Specifies that the decoded destination ip must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_dstip />

same_srcport

Specifies that the decoded source port must be the same. This option is used in conjunction with frequency and timeframe.

Example of use <same_srcport />

different_srcport

Specifies that the decoded source port must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_srcport />

same_dstport

Specifies that the decoded destination port must be the same. This option is used in conjunction with frequency and timeframe.

Example of use <same_dstport />

different_dstport

Specifies that the decoded destination port must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_dstport />

same_location

Specifies that the location must be the same. This option is used in conjunction with frequency and timeframe.

Example of use <same_location />

different_location

Specifies that the decoded location must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_location />

same_srcuser

Specifies that the decoded source user must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_srcuser />

different_srcuser

Specifies that the decoded source user must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_srcuser />

same_user

Specifies that the decoded user must be the same. This option is used in conjunction with frequency and timeframe.

Example of use <same_user />

not_same_user

3.13.0 Use different_user instead.

Specifies that the decoded user must be different. This option is used in conjunction with frequency and timeframe.

Example of use <not_same_user />

different_user

Specifies that the decoded user must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_user />

not_same_agent

3.13.0

Specifies that the decoded agent must be different. This option is used in conjunction with frequency and timeframe.

Example of use <not_same_agent />

same_field

3.9.0

The value of the dynamic field specified in this option must appear in previous events a frequency number of times within the required timeframe.

Example of use <same_field>key</same_field>

As an example of this option, check these rules:

<!-- {"key":"value", "key2":"AAAA"} -->
<rule id="100001" level="3">
  <decoded_as>json</decoded_as>
  <field name="key">value</field>
  <description>Testing JSON alert</description>
</rule>

<rule id="100002" level="10" frequency="4" timeframe="300">
  <if_matched_sid>100001</if_matched_sid>
  <same_field>key2</same_field>
  <description>Testing same_field option</description>
</rule>

Rule 100002 will fire when key2 in the currently considered event is the same in four events that matched rule 100001 before within the last 300 seconds. Therefore, for the following events sequence:

{"key":"value", "key2":"AAAA"}
{"key":"value", "key2":"AAAA"}
{"key":"value", "key2":"BBBB"}
{"key":"value", "key2":"AAAA"}
{"key":"value", "key2":"CCCC"}
{"key":"value", "key2":"CCCC"}
{"key":"value", "key2":"AAAA"}

The last event will fire rule 100002 instead of 100001 because it found the value AAAA in three of the previous events. The corresponding alert looks like this one:

not_same_field

3.9.0

3.13.0 Use different_field instead.

It is the opposite setting of same_field. The value of the dynamic field specified in this option must be different than the ones found in previous events a frequency number of times within the required timeframe.

Example of use <not_same_field>key2</not_same_field>

As an example of this option, check these rules:

<!-- {"key":"value", "key2":"AAAA"} -->
<rule id="100001" level="3">
  <decoded_as>json</decoded_as>
  <field name="key">value</field>
  <description>Testing JSON alert</description>
</rule>

<rule id="100002" level="10" frequency="4" timeframe="300">
  <if_matched_sid>100001</if_matched_sid>
  <not_same_field>key2</not_same_field>
  <description>Testing not_same_field option</description>
</rule>

Rule 100002 will fire when key2 in the currently considered event has a different value that the same field in four previous events that matched rule 100001 before within the last 300 seconds. Therefore, for the following events sequence:

{"key":"value", "key2":"AAAA"}
{"key":"value", "key2":"AAAA"}
{"key":"value", "key2":"BBBB"}
{"key":"value", "key2":"CCCC"}

The last event will fire rule 100002 instead of 100001 due to the value CCCC does not appear in three previous events. The corresponding alert looks like this one:

different_field

3.13.0

It is the opposite setting of same_field. The value of the dynamic field specified in this option must be different than the ones found in previous events a frequency number of times within the required timeframe.

Example of use <different_field>key2</different_field>

global_frequency

3.11.0

Specifies that the events of all agents will be contemplated when using the frequency and timeframe options. By default, only the events generated by the same agent will be taken into account to increase the frequency counter for a rule.

Example of use <global_frequency />

Warning

Although the label contains the word global, this option works at manager level, not at cluster level.

same_protocol

Specifies that the decoded protocol must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_protocol />

different_protocol

Specifies that the decoded protocol must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_protocol />

same_action

Specifies that the decoded action must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_action />

different_action

Specifies that the decoded action must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_action />

same_data

Specifies that the decoded data must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_data />

different_data

Specifies that the decoded data must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_data />

same_extra_data

Specifies that the decoded extra data must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_extra_data />

different_extra_data

Specifies that the decoded extra data must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_extra_data />

same_status

Specifies that the decoded status must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_status />

different_status

Specifies that the decoded status must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_status />

same_system_name

Specifies that the decoded system name must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_system_name />

different_system_name

Specifies that the decoded system name must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_system_name />

same_url

Specifies that the decoded url must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_url />

different_url

Specifies that the decoded url must be different. This option is used in conjunction with frequency and timeframe.

Example of use <different_url />

same_srcgeoip

Specifies that the source geoip location must be the same. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <same_srcgeoip />

different_srcgeoip

Specifies that the source geoip location must be different. This option is used in conjunction with frequency and timeframe.

Example of use <different_srcgeoip />

Example:

As an example of these last options, check this rule:

<rule id=100005 level="0">
  <match> Could not open /home </match>
  <same_user />
  <different_srcgeoip />
  <same_dstport />
</rule>

That rule filters when the same user tries to open file /home but returns an error, on a different ip and using the same port.

same_dstgeoip

3.13.0

Specifies that the destination geoip location must be the same. This option is used in conjunction with frequency and timeframe.

Example of use <same_dstgeoip />

different_dstgeoip

Specifies that the destination geoip location must be different. This option is used in conjunction with frequency and timeframe.

3.13.0

Example of use <different_dstgeoip />

description

Specifies a human-readable description to the rule in order to provide context to each alert regarding the nature of the events matched by it.

Default Value n/a
Allowed values Any string

Examples:

<rule id="100015" level="2">
  ...
  <description> A timeout occurred. </description>
</rule>

<rule id="100035" level="4">
  ...
  <description> File missing. Root access unrestricted. </description>
</rule>

Since Wazuh version 3.3 it is possible to include any decoded field (static or dynamic) to the description message. You can use the following syntax: $(field_name) to add a field to the description.

Example:

<rule id="100005" level="8">
  <match>illegal user|invalid user</match>
  <description>sshd: Attempt to login using a non-existent user from IP $(attempt_ip)</description>
  <options>no_log</options>
</rule>

If description label is declared multiple times within the rule, the following rules apply:

  • The resulting value is their concatenation.

list

Perform a CDB lookup using an ossec list. This is a fast on-disk database which will always find keys within two seeks of the file.

Default Value n/a
Allowed values Path to the CDB file to be used for lookup from the OSSEC directory. Must also be included in the ossec.conf file.
Attribute Description
field key in the CDB: srcip, sr cport, dstip, dstport, extra_data, user, url, id, hostname, program_name, status, action, dynamic field.
lookup match_key key to search within the cdb and will match if they key is present. Default.
not_match_key key to search and will match if it is not present in the database.
match_key_value searched for in the cdb. It will be compared with regex from attribute check_value.
address_match_key IP and the key to search within the cdb and will match if they key is present.
not_address_match_key IP the key to search and will match if it IS NOT present in the database
address_match_key_value IP to search in the cdb. It will be compared with regex from attribute check_value.
check_value regex for matching on the value pulled out of the cdb when using types: address_match_key_value, match_key_value

Example:

<rule id="80780" level="3">
    <if_sid>80700</if_sid>
    <list field="audit.key" lookup="match_key_value" check_value="write">etc/lists/audit-keys</list>
    <description>Audit: Watch - Write access</description>
    <group>audit_watch_write,gdpr_IV_30.1.g,</group>
</rule>

The rule will look for "audit.key" in the CDB list. Where it will check if its equal to "write", in which case it will match and trigger a level 3 alert.

info

Extra information may be added through the following attributes:

Default Value n/a
Allowed values Any string

+-----------+----------------+-----------------------------------------------------------------------------------------------------------+ | Attribute | Allowed values | Description | +-----------+----------------+-----------------------------------------------------------------------------------------------------------+ | type | text | This is the default when no type is selected. Additional information about the alert/event. | + +----------------+-----------------------------------------------------------------------------------------------------------+ | | link | Link to more information about the alert/event. | + +----------------+-----------------------------------------------------------------------------------------------------------+ | | cve | The CVE Number related to this alert/event. | + +----------------+-----------------------------------------------------------------------------------------------------------+ | | ovsdb | The osvdb id related to this alert/event. | +-----------+----------------+-----------------------------------------------------------------------------------------------------------+

Example:

<rule id="5714" level="14" timeframe="120" frequency="3">
  <if_matched_sid>5713</if_matched_sid>
  <match>Local: crc32 compensation attack</match>
  <description>sshd: SSH CRC-32 Compensation attack</description>
  <info type="cve">2001-0144</info>
  <info type="link">http://www.securityfocus.com/bid/2347/info/</info>
  <group>exploit_attempt,pci_dss_11.4,pci_dss_6.2,gpg13_4.12,gdpr_IV_35.7.d,nist_800_53_SI.4,nist_800_53_SI.2,</group>
</rule>

The rule provides additional information about the threat it detects.

options

Additional rule options.

Attribute Description
alert_by_email Always alert by email.
no_email_alert Never alert by email.
no_log Do not log this alert.
no_full_log Do not include the full_log field in the alert.
no_counter Omit field rule.firedtimes in the JSON alert.

Example:

<rule id="9800" level="8">
  <match>illegal user|invalid user</match>
  <description>sshd: Attempt to login using a non-existent user</description>
  <options>no_log</options>
</rule>

Note

Use one <options> tag for each option you want to add.

check_diff

Used to determine when the output of a command changes.

Example:

<rule id="534" level="1">
  <if_sid>530</if_sid>
  <match>ossec: output: 'w'</match>
  <check_diff />
  <options>no_log</options>
  <description>List of logged in users. It will not be alerted by default.</description>
</rule>

group

Add additional groups to the alert. Groups are optional tags added to alerts.

They can be used by other rules by using if_group or if_matched_group, or by alert parsing tools to categorize alerts.

Groups are variables that define behavior. When an alert includes that group label, this behavior will occur.

Example:

<rule id="3801" level="4">
  <description>Group for rules related with spam.</description>
  <group>spam,</group>
</rule>

Now, every rule with the line <group>spam,</group> will be included in that group.

It's a very useful label to keep the rules ordered.

Default Value n/a
Allowed values Any String

mitre

3.13.0

Specifies the MITRE ATT&CK technique ID or IDs that fit in well with the rule.

Required label Value
id MITRE ATT&CK technique ID.

Example:

<rule id="100002" level="10">
  <description>Attack technique sample.</description>
  <mitre>
    <id>T1110</id>
    <id>T1037</id>
  </mitre>
</rule>

var

Defines a variable that may be used in any place of the same file.

Attribute Value
name Name for the variable.

Example:

<var name="joe_folder">/home/joe/</var>

 <group name="local,">

   <rule id="100001" level="5">
     <if_sid>550</if_sid>
     <field name="file">^$joe_folder</field>
     <description>A Joe's file was modified.</description>
     <group>ossec,pci_dss_10.6.1,gpg13_10.1,gdpr_IV_35.7.d,</group>
   </rule>

</group>

BAD_WORDS

<var name="BAD_WORDS">errorfailure</var>

BAD_WORDS is a very used use case of <var> option.

It is used to include many words in the same variable. Later, this variable can be matched into the decoders to check if any of those words are in a caught event.

Example:

<var name="BAD_WORDS">error|warning|failure</var>

<group name="syslog,errors,">
  <rule id="XXXX" level="2">
    <match>$BAD_WORDS</match>
    <description>Error found.</description>
  </rule>
</group>