# Windows Event Logs & Finding Evil Module

## Section One: Windows Event Logging Basics

`Windows Event Logs` are an intrinsic part of the Windows Operating System, storing logs from different components of the system including the system itself, applications running on it, ETW providers, services, and others.

The default Windows event logs consist of `Application`, `Security`, `Setup`, `System`, and `Forwarded Events`. While the first four logs cover application errors, security events, system setup activities, and general system information, the "Forwarded Events" section is unique, showcasing event log data forwarded from other machines. This central logging feature proves valuable for system administrators who desire a consolidated view.&#x20;

### The Anatomy of an Event Log

When examining `Application` logs, we encounter two distinct levels of events: `information` and `error`.

Information events provide general usage details about the application, such as its start or stop events. Conversely, error events highlight specific errors and often offer detailed insights into the encountered issues.

### Leveraging Custom XML Queries

To streamline our analysis, we can create custom XML queries to identify related events using the "Logon ID" as a starting point. By navigating to "Filter Current Log" -> "XML" -> "Edit Query Manually," we gain access to a custom XML query language that enables more granular log searches.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FKkUyXrnGEFOFZw3zc6EM%2FScreenshot(1).png?alt=media&#x26;token=67e4f089-d3d4-4ed5-9d3b-e674bb91646f" alt=""><figcaption></figcaption></figure>

The "Subject Logon ID" with a value of `0x3E7` in Windows Security Event Logs refers to the unique identifier for the session of the local system account, also known as the LocalSystem account. This account is a built-in account used by the operating system for system-level operations and has extensive privileges on the system.

### Useful Windows Event Logs

**Windows System Logs**

