Practice library / Security operations basics
Lab · Medium · 1.5 hoursFree account
Windows Event Log Analysis
Find failed logons, new accounts, encoded commands, new services and cleared logs.
On this page 15 sections
- ·What you need first
- ·Lab setup
- 1Open the logs and read one event
- 2Turn on the audit settings
- Locked: Make failed and successful logons
- Locked: Find the failed logons
- Locked: Find the logon that followed
- Locked: Find a new account and a group change
- Locked: Find commands that run on the host
- Locked: Find a new service
- Locked: Clear the log and detect it
- Locked: Check
- Locked: Technique and event map
- Locked: Clean up
- Locked: Next lab
Before you start
Windows writes a dense audit trail of logon, process, account and service activity, but only when the right audit policies are on. SOC analysts live in these logs because every post-breach report leans on event IDs like 4625, 4688 and 1102. The work here is to generate attacker-like noise on a lab host, then recover the evidence with Get-WinEvent, map each event ID to its technique and spot a cleared log before an attacker walks away quietly.
Lab Objectives
- Turn on the audit settings that make logon, account and process evidence appear in the Security log
- Query Windows event logs with
Get-WinEventand read event fields by name - Find a password-guessing attack and the logon that follows it
- Find a new account, a group change, an encoded PowerShell command and a new service
- Detect a cleared log, and export logs for offline analysis
- Map each event ID to the attacker technique it reveals
What you need first
Complete these items before you start:
- Windows Fundamentals. You must know users, groups, services and PowerShell basics.
- SOC Operations & SIEM, chapter 1. You must know what a log source is and why the Security log matters.
SOC Alert Triage with a SIEM is a good lab to do before this one. It is not a prerequisite, but it shows how an analyst uses the events you find here.
Lab setup
You attack nothing in this lab. You run small, harmless actions on your own Windows machine. You then find the evidence they leave behind. Defenders do the second part every day.
In this lab, the lab host is the Windows machine. The Kali machine is the optional second machine. An event ID is the number that tells you what happened. A logon type is the number inside a logon event that tells you how the user signed in.
| Item | Requirement |
|---|---|
| Lab host | A Windows 10, Windows 11, Windows Server 2019 or Windows Server 2022 virtual machine that you own. Use a standalone machine, not a domain member. |
| Account | A local administrator account. Open Windows PowerShell with Run as administrator. |
| Shell | Windows PowerShell 5.1. It is built in. |
| Snapshot | Take a snapshot of the lab host before Step 1. You can then undo every change. |
| Optional | A Kali Linux machine on the same lab network. It makes failed logons from a second machine. |
Authorized use only. Run every command in this lab on the lab host that you own. Do not run it on a work computer, a shared server or any system that you do not own. Step 9 clears the Security log. Clearing a log on a real system destroys evidence.
Step 1: Open the logs and read one event
Read the logs
List the main logs. Read one event as XML. Then define a helper function that reads the named fields. Every later step uses it.
Windows stores logs as .evtx files in C:\Windows\System32\winevt\Logs\. Event Viewer (eventvwr.msc) shows them in a window. PowerShell reads them as objects, and objects are easier to filter.
| Log | What it records |
|---|---|
Security | Logons, account changes, process creation. This is the main log for this lab. |
System | Services, drivers, startup and shutdown. |
Application | Messages from installed programs. |
Microsoft-Windows-PowerShell/Operational | PowerShell activity. Script block logging (event 4104) needs a policy. This lab does not use it. |
Microsoft-Windows-Sysmon/Operational | Sysmon events. This log exists only if you install Sysmon. |
# Size and mode of the three main logs
Get-WinEvent -ListLog Security,System,Application |
Select-Object LogName, RecordCount, MaximumSizeInBytes, LogMode |
Format-Table -AutoSize
# Retention settings of the Security log
wevtutil gl Security | Select-String 'retention|maxSize'
# Read the newest logon event
Get-WinEvent -FilterHashtable @{ LogName='Security'; Id=4624 } -MaxEvents 1 |
Format-List Id, ProviderName, TimeCreated, LogName, MachineName
# Show the same event as XML
(Get-WinEvent -FilterHashtable @{ LogName='Security'; Id=4624 } -MaxEvents 1).ToXml()LogName RecordCount MaximumSizeInBytes LogMode
------- ----------- ------------------ -------
Security 2316 20971520 Circular
System 1874 20971520 Circular
Application 1102 20971520 Circular
retention: false
maxSize: 20971520The Circular mode is the line to read. A circular log overwrites its oldest events when it is full. On a busy server, a small Security log holds only a few hours of evidence. Your values will differ.
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="Microsoft-Windows-Security-Auditing" />
<EventID>4624</EventID>
<TimeCreated SystemTime="2026-11-18T09:02:41.512Z" />
<Channel>Security</Channel>
<Computer>WIN-LAB01</Computer>
</System>
<EventData>
<Data Name="TargetUserName">SYSTEM</Data>
<Data Name="LogonType">5</Data>
...
</EventData>
</Event>LogonType 5 means a service logon. Step 5 explains all logon types.
Why this matters. The Message text of an event is only a readable summary. The evidence is in the <EventData> fields. In the next steps you read those fields by name.
Now define the helper function. It turns the <EventData> fields of any event into an object. Steps 4 to 9 and the Check use it.
# Helper: read EventData fields by name
function Get-EventData($e) {
$x = [xml]$e.ToXml()
$h = @{}
foreach ($d in $x.Event.EventData.Data) { if ($d.Name) { $h[$d.Name] = $d.'#text' } }
[pscustomobject]$h
}Keep this window open. If you close it, define the function again.
Step 2: Turn on the audit settings
Enable process auditing
Check the audit policy. Then turn on process creation events and command-line capture. Without them, Step 7 finds nothing.
Windows writes an event only if its audit policy is on. Logon and account events are usually on by default. Process creation events (4688) are usually off, and 4688 does not include the command line unless you also set a registry value.
# Show the current setting of four subcategories
auditpol /get /subcategory:"Logon"
auditpol /get /subcategory:"User Account Management"
auditpol /get /subcategory:"Security Group Management"
auditpol /get /subcategory:"Process Creation"
# Turn on the settings this lab needs
auditpol /set /subcategory:"Logon" /success:enable /failure:enable
auditpol /set /subcategory:"User Account Management" /success:enable
auditpol /set /subcategory:"Security Group Management" /success:enable
auditpol /set /subcategory:"Process Creation" /success:enable
# Put the command line inside event 4688
reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System\Audit" /v ProcessCreationIncludeCmdLine_Enabled /t REG_DWORD /d 1 /f
# Confirm
auditpol /get /subcategory:"Process Creation"System audit policy
Category/Subcategory Setting
Detailed Tracking
Process Creation SuccessThe auditpol /set and reg add commands print a success message. A domain group policy can override these settings. On a standalone lab host, no override exists.
Why this matters. A missing setting looks the same as a quiet system. Before you hunt, you must know which events the lab host writes at all. This is the first question to ask on a real investigation.
Sign in to continue
11 more sections are for signed-in members. It is free: sign in with Google.
Related
This lab is extra practice for the course Security operations basics. Do the lessons first.Open the course