TExcelTAD
Home › Security Foundations: Concepts, Law, Ethics & Your Lab › The Windows Registry and Event Log

The Windows Registry and Event Log

When a Windows machine is suspected of compromise, the first two places an investigator opens are the Registry and the Event Log. The Registry is where Windows and its programs keep their configuration: which services start at boot, which programs start at sign-in, whether UAC is on, where the password hashes live. An attacker who wants to stay on a machine has to change some of it. The Event Log is where Windows writes down what happened: logons, failed logons, new accounts, new services, a cleared log. An attacker who wants to stay hidden has to fight it.

The structure of the Registry (keys, values, hives, reg and the PowerShell HKLM: drive) is taught in The Windows Registry, services in Windows Services, and day-to-day PowerShell administration in Windows administration. This lesson picks out the parts that matter for security.

Security-relevant hives and keys

Location What it holds Why it matters
HKLM\SAM (file C:\Windows\System32\config\SAM) local accounts and their password hashes readable only by SYSTEM; a copy of it (with SYSTEM) is a credential-theft target
HKLM\SECURITY LSA secrets, cached domain logons, policy the same
HKLM\SYSTEM\CurrentControlSet\Services\<name> every service and driver: ImagePath, Start, ObjectName (the account) a new or changed service is a classic way to run code as SYSTEM at boot
HKLM\...\Microsoft\Windows\CurrentVersion\Run and RunOnce (also under HKCU) programs started at sign-in the best-known autostart location defenders check
HKLM\...\Windows\CurrentVersion\Policies\System UAC: EnableLUA, ConsentPromptBehaviorAdmin, PromptOnSecureDesktop, FilterAdministratorToken UAC turned off here is a red flag
HKLM\SYSTEM\CurrentControlSet\Control\Lsa LSA settings, e.g. RunAsPPL (LSA protection) protects LSASS memory from credential dumping
HKCU (file NTUSER.DAT in the profile) one user's settings per-user autostarts, recently used files (forensics)

Defenders call the set of places that make code run automatically autostart extensibility points. There are dozens (scheduled tasks, services, Run keys, WMI subscriptions, Winlogon values…); Sysinternals Autoruns lists them all on one screen and is the standard tool for comparing a machine against a known-good baseline.

A lab session on the test workstation WS01.lab.test (10.10.0.21), elevated PowerShell, sample output:

console
PS C:\> reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v EnableLUA

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
    EnableLUA    REG_DWORD    0x1

PS C:\> Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Run' |
>>   Select-Object * -ExcludeProperty PS*

SecurityHealth : C:\Windows\system32\SecurityHealthSystray.exe
LabUpdater     : C:\Users\Public\updater.exe

SecurityHealth is Windows' own. LabUpdater, running a program from C:\Users\Public (writable by every user), is the kind of entry that gets investigated: who added it, when (the key's last-write time), and what the file is. In this lab it was planted for the exercise.

The Event Log

Windows keeps several logs ("channels"). The three classic ones plus the most useful extras:

Channel Examples
Security logons, privilege use, account and group changes, process creation (when audited)
System services installed or failing, driver loads, the System log being cleared
Application programs' own events
Microsoft-Windows-PowerShell/Operational script-block logging (4104)
Microsoft-Windows-Sysmon/Operational Sysmon, if installed: detailed process, network and file events

The Security event IDs every analyst knows by heart:

ID Channel Meaning
4624 / 4625 Security an account logged on / failed to log on (with a logon type: 2 interactive, 3 network, 5 service, 10 remote interactive / RDP)
4634 Security an account logged off
4672 Security special privileges assigned to a new logon (admin-equivalent)
4688 Security a new process was created (needs "Audit Process Creation"; command lines need one more policy)
4720 Security a user account was created
4732 Security a member was added to a security-enabled local group
4740 Security a user account was locked out
1102 Security the audit log was cleared
7045 System a new service was installed (Service Control Manager)

Hunting through an exported log

On a real machine you would read events with Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4625} or collect them centrally. To keep the example runnable, the events of a short, made-up incident on WS01.lab.test are embedded as CSV, the shape you get from Get-WinEvent … | Export-Csv after picking a few fields. The script answers four questions in order: what happened how often, who failed to log on from where, was an account created and made an admin, and did anyone cover their tracks.

powershell · try it yourself
$events = @'
Time,Id,Account,Source,Detail
2026-01-15T10:00:05,4624,helpdesk,10.10.0.5,LogonType=2
2026-01-15T10:01:10,4625,administrator,10.10.0.66,LogonType=3
2026-01-15T10:01:11,4625,administrator,10.10.0.66,LogonType=3
2026-01-15T10:01:12,4625,admin,10.10.0.66,LogonType=3
2026-01-15T10:01:14,4625,helpdesk,10.10.0.66,LogonType=3
2026-01-15T10:01:20,4624,helpdesk,10.10.0.66,LogonType=3
2026-01-15T10:01:20,4672,helpdesk,10.10.0.66,SeDebugPrivilege
2026-01-15T10:02:30,4720,helpdesk,,NewAccount=support$
2026-01-15T10:02:41,4732,helpdesk,,Group=Administrators Member=support$
2026-01-15T10:03:05,7045,helpdesk,,Service=LabSync ImagePath=C:\Users\Public\sync.exe
2026-01-15T10:04:00,1102,helpdesk,,AuditLogCleared
'@ | ConvertFrom-Csv

