# Wazuh 4 training, part 4: log analysis

> Wazuh 4 training part 4: three analysis phases, retention and archives, SSH brute force with rules 5710 and 5712, alert assessment and rule lookup.

Published: 2026-11-28. Category: Analysis. Tags: Wazuh 4, Wazuh 4 training. URL: https://wazuh.blog/en/blog/wazuh-4-training-part-4/ Polish original: https://wazuh.blog/blog/szkolenie-wazuh-4-czesc-4/

The fourth part of the [Wazuh 4 training](/en/blog/wazuh-4-training-introduction/) moves from agent management in [part 3](/en/blog/wazuh-4-training-part-3/) to what the manager does with a single event. The exercises cover log retention, a controlled SSH brute force attack, assessment of the generated alerts and reading the rules that fired them. The description applies to Wazuh 4.14.

## Three phases of event analysis

The documentation describes log analysis in three phases: pre-decoding, decoding and rule matching. The example is an SSH daemon entry about a successful login:

```text
Feb 14 12:19:04 192.0.2.1 sshd[25474]: Accepted password for example-user from 192.0.2.133 port 49765 ssh2
```

In pre-decoding the analysis engine extracts syslog header data: `timestamp` (`Feb 14 12:19:04`), `hostname` and `program_name` (`sshd`). This phase needs no application decoder.

In decoding the engine looks for a decoder that matches the log. For SSH two decoders from `/var/ossec/ruleset/decoders/0310-ssh_decoders.xml` handle it: the parent `sshd` matches the program name and the child `sshd-success` extracts the fields.

```xml
<decoder name="sshd">
  <program_name>^sshd</program_name>
</decoder>
<decoder name="sshd-success">
  <parent>sshd</parent>
  <prematch>^Accepted</prematch>
  <regex offset="after_prematch">^ \S+ for (\S+) from (\S+) port (\S+)</regex>
  <order>user, srcip, srcport</order>
  <fts>name, user, location</fts>
</decoder>
```

The decoding result is the user, the source address `srcip` and the source port `srcport`. I take decoders apart in [part 5](/en/blog/wazuh-4-training-part-5/).

In the third phase the manager compares the decoded event with the rules. Rule 5715 from `/var/ossec/ruleset/rules/0095-sshd_rules.xml` matches here:

```xml
<rule id="5715" level="3">
  <if_sid>5700</if_sid>
  <match>^Accepted|authenticated.$</match>
  <description>sshd: authentication success.</description>
  <group>authentication_success,pci_dss_10.2.5,</group>
</rule>
```

The documentation notes that by default the manager generates alerts for rules with a level above 2. Rule 5715 has level 3, so this login becomes an alert visible in the dashboard. The `log_alert_level` setting from [part 1](/en/blog/wazuh-4-training-part-1/) changes that threshold, and the levels are described in the [post on rule levels](/en/blog/wazuh-rule-levels-and-thresholds/).

The directory layout from the documentation matters for every custom change:

| Path | Content |
|------|---------|
| `/var/ossec/ruleset/decoders/` | decoders shipped with Wazuh |
| `/var/ossec/ruleset/rules/` | rules shipped with Wazuh |
| `/var/ossec/etc/decoders/local_decoder.xml` | default file for custom decoders |
| `/var/ossec/etc/rules/local_rules.xml` | default file for custom rules |

Files in `/var/ossec/ruleset/` are overwritten or modified on upgrade, so the documentation says to make changes in `/var/ossec/etc/`. Wazuh ships more than 3000 rules and decoders.

## Where logs and alerts end up

The documentation distinguishes the server's internal logs from events collected from monitored endpoints. The server stores them in `/var/ossec/logs/` with no time limit:

| File | Source | Content |
|------|--------|---------|
| `/var/ossec/logs/ossec.log` | internal | all informational server logs |
| `/var/ossec/logs/api.log` | internal | server API logs |
| `/var/ossec/logs/cluster.log` | internal | cluster operation |
| `/var/ossec/logs/integrations.log` | internal | module integrating with external systems |
| `/var/ossec/logs/active-responses.log` | internal | Active Response module |
| `/var/ossec/logs/firewall/firewall.log` | internal | firewall logs |
| `/var/ossec/logs/archives/archives.log` | external | events in text form, disabled by default |
| `/var/ossec/logs/archives/archives.json` | external | events in JSON, disabled by default |