* [Event ID 1074](https://serverfault.com/questions/885601/windows-event-codes-for-startup-shutdown-lock-unlock) `(System Shutdown/Restart)`
* [Event ID 6005](https://superuser.com/questions/1137371/how-to-find-out-if-windows-was-running-at-a-given-time) `(The Event log service was started)`
* [Event ID 6006](https://learn.microsoft.com/en-us/answers/questions/235563/server-issue) `(The Event log service was stopped)`
* [Event ID 6013](https://serverfault.com/questions/885601/windows-event-codes-for-startup-shutdown-lock-unlock) `(Windows uptime)`
* [Event ID 7040](https://www.slideshare.net/Hackerhurricane/finding-attacks-with-these-6-events) `(Service status change)`

**Windows Security Logs**

* [Event ID 1102](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=1102) `(The audit log was cleared)`
* [Event ID 1116](https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/troubleshoot-microsoft-defender-antivirus?view=o365-worldwide) `(Antivirus malware detection)`
* [Event ID 1118](https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/troubleshoot-microsoft-defender-antivirus?view=o365-worldwide) `(Antivirus remediation activity has started)`
* [Event ID 1119](https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/troubleshoot-microsoft-defender-antivirus?view=o365-worldwide) `(Antivirus remediation activity has succeeded)`
* [Event ID 1120](https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/troubleshoot-microsoft-defender-antivirus?view=o365-worldwide) `(Antivirus remediation activity has failed)`
* [Event ID 4624](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4624) `(Successful Logon)`
* [Event ID 4625](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4625) `(Failed Logon)`
* [Event ID 4648](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4648) `(A logon was attempted using explicit credentials)`
* [Event ID 4656](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4656) `(A handle to an object was requested)`
* [Event ID 4672](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4672) `(Special Privileges Assigned to a New Logon)`
* [Event ID 4698](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4698) `(A scheduled task was created)`
* [Event ID 4700](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4700) & [Event ID 4701](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4701) `(A scheduled task was enabled/disabled)`
* [Event ID 4702](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4702) `(A scheduled task was updated)`
* [Event ID 4719](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4719) `(System audit policy was changed)`
* [Event ID 4738](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4738) `(A user account was changed)`
* [Event ID 4771](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4771) `(Kerberos pre-authentication failed)`
* [Event ID 4776](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4776) `(The domain controller attempted to validate the credentials for an account)`
* [Event ID 5001](https://learn.microsoft.com/en-us/microsoft-365/security/defender-endpoint/troubleshoot-microsoft-defender-antivirus?view=o365-worldwide) `(Antivirus real-time protection configuration has changed)`
* [Event ID 5140](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=5140) `(A network share object was accessed)`
* [Event ID 5142](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=5142) `(A network share object was added)`
* [Event ID 5145](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=5145) `(A network share object was checked to see whether client can be granted desired access)`
* [Event ID 5157](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=5157) `(The Windows Filtering Platform has blocked a connection)`
* [Event ID 7045](https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=7045) `(A service was installed in the system)`

Remember, one of the key aspects of threat detection is having a good understanding of what is "normal" in our environment. Anomalies that might indicate a threat in one environment could be normal behavior in another. It's crucial to tune our monitoring and alerting systems to our environment to minimize false positives and make real threats easier to spot.

### Practical Exercises

Let's proceed to solve the questions.

For the first question, let's solve it using two methods: directly from the Event Viewer and via PowerShell.

1\) Open the Event Viewer and navigate to Windows Logs -> Security .

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FoO431kHB47ZiwZX7zRGk%2FScreenshot(3).png?alt=media&#x26;token=99ff0282-9804-4f76-a6e4-5db6b9d657b6" alt=""><figcaption></figcaption></figure>

2\) Let's Analyze the event with ID 4624, within this log, we find crucial details, including the "Logon ID", which allows us to correlate this logon with other events sharing the same "Logon ID". Another important detail is the "Logon Type", indicating the type of logon. In this case, it specifies a Service logon type, suggesting that "SYSTEM" initiated a new service. However, further investigation is required to determine the specific service involved, utilizing correlation techniques with additional data like the "Logon ID".

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FueS5YU1N7hQX4Bpyrorc%2FScreenshot(4).png?alt=media&#x26;token=236f85da-1b1d-48cb-bc23-8689dcbb482a" alt=""><figcaption></figcaption></figure>

3\) Let's create a custom XML query based on the logon ID.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FXWxY1M2ADHJiLwTHJwf3%2FScreenshot(5).png?alt=media&#x26;token=76cb823d-6bea-479a-8563-a466406276a8" alt=""><figcaption></figcaption></figure>

4\) I analyzed event ID 4907 occurrences after "8/3/2022 at 10:23:25" and identified a process named "TiWorker.exe", it's the executable responsible for the modification of the auditing settings.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fs3M9krMBaETVh1mupYhZ%2FScreenshot(7).png?alt=media&#x26;token=64ae1cfd-e955-4cfa-8d05-5d445836d65e" alt=""><figcaption></figcaption></figure>

We can address this directly using PowerShell. Let's proceed.

<pre class="language-powershell"><code class="lang-powershell">function Get-SecurityEvent{ 
<strong>    param ( $eventid, $start, $end ) 
</strong><strong>    
</strong>    $filters = @{LogName = "Security"} 
 
    if ($eventid -ne $null) { 
 
       $filters.ID = $eventid 
    } 
    if ($start -ne $null) { 
       $filters.StartTime = $start 
    } 
    if ($end -ne $null) { 
       $filters.EndTime = $end 
    } 
    Get-WinEvent -FilterHashtable $filters 
}
</code></pre>

I implemented this code in the solution using three parameters: Event ID, Start Time, and End Time.

1\) I saved the code in a file named `Get-Security.psm1` and then imported it.

```powershell
New-Item -Path Get-Security.psm1 -ItemType File
```

```powershell
Import-Module .\Get-Security.psm1
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FjLdchCI1ihGYhixX8BP6%2FScreenshot(9).png?alt=media&#x26;token=f3178b03-7ad6-4695-ba61-402c11a9e857" alt=""><figcaption></figcaption></figure>

2\) I used this command to list all events with ID 4907 that occurred after the login attempt on 8/3/2022 at 10:23:25.

```powershell
Get-SecurityEvent 4907 "8/3/2022 10:23:25" "8/3/2022 10:24:00" | Select-Object -Property TimeCreated, @{Name="ProcessName"; Expression={$_.Message -match 'Process Name:\s+(.+)' | Out-Null; $matches[1]}} | Format-List TimeCreated, ProcessName
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FiSw2AolIGuidkS9fcpSI%2FScreenshot(10).png?alt=media&#x26;token=ca77c3ec-3b6a-4dbd-86c2-570a56356d7c" alt=""><figcaption></figcaption></figure>

For the second question, I used two methods to solve it: an XML query and PowerShell. Let's begin with the XML query method.

```xml
<QueryList>
  <Query Id="0" Path="Security">
    <Select Path="Security">
*[EventData[Data[@Name='ProcessName'] and (Data='C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF\wpfgfx_v0400.dll')]]
</Select>
  </Query>
</QueryList>
```

After applying the query, I got two events only and found the answer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FrkLgQKXxLme8ZrXA7MMg%2FScreenshot(11).png?alt=media&#x26;token=1c621321-e896-4bf1-beab-a01d6e52b550" alt=""><figcaption></figcaption></figure>

Another approach involves using PowerShell; we will proceed with this method.

I utilized the previously employed function to retrieve the solution, filtering for instances where the Object Name matches (C:\Windows\Microsoft.NET\Framework64\v4.0.30319\WPF\wpfgfx\_v0400.dll).

```powershell
Get-SecurityEvent 4907 "8/3/2022 10:23:24" "8/3/2022 10:24:00" | Where-Object { $_.Message -match 'Object Name:\s+C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\WPF\\wpfgfx_v0400.dll' } | Select-Object -Property TimeCreated
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FZXNgeGMtSPl2Pcccpymw%2FScreenshot(12).png?alt=media&#x26;token=2f377d45-a936-4776-bb49-1951beb7af2e" alt=""><figcaption></figcaption></figure>

## Section two: Analyzing Evil With Sysmon & Event Logs

#### Sysmon Basics&#x20;

`System Monitor (Sysmon)` is a Windows system service and device driver that remains resident across system reboots to monitor and log system activity to the Windows event log. Sysmon provides detailed information about process creation, network connections, changes to file creation time, and more.

Sysmon's primary components include:

* A Windows service for monitoring system activity.
* A device driver that assists in capturing the system activity data.
* An event log to display captured activity data.

Sysmon's unique capability lies in its ability to log information that typically doesn't appear in the Security Event logs, and this makes it a powerful tool for deep system monitoring and cybersecurity forensic analysis.

Sysmon categorizes different types of system activity using event IDs, where each ID corresponds to a specific type of event. For example, `Event ID 1` corresponds to "Process Creation" events, and `Event ID 3` refers to "Network Connection" events. The full list of Sysmon event IDs can be found [here](https://learn.microsoft.com/en-us/sysinternals/downloads/sysmon).

For a comprehensive configuration, we can visit: <https://github.com/SwiftOnSecurity/sysmon-config>.

To get started, you can install Sysmon by downloading it from the official Microsoft documentation (<https://docs.microsoft.com/en-us/sysinternals/downloads/sysmon>). Once downloaded, open an administrator command prompt and execute the following command to install Sysmon.

```bash
sysmon.exe -i -accepteula -h md5,sha256,imphash -l -n
```

To utilize a custom Sysmon configuration, execute the following after installing Sysmon.

```bash
sysmon.exe -c filename.xml
```

### Practical Exercises

Let's proceed to solve the questions.

Let's address the first question using two methods: directly through the Event Viewer and via PowerShell.

1\) To detect DLL hijacks, we modify Event Id 7 in the sysmonconfig-export file from "include" to "exclude" to ensure all data is captured.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FCn3Unke40p2CPJCFPkDw%2FScreenshot(1).png?alt=media&#x26;token=9f19fcd2-90c2-416a-bc30-90ba08151cf5" alt=""><figcaption></figcaption></figure>

2\) Then to utilize the updated Sysmon configuration, execute the following.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F05vZ8fyWSui3i2MZlLO6%2Fimage16.webp?alt=media&#x26;token=cbf2b415-b079-4a63-9e40-c51d6e329d6e" alt=""><figcaption></figcaption></figure>

3\) Let's attempt the hijack using "calc.exe" and "`reflective_dll.x64.dll`" . I copied the files to to a writable directory and renamed `reflective_dll.x64.dll` to `WININET.dll`and executing `calc.exe`, we achieve success. Instead of the Calculator application, a MessageBox is displayed.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FAi1eKA4T09dWdC5gLgPh%2FScreenshot(4).png?alt=media&#x26;token=41184ee1-e6d9-4ea0-b33c-61022db9a417" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FynQ6Mzb0NfsWhhosWEVn%2FScreenshot(5).png?alt=media&#x26;token=2c192137-d779-4a0c-9f90-d6b26a93fc10" alt=""><figcaption></figcaption></figure>

4\) Next, let's attempt to detect this attack. First, we filter the event logs to focus on `Event ID 7`, which represents module load events, by clicking "Filter Current Log" .

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FnhbFhjhYzDqwLB5vFSEU%2FScreenshot(6).png?alt=media&#x26;token=a833c8eb-f919-472c-8587-39c941de72ff" alt=""><figcaption></figcaption></figure>

5\) I used "Find Next" to search for instances of "calc.exe" and identify the DLL load linked to our hijack.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FEx8X6YU3sxZcBq86m2i1%2FScreenshot(8).png?alt=media&#x26;token=408ed3a2-5df5-4536-b808-d3be7dfcb047" alt=""><figcaption></figcaption></figure>

Now, we can observe several indicators of compromise, let's explore these IOCs:

* "calc.exe", originally located in System32, should not be found in a writable directory. Therefore, a copy of "calc.exe" in a writable directory serves as an IOC, as it should always reside in System32 or potentially Syswow64.
* "WININET.dll", originally located in System32, should not be loaded outside of System32 by calc.exe.
* The original "WININET.dll" is Microsoft-signed, while our injected DLL remains unsigned.

Here is an alternative solution for the first question using PowerShell directory. Let's review it.

```powershell
Get-SysmonEvent 7 "7/18/2024 9:03:00" "7/18/2024 9:04:00" | Where-Object { $_.properties[4].value -like "*calc.exe" -and $_.properties[5].value -like "*WININET.dll" } | Format-List
```

* `properties[4].value -like "*calc.exe"` filters the events where the 5th property (index 4) contains "calc.exe". This property likely represents the image (executable) name.
* `properties[5].value -like "*WININET.dll"` filters the events where the 6th property (index 5) contains "WININET.dll". This property likely represents the ImageLoaded.

Here is the code for the `Get-SysmonEvent` function.

```powershell
function Get-SysmonEvent {
	param( $eventid, $start, $end)

	$filters = @{ LogName = "Microsoft-Windows-Sysmon/Operational"}
	
	if ($eventid -ne $null){
		$filters.ID = $eventid
	}
	if ($start -ne $null){
		$filters.StartTime = $start
	}
	if ($end -ne $null){
		$filters.EndTime = $end
	}
	Get-WinEvent -FilterHashtable $filters
   }
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FfwuvgdiLd0uKCmSBi67U%2FScreenshot(12).png?alt=media&#x26;token=0aefbb28-4680-428d-b769-6cac865cecc0" alt=""><figcaption></figcaption></figure>

Next, we will address the second question, which concerns Unmanaged PowerShell attacks.

Let's gain a brief understanding of C# and its runtime environment. C# is considered a "managed" language, meaning it requires a backend runtime to execute its code. The Common Language Runtime (CLR) serves as this runtime environment. Managed code does not directly run as assembly; instead, it is compiled into a bytecode format that the runtime processes and executes. Consequently, a managed process relies on the CLR to execute C# code.

1\) In this attack, we will utilize "spoolsv.exe"; let's examine it in Process Hacker.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fo7uoLaeO1z9hok281kSc%2FScreenshot(3).png?alt=media&#x26;token=ad90e569-f02e-4d48-ba5a-e670ce7a6723" alt=""><figcaption></figcaption></figure>

