# Uncover Malicious Activity with Windows Event Log Analysis

## Windows Event Logs Overview

Uncovering malicious activity with **Windows Event Log Analysis** involves examining specific logs to identify abnormal behaviors, trace attackers' activities, and understand the scope of an incident.

**Path:** `C:\Windows\System32\winevt\logs`

The target system logs are located at:\
`C:\Cases\E\Windows\System32\winevt\logs`

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FulYdNUreJMpI8bx0rq5a%2FScreenshot(4).png?alt=media&#x26;token=099aa482-1492-4dcc-b597-c993d8de6f46" alt=""><figcaption></figcaption></figure>

We can see our logs using Event Viewer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F0B7Alp4nZMgtL5rtJPD4%2FScreenshot(5).png?alt=media&#x26;token=d3299382-b4e9-460b-b429-89144bb274de" alt=""><figcaption></figcaption></figure>

## Analyzing Windows Event Logs with EventLogExplorer and EvtxECmd

Let's open the Application.evtx log file in EventLogExplorer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FhAW8emUSKLbb2HkUtPji%2FScreenshot(6).png?alt=media&#x26;token=8937adc6-fdf0-40bf-9302-f57dbfda0b9a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FYPUaDg6q3DkfPQVVWB5J%2FScreenshot(7).png?alt=media&#x26;token=3640f272-3b87-46a4-9fa8-42869559822b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F1kJFPPz5Bb8gRO7DqL5d%2FScreenshot(8).png?alt=media&#x26;token=b2ceab27-9f01-4695-8c99-f3ec317ae8f6" alt=""><figcaption></figcaption></figure>

Let’s explore what can be achieved with this tool.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FLgvTCG1jz71caiywa0ZC%2FScreenshot(9).png?alt=media&#x26;token=10dd527f-ec9e-4568-8c04-9e59da7fd48d" alt=""><figcaption></figcaption></figure>

We can filter logs by Event ID, description text, time frame, and other criteria.

We can also use the EvtxCmd tool to analyze all event logs from the target system.

```bash
EvtxECmd.exe -d C:\Cases\E\Windows\System32\winevt\logs --csv C:\Cases\Analysis\EventLogs
```

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FcdCnxfZ5Ov4eFAaLxhH7%2FScreenshot(10).png?alt=media&#x26;token=fd4969bd-efeb-421e-952d-557a58bbb910" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FtwWS4of840och0NkYQDt%2FScreenshot(11).png?alt=media&#x26;token=385ef583-6bdc-43e8-96bc-155055a69731" alt=""><figcaption></figcaption></figure>

Let's open this file using Timeline Explorer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FpF2ymwoCEWhWLeKRH33g%2FScreenshot(12).png?alt=media&#x26;token=ef668f17-867a-4e2a-b281-8f466417dc36" alt=""><figcaption></figcaption></figure>

We can sort or filter using any of these columns.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FIVolETuyx6PpYk60oWF6%2FScreenshot(14).png?alt=media&#x26;token=38246ac4-08e8-4f64-89fb-812d500e1b43" alt=""><figcaption></figcaption></figure>

## Windows Defender event Log Analysis

Windows Defender, part of the built-in security suite in Windows, generates logs that provide detailed information about security-related activities on the system. These logs can be critical for detecting malicious behavior, monitoring threats, and troubleshooting security issues. Windows Defender logs events related to malware detection, scan results, real-time protection, and updates.

<table><thead><tr><th width="344">Source</th><th width="132">Event ID</th><th>Description</th></tr></thead><tbody><tr><td>Microsoft-Windows-Windows-Defender</td><td>5000</td><td>Defender Enabled</td></tr><tr><td>Microsoft-Windows-Windows-Defender</td><td>5001</td><td>Defender Disabled</td></tr></tbody></table>

## Analyzing Service Installs

When a new service is installed or modified on a Windows system, it generates event logs that can provide valuable information about the service's installation, configuration, and any changes made. By analyzing these event logs, you can detect malicious activities, unauthorized service installations, or changes to legitimate services.

**Event ID:** 7045 (A new service was installed)

Let's open System.evtx log file using Event Log Explorer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FwRFeOTJkCDSAXMt3V6BK%2FScreenshot(15).png?alt=media&#x26;token=21109d11-fd51-434c-94a4-e49fe05ad2c6" alt=""><figcaption></figcaption></figure>

Let's filter by Event Id 7045.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FChketqSHXbAX5qySGhIb%2FScreenshot(16).png?alt=media&#x26;token=a58cbb67-d558-4bde-aceb-a38ed5959f8b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FdAg76ua4DwOZyX2kNAPn%2FScreenshot(17).png?alt=media&#x26;token=6f3f7432-ac5c-4fe2-9d7e-cde18b4dc216" alt=""><figcaption></figcaption></figure>

## Security Event Log and Authentication Events

The **Security Event Log** on Windows systems records significant security-related events, including user logons, logoff activities, authentication attempts, and account management actions. Analyzing these events helps to detect potential security incidents such as unauthorized access, privilege escalation, or lateral movement within a network.

