Hello,
I have a few questions regarding filtering Windows events in the logcollector of a Wazuh agent.
According to the official Wazuh documentation (
https://documentation.wazuh.com/current/user-manual/reference/ossec-conf/localfile.html#query) you can use queries in XPATH format and there is an example where a query with logical operators is used.
In the Wazuh GitHub repository (
https://github.com/wazuh/wazuh-agent/blob/master/src/modules/logcollector/README.md) you will find the following note for the log collector under Windows: “query:
Query string to filter logs. XPATH and QueryLists supported.”
There does not seem to be any more information from the official side.
Question 1:
Which subset of the XPATH syntax is used/supported by Wazuh?
Question 2:
The example in the documentation uses a query that appears to use a “whitelisting” mechanism, i.e. the events that should NOT be filtered out are included in the query. Given the number of existing Windows events, this would (in most cases) result in very large queries. Is this really what you want?
Question 3:
When using common XPATH validators, there are differences when evaluating file/process paths.
The following query works in the common XPATH validators. The character “\” does not need to be escaped.
<query>
Event[EventData/Data[@Name='CallerProcessName'] != “C:\Windows\System32\net1.exe”]
</query>
The previous example does not work in our Wazuh productive systems but must be adapted as follows.
<query>
Event[EventData/Data[@Name='CallerProcessName'] != “C:\\Windows\\System32\\net1.exe”]
</query>
Is this desired behavior or could it be the (or one of the) causes of the following problem (question 4)?
Question 4:
<query>
Event[
System/EventID != 5145 and
System/EventID != 5156 and
System/EventID != 5447 and
System/EventID != 4656 and
System/EventID != 4658 and
System/EventID != 4663 and
System/EventID != 4660 and
System/EventID != 4670 and
System/EventID != 4690 and
System/EventID != 4703 and
System/EventID != 4907 and
System/EventID != 5152 and
System/EventID != 5157 and
System/EventID != 4768 and
(System/EventID != 4634 or (System/EventID = 4634 and EventData[Data[@Name='LogonType'] != 3])) and
System/EventID != 4627 and
(System/EventID != 4798 or (System/EventID = 4798 and EventData/Data[@Name='CallerProcessName'] != 'C:\\Program Files\\Trend Micro\\Deep Security Agent\\dsa.exe')) and
(System/EventID != 4799 or (System/EventID = 4799 and EventData/Data[@Name='CallerProcessName'] != 'C:\\Program Files\\Trend Micro\\Deep Security Agent\\dsa.exe')) and
(System/EventID != 192 or (System/EventID = 192 and System/Provider[@Name != 'DriveLock'])) and
(System/EventID != 286 or (System/EventID = 286 and System/Provider[@Name != 'DriveLock']))
]
</query>
This query should filter out the listed events. Unfortunately, it does not work as desired. No event is filtered at all, i.e. all events are collected by the log collector.
If you remove the last line “(System/EventID != 286 or (System/EventID = 286 and System/Provider[@Name != ‘DriveLock’])” or change the order of the events as follows, the query works as desired and filters the listed events.
<query>
Event[
(System/EventID != 4634 or (System/EventID = 4634 and EventData[Data[@Name='LogonType'] != 3])) and
System/EventID != 4627 and
(System/EventID != 4798 or (System/EventID = 4798 and EventData/Data[@Name='CallerProcessName'] != 'C:\\Program Files\\Trend Micro\\Deep Security Agent\\dsa.exe')) and
(System/EventID != 4799 or (System/EventID = 4799 and EventData/Data[@Name='CallerProcessName'] != 'C:\\Program Files\\Trend Micro\\Deep Security Agent\\dsa.exe')) and
(System/EventID != 192 or (System/EventID = 192 and System/Provider[@Name != 'DriveLock'])) and
(System/EventID != 286 or (System/EventID = 286 and System/Provider[@Name != 'DriveLock']))
System/EventID != 5145 and
System/EventID != 5156 and
System/EventID != 5447 and
System/EventID != 4656 and
System/EventID != 4658 and
System/EventID != 4663 and
System/EventID != 4660 and
System/EventID != 4670 and
System/EventID != 4690 and
System/EventID != 4703 and
System/EventID != 4907 and
System/EventID != 5152 and
System/EventID != 5157 and
System/EventID != 4768
]
</query>
Can anyone explain this behavior?
Thank You!