Wazuh 4 training, part 8: inventory, vulnerabilities and rootkits
Part 8 of the Wazuh 4 training: Syscollector options, inventory queries via API and indexer, CVE alerts and rootcheck checks with rules 510 and 521.
Part 8 of the Wazuh 4 training covers three agent and manager modules that answer the question of what runs on an endpoint and whether it is safe. After part 7 on file integrity monitoring I configure Syscollector, check how its data reaches vulnerability detection, and run rootcheck.
Exercise 1: Syscollector and the inventory
Syscollector is an agent module that collects system data. After the agent starts, it runs periodic scans and first stores the results in a temporary local database on the endpoint. The agent sends new data to the server, where each agent has its own database. Hardware data goes, for example, to the sys_hwinfo table. The Inventory Harvester module on the manager standardizes this data according to the Wazuh Common Schemas and sends it to the indexer as global state data, in a separate index for each type. The package inventory uses the pattern wazuh-states-inventory-packages-*.
Module options
The module is configured by a wodle section named syscollector in the agent ossec.conf:
| Option | Default | Meaning |
|---|---|---|
disabled | no | disables the module |
interval | 1h | time between scans, suffixes s, m, h, d |
scan_on_start | yes | scan right after the service starts |
hardware, os, network, packages | yes | hardware, system, network and package scans |
ports | yes | port scan; the attribute all="no" limits the scan to listening ports |
processes, users, groups, services, browser_extensions | yes | processes, accounts, groups, services and browser extensions |
hotfixes | yes | Windows hotfixes; the option is enabled by default but absent from the initial configuration |
synchronization / max_eps | 10 | maximum event reporting throughput, an integer from 0 to 1000000, 0 means the default value |
Two documentation pages disagree about ports. The example in the section description shows all="no", while the inventory configuration page states that the ossec.conf installed with the agent sets all="yes", and that omitting the attribute scans only listening ports. When you compare agents, check which value they actually have.
Default configuration from the agent file:
<!-- System inventory -->
<wodle name="syscollector">
<disabled>no</disabled>
<interval>1h</interval>
<scan_on_start>yes</scan_on_start>
<hardware>yes</hardware>
<os>yes</os>
<network>yes</network>
<packages>yes</packages>
<ports all="yes">yes</ports>
<processes>yes</processes>
<users>yes</users>
<groups>yes</groups>
<services>yes</services>
<browser_extensions>yes</browser_extensions>
<!-- Database synchronization settings -->
<synchronization>
<max_eps>10</max_eps>
</synchronization>
</wodle>
The agent file is at /var/ossec/etc/ossec.conf (Linux), C:\Program Files (x86)\ossec-agent\ossec.conf (Windows) or /Library/Ossec/etc/ossec.conf (macOS). The same settings can be pushed to an agent group through centralized configuration, for example through /var/ossec/etc/shared/default/agent.conf for the default group. The centralized value takes precedence over the local one, and the agent reloads itself after it receives a change. After a local edit you have to restart it. The group mechanism is described in part 3 and in the post on agent groups.
Shortening the interval in the lab
In the lab I shorten interval to 2m, so that consecutive scans appear within minutes instead of hours. I put the same block into the group with the Windows agent, changing only that one value. This is a lab setting. The documentation gives no recommended interval for production.
Inventory queries
You can read agent data in four ways: from the IT Hygiene tabs in the dashboard (Security operations > IT Hygiene), from the server API, from the indexer API and directly from the SQLite database.
In Server management > Dev Tools, queries go to the server API. The inventory tables map to subpaths /syscollector/<AGENT_ID>/<property>:
GET /syscollector/<AGENT_ID>/
GET /syscollector/<AGENT_ID>/packages?pretty=true&name=wazuh-agent
The available properties are hardware, hotfixes, netaddr, netiface, netproto, os, ports, processes, users, groups, browser_extensions, services and packages. From the command line the query needs a JWT token:
# Get a JWT token, then list packages of agent 001 and print name and version
TOKEN=$(curl -u <USER> -k -X GET "https://<WAZUH_SERVER_IP>:55000/security/user/authenticate?raw=true")
curl -k -X GET "https://<WAZUH_SERVER_IP>:55000/syscollector/001/packages?pretty=true" \
-H "Authorization: Bearer $TOKEN" \
| jq -r '.data.affected_items[] | [.name, .version] | @tsv' | LC_ALL=C sort
The response has items in data.affected_items with the fields name, version, architecture, format, vendor, size, description, scan.time and agent_id, and next to them total_affected_items, total_failed_items, failed_items, a message and error.
In Indexer management > Dev Tools, queries go to the indexer. The pattern wazuh-states-inventory-* covers one index for each of these types: hotfixes, networks, services, users, browser-extensions, system, interfaces, packages, groups, ports, hardware, protocols and processes:
GET /_cat/indices/wazuh-states-inventory-*?v
GET /wazuh-states-inventory-packages-*/_search?pretty
{
"query": {
"bool": {
"must": [
{ "term": { "agent.name": "agent-01" }},
{ "match": { "package.name": "wazuh-agent" }}
]
}
}
}
A package document has the fields agent.id, agent.name, agent.version, package.name, package.version, package.vendor, package.type, package.architecture, package.size, package.installed and package.description. A full query pattern for system versions is in the post on the systems inventory.
On the server, the SQLite databases are in /var/ossec/queue/db/<AGENT_ID>.db. The inventory tables include sys_hwinfo, sys_osinfo, sys_programs, sys_ports, sys_processes, sys_netaddr, sys_netiface, sys_netproto, sys_hotfixes, sys_users, sys_groups, sys_services and sys_browser_extensions:
# Query the inventory database of one agent on the manager
sqlite3 /var/ossec/queue/db/001.db 'select * from sys_programs where name="wazuh-agent";'
Alerts from Syscollector data
Syscollector events are matched by rule 221 from the 0016-wazuh_rules.xml file: level 0, decoded_as equal to syscollector, description “Syscollector event.”. At level 0 they do not reach the dashboard. The documentation tells you to create child rules with a level of at least 3. The documentation example, with the IDs changed to custom ones, reacts to a port being opened, changed and closed:
<group name="syscollector,">
<rule id="100310" level="3">
<if_sid>221</if_sid>
<field name="type">dbsync_ports</field>
<description>Syscollector ports event.</description>
</rule>
<rule id="100311" level="3">
<if_sid>100310</if_sid>
<field name="operation_type">INSERTED</field>
<description>The port: $(port.local_port), with local ip: $(port.local_ip) has been opened. Syscollector creation event detected.</description>
</rule>
<rule id="100312" level="3">
<if_sid>100310</if_sid>
<field name="operation_type">MODIFIED</field>
<description>The port: $(port.local_port), with local ip: $(port.local_ip) has been modified. Syscollector modification event detected.</description>
</rule>
<rule id="100313" level="3">
<if_sid>100310</if_sid>
<field name="operation_type">DELETED</field>
<description>The port: $(port.local_port), with local ip: $(port.local_ip) has been closed. Syscollector deletion event detected.</description>
</rule>
</group>
The first scan generates no alerts. An alert appears only after a difference between the first and the second scan, that is, after interval has passed. The indexer stores the alert fields as data.<type>.<field>, for example data.port.inode, data.program.name or data.os.codename. The mechanics of child rules are described in part 6.
Exercise 2: vulnerability detection
The Vulnerability Detection module runs on the manager and does not scan endpoints itself. It compares the inventory sent by Syscollector with CVE documents from the Wazuh Cyber Threat Intelligence platform. A detailed description of sources, statuses and result fields is in the post on Vulnerability Detection. Here I cover the settings and the verification procedure.
Configuration
The section is named <vulnerability-detection>. Before version 4.8.0 it was named <vulnerability-detector>. The default block in the manager /var/ossec/etc/ossec.conf:
<vulnerability-detection>
<enabled>yes</enabled>
<index-status>yes</index-status>
<feed-update-interval>60m</feed-update-interval>
</vulnerability-detection>
| Option | Default | Meaning |
|---|---|---|
enabled | yes | enables the module |
index-status | yes | indexing of the vulnerability inventory in the indexer |
feed-update-interval | 60m | interval between CVE database updates; minimum 60m, lower values are changed to 60m |
offline-url | empty | a file:// path or an http[s]:// address of the offline content |
The options interval, run_on_start, retry_interval and the provider block have been deprecated since 4.8.0. The manager ignores them and logs a warning about an invalid element. Because the module analyzes data as it arrives, the check frequency is set by the Syscollector interval, which explains why exercise 1 shortens it. An additional note from the documentation: for the module to scan the manager host as well, set vulnerability-detection.disable_scan_manager from 1 to 0 in /var/ossec/etc/internal_options.conf and restart the manager.
The result reaches the indexer through the <indexer> block in the manager ossec.conf. It is enabled by default, but it can be missing after an old configuration file or after the module was disabled at installation. The indexer credentials are stored in the keystore:
# Store the indexer credentials in the manager keystore
echo '<WAZUH_INDEXER_USERNAME>' | /var/ossec/bin/wazuh-keystore -f indexer -k username
echo '<WAZUH_INDEXER_PASSWORD>' | /var/ossec/bin/wazuh-keystore -f indexer -k password
systemctl restart wazuh-manager
You check the connection with a curl request to https://<INDEXER_IP_ADDRESS>:9200/_cluster/health using the certificates from /etc/filebeat/certs/. If it fails, the module does not send results to the indexer.
Offline mode
A server without internet access can use a snapshot of the CTI repository. The first command returns the address of the latest snapshot and its time:
curl -s -X GET https://cti.wazuh.com/api/v1/catalog/contexts/vd_1.0.0/consumers/vd_4.8.0 | jq -r '.data | "\(.last_snapshot_link)\n\(.last_snapshot_at)"'
You download the file with curl to cves.zip, then set its permissions and owner, and finally put the path into <offline-url>:
chmod 750 /FILE_PATH_TO_OFFLINE_REPOSITORY/cves.zip
chown root:wazuh /FILE_PATH_TO_OFFLINE_REPOSITORY/cves.zip
<vulnerability-detection>
<enabled>yes</enabled>
<index-status>yes</index-status>
<feed-update-interval>60m</feed-update-interval>
<offline-url>file:///path/to/the/cves.zip</offline-url>
</vulnerability-detection>
In offline-url you enter the full path to the downloaded file. After a manager restart the module reads the content from that file. Zip, xz and gzip files are supported, as well as plain JSON in a text file.
Vulnerability alert rules
The ruleset 0520-vulnerability-detector_rules.xml maps status and severity to the alert level. All rules read fields of the JSON document, for example vulnerability.status and vulnerability.severity:
| Rule | Level | Condition |
|---|---|---|
| 23501 | 0 | JSON document with the vulnerability.cve field (base rule) |
| 23502 | 3 | vulnerability.status equal to Solved |
| 23503 | 5 | Active and severity Low |
| 23504 | 7 | Active and severity Medium or Untriaged |
| 23505 | 10 | Active and severity High |
| 23506 | 13 | Active and severity Critical |
| 23507 | 3 | vulnerability.status equal to Clear, description “Vulnerabilities cleared” |
| 23508 | 3 | severity -, meaning no information, the CVE awaits analysis |
Custom child rules with if_sid 23501 let you change this split; level tuning is described in the post on rule levels.
When an alert is created
The documentation lists the scenarios in which no alert is generated, even though the vulnerability is in the inventory:
- The first inventory scan generates no alerts about the operating system. An alert appears after a later change of the system version or patch state.
- A package alert is created when a vulnerability was added or removed by installing or removing a package, and a scheduled Syscollector scan caught the change.
- Changes made while the agent is stopped, detected only after its restart, produce no alert.
- An agent that connects to a different cluster node synchronizes its inventory without alerts, even when there are changes.
- A CVE content update re-evaluates all agents, but the synchronization triggered by the update sends no alerts.
On a Windows agent, the hotfixes option gives the module data about installed patches. The module then checks, based on Microsoft data, whether a patch closes a given CVE, and updates the status in the inventory.
Verification procedure
The procedure below is my recommendation. It requires an agent with interval set to 2m and a package that appears in the CTI content with a vulnerable version.
- Install on the agent an older version of a package that you know has a public CVE. Wait for a scan that runs after this change.
- In Threat intelligence > Vulnerability Detection open the Inventory tab and find the package. The Inventory entry itself confirms the detection; an alert is not needed for that.
- Open the Events tab and look for an alert with rule 23503 to 23506, depending on severity.
- Update or remove the package and, after the next scan, check for an alert from rule 23502 with the status
Solved. - You read manager messages in Server management > Logs, which is a view of the file
/var/ossec/logs/ossec.log.
Exercise 3: rootkit detection with rootcheck
Rootcheck looks for anomalies that may point to malware hiding in the system. The module runs on the agent, and the <rootcheck> section in ossec.conf sets which checks it performs.
Options
| Option | Default | Meaning |
|---|---|---|
frequency | 43200 | interval between scans in seconds, that is 12 hours |
disabled | no | disables the module |
base_directory | / (Unix), C:\ (Windows) | directory prepended to the paths used for rootkit, trojan, /dev and hidden file checks |
rootkit_files | etc/shared/rootkit_files.txt | database of file names of known rootkits |
rootkit_trojans | etc/shared/rootkit_trojans.txt | database of signatures of trojaned files |
scanall | no | scan of the whole system, may produce false positives |
readall | no | compares the bytes read with the file size; with no only selected system directories |
skip_nfs | no | skips CIFS and NFS file systems; the file installed with the manager and the agent sets yes |
ignore | none | list of files and directories skipped in check_sys, check_dev and check_files, attribute type="sregex" |
check_dev, check_files, check_if, check_pids, check_ports, check_sys, check_trojans, check_unixaudit | yes | enable individual checks on Unix |
check_winapps, check_winaudit, check_winmalware | yes | Windows checks |
The options windows_audit, system_audit, windows_apps and windows_malware point to definition files and have no default value. The default Unix configuration from the documentation:
<!-- Policy monitoring -->
<rootcheck>
<disabled>no</disabled>
<check_unixaudit>yes</check_unixaudit>
<check_files>yes</check_files>
<check_trojans>yes</check_trojans>
<check_dev>yes</check_dev>
<check_sys>yes</check_sys>
<check_pids>yes</check_pids>
<check_ports>yes</check_ports>
<check_if>yes</check_if>
<ignore type="sregex">^/etc/</ignore>
<!-- Frequency that rootcheck is executed - every 12 hours -->
<frequency>43200</frequency>
<rootkit_files>etc/shared/rootkit_files.txt</rootkit_files>
<rootkit_trojans>etc/shared/rootkit_trojans.txt</rootkit_trojans>
<skip_nfs>yes</skip_nfs>
</rootcheck>
By default rootcheck scans these directories on Unix: /bin, /sbin, /usr/bin, /usr/sbin, /dev, /lib, /etc, /root, /var/log, /var/mail, /var/lib, /var/www, /usr/lib, /usr/include, /tmp, /boot, /usr/local, /var/tmp and /sys, and on Windows C:\WINDOWS and C:\Program Files. Since Wazuh 4.13.0 these options do not support UNC paths or mapped network drives, only local directories.
In the lab I shorten frequency to 300 in the Linux agent group, so I do not have to wait 12 hours, and I disable other modules to make the result easier to read. This interval is a training setting.
What rootcheck checks
| Check | Mechanism according to the documentation |
|---|---|
| Hidden processes | compares the results of the getsid and getpgid system calls for PIDs up to rootcheck.max_pid (32768 by default on Linux) |
| Hidden ports | a bind() attempt on every port; if it fails and the port is not in the netstat output, a rootkit is possible |
| Unusual files and permissions | root files writable by others, suid files, hidden directories |
| Hidden files | size from stat versus a fopen and read, inode count versus opendir and readdir |
The /dev directory | should contain only device files; every additional file is checked |
| Network interfaces | promiscuous mode visible in the ifconfig output |
| Signatures | rootkit_files.txt, rootkit_trojans.txt and win_malware_rcl.txt |
Rootcheck rules
Rootcheck events are matched by the ruleset 0015-ossec_rules.xml. The base rule 509 (level 0, decoded_as equal to rootcheck) is inherited by 510:
| Rule | Level | Condition |
|---|---|---|
| 510 | 7 | “Host-based anomaly detection event (rootcheck).” |
| 521 | 11 | child of 510, text “Possible kernel level rootkit”, MITRE T1014 |
| 522 | 2 | root file writable by everyone |
| 512, 516 | 3 | messages starting with “Windows Audit” and “System Audit” |
| 513, 518 | 9 | “Windows Malware” and adware and spyware in Windows applications |
| 519 | 7 | “System Audit: Web vulnerability” |
| 515 | 0 | scan start and end messages, ignored |
An example alert for a file in /dev: rule 510 with the message File '/dev/.hidden' present on /dev. Possible hidden file. For a hidden process, rule 521 returns a message like Process '659' hidden from /proc. Possible kernel level rootkit.
Test with a hidden file in /dev
The simplest test needs nothing dangerous. On a Linux agent, on a lab machine, create a hidden file in /dev. After a scan that matches frequency, look for the alert on the manager:
touch /dev/.example-hidden
ls -a /dev | grep '^\.'
tail -f /var/ossec/logs/alerts/alerts.log
The alert from rule 510 should contain the file name. In the dashboard you find the same event with the filter decoder.name:rootcheck. Delete the file after the test.
Custom rootkit signatures
The rootkit_files.txt file holds paths of files used by rootkits in the format file_path ! Rootkit_Name ::. Lines starting with # are comments. The documentation gives an example for Reptile:
#Reptile
reptile/reptile_cmd ! Reptile rootkit ::
reptile/reptile_rc ! Reptile rootkit ::
reptile/reptile_shell ! Reptile rootkit ::
reptile/reptile_start ! Reptile rootkit ::
lib/udev/reptile ! Reptile rootkit ::
The rootkit_trojans.txt file holds string signatures that rootkits leave in replaced binaries. The format is file_name !string_to_search!Description, and here is the documentation example for common tools:
# Common binaries and public trojan entries
ls !bash|^/bin/sh|dev/[^clu]|\.tmp/lsfile|duarawkz|/prof|/security|file\.h!
env !bash|^/bin/sh|file\.h|proc\.h|/dev/|^/bin/.*sh!
Paths in both files are relative to base_directory, which is why they do not start with /.
Hidden process and kernel module
A kernel-mode rootkit such as diamorphine can hide a module and selected processes from ps. Rootcheck detects a hidden process through a mismatch between system call results and reports it with rule 521 at level 11. The Wazuh documentation gives only the alert result, without the steps to build and load the module, so I do not describe them here. Load a rootkit, even a test one, only on a disposable virtual machine, with no data and no access to the production network, and remove it before you finish the exercise.
False positives
The documentation pattern is a rule with level 0 that inherits from the rootcheck group and matches only a specific message:
<rule id="100100" level="0">
<if_group>rootcheck</if_group>
<match>/dev/.blkid.tab</match>
<description>Ignore false positive for /dev/.blkid.tab</description>
</rule>
IDs of custom rules start at 100000. Narrow the match to a single file, because a broader level 0 rule also silences real detections.
Checklist after part 8
- Syscollector
intervallowered to2min the lab group,ports allvalue checked. -
GET /syscollector/<AGENT_ID>/packagesreturns packages, and so does a query towazuh-states-inventory-packages-*. - Database
/var/ossec/queue/db/<AGENT_ID>.dbopened insqlite3, tablesys_programsread. - A custom rule with
if_sid221 has level 3 or higher. - The
<vulnerability-detection>block reviewed,index-statusandfeed-update-intervalknown. - A package with a public CVE visible in Inventory, an alert 23503 to 23506 in Events, an alert 23502 after the update.
- Rootcheck
frequencylowered to300only for the duration of the exercise. - An alert from rule 510 for the file
/dev/.example-hidden, file deleted. - Formats of
rootkit_files.txtandrootkit_trojans.txtknown, a false positive silenced with a level 0 rule withmatchon a single file.
In part 9 I move on to CDB lists, Active Response and integrations: an address list in a rule for SSH logins, the firewall-drop command and the integrator.
What the documentation does not specify
- The documentation does not say how long re-evaluation of agents takes after a CVE database update, or what Syscollector
intervalis recommended in production. - It does not describe the delay between installing a package and the alert, other than the requirement that a scheduled scan catches the change.
- The rootcheck page points to the
rootcheck.max_pidoption in the internal configuration. The default value is 32768. - The documentation does not describe the steps to install the diamorphine test module or rootcheck debug options.
- It does not explain whether changes to
rootkit_files.txton the manager reach agents automatically. The default path is inetc/shared. - Two pages of the 4.14 documentation give different default values for
ports all=.
Sources
- https://documentation.wazuh.com/4.14/user-manual/reference/ossec-conf/wodle-syscollector.html
- https://documentation.wazuh.com/4.14/user-manual/capabilities/system-inventory/how-it-works.html
- https://documentation.wazuh.com/4.14/user-manual/capabilities/system-inventory/configuration.html
- https://documentation.wazuh.com/4.14/user-manual/capabilities/system-inventory/viewing-system-inventory-data.html
- https://documentation.wazuh.com/4.14/user-manual/capabilities/system-inventory/using-syscollector-information-to-trigger-alerts.html
- https://documentation.wazuh.com/4.14/user-manual/reference/ossec-conf/vuln-detector.html
- https://documentation.wazuh.com/4.14/user-manual/capabilities/vulnerability-detection/how-it-works.html
- https://documentation.wazuh.com/4.14/user-manual/capabilities/vulnerability-detection/configuring-scans.html
- https://documentation.wazuh.com/4.14/user-manual/reference/ossec-conf/rootcheck.html
- https://documentation.wazuh.com/4.14/user-manual/capabilities/malware-detection/rootkits-behavior-detection.html
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/rules/0015-ossec_rules.xml
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/rules/0016-wazuh_rules.xml
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/rules/0520-vulnerability-detector_rules.xml