2\) We have identified that spoolsv.exe is unmanaged. Let’s proceed with the attack to observe its response.

```powershell
powershell -ep bypass
Import-Module .\Invoke-PSInject.ps1
Invoke-PSInject -ProcId [Process ID of spoolsv.exe] -PoshCode "V3JpdGUtSG9zdCAiSGVsbG8sIEd1cnU5OSEi"
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FWQAOPMRsWQglajDOYj3u%2FScreenshot(5).png?alt=media&#x26;token=ed9872e3-ba49-4e5a-b27d-8f47b8b79fbc" alt=""><figcaption></figcaption></figure>

Spoolsv.exe is now managed. Let's explore how to detect the attack.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FIfGJUJMLUxCZarbW9dtt%2FScreenshot(4).png?alt=media&#x26;token=409190b5-84bb-4077-ab1a-d14e7800488c" alt=""><figcaption></figcaption></figure>

3\) First, we'll use Event Viewer to detect the attack, then PowerShell. I searched for spoolsv.exe using Ctrl + F and found it.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FSBVEPq2oLhpLUR9BjR6V%2FScreenshot(6).png?alt=media&#x26;token=580fc074-1c36-42a6-8492-8c006d4de9f3" alt=""><figcaption></figcaption></figure>

The presence of "Microsoft .NET Runtime...", `clr.dll`, and `clrjit.dll` should attract our attention. These 2 DLLs are used when C# code is ran as part of the runtime to execute the bytecode. If we observe these DLLs loaded in processes that typically do not require them, it suggests a potential execute-assembly or unmanaged PowerShell injection attack.

Let’s proceed with the second method using PowerShell. First, we'll create a function called `Get-SysmonEvent` to utilize Sysmon.

```powershell
function Get-SysmonEvent {
	param( $eventid, $start, $end)

	$filters = @{ LogName = "Microsoft-Windows-Sysmon/Operational"}
	
	if ($eventid -ne $null){
		$filters.ID = $eventid
	}
	if ($start -ne $null){
		$filters.StartTime = $start
	}
	if ($end -ne $null){
		$filters.EndTime = $end
	}
	Get-WinEvent -FilterHashtable $filters
  }
