PL EN
WB-8098067FTLP:CLEARWazuh 4

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.

AttributeDefaultAllowed valuesMeaning
realtimenoyes, noContinuous monitoring: inotify on Linux, also Windows. Works on directories, not on single files
whodatanoyes, noRecords who changed the file (Linux and Windows)
report_changesnoyes, noReports content differences, text files only
diff_size_limit50MBa number with KB, MB or GBLarger files do not report a diff
check_allyesyes, noSets all check_* attributes at once
check_sumyesyes, noShortcut for check_md5sum, check_sha1sum and check_sha256sum
check_md5sum, check_sha1sum, check_sha256sumyesyes, noSingle hashes
check_size, check_owner, check_group, check_perm, check_mtimeyesyes, noSize, owner, group, permissions, modification time
check_attrsyesyes, noFile attributes, applies to Windows
check_inodeyesyes, noInode, applies to UNIX (always 0 on Windows)
restrictnonesregexLimits the check to files whose name matches
tagsnonecomma-separated listTags added to alerts from this directory
recursion_level256a number from 0 to 320Maximum nesting depth
follow_symbolic_linknoyes, noUNIX: 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:

OptionDefaultRangeDescription
max_eps500 to 1000000, 0 disablesMaximum event reporting throughput
max_files_per_second0positive number, 0 no limitLimit of files per second
process_priority10-20 to 19Nice value of the syscheck process, higher means lower priority
file_limitenabled yes, entries 1000001 to 2147483647Limit on the number of monitored files, new files are ignored once the limit is reached
skip_nfsyesyes, noSkips CIFS and NFS mounts
auto_ignorenoyes, noRead 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:

OptionDefaultRangeDescription
providerauditaudit, ebpfWho-data mode, Linux only
restart_audityesyes, noRestarts auditd after the plugin is installed. With no the new rules are not applied automatically
audit_keyemptycomma-separated stringsCollects Audit events recorded under keys, when Audit already monitors the folders
startup_healthcheckyesyes, noDisabling it can cause whodata problems and lost events
queue_size1638410 to 1048576Audit 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 fieldAlert fieldDescription
filepathFile path
size, mtime, inodesize_after, mtime_after, inode_afterValues after the change
permperm_after, win_perm_afterPermissions, the name depends on the system
uid, gid, uname, gnameuid_after, gid_after, uname_after, gname_afterOwner and group
md5, sha1, sha256md5_after, sha1_after, sha256_afterHashes after the change
changed_fieldschanged_attributesList of changed attributes
changed_contentdiffContent difference
win_attributesattrs_afterWindows file attributes
tagtagTag from the tags attribute
user_id, user_nameaudit.user.id, audit.user.nameUser who triggered the event
group_id, group_nameaudit.group.id, audit.group.nameGroup of that user
process_id, process_name, ppidaudit.process.id, audit.process.name, audit.process.ppidProcess and its parent
parent_name, cwd, parent_cwdaudit.process.parent_name, audit.process.cwd, audit.process.parent_cwdParent process and working directories
audit_uid, audit_nameaudit.login_user.id, audit.login_user.nameLogin session user
effective_nameaudit.effective_user.nameEffective 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:

RuleLevelDecoderDescription
5507syscheck_integrity_changedIntegrity checksum changed (MITRE T1565.001)
5537syscheck_deletedFile deleted (MITRE T1070.004, T1485)
5545syscheck_new_entryFile 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

SymptomWhat to check
A path is not monitoreddirectories, the ? and * patterns (expanded at scan time), recursion_level, whether the directory exists at agent start
The file is scanned, no alertignore, a level 0 rule, restrict, auto_ignore on the manager
A change is detected only after a scanrealtime works on directories only, frequency, scan_time
No author of the changewhodata, auditd and the -a never,task rule, messages 6048 and 6959, the queue_size queue
No diffreport_changes, a text file, diff_size_limit, disk_quota, nodiff
An attribute is missing from the alertorder 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

↑↓ select Enter open Esc close