Windows records a lot by default, but not the things you need to catch an attacker. This lesson turns on the high-value telemetry and sends it where an intruder cannot erase it.
Advanced Audit Policy
Use the Advanced Audit Policy subcategories (they are precise) rather than the old broad categories. Apply them with Group Policy in a domain; auditpol works on a single host.
auditpol /backup /file:C:\audit-before.csv # keep what you had
auditpol /set /subcategory:"Logon" /success:enable /failure:enable
auditpol /set /subcategory:"Special Logon" /success:enable
auditpol /set /subcategory:"Account Lockout" /failure:enable
auditpol /set /subcategory:"Credential Validation" /success:enable /failure:enable
auditpol /set /subcategory:"User Account Management" /success:enable /failure:enable
auditpol /set /subcategory:"Security Group Management" /success:enable /failure:enable
auditpol /set /subcategory:"Process Creation" /success:enable
auditpol /set /subcategory:"Audit Policy Change" /success:enable /failure:enable
auditpol /set /subcategory:"Sensitive Privilege Use" /success:enable /failure:enable
auditpol /set /subcategory:"Security State Change" /success:enable
auditpol /get /category:* # review the resultMake process-creation events include the full command line, which turns event 4688 from "something ran" into "this exact command ran":
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit" /v ProcessCreationIncludeCmdLine_Enabled /t REG_DWORD /d 1 /fGive the Security log room so events are not overwritten before you can read them (1 GB here):
wevtutil sl Security /ms:1073741824
wevtutil gl SecurityPowerShell logging
Attackers use PowerShell constantly. Script block logging records the code that actually runs, even if it was obfuscated.
$p = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging'
New-Item -Path $p -Force | Out-Null
Set-ItemProperty -Path $p -Name EnableScriptBlockLogging -Value 1 -Type DWordScript blocks appear as event 4104 in Microsoft-Windows-PowerShell/Operational. Consider module logging and transcription too (both under the same policy path in Group Policy), writing transcripts to a protected network share. Remember to remove PowerShell v2 (lesson 7), or attackers can run it to avoid these logs.
Sysmon: the missing telemetry
Sysmon (Microsoft Sysinternals) adds rich, tamper-resistant events that the built-in log lacks. Use a reviewed community configuration rather than the empty default, for example the widely used SwiftOnSecurity config or Olaf Hartong's sysmon-modular, and read it before deploying.
.\Sysmon64.exe -accepteula -i .\sysmonconfig.xml # install with a config
.\Sysmon64.exe -c .\sysmonconfig.xml # update the config later
Get-WinEvent -LogName 'Microsoft-Windows-Sysmon/Operational' -MaxEvents 5| Sysmon event | What it records |
|---|---|
| 1 | Process created (with command line and parent) |
| 3 | Network connection by a process |
| 7 | Image (DLL) loaded |
| 11 | File created |
| 13 | Registry value set |
| 22 | DNS query by a process |
Start with a tuned config to keep volume and performance reasonable, and test on a representative server first.
Send it off the box
Local logs can be cleared by an attacker (that action itself is event 1102). Forward them:
- Windows Event Forwarding (WEF): a collector server pulls events from sources using WinRM. Good for domains with no agent budget.
# On the collector
wecutil qc /q
# On each source
winrm quickconfig -qAdd the collector's computer account or Network Service to Event Log Readers on sources, then create a subscription on the collector.
- An agent (Azure Monitor Agent, Wazuh, Elastic Agent, Splunk forwarder) sending to your SIEM. Often simpler and gives you filtering at the source.
The events worth alerting on
| Event ID | Log | Alert when |
|---|---|---|
| 4624 / 4625 | Security | Logon success from an odd source, or a burst of failures |
| 4672 | Security | Special privileges on an unexpected account |
| 4688 / Sysmon 1 | Security / Sysmon | Suspicious command lines (encoded PowerShell, vssadmin delete shadows) |
| 4720, 4732 | Security | New user; user added to a local admin group |
| 4697 / 7045 | Security / System | New service installed (common persistence) |
| 4719 | Security | Audit policy changed |
| 1102 | Security | The audit log was cleared |
| 4104 | PowerShell Operational | Script-block content with known attack patterns |
Ransomware tell. Attackers delete shadow copies before encrypting. An alert on
vssadmin delete shadowsorwmic shadowcopy deletein process-creation events is one of the highest-value, lowest-noise detections you can add.
🧪 Lab
- Back up and apply the audit policy, enable command-line logging, and enlarge the Security log.
- Enable script-block logging, run a harmless PowerShell command, and find event 4104.
- Install Sysmon with a reviewed config and find a process-creation (event 1) record for something you ran.
- Clear a test log (lab only) and find event 1102.
Checkpoint
- Why enable command-line logging on process creation?
- What does PowerShell script-block logging capture, and which event ID?
- Name two Sysmon event types and what each records.
- Why forward logs off the server?
- What does event 1102 mean?