```

Let's create the file, save the code in it, and then import it.

```powershell
New-Item -Path Get-Sysmon.psm1 -Itemtype File
Import-Module .\Get-Sysmon.psm1
Get-SysmonEvent 7 "7/20/2024 5:51:00" "7/20/2024 5:52:00" | Where-Object { $_.properties[4].value -like "*spoolsv.exe" -and $_.properties[5].value -like "*clr.dll" } | Format-List
```

We can now use the function to retrieve the logs.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F1YYj45yLRnj6toTtahby%2FScreenshot(7).png?alt=media&#x26;token=39add7fa-60a5-4d93-80bc-c6057f1b85ec" alt=""><figcaption></figcaption></figure>

For the third question, which concerns a Credential Dumping attack, we were required to obtain the NTLM hash of the administrator.

Another critical aspect of cybersecurity is detecting credential dumping activities. One widely used tool for credential dumping is Mimikatz, offering various methods for extracting Windows credentials. One specific command, "sekurlsa::logonpasswords", enables the dumping of password hashes or plaintext passwords by accessing the Local Security Authority Subsystem Service (LSASS). LSASS is responsible for managing user credentials and is a primary target for credential-dumping tools like Mimikatz.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FGeHnFyUblO5KI3Sc1xHg%2FScreenshot(8).png?alt=media&#x26;token=85b8aefa-2a35-42b1-a547-bace062a6f5a" alt=""><figcaption></figcaption></figure>

## Section Three: Event Tracing for Windows (ETW)

### Event Tracing for Windows (ETW)

In the realm of effective threat detection and incident response, we often find ourselves relying on the limited log data at our disposal. However, this approach falls short of fully harnessing the immense wealth of information that can be derived from the powerful resource known as `Event Tracing for Windows (ETW)`. Unfortunately, this oversight can be attributed to a lack of awareness and appreciation for the comprehensive and intricate insights that ETW can offer.

### What is ETW?

According to Microsoft, `Event Tracing For Windows (ETW)` is a general-purpose, high-speed tracing facility provided by the operating system. Using a buffering and logging mechanism implemented in the kernel, ETW provides a tracing mechanism for events raised by both user-mode applications and kernel-mode device drivers.

ETW, functioning as a high-performance event tracing mechanism deeply embedded within the Windows operating system, presents an unparalleled opportunity to bolster our defense capabilities. Its architecture facilitates the dynamic generation, collection, and analysis of various events occurring within the system, resulting in the creation of intricate, real-time logs that encompass a wide spectrum of activities.

### Interacting With ETW

`Logman` is a pre-installed utility for managing Event Tracing for Windows (ETW) and Event Tracing Sessions. This tool is invaluable for creating, initiating, halting, and investigating tracing sessions.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F7u7dtNT0k4hGVeD5x2YQ%2FScreenshot(9).png?alt=media&#x26;token=169c5cbe-b1c0-4cde-b0c3-afbf6e79d3c1" alt=""><figcaption></figcaption></figure>

For each provider subscribed to the session, we can acquire critical data:

* `Name / Provider GUID`: This is the exclusive identifier for the provider.
* `Level`: This describes the event level, indicating if it's filtering for warning, informational, critical, or all events.
* `Keywords Any`: Keywords create a filter based on the kind of event generated by the provider.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FbNCoNgvVKSpN3PvJq9ur%2FScreenshot(10).png?alt=media&#x26;token=008f7a35-6504-4110-b5ca-66fcb9f12e4f" alt=""><figcaption></figcaption></figure>

By using the `logman query providers` command, we can generate a list of all available providers on the system, including their respective GUIDs.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FLZ5v43KeMDTwnBBvdHfo%2FScreenshot(11).png?alt=media&#x26;token=0499cb6a-d268-4fd9-846d-b7cc741ba45a" alt=""><figcaption></figcaption></figure>

Due to the high number of providers, it's usually advantageous to filter them using `findstr`. For instance, you will see multiple results for "Winlogon" in the given example.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F9KlwtvhpakhAvKyIU8sD%2FScreenshot(12).png?alt=media&#x26;token=f945d14a-c960-4fba-90ae-c2ba47bc1790" alt=""><figcaption></figcaption></figure>

By specifying a provider with Logman, we gain a deeper understanding of the provider's function. This will inform us about the Keywords we can filter on, the available event levels, and which processes are currently utilizing the provider.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FMymTBWWW3lnEgOz3aIud%2FScreenshot(13).png?alt=media&#x26;token=c31d5108-a4d7-405a-94c2-59b4fe54661a" alt=""><figcaption></figcaption></figure>

### Practical Exercise

Let's work on the lab, which involves executing Seatbelt and providing the ManagedInteropMethodName.

For demonstrative purposes, let's emulate a malicious .NET assembly load by executing a precompiled version of Seatbelt that resides on disk. `Seatbelt` is a well-known .NET assembly, often employed by adversaries who load and execute it in memory to gain situational awareness on a compromised system.

Relying solely on Sysmon Event ID 7 for detecting attacks can be challenging due to the large volume of events it generates (especially if not configured properly). Additionally, while it informs us about the DLLs being loaded, it doesn't provide granular details about the actual content of the loaded .NET assembly.

1\) Let's use SilkETW to collect data from the `Microsoft-Windows-DotNETRuntime` provider. After that, we can proceed to simulate the attack again to evaluate whether ETW can furnish us with more detailed and actionable intelligence regarding the loading and execution of the 'Seatbelt' .NET assembly.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fx1GUZkarlCPSgdN4aYNH%2FScreenshot(14).png?alt=media&#x26;token=87db64f4-bced-41e0-8476-ba98d01a4808" alt=""><figcaption></figcaption></figure>

By using `Microsoft-Windows-DotNETRuntime`, developers can gain a better understanding of how their .NET applications are performing and identify areas for improvement.

2\) Let's emulate a malicious .NET assembly load by executing a precompiled version of [Seatbelt](https://github.com/GhostPack/Seatbelt) that resides on disk. `Seatbelt` is a well-known .NET assembly, often employed by adversaries who load and execute it in memory to gain situational awareness on a compromised system.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F7cgWnlee9oKsd7uqXqQ3%2FScreenshot(15).png?alt=media&#x26;token=22493037-f3da-45c3-8542-676814930707" alt=""><figcaption></figcaption></figure>

3\) Once the attack is complete, open the etw\.json file and search for ManagedInteropMethodName to find the answer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FCt6qMontto43Nu7hyp2Z%2FScreenshot(16).png?alt=media&#x26;token=a3fb66c1-6ea0-49e1-9ee2-0aa16f633e7b" alt=""><figcaption></figcaption></figure>

## Section Four: Get-WinEvent

The `Get-WinEvent` cmdlet is an indispensable tool in PowerShell for querying Windows Event logs en masse. The cmdlet provides us with the capability to retrieve different types of event logs, including classic Windows event logs like System and Application logs, logs generated by Windows Event Log technology, and Event Tracing for Windows (ETW) logs.

To quickly identify the available logs, we can leverage the `-ListLog` parameter in conjunction with the Get-WinEvent cmdlet. By specifying `*` as the parameter value, we retrieve all logs without applying any filtering criteria.

```powershell
Get-WinEvent -ListLog * | Select-Object LogName, RecordCount, IsClassicLog, IsEnabled, LogMode, LogType | Format-Table -AutoSize
```

Additionally, we can explore the event log providers associated with each log using the `-ListProvider` parameter. Event log providers serve as the sources of events within the logs.

```powershell
Get-WinEvent -ListProvider * | Format-Table -AutoSize
```

Retrieving events from the System log. This example retrieves the first 50 events from the System log.

```powershell
Get-WinEvent -LogName 'System' -MaxEvents 50 | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
```

Retrieving events from Microsoft-Windows-WinRM/Operational log.

```powershell
Get-WinEvent -LogName 'Microsoft-Windows-WinRM/Operational' -MaxEvents 30 | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
```

```powershell
Get-WinEvent -LogName 'Microsoft-Windows-WinRM/Operational' -Oldest -MaxEvents 30 | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
```

Retrieving events from .evtx Files.

```powershell
Get-WinEvent -Path 'C:\Tools\chainsaw\EVTX-ATTACK-SAMPLES\Execution\exec_sysmon_1_lolbin_pcalua.evtx' -MaxEvents 5 | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
```

Filtering events with FilterHashtable, this command retrieves events with IDs 1 and 3 from the `Microsoft-Windows-Sysmon/Operational` event log, selects specific properties from those events, and displays them in a table format.

```powershell
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; ID=1,3} | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
```

For exported events the equivalent command is the following.

```powershell
Get-WinEvent -FilterHashtable @{Path='C:\Tools\chainsaw\EVTX-ATTACK-SAMPLES\Execution\sysmon_mshta_sharpshooter_stageless_meterpreter.evtx'; ID=1,3} | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
```

If we want the get event logs based on a date range (`5/28/23 - 6/2/2023`), this can be done as follows.

```powershell
$startDate = (Get-Date -Year 2023 -Month 5 -Day 28).Date
$endDate   = (Get-Date -Year 2023 -Month 6 -Day 3).Date
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; ID=1,3; StartTime=$startDate; EndTime=$endDate} | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
```

Filtering events with FilterHashtable & XML. Consider an intrusion detection scenario where a suspicious network connection to a particular IP (`52.113.194.132`) has been identified.

```powershell
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; ID=3} |
`ForEach-Object {
$xml = [xml]$_.ToXml()
$eventData = $xml.Event.EventData.Data
New-Object PSObject -Property @{
    SourceIP = $eventData | Where-Object {$_.Name -eq "SourceIp"} | Select-Object -ExpandProperty '#text'
    DestinationIP = $eventData | Where-Object {$_.Name -eq "DestinationIp"} | Select-Object -ExpandProperty '#text'
    ProcessGuid = $eventData | Where-Object {$_.Name -eq "ProcessGuid"} | Select-Object -ExpandProperty '#text'
    ProcessId = $eventData | Where-Object {$_.Name -eq "ProcessId"} | Select-Object -ExpandProperty '#text'
}
}  | Where-Object {$_.DestinationIP -eq "52.113.194.132"}
```