**Event ID:** 4624 (Successful Logon)

Let's open the Security.evtx log file in Event Log Explorer and filter by Event ID 4624.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FECYMXWcYOusZSbt87hDD%2FScreenshot(18).png?alt=media&#x26;token=b4678ca8-0cc1-4155-880b-e2b75152e945" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FTLKnXowvmCgigJiORZZS%2FScreenshot(19).png?alt=media&#x26;token=aa8f7f16-df3f-4c0c-b815-f6f47f76bc97" alt=""><figcaption></figcaption></figure>

The **Security ID (SID)** is a unique identifier assigned to a user, group, or computer account in Windows. It is used internally by the operating system to manage access to resources and track actions performed by specific accounts.

* `S-1-5-18`: Local System account.
* `S-1-5-19`: Local Service account.
* `S-1-5-20`: Network Service account.

**Logon types** describe how a user accessed the system. They are crucial for identifying the nature of an authentication event.

<table data-header-hidden><thead><tr><th width="160">Logon Type</th><th width="205">Description</th><th>Use Case</th></tr></thead><tbody><tr><td>2</td><td>Interactive</td><td>Physical logon at a system (e.g., console).</td></tr><tr><td>3</td><td>Network</td><td>Access via network (e.g., SMB, web access).</td></tr><tr><td>10</td><td>RemoteInteractive</td><td>RDP or Terminal Services logon.</td></tr></tbody></table>

Let's filter by Account Name Sec504.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FPp6TiFStty9sVbvkwB84%2FScreenshot(21).png?alt=media&#x26;token=75dde2ca-ba17-49ea-b359-543d5eaf81a4" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fw5aDMmNlDQJtNrqkKTtG%2FScreenshot(22).png?alt=media&#x26;token=49babf2f-c5c1-4b66-8d86-4824a79828e4" alt=""><figcaption></figcaption></figure>

## Authentication Events and Logon IDs

**Logon ID** is a unique hexadecimal identifier that correlates logon sessions across multiple event logs.

When you log in to a Windows system, it is common to see two logon hexadecimal IDs generated: one for a **low-privilege session** and another for a **higher-privilege session**. This behavior occurs because Windows uses **User Account Control (UAC)** to manage privilege levels for interactive logins.

* **Low-Privilege Logon ID**:
  * When you log in interactively, Windows first creates a standard user session by default, even if you are an administrator.
  * This session operates under a **low-privilege token** to reduce the risk of accidental or malicious changes to the system.
  * It is associated with a **Logon Type 2** (Interactive Logon).
* **High-Privilege Logon ID**:
  * If you perform an action that requires administrative rights (e.g., running a program as an administrator), UAC creates a second session with a **high-privilege token**.
  * This session is linked to your account but is treated as a separate process requiring explicit elevation.
  * This elevated session will have its own **Logon ID**.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FZICJkGFBOxD079E9jur7%2FScreenshot(23).png?alt=media&#x26;token=ace3450e-0d05-4076-9897-3ae1429db092" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FTOU9PfEy3mzv5xuaxzuZ%2FScreenshot(24).png?alt=media&#x26;token=f3d93d0e-355e-46cf-a9bc-abd5fe8a381b" alt=""><figcaption></figcaption></figure>

Logon IDs play a crucial role in forensic investigations by enabling analysts to correlate different activities and actions performed during a specific session.

Let's review the actions associated with Logon ID **0xe64e2**.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FtJK8NawEl0LuQR7SXOHX%2FScreenshot(25).png?alt=media&#x26;token=4d328383-797b-470a-9a63-1a5f6ac75ef1" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FwF4CrrmqFnhHIkFc1IKi%2FScreenshot(26).png?alt=media&#x26;token=2536eb8c-71c5-4729-a99e-e55b55bf6fac" alt=""><figcaption></figcaption></figure>

Let's review the actions associated with Logon ID **0xe64b4**.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2F7v5YeRHdEoB6OZdZWmmd%2FScreenshot(27).png?alt=media&#x26;token=2c186524-c411-47e7-8447-cdacadb91b71" alt=""><figcaption></figcaption></figure>

We can see that a new user has been added to the Administrators group.

## PowerShell Event Logs Overview

PowerShell provides detailed logging of its activities, which can be very useful in forensic investigations, especially when analyzing the execution of malicious scripts or tracking administrative activities. The logs capture events related to PowerShell script executions, command usage, and PowerShell module activities. These logs are particularly valuable for detecting malicious activity, lateral movement, or misuse of PowerShell for post-exploitation activities.

**Event ID:** 400 (Engine state is changed from none to available)

* This event logs the start of a PowerShell script execution. It includes:
  * **CommandLine**: The PowerShell command or script that was run.
  * **User**: The user who initiated the command.
  * **ScriptPath**: The location of the script, if applicable.
* **Use Case**: You can use this event to track the start of potentially malicious PowerShell scripts on the system.

**Event ID:** 403 (PowerShell script ended)

* This event logs the completion of a PowerShell script execution. It records:
  * **Exit Code**: The exit status of the script (successful or error).
  * **Duration**: The time taken for the script to execute.