"== events by ID"
$events | Group-Object Id | Sort-Object Name | ForEach-Object { "{0} x{1}" -f $_.Name, $_.Count }

"== failed logons by source"
$events | Where-Object Id -eq '4625' | Group-Object Source | ForEach-Object {
  "{0}: {1} failures, accounts: {2}" -f $_.Name, $_.Count, (($_.Group.Account | Sort-Object -Unique) -join ', ')
}

"== new account added to Administrators within 5 minutes"
foreach ($new in $events | Where-Object Id -eq '4720') {
  $name = $new.Detail -replace '^NewAccount=', ''
  $add = $events | Where-Object { $_.Id -eq '4732' -and $_.Detail -match "Group=Administrators Member=$([regex]::Escape($name))
quot; } foreach ($a in $add) { $gap = ([datetime]$a.Time - [datetime]$new.Time).TotalSeconds if ($gap -le 300) { "ALERT $name created by $($new.Account), admin after $gap s" } } } "== high-value single events" $events | Where-Object { $_.Id -in '7045', '1102' } | ForEach-Object { "{0} {1} {2}" -f $_.Time.Substring(11), $_.Id, $_.Detail }
== events by ID
1102 x1
4624 x2
4625 x4
4672 x1
4720 x1
4732 x1
7045 x1
== failed logons by source
10.10.0.66: 4 failures, accounts: admin, administrator, helpdesk
== new account added to Administrators within 5 minutes
ALERT support$ created by helpdesk, admin after 11 s
== high-value single events
10:03:05 7045 Service=LabSync ImagePath=C:\Users\Public\sync.exe
10:04:00 1102 AuditLogCleared

Read top to bottom it is a short story: a source in the lab network guessed at three account names over the network (logon type 3), got in as helpdesk, which holds admin-equivalent privileges (4672), created support$ (a trailing $ imitates a computer account name), made it an administrator, installed a service that runs a program from a world-writable folder, and cleared the Security log. Each step on its own may be harmless; the sequence is not. That's why detection rules (Defensive Security) correlate events instead of alerting on single lines, and why 1102 is an alert by itself: legitimate log clearing is rare and planned.

How it is detected

  • Forward the logs (Windows Event Forwarding, or a SIEM agent) so that clearing the local log (1102, or 104 in the System log) doesn't erase the evidence: the forwarded copy already holds the events before the clear.
  • Turn on the audit policy you need: process creation (4688) with command lines, logon events, account management, security group management. Many of the events above are off by default or too sparse.
  • Baseline autostarts and services (Autoruns, or Get-CimInstance Win32_Service exported and compared) and alert on 7045 and new Run-key values.
  • Sysmon adds process, network, registry and file events with hashes, which make the story much easier to follow.

How it is fixed or prevented

  • Standard users can't write to HKLM or install services: least privilege (see Windows Accounts, Tokens and UAC) prevents most of the incident above.
  • Keep UAC on and protect LSASS (RunAsPPL, Credential Guard); restrict who may clear logs (by default Administrators).
  • Make the Security log large enough to hold days, not hours, and forward it.
  • Application allow-listing (App Control for Business / AppLocker) stops programs running from C:\Users\Public and other user-writable folders.

Pitfalls

  • Searching one event ID at a time. 4625 alone is noise; 4625 → 4624 → 4672 → 4720 → 4732 is an incident.
  • Trusting event times across machines without synchronised clocks.
  • Editing the Registry of a suspect machine before taking evidence: last-write times are evidence too.
  • Assuming the audit policy is on. Check auditpol /get /category:* on your lab machines before relying on an event.

Practice

  1. In the exported log, how many seconds passed between the creation of support$ and its addition to Administrators?
  2. Which event IDs would you expect if someone adds a program to HKCU\...\Run, and which tool would show it even without them?
  3. Write the Get-WinEvent -FilterHashtable call that returns only failed logons from the Security log.
Answers
  1. 11 seconds (10:02:30 to 10:02:41), the number the script prints.
  2. No Security event by default: Run-key writes are recorded only with registry auditing (SACLs, event 4657) or Sysmon (event 13, registry value set). Autoruns shows the new entry directly, which is why autostart baselines matter.
  3. Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4625 }.

Test yourself

Which event ID means that the Security audit log was cleared?

  1. 4624
  2. 4688
  3. 1102
  4. 7045

Which Registry location lists Windows services and the account each one runs as?

  1. HKCU\Software\Microsoft\Windows\CurrentVersion\Run
  2. HKLM\SYSTEM\CurrentControlSet\Services
  3. HKLM\SAM
  4. HKCR

Why is a 4720 followed seconds later by a 4732 for the same account worth an alert?

  1. Accounts are never created
  2. A new account immediately added to a local group such as Administrators is a common persistence step
  3. 4732 means the account was deleted
  4. Because both are failures

What does logon type 3 in a 4624 or 4625 event mean?

  1. Interactive at the keyboard
  2. Network logon, such as a file share or remote management
  3. A service starting
  4. Unlocking the screen