If we were looking for anomalous `clr.dll` and `mscoree.dll` loading activity in processes that ordinarily wouldn't require them. The command below is leveraging Sysmon's Event ID 7 to detect the loading of abovementioned DLLs.

```powershell
$Query = @"
	<QueryList>
		<Query Id="0">
			<Select Path="Microsoft-Windows-Sysmon/Operational">*[System[(EventID=7)]] and *[EventData[Data='mscoree.dll']] or *[EventData[Data='clr.dll']]
			</Select>
		</Query>
	</QueryList>
	"@
```

```powershell
Get-WinEvent -FilterXml $Query | ForEach-Object {Write-Host $_.Message `n}
```

Filtering events with FilterXPath. To use XPath queries with Get-WinEvent, we need to use the `-FilterXPath` parameter. This allows us to craft an XPath query to filter the event logs.

```powershell
Get-WinEvent -LogName 'Microsoft-Windows-Sysmon/Operational' -FilterXPath "*[EventData[Data[@Name='Image']='C:\Windows\System32\reg.exe']] and *[EventData[Data[@Name='CommandLine']='`"C:\Windows\system32\reg.exe`" ADD HKCU\Software\Sysinternals /v EulaAccepted /t REG_DWORD /d 1 /f']]" | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
```

Suppose we want to investigate any network connections to a particular suspicious IP address (`52.113.194.132`) that Sysmon has logged. To do that we could use the following command.

