| EventData |
| SubjectUserSid | S-1-5-21-1329622929-2207338157-1914140016-1024 |
| SubjectUserName | h |
| SubjectDomainName | CNEHFKSA |
| SubjectLogonId | 0x7282d |
| NewProcessId | 0x3028 |
| NewProcessName | C:\Windows\System32\HOSTNAME.EXE |
| TokenElevationType | %%1938 |
| ProcessId | 0x34f8 |
| CommandLine | hostname |
| TargetUserSid | S-1-0-0 |
| TargetUserName | - |
| TargetDomainName | - |
| TargetLogonId | 0x0 |
| ParentProcessName | C:\Windows\System32\cmd.exe |
| MandatoryLabel | S-1-16-8192 it's useful for me to see exe like cmd or powershell and it's command line parameter, but there is also a lot of noisy, like svchost and SearchHost and a lot of windows process, I hope there is a way to filter which condition of a log not to send to wazuh manager or only send specific log, like this case I want to send event 4668 and also the ParatProcessName or NewProcessName matchs cmd.exe, because windows seems don't have a way to filter it, so when it comes to a large scale, it won't take a lot of network bandwidth, in order to achieve that, the agent must do the filter work, I know there is a <query> tag, but I haven't find it's syntax, I don't know the <match> tag in rule configuration can be used here? And suddenly a question came to my mind, if a agent can't communicate to manager, how many logs does it temporary cache till next successful connection. Or it mark last successful send is like "point A" and wait till next successful manager connection and send from "point A" to every new events. |
it's useful for me to see exe like cmd or powershell and it's command line parameter, but there is also a lot of noisy, like svchost and SearchHost and a lot of windows process, I hope there is a way to filter which condition of a log not to send to wazuh manager or only send specific log, like this case I want to send event 4668 and also the ParatProcessName or NewProcessName matchs cmd.exe, because windows seems don't have a way to filter it, so when it comes to a large scale, it won't take a lot of network bandwidth, in order to achieve that, the agent must do the filter work
<rule id="200002" level="5"> <if_sid>60103</if_sid> <field name="win.system.eventID">4688</field> <field name="win.eventdata.parentProcessName">C:\\Windows\\System32\\cmd.exe</field> <description> New CMD process </description> </rule>And suddenly a question came to my mind, if a agent can't communicate to manager, how many logs does it temporary cache till next successful connection. Or it mark last successful send is like "point A" and wait till next successful manager connection and send from "point A" to every new events
<client_buffer> <disabled>no</disabled> <queue_size>5000</queue_size> <events_per_second>500</events_per_second> </client_buffer>So, the agent collect log can only choose eventID, can't choose field like "win.eventdata.parentProcessName" equal to "cmd.exe" in the event, and if I choose to collect event 4688, all the 4688 event will be send to wazuh manager, right? I don't have a alert flood issue, just think the event may flood.
<localfile> <location>Security</location> <log_format>eventchannel</log_format> <query>Event/System[EventID != 5145 and EventID != 5156 and EventID != 5447 and EventID != 4656 and EventID != 4658 and EventID != 4663 and EventID != 4660 and <!-- The events here are silenced as they are known flooders --> EventID != 4670 and EventID != 4690 and EventID != 4703 and EventID != 4907 and EventID != 5152 and EventID != 5157]</query> </localfile>So is there a way to test windows agent's log are all collected to wazuh manager without missing, so I can do a stress test, like is there a file I can tail in linux to see the collected events. So I will know when to added a additional wazuh server to collect.
2019 Nov 04 09:53:36 (W10) 192.168.75.141->EventChannel {"win":{"system":{"providerName":"Microsoft-Windows-Security-Auditing","providerGuid":"{54849625-5478-4994-a5ba-3e3b0328c30d}","eventID":"4689","version":"0","level":"0","task":"13313","opcode":"0","keywords":"0x8020000000000000","systemTime":"2019-11-04T08:53:35.919292100Z","eventRecordID":"2678","processID":"4","threadID":"1376","channel":"Security","computer":"DESKTOP-D33AN6I","severityValue":"AUDIT_SUCCESS","message":"Se salió de un proceso."},"eventdata":{"subjectUserSid":"S-1-5-21-2635242741-4024004514-10403589-1001","subjectUserName":"Zenidd","subjectDomainName":"DESKTOP-D33AN6I","subjectLogonId":"0x194a5","status":"0x1","processId":"0x15cc","processName":"C:\\Windows\\System32\\backgroundTaskHost.exe"}}}# State file for ossec-agent
# Agent status:# - pending: waiting to get connected.# - connected: connection established with manager in the last 10 seconds.# - disconnected: connection lost or no ACK received in the last 10 seconds.status='connected'
# Last time a keepalive was sentlast_keepalive='2019-11-04 09:59:51'
# Last time a control message was receivedlast_ack='2019-11-04 09:59:51'
# Number of generated eventsmsg_count='6416'
# Number of messages (events + control messages) sent to the managermsg_sent='6526'<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>
I tried it and it's working.
And I also found this one:
https://documentation.wazuh.com/3.10/user-manual/capabilities/log-data-collection/how-to-collect-wlogs.html?highlight=querylist#filtering-events-from-windows-event-channel-with-queries
It directly uses windows filtering sytax:<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4689)]] and (*[EventData[Data[@Name="ProcessName"]="c:\windows\system32\cmd.exe"]])</Select>
</Query>
</QueryList>
If I put this into eventvwr.msc-->"Filter Current Log"-->"XML"-->"Edit query manually", it will apply successfully.
But when I put this to agent.conf:
<localfile>
<location>Security</location>
<log_format>eventchannel</log_format>
<query>
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4689)]] and (*[EventData[Data[@Name="ProcessName"]="c:\windows\system32\cmd.exe"]])</Select>
</Query>
</QueryList>
</query>
</localfile>
My rule is like this:
<rule id="100011" level="14">
<if_sid>60103</if_sid>
<field name="win.system.eventID">^4689$</field>
<description>test4689</description>
</rule>
No alert will generated when I created new events, I don't know why.
Hello again Harvey,
No alert will generated when I created new events, I don't know why.
Your snippet is almost valid but there are characters that should be escaped:
<localfile>
<location>Security</location>
<log_format>eventchannel</log_format>
<query>
\<QueryList>
\<Query Id="0" Path="Security">
\<Select Path="Security">*[System[(EventID=4689)]] and (*[EventData[Data[@Name="ProcessName"]="c:\\windows\\system32\\cmd.exe"]])\</Select>
\</Query>
\</QueryList>
</query>
</localfile>
After escaping the characters above and using your rule, I can see the related alert:
** Alert 1575365357.111750: mail - local,syslog,sshd,
2019 Dec 03 10:29:17 (w10) 192.168.75.141->EventChannel
Rule: 100011 (level 14) -> 'test4689'
{"win":{"system":{"providerName":"Microsoft-Windows-Security-Auditing","providerGuid":"{54849625-5478-4994-a5ba-3e3b0328c30d}","eventID":"4689","version":"0","level":"0","task":"13313","opcode":"0","keywords":"0x8020000000000000","systemTime":"2019-12-03T09:29:17.067544800Z","eventRecordID":"47432","processID":"4","threadID":"96","channel":"Security","computer":"DESKTOP-D33AN6I","severityValue":"AUDIT_SUCCESS","message":"Se salió de un proceso."},"eventdata":{"subjectUserSid":"S-1-5-21-2635242741-4024004514-10403589-1001","subjectUserName":"Zenidd","subjectDomainName":"DESKTOP-D33AN6I","subjectLogonId":"0x6e03e","status":"0xc000013a","processId":"0x7e8","processName":"C:\\Windows\\System32\\cmd.exe"}}}
win.system.providerName: Microsoft-Windows-Security-Auditing
win.system.providerGuid: {54849625-5478-4994-a5ba-3e3b0328c30d}
win.system.eventID: 4689
win.system.version: 0
win.system.level: 0
win.system.task: 13313
win.system.opcode: 0
win.system.keywords: 0x8020000000000000
win.system.systemTime: 2019-12-03T09:29:17.067544800Z
win.system.eventRecordID: 47432
win.system.processID: 4
win.system.threadID: 96
win.system.channel: Security
win.system.computer: DESKTOP-D33AN6I
win.system.severityValue: AUDIT_SUCCESS
win.system.message: Se salió de un proceso.
win.eventdata.subjectUserSid: S-1-5-21-2635242741-4024004514-10403589-1001
win.eventdata.subjectUserName: Zenidd
win.eventdata.subjectDomainName: DESKTOP-D33AN6I
win.eventdata.subjectLogonId: 0x6e03e
win.eventdata.status: 0xc000013a
win.eventdata.processId: 0x7e8
win.eventdata.processName: C:\Windows\System32\cmd.exe
If I changed it to no, it'll collect log since last agent stop time, right?
So if I wrote a script or something, when the wazuh-agent can't communicate with the wazuh-server some times and some duration, like a laptop not in office, or the network cable is unplugged, the script stops wazuh-agent, next time the connection is good, it'll send logs since the agent stopped, right?
When <only-future-events> is set to no, the agent will collect the events missed in the time it was off. If the <only-future-events> is set to yes, it will only collect the events that occur since the agent is active. On the other hand, Wazuh agents have a queue where the events wait when the agent, for any reason, can’t communicate with the server. By default, this queue can hold 5000 events.
I hope this information is useful for you Harvey. Let me know if you need anything else. Greetings,
JP Sáez