Lesson 10 of 12 · 15 min · Intermediate

Windows Server: audit policy, PowerShell logging, Sysmon and forwarding

Turn on the Advanced Audit Policy subcategories that matter, capture command lines, enable PowerShell script-block logging, add Sysmon for process, network and registry telemetry, size the logs, and forward them off the server.

In this lesson you will

  • Enable the audit subcategories that expose real attacks
  • Capture process command lines and PowerShell script blocks
  • Install Sysmon with a reviewed configuration
  • Forward logs off the host and know the key event IDs

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.

From event to alert: a logging pipeline

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.

powershell
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 result

Make process-creation events include the full command line, which turns event 4688 from "something ran" into "this exact command ran":

powershell
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit" /v ProcessCreationIncludeCmdLine_Enabled /t REG_DWORD /d 1 /f

Give the Security log room so events are not overwritten before you can read them (1 GB here):

powershell
wevtutil sl Security /ms:1073741824
wevtutil gl Security

PowerShell logging

Attackers use PowerShell constantly. Script block logging records the code that actually runs, even if it was obfuscated.

powershell
$p = 'HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging'
New-Item -Path $p -Force | Out-Null
Set-ItemProperty -Path $p -Name EnableScriptBlockLogging -Value 1 -Type DWord

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

powershell
.\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.
powershell
# On the collector
wecutil qc /q
# On each source
winrm quickconfig -q

Add 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 shadows or wmic shadowcopy delete in process-creation events is one of the highest-value, lowest-noise detections you can add.

🧪 Lab

  1. Back up and apply the audit policy, enable command-line logging, and enlarge the Security log.
  2. Enable script-block logging, run a harmless PowerShell command, and find event 4104.
  3. Install Sysmon with a reviewed config and find a process-creation (event 1) record for something you ran.
  4. Clear a test log (lab only) and find event 1102.

Checkpoint

  1. Why enable command-line logging on process creation?
  2. What does PowerShell script-block logging capture, and which event ID?
  3. Name two Sysmon event types and what each records.
  4. Why forward logs off the server?
  5. What does event 1102 mean?