Alerts follow a separate path: `/var/ossec/logs/alerts/alerts.log` and `/var/ossec/logs/alerts/alerts.json`. Two options in the `<global>` section control these files:

| Option | Default | Effect |
|--------|---------|--------|
| `alerts_log` | `yes` | write alerts to `alerts.log` |
| `jsonout_output` | `yes` | write alerts to `alerts.json` |

Disabling `jsonout_output` stops alert indexing, because Filebeat in the default installation reads `alerts.json`. The documentation adds that disabling both the JSON and the text format at once breaks the integrator, the syslog client and email notifications.

## Exercise 1: log retention and archives

The first question is how long the manager keeps logs. According to the documentation the server stores them indefinitely, and to save space it compresses files during rotation. Files are compressed daily and signed with MD5, SHA1 and SHA256 sums. They land in nested directories named after the source file, the year and the month. The example is an `archives.log` file compressed on 13 April 2024:

```bash
ls -la /var/ossec/logs/archives/2024/Apr/
# -rw-r----- 1 wazuh wazuh 0 Apr 13 00:00 ossec-archive-13.log.gz
# -rw-r----- 1 wazuh wazuh 0 Apr 13 00:00 ossec-archive-13.log.sum
```

The name gets the `ossec` prefix and the day of the month, and the checksum file follows the same pattern with the `.sum` extension. The documentation leaves deleting old files to the administrator: they can be configured to be deleted after a given time or moved to a log management system, a backup server or the cloud.

The default rotation policy works on three levels: files are rotated and compressed daily, monthly and yearly. This keeps the disk from filling up with uncompressed logs, and older data stays in directories laid out by year and month. The checksums sit next to every compressed file, so comparing them with a freshly computed sum shows whether a file changed after rotation. Compressed files still take up space. On a server that collects logs for a long time you therefore have to decide what happens to them after a set period.

Two options control the rotation of alert and archive files:

| Option | Default | Range and notes |
|--------|---------|-----------------|
| `rotate_interval` | `0` (disabled) | from `10m` to `1d`; the minimum comes from `analysisd.min_rotate_interval` in `/var/ossec/etc/internal_options.conf` |
| `max_output_size` | `0` (disabled) | from 1 MiB to 1 TiB, with an `M` or `G` suffix, for example `20M` |

### Enabling archives

Archives hold every event, including those that fired no rule, so they grow fast. The documentation warns that they collect logs from all endpoints and load the server disk. Security teams use archived logs to review historical data about incidents, analyze trends, build reports and hunt for threats. The archives are disabled by default because they store logs indefinitely. Once enabled, the manager creates files that retain security data for compliance and forensic analysis. Before enabling them I assess the impact on disk space and server performance, and with many agents I estimate the size up front.

The difference between archives and alerts is described in the [post on archives and alerts](/en/blog/wazuh-archives-vs-alerts/). In the lab I enable them in the manager's `/var/ossec/etc/ossec.conf`:

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

`logall` writes events in syslog format to `archives.log`, and `logall_json` writes JSON to `archives.json`; both options default to `no`. An index visible in the dashboard can be created only from the JSON variant. After the edit, restart the manager:

```bash
systemctl restart wazuh-manager
```

For the events to reach the indexer, in `/etc/filebeat/filebeat.yml` I change `archives: enabled` from `false` to `true` and restart Filebeat:

```yaml
archives:
  enabled: true
```

```bash
systemctl restart filebeat
```

I create the index pattern under Dashboard Management > Index patterns > Create index pattern. The name is `wazuh-archives-*` and the time field is `timestamp`. In Explore > Discover I select this pattern, narrow the time range to a few minutes around the test and filter events by `agent.id`, `agent.ip` or `agent.name`. Some archived events also show up as alerts, but the rest triggered no rule and are visible only here. These are the events that can become the basis for custom rules: the documentation points to the archives as a source for building detection logic, custom decoders and rules, and a log collected this way can be tested in `wazuh-logtest`, which I describe in exercise 2. Retention of the indices themselves in the indexer is covered by the [post on OpenSearch retention](/en/blog/opensearch-retention/).

