Following xpath expression you need to do while searching for event mentioning event id:
-FilterXPath 'Events/System/EventId=4624'
the following two queries are same because eventid appears from only one single place in the schema.
-FilterXPath '*/System/EventId=4624'
or
-FilterXPath '*/*/EventId=4624'
for example, when you are given a .evtx file to query:
Get-WinEvent -Path C:\Users\ContosoAdmin\Desktop\SecurityLog.evtx -FilterXPath '*/System/EventID=4624' -MaxEvents 1
C:\Windows\system32>wevtutil.exe qe C:\Users\ContosoAdmin\Desktop\SecurityLog.evtx /lf:true /q:*/System/EventID=4624 /c:1 /rd:true /f:text
Query events based on time:
# Query on a specific timestamp (must go to milliseconds!)
Get-WinEvent -LogName System -FilterXPath '*/*/TimeCreated[@SystemTime="2020-03-08T16:24:27.042Z"]'
# Query events before a date
Get-WinEvent -LogName System -FilterXPath '*/System/TimeCreated[(@SystemTime<"2020-03-01T00:00:00Z")]'
# Query events in a given hour of a day
Get-WinEvent -LogName System -FilterXPath '*/System/TimeCreated[(@SystemTime>"2020-02-11T11:00:00Z") and (@SystemTime<"2020-02-11T12:00:00Z")]'
# Query events in the last 24 hours (86400000 ms)
Get-WinEvent -LogName System -FilterXPath '*/*/TimeCreated[timediff(@SystemTime) <= 86400000]'
Get-WinEvent -Path C:\Users\ContosoAdmin\Desktop\SystemLog.evtx -FilterXPath '*/System/TimeCreated[@SystemTime="2019-12-13T08:24:27.5440626"]'
Query by username:
Get-WinEvent -Path C:\Users\ContosoAdmin\Desktop\SecurityLog.evtx -MaxEvents 1 -FilterXPath '*/EventData/Data[@Name="TargetUserName"]="eleanor"'
or
Get-WinEvent -Path C:\Users\ContosoAdmin\Desktop\SecurityLog.evtx -MaxEvents 1 -FilterXPath '*/*/Data[@Name="TargetUserName"]="eleanor"'
combining queries:
Get-WinEvent -Path C:\Users\ContosoAdmin\Desktop\SecurityLog.evtx -FilterXPath '*/System/EventID=4624 and */EventData/Data[@Name="TargetUserName"]="eleanor"' -MaxEvents 1
Get-WinEvent -Path C:\Users\ContosoAdmin\Desktop\SecurityLog.evtx -FilterXPath '*/System/EventID=4624 and */System/TimeCreated[@SystemTime>"2020-02-26T00:00:00"] and */EventData/Data[@Name="TargetUserName"]="eleanor"' -Oldest -MaxEvents 1
Reverse sort order:
-Oldest
Get-WinEvent -path C:\Users\ContosoAdmin\Desktop\SecurityLog.evtx -FilterXPath '*/System/EventID=4624 and */EventData/Data[@Name="TargetUserName"]="eleanor"' -Oldest -MaxEvents 1
Application query:
package installation event id is 1033. what is the product name of msi that was installed on 02/11/2020 around 11 am?
Get-WinEvent -Path C:\Users\ContosoAdmin\Desktop\ApplicationLog.evtx -FilterXPath '*/*/EventID=1033 and */*/TimeCreated[@SystemTime<"2020-02-11T12:00:00"]'
shutdown events query:
what was the first shutdown time on 02/03/2020? shutdown event id is 13.
Get-WinEvent -Path C:\Users\ContosoAdmin\Desktop\SystemLog.evtx -FilterXPath '*/*/EventID=13 and */*/TimeCreated[@SystemTime>"2020-02-03T00:00:00"]' -Oldest -MaxEvents 1
Get-Winevent -Path C:\Users\ContosoAdmin\Desktop\SecurityLog.evtx -FilterXPath '*/*/EventID=4616 and */*/Data[@Name="SubjectDomainName"]="NT AUTHORITY"'
Get-Winevent -Path C:\Users\ContosoAdmin\Desktop\SecurityLog.evtx -FilterXPath '*/*/EventID=4624 and */*/Data[@Name="TargetUserName"]="NETWORK SERVICE" and */*/TimeCreated[@SystemTime>"2020-02-26T00:00:00"]' | Format-List -Property Message
From user system, say user system is amy.contoso.azure query to domain controller to check users access log:
Get-WinEvent -LogName 'Security' -FilterXPath '*/*/Data="bob"' -MaxEvents 20 -ComputerName dc.contoso.azure
Get-WinEvent -LogName 'Security' -FilterXPath '*/*/EventID="4624" and */*/Data="nadia"' -MaxEvents 20 -ComputerName dc.contoso.azure
Detection pass the hash log on to dc using logon type 9:
say from your system you use mimikatz to pass the hash login to the dc. how can we detect those? by doing Pass-the-hash using Mimikatz on your desktop, you left a trace in the security log — a cached interactive logon type 9
Get-WinEvent -LogName 'Security' -FilterXPath '*/*/EventID="4624" and */*/Data="nadia"' -MaxEvents 20 | Format-List | findstr /R /C:'Logon Type:'
Get-WinEvent -LogName 'Security' -FilterXPath '*/*/EventID="4624" and */*/Data[@Name="LogonType"]="9"' | Format-List | findstr /R \<Network.Account.Name
Avi
Comments
Post a Comment