Win Event Logs

Event ID Filter Hash Table XPath Queries Get-WinEvent wevtutil.exe

Windows Event Logs

The Windows Event Logs are not text files that can be viewed using a text editor. However, the raw data can be translated into XML using the Windows API. The events in these log files are stored in a proprietary binary format with a .evt or .evtx extension. The log files with the .evtx file extension typically reside in C:\Windows\System32\winevt\Logs

Event logs classified into types:

There are three main ways of accessing these event logs within a Windows system:

Event Viewer

wevutil.exe

Esempi utili:

Per utilizzare wevtutil.exe e ottenere il numero dei nomi dei log, puoi eseguire il seguente comando in PowerShell:

Per utilizzare il comando wevtutil con query-events, puoi usare la seguente sintassi:

wevtutil qe Application /c:3 /rd:true /f:text

Get-WinEvent

This is a PowerShell cmdlet called Get-WinEvent. Per Microsoft, the Get-WinEvent cmdlet "gets events from event logs and event tracing log files on local and remote computers." It provides information on event logs and event log providers. Additionally, you can combine numerous events from multiple sources into a single command and filter using XPath queries, structured XML queries, and hash table queries.

Guida ufficiale su Get-WinEvent Torna all'indice!

When working with large event logs, per Microsoft, it's inefficient to send objects down the pipeline to a Where-Object command. The use of the Get-WinEvent cmdlet's FilterHashtable parameter is recommended to filter event logs.

Get-WinEvent -FilterHashtable @{ LogName='Application' ProviderName='WLMS' }

The syntax of a hash table is as follows: @{ = ; [ = ] ...}

FilterHashtable per Livello: Livelli evento (syslog / Windows)

⚠️ In Windows Event Log, di solito: Level = 4 → Information

Esempio:

Get-WinEvent -FilterHashtable @{ LogName = 'Application' Level = 4 StartTime = (Get-Date).AddDays(-1) }

The valid Get-WinEvent key/value pairs are as follows:

When building a query with a hash table, Microsoft recommends making the hash table one key-value pair at a time. Event Viewer can provide quick information on what you need to build your hash table.

Get-WinEvent - PS 7.5

Esempio: Filter Event log results

# Using the Where-Object cmdlet:
$Yesterday = (Get-Date) - (New-TimeSpan -Day 1)
Get-WinEvent -LogName 'Windows PowerShell' | Where-Object { $_.TimeCreated -ge $Yesterday }
# Using the FilterHashtable parameter:
$Yesterday = (Get-Date) - (New-TimeSpan -Day 1)
Get-WinEvent -FilterHashtable @{ LogName='Windows PowerShell'; Level=3; StartTime=$Yesterday }
# Using the FilterXML parameter: (<> equivale a < , perchè mi dava errore di visualizzazione)
$xmlQuery = @'
<>QueryList>
<>Query Id="0" Path="Windows PowerShell">
<>Select Path="System">*[System[(Level=3) and TimeCreated[timediff(@SystemTime) &lt;= 86400000]]]
<>/Query>
<>/QueryList>
'@ Get-WinEvent -FilterXML $xmlQuery
# Using the FilterXPath parameter:
$XPath = '*[System[Level=3 and TimeCreated[timediff(@SystemTime) &lt;= 86400000]]]'
Get-WinEvent -LogName 'Windows PowerShell' -FilterXPath $XPath

Torna all'indice!

XPath Queries

The W3C created XPath, or XML Path Language in full, to provide a standard syntax and semantics for addressing parts of an XML document and manipulating strings, numbers, and booleans . The Windows Event Log supports a subset of XPath 1.0

Nota Bene: Prendendo i dettagli dal file XML, è facile scomporre la struttura e creare qualsiasi query ( ho scritto in sequenza le query per velocizzare la comprensione! )

Esempi:

Risorse Utilissime:

Torna all'indice!

Event ID:

Eventi di cancellazione o manomissione dei log
Attività utente / amministrativa sospetta

PowerShell downgrade attack

è una tecnica in cui un attaccante sfrutta le versioni precedenti di PowerShell per eludere le misure di sicurezza

Ricerca su MITRE: Impair Defenses: Downgrade Attack : ID: T1562.010 , Sub-technique of: T1562 , Tactic: Defense Evasion

Detecting Downgrade Attacks : DET0350

Abuse of PowerShell for Arbitrary Execution Technique Detected: PowerShell | T1059.001 , ID: DET0455

Process Metadata: Contextual data about a running process, which may include information such as environment variables, image name, user/owner, etc.
WinEventLog:PowerShell EventCode=400, 403

Torna all'indice!