### A custom cleanup rule

The documentation provides no tool for deleting old files, so I suggest a plain `find` on the directory structure from the example, selecting `ossec-archive-*` files by modification date. The threshold is set by the organization's retention policy, and the value 2026-06-01 is only an example:

```bash
# List compressed archive files and checksums older than the cutoff date (dry run)
find /var/ossec/logs/archives -type f -name 'ossec-archive-*' ! -newermt 2026-06-01

# Delete them after reviewing the list
find /var/ossec/logs/archives -type f -name 'ossec-archive-*' ! -newermt 2026-06-01 -delete
```

Always run the version without `-delete` first. Deleted files do not come back, so move a copy off the server before the first cleanup.

## Exercise 2: SSH brute force attack

The exercise has three steps: replaying events in the `wazuh-logtest` tool, a real attack on your own lab host and analysis of the alerts in the dashboard. I start with the tool, because it shows how the rules work without any network traffic. The tool itself is covered in the [post on wazuh-logtest](/en/blog/wazuh-logtest/).

### Replay in wazuh-logtest

The tool runs on the server (`/var/ossec/bin/wazuh-logtest`), in the dashboard as Ruleset Test in the Server management section and through the server API. The default configuration in the `<rule_test>` section:

```xml
<rule_test>
  <enabled>yes</enabled>
  <threads>1</threads>
  <max_sessions>64</max_sessions>
  <session_timeout>15m</session_timeout>
</rule_test>
```

Each session has its own set of rules and decoders and a `firedtimes` counter that grows with every match of a rule in that session. The log to paste:

```text
Oct 15 21:07:00 agent-01 sshd[29205]: Invalid user example-user from 203.0.113.10 port 48928
```

Expected result, derived from the rules in the v4.14.0 file: the first paste gives three phases. Phase 1 shows `timestamp`, `hostname` and `program_name: 'sshd'`, phase 2 shows the `sshd` decoder with the fields `srcip`, `srcport` and `srcuser`, and phase 3 shows rule 5710 with level 5, the description "sshd: Attempt to login using a non-existent user" and `firedtimes: '1'`. Further pastes give the same rule with a growing counter. The eighth paste triggers rule 5712 with level 10 and the field `frequency: '8'` instead of 5710.

The same works through the API. The first `PUT /logtest` request without a token opens a session and returns the token in `data.token`; further requests with that token keep the event history. An invalid token creates a new session. Idle sessions are closed by the `session_timeout` limit, and once `max_sessions` is reached the longest idle session gives way to a new one.

```bash
# Open a logtest session and keep its token for the following requests
TOKEN=$(curl -u <WAZUH_API_USER>:<WAZUH_API_PASSWORD> -k -X POST "https://localhost:55000/security/user/authenticate?raw=true")
curl -k -X PUT "https://localhost:55000/logtest?pretty=true" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"event": "Oct 15 21:07:00 agent-01 sshd[29205]: Invalid user example-user from 203.0.113.10 port 48928", "log_format": "syslog", "location": "master->/var/log/syslog"}'
```

Besides `rule`, the response also contains `predecoder`, `decoder`, `data` (`srcip`, `srcport`, `srcuser`), `full_log` and `location`.

### Attack with hydra

For real events the Wazuh documentation uses the Hydra tool on a separate attacker host. Installation and the attack from the example about blocking brute force with Active Response:

```bash
sudo apt update && sudo apt install -y hydra
sudo hydra -t 4 -l <USERNAME> -P <PASSWD_LIST.txt> <TARGET_IP> ssh
```

I run the attack only against my own lab host. To trigger rule 5712, I give `<USERNAME>` an account name that does not exist on the target, and a file with at least eight passwords. If the account exists, the scenario is different, as described below.

### Rules 5700, 5710 and 5712

Everything rests on three rules from `0095-sshd_rules.xml` (tag v4.14.0):