```powershell
Get-WinEvent -LogName 'Microsoft-Windows-Sysmon/Operational' -FilterXPath "*[System[EventID=3] and EventData[Data[@Name='DestinationIp']='52.113.194.132']]"
```

Filtering events based on property values. The `-Property *` parameter, when used with `Select-Object`, instructs the command to select all properties of the objects passed to it.

```powershell
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; ID=1} -MaxEvents 1 | Select-Object -Property *
```

Let's now see an example of a command that retrieves `Process Create` events from the `Microsoft-Windows-Sysmon/Operational` log, checks the parent command line of each event for the string `-enc`, and then displays all properties of any matching events as a list.

```powershell
Get-WinEvent -FilterHashtable @{LogName='Microsoft-Windows-Sysmon/Operational'; ID=1} | Where-Object {$_.Properties[21].Value -like "*-enc*"} | Format-List
```

### Practical Exercise

The lab requires me to use the Get-WinEvent cmdlet to search all event logs in the "C:\Tools\chainsaw\EVTX-ATTACK-SAMPLES\Lateral Movement" directory and find when the \*\PRINT share was added. Enter the time of the event in the format HH:MM:SS.

```powershell
Get-WinEvent -FilterHashtable @{Path='C:\Tools\chainsaw\EVTX-ATTACK-SAMPLES\Lateral Movement\*'; } | Where-Object { $_.Id -eq "5142" } 
   | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Format-Table -AutoSize
```

Here I used Event ID 5142 in the Windows Security log indicates a "A network share object was added." This event is logged when a new network share is created on a system. Monitoring this event can be useful for detecting unauthorized or suspicious activity, particularly in the context of lateral movement within a network.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FoD5ujTNyo0CrtIMeHmGr%2FScreenshot(18).png?alt=media&#x26;token=8146cc92-3afd-493d-9bb0-2754ed3937e9" alt=""><figcaption></figcaption></figure>

### Section Five: Skills Assessment

Let's complete this lab to apply what we've learned in this module.

In the first question, we need to examine the logs in the "C:\Logs\DLLHijack" directory to identify the process responsible for a DLL hijacking attack.

Let's solve this question first using Event Viewer, then using PowerShell.

1\) Open the DLLHijack log file in Event Viewer and filter the current log by Event ID 7.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FuvSlJ7k1uO06ZBpoI33s%2FScreenshot(23).png?alt=media&#x26;token=f172f83d-7e91-4c4e-84e1-53ee702547e3" alt=""><figcaption></figcaption></figure>

The DismCore.dll is not digitally signed, indicating it is responsible for executing a DLL hijacking attack.

Explanation of "Signed: false"

* The attribute "Signed: false" indicates that the file `C:\ProgramData\DismCore.dll` is not digitally signed.
* This means there is no digital signature present in the file to verify its source or integrity.

#### Digital Signatures

A digital signature is a cryptographic technique used to validate the authenticity and integrity of a file. When a file is digitally signed, it means that a certificate, issued by a trusted Certificate Authority (CA), is used to sign the file. This signature serves as a proof of origin and ensures that the file has not been altered since it was signed.

We can solve this with a single PowerShell command. Let's take a look.

```powershell
 Get-WinEvent -FilterHashtable @{Path="C:\Logs\DLLHijack\*"; ID=7} | Select-Object TimeCreated, ID, ProviderName, LevelDisplayName, Message | Where-Object {$_.Message -match ‘Signed: false’} | ForEach-Object {Write-Host $_.Message `n}
```

1\) I utilized the previously used Get-SysmonEvent function to obtain the solution.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FOcQHftw7iwd2qoEibmEg%2FScreenshot(25).png?alt=media&#x26;token=d31a7004-444c-4305-a3cf-578cde848f66" alt=""><figcaption></figcaption></figure>

For the second question, we need to review the logs in the "C:\Logs\PowershellExec" directory to identify the process that ran unmanaged PowerShell code.

1\) I opened the PowershellExec log file in Event Viewer and filtered for Event ID 7.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F5EntnZ9nIQhGnYmOnDFp%2FScreenshot(27).png?alt=media&#x26;token=2e874b6e-7794-4a0e-bf33-6cb1f3077fe3" alt=""><figcaption></figcaption></figure>

The presence of "Microsoft .NET Runtime...", `clr.dll`, and `clrjit.dll` should attract our attention. These 2 DLLs are used when C# code is ran as part of the runtime to execute the bytecode. If we observe these DLLs loaded in processes that typically do not require them, it suggests a potential execute-assembly or unmanaged PowerShell injection attack.]

Let's solve this question with a single PowerShell command.

```powershell
Get-WinEvent -FilterHashtable @{Path='C:\Logs\PowershellExec\*'; Id=7} | Select-Object TimeCreated, Id, Message | Where-Object {$_.Message -match 'ImageLoaded:\s+C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\clr.dll'} | Format-List
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F6cGW32L7pxMRLYvPpZ0Y%2FScreenshot(28).png?alt=media&#x26;token=66f83eef-be3b-4450-bec8-ddd24264a1e2" alt=""><figcaption></figcaption></figure>