* **Use Case**: Investigating the completion of PowerShell scripts, especially if the exit code indicates a failure or error during execution.

Two files are available. Let's load them into Event Log Explorer.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FlIosQZ3UHhnIL4mKFK9p%2FScreenshot.png?alt=media&#x26;token=67a0db45-22d3-475e-8667-044eaf77787f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FtPRjhdYJ1R0UXze5zTkY%2FScreenshot(2).png?alt=media&#x26;token=9c0ef502-ec3f-4951-9a9d-750848678c5e" alt=""><figcaption></figcaption></figure>

The **HostApplication** field in PowerShell event logs refers to the application that is running the PowerShell script or command. It helps identify which process is executing the PowerShell command. In the context of your example:

* **HostApplication**: `powershell.exe`
  * This indicates that the PowerShell command is being executed from the **PowerShell** executable, meaning that a standard PowerShell process is running the command.
* **Command**: `{Remove-Item -path $env:TEMP\deleteme_T1551.004}`
  * This is the PowerShell command being executed. In this case, the command is attempting to remove a file named `deleteme_T1551.004` located in the `TEMP` directory.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FaUnGQRIm3LJAfcn1mwRb%2FScreenshot(3).png?alt=media&#x26;token=3909b1bb-e678-4565-baf7-0006400365a2" alt=""><figcaption></figcaption></figure>

Regularly monitor Event ID 4104 to detect potentially malicious commands being executed in your environment, especially from non-administrative users or unexpected processes. If a system is compromised, Event ID 4104 will show what scripts or commands were executed by the attacker, helping you trace their activity.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2Fd49XSj5tiys7Ca1Y92Kn%2FScreenshot(4).png?alt=media&#x26;token=a33da9e1-b8a4-43b9-9128-7ef47bbe6020" alt=""><figcaption></figcaption></figure>

This command runs a PowerShell script that:

1. Sets the variable `$url` to the location of a malicious Excel file (`PhishingAttachment.xlsm`) hosted on GitHub.
2. Configures the PowerShell session to use **TLS 1.2** for secure communication (`[Net.ServicePointManager]::SecurityProtocol`).
3. Uses `Invoke-WebRequest` to download the malicious Excel file from the URL and saves it to the system's **TEMP** directory with the name `PhishingAttachment.xlsm`.

This type of command is typically used in phishing attacks, where a malicious file is downloaded and potentially executed to compromise the system.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FNu5pBQSwwlb2VYtS2iPL%2FScreenshot(6).png?alt=media&#x26;token=20d951ac-599c-49f3-a54f-56f1c32249ef" alt=""><figcaption></figcaption></figure>

Here's a brief explanation of what it does:

1. **Copying the Batch File**:
   * It copies the file `batstartup.bat` from the source directory (`C:\AtomicRedTeam\atomics\T1547.001\src\batstartup.bat`) to two startup locations:
     * `$env:APPDATA\Microsoft\Windows\Start Menu\Programs\Startup\batstartup.bat` (for the current user).
     * `C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp\batstartup.bat` (for all users).
2. **Executing the Batch File**:
   * It uses `Start-Process` to run the batch file from both startup locations. This ensures that the batch file is executed every time the system starts, maintaining persistence.

## Detecting Malicious Events in Sysmon Event Logs

Detecting malicious activity in Sysmon logs involves analyzing specific event IDs and correlating patterns of suspicious behavior. Sysmon, or **System Monitor**, provides detailed information about system activity that can be used to detect anomalies and threats.

* **Event ID 1: Process Creation**
  * Logs every process start, including command-line arguments.
* **Event ID 3: Network Connection**
  * Logs TCP/UDP connections made by processes.
* **Event ID 7: Image Load**
  * Detects DLL injection or unusual libraries loaded into processes.
* **Event ID 8: CreateRemoteThread**
  * Tracks threads created in the address space of another process.
* **Event ID 11: File Creation**
  * Monitors file creation activities.
* **Event ID 12 & 13: Registry Key and Value Changes**
  * Tracks changes to the registry.
* **Event ID 22: DNS Query**
  * Logs DNS requests made by processes.

Let's open the "Microsoft-Windows-Sysmon" file and filter by Event ID 1 and the keyword "mavinject."

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FJjqhYMZ5tnBfLF2HNpcT%2FScreenshot.png?alt=media&#x26;token=5e9e7ade-b9c2-4a9c-b5c5-27dff6cc0126" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FsHmnXV2SPjODpnEywCXQ%2FScreenshot(2).png?alt=media&#x26;token=a0ff6d67-3e60-43be-ab39-4fc669c2f947" alt=""><figcaption></figcaption></figure>

Let's filter for Event ID 3 to analyze network connections.

<figure><img src="https://2537271824-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FIswWWP3l0rGuQmG2WUcr%2Fuploads%2FHsY83hNpJi2AJ2xvy27n%2FScreenshot(3).png?alt=media&#x26;token=db0aa6f1-dabd-4acd-934a-20b73e77f8f1" alt=""><figcaption></figcaption></figure>
