EventChannel filtering in Wazuh: query, XPath and win.* fields in rules
EventChannel in Wazuh: localfile, query with XPath and QueryList, Windows Event Log syntax limits, and the win.system and win.eventdata fields used in rules.
The Wazuh agent collects events from Windows channels through the EventChannel format, and the optional XPath filter in query limits events already on the agent. This post covers the localfile options, the syntax and limits of queries, and the win.system and win.eventdata fields that rules work on. The values in the examples are synthetic.
The EventChannel source in localfile
The <localfile> block points to the channel in <location> and the format in <log_format>eventchannel</log_format>. The format works on Windows Vista and later, covers the Application, Security and System logs as well as the Applications and Services logs, and events reach the server with all fields in JSON format. By default the agent monitors the System, Application and Security channels. You add another channel with a separate block in C:\Program Files (x86)\ossec-agent\ossec.conf, and you apply the change by restarting the agent (Restart-Service -Name wazuh in PowerShell with administrator rights). The Microsoft-Windows-PowerShell/Operational channel with event 4104 is covered in the post on PowerShell 4104.
<localfile>
<location>Microsoft-Windows-PrintService/Operational</location>
<log_format>eventchannel</log_format>
</localfile>
| Option | Effect | Default and limits |
|---|---|---|
location | Channel name, for example Security or Microsoft-Windows-Windows Firewall With Advanced Security/Firewall | Depends on the channels available in the system |
log_format | eventchannel enables receiving Windows channels | Windows Vista or later |
query | XPath filter matching the event schema | None |
only-future-events | no also collects events from the time the collector was stopped | yes: only events since the collector started |
reconnect_time | Interval between connection attempts when the Windows Event Channel service is down | 5s; suffixes s, m, h, d, w; only for eventchannel |
The ignore and restrict options do not work for the eventchannel format. Only query is used for filtering.
There is also the eventlog format, compatible with all Windows versions, which monitors the logs except some of the Applications and Services logs. By default the agent uses only event channels. The query filter and the win.* fields apply to the eventchannel format.
The documentation shows the channels and providers supported by the agent. Some sources share a channel with others, so the provider decides the match.
| Source | Channel | Provider |
|---|---|---|
| Sysmon | Microsoft-Windows-Sysmon/Operational | Microsoft-Windows-Sysmon |
| Windows Defender | Microsoft-Windows-Windows Defender/Operational | Microsoft-Windows-Windows Defender |
| McAfee | Application | McLogEvent |
| EventLog | System | Eventlog |
| Microsoft Security Essentials | System | Microsoft Antimalware |
| PowerShell | Microsoft-Windows-PowerShell/Operational | Microsoft-Windows-PowerShell |
Receiving Sysmon is covered in the post Sysmon in Wazuh.
Queries in query
The Wazuh documentation gives three forms of query for the Security or System channel. The first selects events with one ID, the second excludes two IDs, and the third combines an ID with a data field.
<!-- collects only events with event ID 7040 from the System channel -->
<localfile>
<location>System</location>
<log_format>eventchannel</log_format>
<query>Event/System[EventID=7040]</query>
</localfile>
<!-- drops two event IDs, collects the rest of the Security channel -->
<localfile>
<location>Security</location>
<log_format>eventchannel</log_format>
<query>Event/System[EventID != 5145 and EventID != 5156]</query>
</localfile>
<!-- logon events (4624) with LogonType 2 or 10 -->
<localfile>
<location>Security</location>
<log_format>eventchannel</log_format>
<query>Event[System/EventID = 4624 and (EventData/Data[@Name='LogonType'] = 2 or EventData/Data[@Name='LogonType'] = 10)]</query>
</localfile>
The Wazuh documentation filters the event severity level (Level) with the QueryList syntax. The example collects events of level 3 (warning) or lower from the System channel, and a note in the documentation requires escaping XML markup inside query. Below is the notation as printed on the page:
<location>System</location>
<log_format>eventchannel</log_format>
<query>
\<QueryList\>
\<Query Id="0" Path="System"\>
\<Select Path="System"\>*[System[(Level<=3)]]\</Select\>
\</Query\>
\</QueryList\>
</query>
Simpler expressions are written without QueryList. Microsoft shows such forms for Level, data fields and time:
*[System/Level=1]
*[UserData/*/PrinterName="MyPrinter" and System/Level=1]
*[System[(Level <= 3) and TimeCreated[timediff(@SystemTime) <= 86400000]]]
The first expression selects events of level 1 (Critical), the second combines conditions on different nodes, and the third selects events of level 3 or lower from the last 24 hours. Expressions with the timediff function refer to the current system time when the second argument is not given. The Wazuh documentation does not show time filters in query, and the read range at collector start is controlled by only-future-events, so test a time filter separately.
A query by provider follows from the schema: the System element has a Provider child element with a Name attribute, and the attribute axis is allowed. The Wazuh documentation does not show such an example, so treat the query Event/System/Provider[@Name='Microsoft-Windows-Security-Auditing'] as a hypothesis to verify on the agent.
XPath syntax limits
Windows Event Log supports a subset of XPath 1.0, and the agent sends query to this mechanism. The rules below come from the Microsoft page.
| Area | Limit |
|---|---|
| Path | Only event elements can be selected. The path starts with * or Event |
| Axes | Only child (default) and attribute (shorthand @) |
| Operators | OR, AND, comparison operators (equal, not equal, less, less or equal, greater, greater or equal) and parentheses |
| Functions | position (on leaf nodes only), Band (bitwise AND, a nonzero result is true), timediff (time difference in milliseconds, arguments in FILETIME format) |
| Unavailable | Node sets, variables, namespaces, reverse-order evaluation, context size |
| Complexity | An expression with more than 20 subexpressions or a query to multiple sources needs a structured XML query |
A structured query has Select (selects events) and Suppress (excludes) elements. When both point at the same event, the result does not contain it. A simplified Microsoft example selects events of level 3 or lower from the Application channel, rejects level 2, and adds a selection from the System channel:
<QueryList>
<Query Id="0">
<Select Path="Application">*[System[(Level <= 3)]]</Select>
<Suppress Path="Application">*[System[(Level = 2)]]</Suppress>
<Select Path="System">*[System[(Level=1 or Level=2 or Level=3)]]</Select>
</Query>
</QueryList>
The example shows the syntax of the Windows mechanism. The documentation does not say whether the Wazuh agent accepts a query with multiple channels in one localfile block. Query results include events that exist at the time of the query and new ones that match it during reading.
win.system and win.eventdata fields in rules
An event from the channel goes to the windows_eventchannel decoder, and its fields have the win. prefix: standard event fields in win.system, and event-specific data in win.eventdata. The shape below comes from a comment in the 0580-win-security_rules.xml file (values changed).
{
"win": {
"system": {
"providerName": "Microsoft-Windows-Security-Auditing",
"eventID": "4624",
"level": "0",
"channel": "Security",
"computer": "agent-01",
"severityValue": "AUDIT_SUCCESS"
},
"eventdata": {
"targetUserName": "example-user",
"logonType": "10",
"workstationName": "agent-01",
"ipAddress": "192.0.2.10"
}
}
}
The built-in rules from the 0575-win-base_rules.xml file (Wazuh 4.14.0) build a chain from these fields. Rule 60000 has level 0, requires the windows_eventchannel decoder and a non-empty win.system.providerName. Rules 60001, 60002, 60003 and 60004 recognize the Security, System, Application and Microsoft-Windows-Sysmon/Operational channels by win.system.channel. Rules 60009, 60010, 60011 and 60012 classify events by win.system.severityValue: INFORMATION and WARNING have level 0, ERROR level 5, and CRITICAL level 10. In the Security channel, rules 60103 and 60104 split events by the values AUDIT_SUCCESS and AUDIT_FAILURE. Rule 60106 (level 3, “Windows Logon Success”) matches win.system.eventID against ^528$|^540$|^673$|^4624$|^4769$, and 60118 adds conditions with win.eventdata.workstationName and win.eventdata.logonType equal to 2.
Rule ID ranges for individual files:
| Source | Rule IDs | File |
|---|---|---|
| Base rules | 60000 - 60099 | 0575-win-base_rules.xml |
| Security | 60100 - 60599 | 0580-win-security_rules.xml |
| Application | 60600 - 61099 | 0585-win-application_rules.xml |
| System | 61100 - 61599 | 0590-win-system_rules.xml |
| Sysmon | 61600 - 62099 | 0595-win-sysmon_rules.xml |
| Windows Defender | 62100 - 62599 | 0600-win-wdefender_rules.xml |
| McAfee | 62600 - 63099 | 0605-win-mcafee_rules.xml |
| Eventlog | 63100 - 63599 | 0610-win-ms_logs_rules.xml |
| Microsoft Security Essentials | 63600 - 64099 | 0615-win-ms-se_rules.xml |
| Other | 64100 - 64599 | 0620-win-generic_rules.xml |
| PowerShell | 91801 - 92000 | 0915-win-powershell_rules.xml |
You write a custom child rule on top of an existing one (an example with if_sid 60106, ID from 100000 up):
<group name="windows,">
<rule id="100210" level="6">
<if_sid>60106</if_sid>
<field name="win.eventdata.logonType">^10$</field>
<description>Example: Windows logon success with logonType 10</description>
</rule>
</group>
The rules for matching and testing rules are described in the post Testing rules and decoders with wazuh-logtest.
Filter versus built-in rules
Recommendation: query removes events before they are sent to the server, so an excluded ID will not reach any rule or the archives. When you exclude an EventID, check that it does not appear in the expressions of rules you want to keep. Rule 60106 matches 4624, among others, and 60122 matches IDs 529 and 4625, so a filter excluding 4624 or 4625 cuts these rules off from newer logon events. The LogonType filter from the documentation example (2 or 10) skips the other logon types, and rule 60118 requires exactly type 2.
For a configuration spread over many agents, the localfile block can be distributed as a group configuration (agent groups and agent.conf). The EventChannel page does not describe this scenario, so check it first on a single agent.
Testing a query
Microsoft lists the standard tools for reading events: Event Viewer, the Get-WinEvent command in PowerShell and WevtUtil. Recommended test procedure:
- Write the XPath query and check it with a Microsoft tool on the right channel to make sure it returns the expected events.
- Paste the expression into
<query>in thelocalfileblock of a test agent and restart the agent. - Generate an event that matches the query and an event that should be rejected.
- On the server side, check that the matching event triggers an alert from the right rule chain (for example 60106 for 4624), and that the rejected one does not appear in the data.
What the documentation does not specify
The Wazuh documentation does not specify which XPath constructs beyond the shown examples the agent accepts, what exactly the backslashes in the printed QueryList example mean, or how the agent reacts to an invalid query. It does not give the performance impact of complex queries, a limit on the number of query elements in one localfile block, or a way to check XPath on the agent before use. It also does not describe whether wazuh-logtest accepts EventChannel events in JSON format.
Sources
- https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/localfile.html
- https://documentation.wazuh.com/current/user-manual/capabilities/log-data-collection/configuration.html
- https://learn.microsoft.com/en-us/windows/win32/wes/consuming-events
- https://learn.microsoft.com/en-us/windows/win32/wes/eventschema-systempropertiestype-complextype
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/rules/0575-win-base_rules.xml
- https://raw.githubusercontent.com/wazuh/wazuh/v4.14.0/ruleset/rules/0580-win-security_rules.xml