In the third question, we need to review the logs in the "C:\Logs\PowershellExec" directory and determine the process that injected into the process that executed unmanaged PowerShell code.

1\) I opened the PowershellExec log file in Event Viewer and filtered for Event ID 8.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F5rTfCyD6GS44DUF8oG1z%2FScreenshot(30).png?alt=media&#x26;token=b6b6aa16-ec95-42d4-ba76-a8db916c7368" alt=""><figcaption></figcaption></figure>

We used Event ID 8 and will search for CreateRemoteThread because:

* `CreateRemoteThread` is a Windows API function often used by malicious actors to inject code into another process.
* Event ID 8 is related to specific logging or security events that capture details about process injection or similar activities.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F9cfDtiLnj0GA6Z3RODoh%2FScreenshot(32).png?alt=media&#x26;token=ef6bacd1-a59e-4efd-8dff-a43af82e2ad8" alt=""><figcaption></figcaption></figure>

We can also achieve this by searching for Calculator.exe and filtering by Event ID 8, but let's proceed with a PowerShell solution.

```powershell
Get-WinEvent -FilterHashtable @{Path='C:\Logs\PowershellExec\*'; Id=8} | Select-Object TimeCreated, Id, Message | Where-Object {$_.Message -match 'TargetImage:\s+C:\\Program Files\\WindowsApps\\Microsoft.WindowsCalculator_10.1906.55.0_x64__8wekyb3d8bbwe\\Calculator.exe'} | Format-List
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F7jHx8fkG3KD67A1O500l%2FScreenshot(33).png?alt=media&#x26;token=24a53cb5-6789-4b51-bc54-e4b7a3f2ff00" alt=""><figcaption></figcaption></figure>

For the fourth question, we need to examine the logs in the "C:\Logs\Dump" directory to identify the process that performed an LSASS dump.

1\) Let's open the log file at C:\Logs\Dump\LsassDump in Event Viewer and filter by Event ID 10.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FOmvFruh0rnAA6aZYtgjM%2FScreenshot(1).png?alt=media&#x26;token=510449ed-bb4e-41ca-b525-1485f144ec26" alt=""><figcaption></figcaption></figure>

#### Understanding LSASS and Its Importance

* **LSASS**: This process is responsible for enforcing security policies on the system. It verifies users logging on to the computer, handles password changes, and creates access tokens.
* **Dumping LSASS**: Attackers often target LSASS to dump its memory because it contains sensitive information like user credentials (password hashes, Kerberos tickets, etc.).

#### Event ID 10: Process Access

Event ID 10 in Windows Event Logs often corresponds to WMI (Windows Management Instrumentation) activities or process accesses that are unusual. Specifically, this ID can be linked to the following:

1. **WMI Activity**: When a process interacts with WMI to execute commands or gather data.
2. **Process Access**: When a suspicious process attempts to access or interact with another process (like LSASS), especially using tools or methods known for credential dumping.

2\) I searched for the SourceImage responsible for the LSASS dump using the TargetImage: C:\Windows\System32\lsass.exe.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fa4AYHRWVZxr0WKk8fhDK%2FScreenshot(3).png?alt=media&#x26;token=217a6a9e-3d67-4f13-91fa-5a8deb9a89e9" alt=""><figcaption></figcaption></figure>

The access mask `0x1400` indicates specific rights that were granted to the source process over the target process. This value includes permissions like `PROCESS_VM_READ` and `PROCESS_QUERY_INFORMATION`, which are often used to read the memory of another process. This access is typical in the context of process manipulation and dumping.

We can also obtain the solution using PowerShell. First, let's find the path for lsass.exe.

```powershell
(Get-Command lsass.exe).Source
```

```powershell
Get-WinEvent -FilterHashtable @{Path='C:\Logs\Dump\*'; Id=10} | Select-Object TimeCreated, Id, Message | Where-Object {$_.Message -match 'TargetImage:\s+C:\\Windows\\system32\\lsass.exe' -and $_.Message -notmatch 'SourceImage:\s+C:\\Windows\\system32\\svchost.exe'} | Format-List
```

`| Where-Object {$_.Message -match 'TargetImage:\s+C:\\Windows\\system32\\lsass.exe' -and $_.Message -notmatch 'SourceImage:\s+C:\\Windows\\system32\\svchost.exe'}`:

* **`{$_.Message -match 'TargetImage:\s+C:\\Windows\\system32\\lsass.exe'`**: Filters events where the `Message` property matches the regular expression for `TargetImage: C:\Windows\system32\lsass.exe`.
  * **`\s+`**: Matches one or more whitespace characters.
* **`-and`**: Logical AND operator to combine conditions.
* **`$_.Message -notmatch 'SourceImage:\s+C:\\Windows\\system32\\svchost.exe'}`**: Further filters out events where the `Message` property matches the regular expression for `SourceImage: C:\Windows\system32\svchost.exe`.
  * **`-notmatch`**: Operator for checking that a string does not match a regular expression pattern.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FKcisT4HXcxYDzzYszrgg%2FScreenshot(5).png?alt=media&#x26;token=1c0ace61-09d4-4ebe-a965-f97e1977481d" alt=""><figcaption></figcaption></figure>

For the fifth question, we need to examine the logs in the "C:\Logs\Dump" directory to determine if there was a malicious login after the LSASS dump.

After an LSASS dump, various types of logon events can occur, depending on the nature of the attack and subsequent activities by the attacker.

**Interactive (Logon Type 2)**:

* This logon type occurs when a user logs on to the system interactively by entering credentials at the local console (e.g., via physical access or remote desktop).

**RemoteInteractive (Logon Type 10)**:

* Similar to Interactive logon, but performed via Remote Desktop Services (RDP). An attacker might attempt to gain remote access to the system after compromising LSASS.

To determine if an ill-intended login took place after an LSASS dump, you need to correlate the events related to the LSASS dump with subsequent login events.

**Define Logon Types**: `$logonTypes = @(2, 10)` specifies the logon types of interest (`2` for Interactive and `10` for RemoteInteractive):

```powershell
$suspiciousLogonTypes = @(2, 10)
```

**Identify Login Events**: `$loginEvents` retrieves all login events (Event ID 4624) from the Security log:

```powershell
$loginEvents = Get-WinEvent -FilterHashtable @{Path='C:\Logs\Dump\*'; Id=4624}
```

**Identify LSASS Dump Events**: `$lsassDumpEvents` uses your existing command to filter LSASS dump events based on the specified criteria:

```powershell
$lsassDumpEvents = Get-WinEvent -FilterHashtable @{Path='C:\Logs\Dump\*'; Id=10} | Select-Object TimeCreated, Id, Message | Where-Object {$_.Message -match 'TargetImage:\s+C:\\Windows\\system32\\lsass.exe' -and $_.Message -notmatch 'SourceImage:\s+C:\\Windows\\system32\\svchost.exe'} | Format-List
```

```powershell
foreach ($lsassEvent in $lsassDumpEvents) {
    $lsassTime = $lsassEvent.TimeCreated

    $suspiciousLogins = $loginEvents | Where-Object { 
        $logonType = $_.Properties[8].Value  # Assuming logon type property index is 8
        $suspiciousLogonTypes -contains $logonType
    }

    if ($suspiciousLogins) {
        Write-Output "LSASS dump detected at $($lsassTime). Following suspicious logins detected:"
        $suspiciousLogins | Format-List TimeCreated, Id, Message
    }
}
```

This block iterates over each LSASS dump event stored in `$lsassDumpEvents`. For each LSASS dump event:

1. It retrieves the time of the LSASS dump event (`$lsassTime`).
2. It filters the login events (`$loginEvents`) to find those that occurred after the LSASS dump event and match the logon types specified in `$suspiciousLogonTypes`. This is done using the `Where-Object` cmdlet, where the logon type is extracted from the event's properties (assuming it is at index 8).
3. If there are any suspicious logins (`$suspiciousLogins`), it outputs a message indicating that an LSASS dump was detected at the specified time and lists the suspicious logins with their details (time created, event ID, and message).

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FaeHWul46TCQgOeCVw9dY%2FScreenshot(6).png?alt=media&#x26;token=9df64b4b-d947-4dd0-b28a-f93db9cfec7e" alt=""><figcaption></figcaption></figure>

Therefore, no login attempts were made after the LSASS dump occurred.

For the final question, we need to review the logs located in the "C:\Logs\StrangePPID" directory, determine a process that was used to temporarily execute code based on a strange parent-child relationship.

1\) Let's open the **`StrangePPID`** log file located at C:\Logs\StrangePPID in Event Viewer and filter by Event ID 1.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F9yQPk6nU6jrXBjZUdkRj%2FScreenshot(7).png?alt=media&#x26;token=a9c6f3d5-3a8f-44eb-9082-16e0fb6c6622" alt=""><figcaption></figcaption></figure>

**Event ID 1**: This event ID is generated by the Sysmon (System Monitor) utility from Sysinternals, a suite of advanced system utilities provided by Microsoft. Event ID 1 specifically logs process creation events.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FgcbaD4RgEIHWJbij7gPG%2FScreenshot(8).png?alt=media&#x26;token=2655a252-e372-4f3a-950a-0338160482cb" alt=""><figcaption></figcaption></figure>

The WerFault.exe process was used to temporarily execute code due to an unusual parent-child relationship. Let's investigate the reasons behind this.

1. **Unexpected Parent Process**:
   * **WerFault.exe**: This executable is the Windows Error Reporting tool, which handles errors and crashes for Windows applications. It is not common for `werfault.exe` to spawn a command prompt (`cmd.exe`). This unusual behavior can indicate that the error reporting process is being misused to execute commands, possibly as part of an exploitation or persistence mechanism.
2. **Command Execution**:
   * **Command Line**: `cmd.exe /c whoami` is a benign command that simply outputs the current user. However, the fact that it was initiated by `werfault.exe` makes it suspicious. Attackers sometimes run simple commands to test the waters before executing more harmful payloads.
3. **User Context**:
   * **User**: `DESKTOP-R4PEEIF\waldo` is the user under which both processes are running. This information alone isn't suspicious but combined with the unusual parent-child relationship, it adds to the concern.
4. **Current Directory**:
   * **Current Directory**: `C:\ProgramData\` is a common location where malware might operate from, as it often has read/write permissions for all users and is less scrutinized than system directories like `C:\Windows`.

As the module concludes, I hope you found it helpful and enjoyable. Thank you for your time.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://faresbltagy.gitbook.io/footprintinglabs/soc-hackthebox-notes-and-labs/windows-event-logs-and-finding-evil-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
