Wazuh ships with thousands of detection rules, but no default ruleset knows your environment. Maybe nobody should ever log in as root, or a particular service account should never be used interactively. Custom rules let you encode that knowledge. In this post you will write, test and deploy your first one.
How Wazuh rules work
Every event goes through two stages on the Wazuh server:
- Decoders parse the raw log line and extract fields such as
srcip,userandprogram_name. - Rules check those fields and assign the event a level from 0 to 15. Higher levels mean more important alerts.
Rules can build on each other. A child rule uses if_sid to say "only check me when this parent rule has already matched". That keeps custom rules small and precise.
The scenario
Our policy says administrators must log in with their own accounts and use sudo. A successful SSH login directly as root should therefore raise a high-priority alert.
Wazuh already has a built-in rule for successful SSH authentication, rule 5715. We will create a child rule that only fires when the user is root.
Step 1: Add the rule
Custom rules belong in /var/ossec/etc/rules/local_rules.xml on the Wazuh server, so they survive upgrades. Use rule IDs from 100000 upwards to avoid clashing with built-in rules.
<group name="local,sshd,">
<rule id="100100" level="12">
<if_sid>5715</if_sid>
<user>root</user>
<description>Successful SSH login as root on $(hostname)</description>
<mitre>
<id>T1078</id>
</mitre>
</rule>
</group>
What each part does:
if_sidlimits the rule to events already matched by rule 5715.usermatches the username field extracted by the decoder.level="12"makes it a high-priority alert.mitremaps the alert to the ATT&CK technique for valid accounts.
Step 2: Test before you restart
Never guess whether a rule works. Wazuh includes a testing tool that shows exactly how a log line is decoded and which rules match:
sudo /var/ossec/bin/wazuh-logtest
Paste a sample log line, such as:
Mar 4 10:20:01 web01 sshd[3120]: Accepted password for root from 192.0.2.10 port 50122 ssh2
The output shows the decoder fields and, if everything is correct, your rule 100100 firing at level 12.
Step 3: Apply the rule
Once the test passes, restart the manager to load the rule:
sudo systemctl restart wazuh-manager
Now log in as root on a monitored lab machine and watch the alert appear on the dashboard.
Tips for good custom rules
- Start specific. Narrow rules produce fewer false positives.
- Reuse built-in rules with
if_sidinstead of rewriting their logic. - Write clear descriptions, because analysts read them at 3 a.m.
- Keep a test log line for every rule, so you can re-test after changes.
- Review levels regularly so important alerts stand out.
Writing and tuning detections is one of the most valuable SOC skills. Our Wazuh XDR SIEM course includes labs where you simulate attacks and build rules to catch them.
Learn this hands-on
Wazuh XDR SIEM
Deploy, tune and run Wazuh in the cloud, from install to custom rules.
View course