```xml
<rule id="5700" level="0" noalert="1">
  <decoded_as>sshd</decoded_as>
  <description>SSHD messages grouped.</description>
</rule>

<rule id="5710" level="5">
  <if_sid>5700</if_sid>
  <match>illegal user|invalid user</match>
  <description>sshd: Attempt to login using a non-existent user</description>
  <mitre>
    <id>T1110.001</id>
    <id>T1021.004</id>
  </mitre>
  <group>authentication_failed,invalid_login,</group>
</rule>

<rule id="5712" level="10" frequency="8" timeframe="120" ignore="60">
  <if_matched_sid>5710</if_matched_sid>
  <same_source_ip />
  <description>sshd: brute force trying to get access to the system. Non existent user.</description>
  <mitre>
    <id>T1110</id>
  </mitre>
  <group>authentication_failures,</group>
</rule>
```

In the `<group>` blocks I shortened the list of compliance groups (PCI DSS, GDPR, HIPAA, NIST, TSC), because the full list adds nothing to the analysis. Rule 5700 matches every event decoded by the `sshd` decoder. It has level 0 and `noalert="1"`, so it generates no alert itself, but the event is still evaluated by the rules that point to it in `if_sid`. Rule 5710 matches the phrases `illegal user` or `invalid user`.

Rule 5712 combines three attributes:

| Attribute | Range | Meaning in 5712 |
|-----------|-------|-----------------|
| `frequency` | from 2 to 9999 | 8 matches of the parent rule before an alert |
| `timeframe` | from 1 to 99999 s | a 120 second window |
| `ignore` | from 1 to 999999 s | after an alert the rule stays silent for 60 seconds to avoid a flood |

`if_matched_sid` works like `if_sid`, but requires that an alert with the given ID occurred within the set time, and `same_source_ip` limits counting to events from the same address. The syntax table in the documentation lists a related option under the name `same_srcip`, while the rules file from tag v4.14.0 uses `<same_source_ip />`. In rules I write, I copy the notation from the working file.

By default the `frequency` counter counts only events from the same agent. The `global_frequency` option extends it to all agents.

### What you see in the dashboard

In the dashboard I open Threat intelligence > Threat Hunting, enter the user name used in the attack in the search field and go to the Events tab. Sorted ascending by time, there should be seven alerts of rule 5710, and then the eighth identical event triggers 5712, exactly what `wazuh-logtest` showed. In the expanded alert I check the fields `rule.id`, `rule.level`, `rule.firedtimes`, `rule.description`, `rule.groups`, `agent.name` and the decoded data in `data`.

Alerts reach the dashboard the usual way: the manager writes them to `alerts.json` and Filebeat forwards them to the indexer. That file can be searched directly. `jq` is not from the Wazuh documentation, it is my recommendation for quick analysis:

```bash
# Count alerts per rule id and level
jq -r '[.rule.id, .rule.level] | @tsv' /var/ossec/logs/alerts/alerts.json | LC_ALL=C sort | uniq -c

# Show alerts at level 10 and above with time, rule and source address
jq -c 'select(.rule.level >= 10) | {t: .timestamp, id: .rule.id, ip: .data.srcip}' /var/ossec/logs/alerts/alerts.json

# Count alerts per source address
jq -r 'select(.data.srcip != null) | .data.srcip' /var/ossec/logs/alerts/alerts.json | LC_ALL=C sort | uniq -c | sort -rn
```

After the attack from the exercise, the first command shows 7 alerts of 5710 (level 5) and 1 alert of 5712 (level 10), and the third assigns all of them to the attacker's address.

### When the account exists

Rule 5712 applies only to accounts that do not exist. With a wrong password for an existing account, the same attack looks different:

| Rule | Level | Condition |
|------|-------|-----------|
| 5716 | 5 | `^Failed` or `^error: PAM: Authentication` |
| 5760 | 5 | `Failed password`, `Failed keyboard` or `authentication error`, parents 5700 and 5716 |
| 5763 | 10 | `frequency="8"`, `timeframe="120"`, `ignore="60"`, `if_matched_sid` 5760, same source address |
| 5720 | 10 | `frequency="8"`, `if_matched_sid` 5716, same source address, no `timeframe` attribute |

