Testing Wazuh rules for WordPress traffic
How to test Wazuh web rules for WordPress: wazuh-logtest phases, the -U option, the PUT /logtest API, positive and negative fixtures, and rules 31100 to 31151.
A rule that loaded without an error is not yet verified, because syntax only tells you the file can be parsed. A set of fixtures with positive and negative logs, run on every change, shows whether the rule works and whether it avoids catching traffic it should not.
What needs testing
For a web rule pack there are three kinds of questions. Does the decoder extract srcip, url and id from the line? Do the parent rule and its children lead to the expected rule.id and level? Do the counters of correlation rules behave the way frequency and timeframe describe? One mechanism is enough for each of them: wazuh-logtest, run by hand or through the API.
The documentation describes the tool as a sandbox in wazuh-analysisd, where rules are checked against the log samples you provide, which helps with writing rules, diagnosing false alarms and finding detection gaps. The basics of use are in the post Testing rules and decoders with wazuh-logtest.
wazuh-logtest phases
The tool /var/ossec/bin/wazuh-logtest prints its result in three phases: Phase 1: Completed pre-decoding., Phase 2: Completed decoding. and Phase 3: Completed filtering (rules).. When a rule generates an alert, the line **Alert to be generated. appears.
| Phase | What you check |
|---|---|
| 1, pre-decoding | Whether the syslog header (date, host, program) was read |
| 2, decoding | The decoder name and the fields srcip, url, id |
| 3, filtering | id, level and description of the matched rule |
The web access decoder needs the type web-log, because a comment in the file 0375-web-accesslog_decoders.xml states that every access log must use this type to be matched against web rules. The rules check url and id as decoded fields, so an error in phase 2 always ends with no match in phase 3.
Command line options
| Option | Action |
|---|---|
-v | Extended results, according to the documentation key for diagnosing a rule or decoder |
-d | Debug mode, prints diagnostic messages |
-q | Quiet run |
-l <location> | Sets a custom log location |
-U <rule-id:alert-level:decoder-name> | Returns exit code 0 if the result matches the given criteria |
-V | Version and license |
The -U option is meant for automation: the documentation notes that it makes sense only with a single log line.
echo 'Jan 11 10:13:05 agent-01 nginx: 198.51.100.7 - - [11/Jan/2026:10:13:05 +0000] "GET /?s=1%20union%20select%20null,null HTTP/1.1" 200 512 "-" "example-client"' \
| /var/ossec/bin/wazuh-logtest -q -U 31106:6:web-accesslog
echo "exit=$?"
The line has code 200, so after 31103 its child 31106 matches (an attack that returned 200) and it is the final result. The decoder name in the criterion (web-accesslog) is an assumption: it depends on which decoder of the web-accesslog* family matches the line, so read it from phase 2 before you save it in a script. Exit code 0 means the result matches the triple, any other result means a mismatch.
Sessions and counters
Logtest keeps a session, and with it the firedtimes counter. The documentation shows this on rule 5710: the firedtimes counter grows on every repeat of the log, and after another paste the correlation rule 5712 matches instead of 5710, which requires eight failed logins from the same address within two minutes. Web rules work the same way, for example 31151 (frequency="14", timeframe="90", if_matched_sid 31101, the same source address), which combines events from consecutive input lines. Testing a correlation rule therefore needs many lines in one session, and a single fixture is enough only for atomic rules.
The default settings of the rule_test section are enabled yes, threads 1, max_sessions 64 and session_timeout 15m. A session idle for longer than session_timeout is closed, and once max_sessions is reached, opening a new one closes the longest idle session. For tests this has one practical consequence: the counter of one fixture should not carry over to the next, so before testing atomic rules start from a fresh session.
Testing through the API
For automated tests the documentation provides the endpoint PUT /logtest and DELETE /logtest/sessions/{token}. Before use, get a JWT token (POST /security/user/authenticate?raw=true). The API runs at https://localhost:55000.
LOGTEST_REQ='{
"event": "Jan 11 10:13:05 agent-01 nginx: 198.51.100.7 - - [11/Jan/2026:10:13:05 +0000] \"GET /?s=1%20union%20select%20null,null HTTP/1.1\" 200 512 \"-\" \"example-client\"",
"log_format": "syslog",
"location": "agent-01->/var/log/example-site/access.log"
}'
curl -k -X PUT "https://localhost:55000/logtest?pretty=true" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$LOGTEST_REQ"
The request fields are event, log_format, location and optionally token. The response contains, among others, data.token, data.output.rule (with id, level, description, firedtimes, groups), data.output.decoder.name, data.output.data and data.alert. If the next request passes the token from the first response, it lands in the same session, and an invalid token creates a new one. This way a test of a rule with a counter can send further events with one token and end the session with a DELETE call. To compare the result with the expectation, a script can use jq, for example jq -e '.data.output.rule.id == "31106"'.
Web rules under test
The file 0245-web_rules.xml gives a tree you need to keep in mind when building fixtures.
| ID | Level | Role |
|---|---|---|
| 31100 | 0 | Groups logs from the web-log category |
| 31108 | 0 | Child of 31100, id starts with 2 or 3, simple request rule |
| 31101 | 5 | Child of 31100, id starts with 4, error 400 |
| 31103 | 7 | SQL injection, if_sid 31100 and 31108 |
| 31104 | 6 | Typical web attack, paths with ../.. and similar |
| 31106 | 6 | Attack from 31103, 31104 or 31105 that returned a code starting with 200 |
| 31151 | 10 | Many 400 errors from the same address, 14 in 90 seconds |
Two conclusions from this tree. First, rule 31106 requires an id starting with 200, so a fixture with code 200 and an SQL pattern tests a different path than a fixture with code 404. Second, 31103 has 31100 and 31108 as parents, so run the SQL fixtures with codes 200, 302 and 404 to check all paths. These conclusions are read from the rule files, not observed on a running engine, so confirm them with your own fixtures.
Fixture table
Recommendation: keep the fixture table as data (a text file with the log line, the expected rule.id and the level), and let a script replay it on every rule change. Sample rows for the service example.com:
| Name | Request fragment | Expected result |
|---|---|---|
| sqli-200 | /?s=1%20union%20select%20null,null status 200 | 31106, level 6 (through 31103) |
| traversal-500 | /wp-content/../..//etc/passwd status 500 | 31104, level 6 |
| plain-page | /o-nas/ status 200 | no alert |
| plain-404 | /brak/ status 404 | 31101, level 5 |
| static-file | /style.css status 404 | no alert from 31101 (31102 silences it) |
Negative rows (plain page, static file) matter as much as positive ones. A rule that reacts to everything passes every positive test, and a negative fixture is the only way to notice it. The expected values in the table come from reading the rules, so on the first run compare them with the actual result and fix the table only when you understand the difference.
A custom rule and its test
A child rule points to its parent through if_sid. The example raises the level for an injection in a REST API address:
<group name="web,wordpress,">
<rule id="100520" level="9">
<if_sid>31103</if_sid>
<url>/wp-json/</url>
<description>WordPress REST: SQL injection attempt in request URL.</description>
</rule>
</group>
Fixtures for it, all with status 500: a request to /wp-json/wp/v2/posts?search=1%20union%20select%20null,null (expected 100520), the same with the path /blog/ (expected 31103, level 7) and a request without an SQL pattern (no alert). Status 200 would send the line to the built-in child 31106, and 404 to the 31101 branch, so the fixture would test a different rule than 100520. When the file changes name or moves to another directory, check the loading order described in the post Wazuh: loading rules and decoders, because it decides whether if_sid finds the parent. A broader workflow for working on rules, from hypothesis to deployment, is described in Detection engineering in Wazuh.
Rules from a single event are only the beginning. An event chain, where consecutive logs from different sources add up to one detection, is covered in The WordPress event chain.
Testing a correlation rule
Recommended scheme for 31151: fourteen lines with code 404 and the same source address in one session, then a check of which line in the sequence raises the 31151 alert. The frequency and timeframe parameters come from the rule file (14 events in 90 seconds), so the boundaries are known and you can write two fixtures: one just below the threshold, which must not raise an alert, and one at the threshold. By default only events from the same agent are counted. A fixture in a logtest session has one agent, so the limit does not get in the way, but on a live stream you have to account for it. Correlation details are covered in Event correlation in Wazuh.
Common mistakes in tests
- Testing after a change to rule files in an old session: the documentation says each session loads its own set of rules and decoders, so after changing the files (recommendation) open a new session.
- Assuming the decoder requires a syslog header: the decoder file has two
web-accesslogvariants, one withprogram_namenginxorapache, the other with aprematchon the access log line itself. Test both line forms if the agent collects them in different ways. - A fixture with code 200 used as a test of a 4xx error path, or the other way around, which gives a different rule tree.
Order of execution in CI
- Before each fixture run, start from a fresh session, or precede the atomic rule test with a new session token.
- Run atomic fixtures one at a time with
-U, and correlation ones as a sequence of API requests with one token. - After the sequence, close the session with
DELETE /logtest/sessions/{token}. - Compare the result of each fixture with the table, and treat a mismatch as a pipeline error, not a warning.
What the documentation does not specify
- A command that checks the syntax of rule files, within the scope of the pages fetched.
- Which of the matching sibling rules is returned when two child rules have the same parent.
- The logtest result for WordPress traffic: the expected identifiers in the tables come from reading the rule files and need confirmation on a running installation.
- The decoder name in the
-Ucriterion for a specific line, which has to be read from phase 2.
Sources
- https://documentation.wazuh.com/current/user-manual/ruleset/testing.html
- https://documentation.wazuh.com/current/user-manual/reference/tools/wazuh-logtest.html
- https://documentation.wazuh.com/current/user-manual/ruleset/ruleset-xml-syntax/rules.html
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/rules/0245-web_rules.xml
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/decoders/0375-web-accesslog_decoders.xml
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/rules/0265-php_rules.xml