Courses3 levels
Level 1 · Foundations11 courses
Level 2 · Core5 courses
Level 3 · Advanced5 courses
Labs8 topics
Library Practice exams AI Range Pricing Start free

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.

  • windows-event-logs
  • event-ids
  • powershell
  • detection
  • dfir
On this page 15 sections
  1. ·What you need first
  2. ·Lab setup
  3. 1Open the logs and read one event
  4. 2Turn on the audit settings
  5. Locked: Make failed and successful logons
  6. Locked: Find the failed logons
  7. Locked: Find the logon that followed
  8. Locked: Find a new account and a group change
  9. Locked: Find commands that run on the host
  10. Locked: Find a new service
  11. Locked: Clear the log and detect it
  12. Locked: Check
  13. Locked: Technique and event map
  14. Locked: Clean up
  15. 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-WinEvent and 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:

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.

ItemRequirement
Lab hostA Windows 10, Windows 11, Windows Server 2019 or Windows Server 2022 virtual machine that you own. Use a standalone machine, not a domain member.
AccountA local administrator account. Open Windows PowerShell with Run as administrator.
ShellWindows PowerShell 5.1. It is built in.
SnapshotTake a snapshot of the lab host before Step 1. You can then undo every change.
OptionalA 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

1

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.

LogWhat it records
SecurityLogons, account changes, process creation. This is the main log for this lab.
SystemServices, drivers, startup and shutdown.
ApplicationMessages from installed programs.
Microsoft-Windows-PowerShell/OperationalPowerShell activity. Script block logging (event 4104) needs a policy. This lab does not use it.
Microsoft-Windows-Sysmon/OperationalSysmon events. This log exists only if you install Sysmon.
powershelllist the logs and read one event
# 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()
textExample output: log sizes
LogName     RecordCount MaximumSizeInBytes LogMode
-------     ----------- ------------------ -------
Security           2316           20971520 Circular
System             1874           20971520 Circular
Application        1102           20971520 Circular

  retention: false
  maxSize: 20971520

The 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.

xmlExample output: event XML (shortened)
<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.

powershelldefine the helper function
# 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

2

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.

powershellcheck and set the audit policy
# 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"
textExample output: after the change
System audit policy
Category/Subcategory                      Setting
Detailed Tracking
  Process Creation                        Success

The 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