Rule 5763 is the one the Wazuh documentation attaches Active Response to in the brute force blocking example; that mechanism is the subject of the [post on Active Response](/en/blog/wazuh-active-response/) and of part 9.

## Exercise 3: alert assessment

The exercise is to go through the alerts from the attack and establish what the data says about it. The documentation describes no assessment procedure, so the order below is my recommendation:

1. Level `rule.level` and description `rule.description`. Level 5 for 5710 is a single attempt, level 10 for 5712 is confirmed repetition.
2. Groups `rule.groups`. The groups `authentication_failed` and `invalid_login` point to failed logins, and `authentication_success` to successful ones.
3. Repetition: `rule.firedtimes` and the number of alerts from one `data.srcip` in a short time window.
4. Account: the `data.srcuser` field gives the user name from the attempt. Rule 5710 marks an attempt on a non-existent account, and whether the account exists can be checked on the host.
5. Mapping to MITRE ATT&CK in `rule.mitre`: 5710 refers to techniques T1110.001 and T1021.004, and 5712 to T1110.
6. Source: the address in `data.srcip` and the agent in `agent.name`.
7. Aftermath: whether after a series of failed attempts an alert of rule 5715 (successful login, level 3) appears from the same address. Such a login needs checking: it does not prove that one of the earlier attempts succeeded, but it may point to it.

Address reputation can be checked outside Wazuh, in public reputation databases.

## Exercise 4: rule lookup

Assessing an alert requires knowing the conditions that triggered it, and rules are spread over many files. There are three ways to look them up.

### Dashboard

In Server management > Rules you can search rules with Wazuh Query Language queries and manage custom rules. From an expanded alert you can also open the rule page by clicking its identifier.

### Server API

The `GET /rules` endpoint returns information about rules: the file where each is defined, the description, the groups and the status. Parameters from the v4.14.0 API specification:

| Parameter | Meaning |
|-----------|---------|
| `rule_ids` | list of rule identifiers |
| `level` | a single level (`4`) or a range (`2-4`) |
| `group` | filter by rule group |
| `filename`, `relative_dirname` | filter by file and directory |
| `mitre` | filter by MITRE technique identifier |
| `status` | `enabled`, `disabled` or `all` |
| `search` | string to search for; a leading `-` gives the complement |
| `q` | filtering query |
| `select`, `sort`, `limit`, `offset` | field selection, sorting, paging; `limit` defaults to 500, maximum 100000 |

An entry in the response contains the fields `filename`, `relative_dirname`, `id`, `level`, `status`, `details`, `groups`, `description`, `mitre` and the compliance mappings (`pci_dss`, `gdpr`, `gpg13`, `hipaa`, `nist_800_53`, `tsc`).

```bash
# Look up the rules from exercise 2 together with their source files
curl -k -X GET "https://localhost:55000/rules?rule_ids=5710,5712&select=id,level,filename,description&pretty=true" -H "Authorization: Bearer $TOKEN"

# Print the raw XML of the whole file that defines them
curl -k -X GET "https://localhost:55000/rules/files/0095-sshd_rules.xml?raw=true" -H "Authorization: Bearer $TOKEN"
```

Additionally `GET /rules/groups` and `GET /rules/files` list the rule groups and files.

### XML file and the if_sid chain

Rules shipped with Wazuh live in `/var/ossec/ruleset/rules/`. A rule's parent is named in `if_sid` or `if_matched_sid`, and the parent's parent in the same element of the parent rule. The loop below walks the chain up to a rule with no parent. The example works on the `0095-sshd_rules.xml` file from tag v4.14.0:

```bash
# Walk the parent chain of a rule (needs xmllint)
F=/var/ossec/ruleset/rules/0095-sshd_rules.xml
id=5712
while [ -n "$id" ]; do
  echo "rule $id level=$(xmllint --xpath "string(//rule[@id='$id']/@level)" "$F") $(xmllint --xpath "string(//rule[@id='$id']/description)" "$F")"
  id=$(xmllint --xpath "string(//rule[@id='$id']/if_sid | //rule[@id='$id']/if_matched_sid)" "$F" | awk '{print $1}')
done
```

