Wazuh FIM: the syscheck options that change the outcome
Syscheck directories attributes with defaults, scan scheduling, whodata on Linux and Windows, syscheck.* alert fields and rules 550, 553 and 554.
The syscheck configuration decides which paths File Integrity Monitoring covers and what lands in the alert after a change is detected. The scan mode, the chosen attributes, filtering and the whodata settings also affect the result. This post collects these options with the defaults from the Wazuh 4.14 documentation, to make it easier to find out why a monitored file raises an alert without the details you expect.
The example values are synthetic. The options live on the agent in /var/ossec/etc/ossec.conf or in an agent.conf pushed from a group, see agent groups and agent.conf.
How the module works
The FIM module scans paths periodically and watches selected directories in real time. Checksums and attributes go to the agent’s local SQLite database (/var/ossec/queue/fim/db on Linux, /Library/Ossec/queue/fim/db on macOS, C:\Program Files (x86)\ossec-agent\queue\fim\db on Windows). wazuh-db keeps a second database for each agent on the server, in /var/ossec/queue/db. Synchronization sends only changed checksums and attributes to the server database. The event flow from agent to server is described in Wazuh architecture.
Since Wazuh 4.13.0 the module on Windows monitors local file systems only. UNC paths (\\server\share\folder) and mapped drives (Z:\folder) are ignored in all modes and generate no events.
Attributes of the directories element
The directories element lists the paths to monitor, separated by commas or placed on consecutive lines. It includes subdirectories. One line can hold up to 64 directories. The ? and * patterns are expanded again on every scheduled scan. On Windows a bare drive letter without a trailing slash is allowed (D:). The default value is /etc,/usr/bin,/usr/sbin,/bin,/sbin, and on macOS /private/etc,/usr/bin,/usr/sbin,/bin,/sbin, because /etc is a link to /private/etc there.
| Attribute | Default | Allowed values | Meaning |
|---|---|---|---|
realtime | no | yes, no | Continuous monitoring: inotify on Linux, also Windows. Works on directories, not on single files |
whodata | no | yes, no | Records who changed the file (Linux and Windows) |
report_changes | no | yes, no | Reports content differences, text files only |
diff_size_limit | 50MB | a number with KB, MB or GB | Larger files do not report a diff |
check_all | yes | yes, no | Sets all check_* attributes at once |
check_sum | yes | yes, no | Shortcut for check_md5sum, check_sha1sum and check_sha256sum |
check_md5sum, check_sha1sum, check_sha256sum | yes | yes, no | Single hashes |
check_size, check_owner, check_group, check_perm, check_mtime | yes | yes, no | Size, owner, group, permissions, modification time |
check_attrs | yes | yes, no | File attributes, applies to Windows |
check_inode | yes | yes, no | Inode, applies to UNIX (always 0 on Windows) |
restrict | none | sregex | Limits the check to files whose name matches |
tags | none | comma-separated list | Tags added to alerts from this directory |
recursion_level | 256 | a number from 0 to 320 | Maximum nesting depth |
follow_symbolic_link | no | yes, no | UNIX: follows a link that is written directly in the configuration |
On Windows check_owner gives a uid of 0, check_group gives a gid of 0 and an empty group name, and check_perm works only on NTFS partitions.
Order of attributes and blocks
When attributes modify the same property, the last one written wins. The first line enables the SHA-256 check, the second disables it, because check_all="no" comes last.
<directories check_all="no" check_sha256="yes">/etc</directories>
<directories check_sha256="yes" check_all="no">/etc</directories>
When a block with wildcards conflicts with a block without them for a specific path, the block without the pattern applies. In the documentation example C:\Users\*\Downloads is scanned periodically, while C:\Users\vagrant\Downloads gets realtime mode, even though it matches the pattern.
Recursion depth
recursion_level="3" gives alerts for files up to and including level_3, not deeper. The value 0 disables recursion, so alerts cover only files directly in the directory. The default 256 is the value of syscheck.default_max_depth from the internal options file.
<syscheck>
<directories check_all="yes" recursion_level="3">/opt/example-app</directories>
</syscheck>
Scan schedule
frequency sets the interval between scheduled scans in seconds, by default 43200 (12 hours). Instead of an interval you can give a time and a day: scan_time accepts 9pm or 8:30, and scan_day a day of the week, one entry per line. The documentation notes that scan_time can delay the start of realtime scans. The example below runs a scan on Saturdays at 22:00.
<syscheck>
<scan_time>10pm</scan_time>
<scan_day>saturday</scan_day>
</syscheck>
The baseline scan at startup always happens, because scan_on_start is accepted but has no effect. Realtime monitoring is paused for the duration of a scheduled scan and resumes when it ends. A directory covered by realtime must exist before the agent restarts, otherwise the module skips it until the next restart. Files added to the configuration after the initial scan are covered in the next scheduled scan.
Other settings of the syscheck section that affect load and scope:
| Option | Default | Range | Description |
|---|---|---|---|
max_eps | 50 | 0 to 1000000, 0 disables | Maximum event reporting throughput |
max_files_per_second | 0 | positive number, 0 no limit | Limit of files per second |
process_priority | 10 | -20 to 19 | Nice value of the syscheck process, higher means lower priority |
file_limit | enabled yes, entries 100000 | 1 to 2147483647 | Limit on the number of monitored files, new files are ignored once the limit is reached |
skip_nfs | yes | yes, no | Skips CIFS and NFS mounts |
auto_ignore | no | yes, no | Read by the manager, suppresses alerts for a file that changes too often, attributes frequency (default 10) and timeframe (default 3600) |
The agent event buffer limits are described in the post about client_buffer.
Exclusions: ignore, nodiff and level 0 rules
Files and directories listed in ignore are still scanned, but the results are not reported. Entries go one per line, and the attribute type="sregex" enables a simple regular expression.
<syscheck>
<ignore>/etc/mtab</ignore>
<ignore type="sregex">.log$|.swp$</ignore>
</syscheck>
An alternative is a level 0 rule on the server. Level 0 alerts are silent. The rule below, from the documentation, silences changes to one file. Save it in /var/ossec/etc/rules/ and restart wazuh-manager.
<group name="syscheck">
<rule id="100345" level="0">
<if_group>syscheck</if_group>
<field name="file">/var/www/htdocs/private.html</field>
<description>Ignore changes to $(file)</description>
</rule>
</group>
A nodiff entry keeps the alert about a file change but omits the diff, which protects private keys and passwords from leaking into alerts. The diff block also holds the space limits:
<diff>
<disk_quota>
<enabled>yes</enabled>
<limit>1GB</limit>
</disk_quota>
<file_size>
<enabled>yes</enabled>
<limit>50MB</limit>
</file_size>
<nodiff>/etc/ssl/private.key</nodiff>
</diff>
disk_quota limits the queue/diff/file directory, where Wazuh keeps the compressed copies of files needed for comparison. Once the limit is exceeded, alerts contain no diff until the size drops below the limit. report_changes works for directories and single files, and the file copies live in /var/ossec/queue/diff/* (Linux), /Library/Ossec/queue/diff/* (macOS) and C:\Program Files (x86)\ossec-agent\queue\diff\file\ (Windows).
Whodata
Who-data adds to the alert the user and the process that changed the file. The diff from report_changes is separate information.
Linux: audit mode
Audit mode uses the Audit subsystem and extends realtime monitoring. It requires the installed daemon (yum install audit or apt-get install auditd). For Audit 3.1.1 and newer you also have to install the audispd-plugins plugin and restart auditd. In most systems auditd has a default rule that skips rule processing, which blocks who-data. Check it with auditctl -l | grep task, and if -a never,task appears, remove it from /etc/audit/rules.d/audit.rules and restart auditd.
<syscheck>
<directories check_all="yes" whodata="yes">/etc</directories>
<whodata>
<provider>audit</provider>
</whodata>
</syscheck>
After the agent restarts, the audit rule shows up in the output of auditctl -l | grep wazuh_fim:
-w /etc -p wa -k wazuh_fim
The rule disappears when the agent stops. Options of the whodata block:
| Option | Default | Range | Description |
|---|---|---|---|
provider | audit | audit, ebpf | Who-data mode, Linux only |
restart_audit | yes | yes, no | Restarts auditd after the plugin is installed. With no the new rules are not applied automatically |
audit_key | empty | comma-separated strings | Collects Audit events recorded under keys, when Audit already monitors the folders |
startup_healthcheck | yes | yes, no | Disabling it can cause whodata problems and lost events |
queue_size | 16384 | 10 to 1048576 | Audit event queue. After an overflow some events may be lost, and a scheduled scan will generate the missing alerts without audit data |
Linux: eBPF mode
The ebpf mode does not need auditd, but it needs a kernel with BPF ring buffer and BTF (upstream kernels from 5.8, some distributions backport them). At startup the agent runs a health check. /var/ossec/logs/ossec.log then shows message 6048 (Healthcheck for eBPF FIM whodata module success.) or 6959 (The eBPF healthcheck has failed. Switching all whodata eBPF configuration to audit.), after which the module falls back to audit mode. Do not combine both modes: the last configured one applies. In eBPF alerts the fields audit.process.name and audit.process.parent_name contain a short task name (up to 15 characters, for example bash) instead of an absolute path, so rules that match the full path will not work. For sharp bursts of events the documentation recommends raising queue_size at the cost of agent memory.
Windows
Who-data on Windows uses system auditing and works on systems newer than Windows Vista. At startup Wazuh configures the local audit policies and the directory SACLs. When another service changes this configuration, FIM switches the whodata directories to realtime. It detects this in two ways: through event 4719 (audit policy change, Success status removed) and through a periodic check every windows_audit_interval (default 300 seconds, range 1 to 9999). When the policies were not configured automatically, enable Success for Audit File System and Audit Handle Manipulation in Advanced Audit Policy Configuration. The processing delay of whodata events is set on the server by the variable syscheck.rt_delay in /var/ossec/etc/internal_options.conf (in milliseconds, a lower value speeds up processing).
%WINDIR%/SysWOW64 is a separate directory from %WINDIR%/System32 and has to be added explicitly.
FIM alert fields
A FIM event is decoded into fields that the server translates into alert fields in the syscheck object. A rule (field name) refers to the decoder field, and the index stores the alert field.
| Decoder field | Alert field | Description |
|---|---|---|
file | path | File path |
size, mtime, inode | size_after, mtime_after, inode_after | Values after the change |
perm | perm_after, win_perm_after | Permissions, the name depends on the system |
uid, gid, uname, gname | uid_after, gid_after, uname_after, gname_after | Owner and group |
md5, sha1, sha256 | md5_after, sha1_after, sha256_after | Hashes after the change |
changed_fields | changed_attributes | List of changed attributes |
changed_content | diff | Content difference |
win_attributes | attrs_after | Windows file attributes |
tag | tag | Tag from the tags attribute |
user_id, user_name | audit.user.id, audit.user.name | User who triggered the event |
group_id, group_name | audit.group.id, audit.group.name | Group of that user |
process_id, process_name, ppid | audit.process.id, audit.process.name, audit.process.ppid | Process and its parent |
parent_name, cwd, parent_cwd | audit.process.parent_name, audit.process.cwd, audit.process.parent_cwd | Parent process and working directories |
audit_uid, audit_name | audit.login_user.id, audit.login_user.name | Login session user |
effective_name | audit.effective_user.name | Effective user, root after sudo |
In modification alerts the _before fields appear next to the _after fields, for example perm_before.
An example of a file change with whodata, shortened from the documentation:
{
"syscheck": {
"path": "/etc/hosts.allow",
"mode": "whodata",
"event": "modified",
"changed_attributes": ["size", "mtime", "md5", "sha1", "sha256"],
"diff": "1c1\n< \n---\n> 198.51.100.5\n",
"audit": {
"login_user": { "name": "example-user", "id": "1001" },
"effective_user": { "name": "root", "id": "0" },
"process": { "name": "/usr/bin/nano", "id": "20337", "ppid": "20274" }
}
}
}
In such an alert login_user is the session user, and effective_user is the account whose privileges were used to change the file.
Built-in rules and custom rules
In the Wazuh 4.14.0 ruleset (file ruleset/rules/0015-ossec_rules.xml) three rules handle FIM events:
| Rule | Level | Decoder | Description |
|---|---|---|---|
550 | 7 | syscheck_integrity_changed | Integrity checksum changed (MITRE T1565.001) |
553 | 7 | syscheck_deleted | File deleted (MITRE T1070.004, T1485) |
554 | 5 | syscheck_new_entry | File added to the system |
Rule levels and alert thresholds are described in a separate post. Rules 550, 553 and 554 serve as parent rules (if_sid) for your own. Collisions with rules from other rule sets on generic field names are described in the post on FIM for WordPress.
Put your own FIM rules in /var/ossec/etc/rules/ in the syscheck group. The documentation example alerts when execute permission is added to a shell script:
<group name="syscheck">
<rule id="100002" level="8">
<if_sid>550</if_sid>
<field name="file">.sh$</field>
<field name="changed_fields">^permission$</field>
<field name="perm" type="pcre2">\w\wx</field>
<description>Execute permission added to shell script.</description>
<mitre>
<id>T1222.002</id>
</mitre>
</rule>
</group>
The documentation shows analogous rules for deletions (if_sid 553 with the fields process_name and user_name) and for raising the level of changes to a sensitive file (level 12 on top of 550). Before deploying, test the rule in wazuh-logtest.
Diagnostics
| Symptom | What to check |
|---|---|
| A path is not monitored | directories, the ? and * patterns (expanded at scan time), recursion_level, whether the directory exists at agent start |
| The file is scanned, no alert | ignore, a level 0 rule, restrict, auto_ignore on the manager |
| A change is detected only after a scan | realtime works on directories only, frequency, scan_time |
| No author of the change | whodata, auditd and the -a never,task rule, messages 6048 and 6959, the queue_size queue |
| No diff | report_changes, a text file, diff_size_limit, disk_quota, nodiff |
| An attribute is missing from the alert | order of check_all and check_*, the field name after mapping |
What the documentation does not specify
The documentation gives no performance recommendations for specific frequency or max_eps values. It does not define the sregex syntax beyond the description “simple pattern”, does not settle whether restrict compares the file name or the full path, and does not describe the bit syntax in perm_after and win_perm_after.
Sources
- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/syscheck.html
- https://documentation.wazuh.com/current/user-manual/capabilities/file-integrity/how-it-works.html
- https://documentation.wazuh.com/current/user-manual/capabilities/file-integrity/basic-settings.html
- https://documentation.wazuh.com/current/user-manual/capabilities/file-integrity/advanced-settings.html
- https://documentation.wazuh.com/current/user-manual/capabilities/file-integrity/creating-custom-fim-rules.html
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/rules/0015-ossec_rules.xml