```text
rule 5712 level=10 sshd: brute force trying to get access to the system. Non existent user.
rule 5710 level=5 sshd: Attempt to login using a non-existent user
rule 5700 level=0 SSHD messages grouped.
```

The loop takes the first parent, so for rules with a list in `if_sid`, such as 5760 (parents 5700 and 5716), it shows only one branch. Rules from several files can have a parent in another file, and then the whole directory has to be searched. The custom rules I write in part 6 follow the same principle.

A few condition options from the rule syntax documentation come back in analysis:

| Option | Meaning |
|--------|---------|
| `decoded_as` | matches logs decoded by the given decoder |
| `match` | expression, sregex by default; `regex` uses regex by default |
| `field` | compares a field extracted by the decoder with an expression |
| `if_sid` | the rule matches when a rule from the list matched earlier |
| `if_group` | the same for a rule group |
| `if_level` | the same for a level |
| `if_matched_sid`, `if_matched_group` | require a match within a set time, together with `frequency` and `timeframe` |
| `noalert` | `1` means no alert, rule analysis continues |

Every rule must belong to at least one group. Groups are given in a `<group name="...">` wrapping the rules or in `<group>` inside a rule, and in the dashboard you filter by them with the `rule.groups` query.

## Checklist after part 4

- [ ] The three analysis phases described using rule 5715 and the decoders from `0310-ssh_decoders.xml`.
- [ ] Location of `alerts.json`, `archives.json` and the rotated `.gz` and `.sum` files checked on the server.
- [ ] Archives enabled (`logall_json`, `archives: enabled` in Filebeat) and the `wazuh-archives-*` pattern visible in Discover.
- [ ] Eight pastes of the log into `wazuh-logtest` end with rule 5712.
- [ ] The Hydra attack on your own host gives seven 5710 alerts and one 5712 in Threat Hunting.
- [ ] I know which rules correspond to an attack on an existing account (5716, 5760, 5763, 5720).
- [ ] Rules 5710 and 5712 found in the dashboard, in the API and in the XML file, the `if_sid` chain to 5700 reviewed.

In part 5 I move from reading decoders to writing my own: decoder options, sibling decoders and the dynamic JSON decoder.

## What the documentation does not define

- The default `timeframe` for a rule with a `frequency` attribute but no `timeframe`, such as 5720.
- Archive retention period: the documentation speaks of indefinite storage and leaves deletion to the administrator. It gives names of rotated files only for archives, not for alerts.
- GeoIP enrichment of the source address in alerts.
- A built-in reputation lookup for the source address.
- A consistent list of MITRE techniques for rule 5710: the file from tag v4.14.0 contains T1110.001 and T1021.004, and the sample logtest response in the documentation adds T1078.
- The notation of the option that checks for the same address: the syntax table gives `same_srcip`, while the rules file uses `same_source_ip`. In my own rules I copy the notation from the file.

## Sources

- https://documentation.wazuh.com/4.14/user-manual/manager/event-logging.html
- https://documentation.wazuh.com/4.14/user-manual/manager/alert-management.html
- https://documentation.wazuh.com/4.14/user-manual/capabilities/log-data-collection/log-data-analysis.html
- https://documentation.wazuh.com/4.14/user-manual/ruleset/index.html
- https://documentation.wazuh.com/4.14/user-manual/ruleset/ruleset-xml-syntax/rules.html
- https://documentation.wazuh.com/4.14/user-manual/ruleset/testing.html
- https://documentation.wazuh.com/4.14/user-manual/reference/ossec-conf/global.html
- https://documentation.wazuh.com/4.14/user-manual/capabilities/active-response/ar-use-cases/blocking-ssh-brute-force.html
- https://documentation.wazuh.com/4.14/user-manual/wazuh-dashboard/navigating-the-wazuh-dashboard.html
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/rules/0095-sshd_rules.xml
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/api/api/spec/spec.yaml
