Guide

Set the audit policy on domain controllers

A new domain controller records very little: no detail on failed sign-ins and nothing about changes to the directory. This guide switches on 24 audit settings on every domain controller, so the Security log shows who signed in, what changed and what ran.

20 minutesRun as a domain admin on CON-DC-01
What improves

The Security log shows who signed in, what changed in the directory and what ran.

Why it matters

A new domain controller records too little to spot an attack or work out what happened afterwards.

How you do it

Create a policy for the Domain Controllers OU, switch on 24 audit settings and raise the log to 1 GB.

Keep one window open

Run every step in the same PowerShell window. Later steps reuse values from earlier ones.

Create the policy

The settings live in a Group Policy object linked to the Domain Controllers OU. This step also raises the Security log to 1 GB, because more auditing fills it faster.

CON-DC-01
$dom = Get-ADDomain

New-GPO -Name 'CON-DC-Audit' -Comment 'Audit policy and Security log size for domain controllers' |
    New-GPLink -Target "OU=Domain Controllers,$($dom.DistinguishedName)" | Out-Null

Set-GPRegistryValue -Name 'CON-DC-Audit' -Key 'HKLM\SYSTEM\CurrentControlSet\Control\Lsa' -ValueName 'SCENoApplyLegacyAuditPolicy' -Type DWord -Value 1 | Out-Null
Set-GPRegistryValue -Name 'CON-DC-Audit' -Key 'HKLM\SOFTWARE\Policies\Microsoft\Windows\EventLog\Security' -ValueName 'MaxSize' -Type DWord -Value 1048576 | Out-Null

List the settings

These are the 24 settings. The list is Microsoft's baseline for domain controllers, plus two that help you spot an attack: Kerberos ticket requests and process creation.

AreaSettingRecords
Sign-in checksCredential ValidationSuccess and failure
Sign-in checksKerberos Authentication ServiceSuccess and failure
Sign-in checksKerberos Service Ticket OperationsSuccess and failure
AccountsUser Account ManagementSuccess and failure
AccountsComputer Account ManagementSuccess
AccountsSecurity Group ManagementSuccess
AccountsOther Account Management EventsSuccess
DirectoryDirectory Service ChangesSuccess
DirectoryDirectory Service AccessFailure
LogonLogonSuccess and failure
LogonLogoffSuccess
LogonAccount LockoutFailure
LogonSpecial LogonSuccess
LogonGroup MembershipSuccess
LogonOther Logon/Logoff EventsSuccess and failure
ProgramsProcess CreationSuccess
PolicyAudit Policy ChangeSuccess
PolicyAuthentication Policy ChangeSuccess
PolicyMPSSVC Rule-Level Policy ChangeSuccess and failure
PrivilegesSensitive Privilege UseSuccess and failure
SystemSecurity State ChangeSuccess
SystemSecurity System ExtensionSuccess
SystemSystem IntegritySuccess and failure
SystemOther System EventsSuccess and failure

Paste the same list into PowerShell. Each line is a setting name, then success, then failure.

CON-DC-01
$settings = @(
    @('Credential Validation','enable','enable'), @('Kerberos Authentication Service','enable','enable'),
    @('Kerberos Service Ticket Operations','enable','enable'), @('Computer Account Management','enable','disable'),
    @('Other Account Management Events','enable','disable'), @('Security Group Management','enable','disable'),
    @('User Account Management','enable','enable'), @('Process Creation','enable','disable'),
    @('Directory Service Access','disable','enable'), @('Directory Service Changes','enable','disable'),
    @('Account Lockout','disable','enable'), @('Group Membership','enable','disable'),
    @('Logoff','enable','disable'), @('Logon','enable','enable'),
    @('Other Logon/Logoff Events','enable','enable'), @('Special Logon','enable','disable'),
    @('Audit Policy Change','enable','disable'), @('Authentication Policy Change','enable','disable'),
    @('MPSSVC Rule-Level Policy Change','enable','enable'), @('Sensitive Privilege Use','enable','enable'),
    @('Other System Events','enable','enable'), @('Security State Change','enable','disable'),
    @('Security System Extension','enable','disable'), @('System Integrity','enable','enable')
)

Set them on this domain controller

This clears the current audit settings on CON-DC-01, switches on the 24, and saves them to a file.

CON-DC-01
auditpol /clear /y | Out-Null
foreach ($s in $settings) { auditpol /set /subcategory:"$($s[0])" /success:$($s[1]) /failure:$($s[2]) | Out-Null }

$tmp = "$env:TEMP\audit-export.csv"
auditpol /backup /file:$tmp | Out-Null
$rows = Import-Csv $tmp | Where-Object { $_.'Subcategory GUID' -like '{*' -and [int]$_.'Setting Value' -gt 0 }
"Settings exported: $($rows.Count)"

It should say Settings exported: 24. If the number is lower, a setting name in step 2 was mistyped.

Put them in the policy

This copies the saved settings into the policy, so every domain controller gets them and keeps them.

CON-DC-01
$gpo = Get-GPO -Name 'CON-DC-Audit'
$id  = $gpo.Id.ToString('B').ToUpper()
$gpoPath = "\\$env:COMPUTERNAME\SYSVOL\$($dom.DNSRoot)\Policies\$id"

# write the settings file
$dir = "$gpoPath\Machine\Microsoft\Windows NT\Audit"
New-Item -ItemType Directory -Path $dir -Force | Out-Null
$lines = @('Machine Name,Policy Target,Subcategory,Subcategory GUID,Inclusion Setting,Exclusion Setting,Setting Value')
$lines += $rows | ForEach-Object { ",System,$($_.Subcategory),$($_.'Subcategory GUID'),$($_.'Inclusion Setting'),,$($_.'Setting Value')" }
Set-Content -Path "$dir\audit.csv" -Value $lines -Encoding ASCII

# tell the policy it holds audit settings, and raise its version
$dn  = "CN=$id,CN=Policies,CN=System,$($dom.DistinguishedName)"
$obj = Get-ADObject $dn -Properties gPCMachineExtensionNames, versionNumber -Server $env:COMPUTERNAME
$ext = $obj.gPCMachineExtensionNames
if ($ext -notlike '*F3CCC681*') { $ext += '[{F3CCC681-B74C-4060-9F26-CD84525DCA2A}{0F3F3735-573D-9804-99E4-AB2A69BA5FD4}]' }
$ver = $obj.versionNumber + 1
Set-ADObject $dn -Replace @{ gPCMachineExtensionNames = $ext; versionNumber = $ver } -Server $env:COMPUTERNAME
(Get-Content "$gpoPath\GPT.INI") -replace '^Version=\d+', "Version=$ver" | Set-Content "$gpoPath\GPT.INI" -Encoding ASCII

Apply it to every domain controller

The pause gives the policy time to copy to the other domain controllers.

CON-DC-01
$dcs = (Get-ADDomainController -Filter *).HostName
repadmin /syncall /AdeP | Select-String 'error|terminated'
Start-Sleep -Seconds 90
Invoke-Command -ComputerName $dcs -ScriptBlock {
    gpupdate /force | Out-Null
    wevtutil sl Security /ms:1073741824
}

The wevtutil line sets the log size straight away. Without it, the log stays at its old size until the Event Log service next restarts.

Check every domain controller

CON-DC-01
Invoke-Command -ComputerName $dcs -ScriptBlock {
    $on = auditpol /get /category:* | Select-String 'Success|Failure'
    [pscustomobject]@{
        SettingsOn  = @($on).Count
        LogMaxBytes = (Get-WinEvent -ListLog Security).MaximumSizeInBytes
    }
} | Format-Table PSComputerName, SettingsOn, LogMaxBytes -AutoSize
ColumnWhat you want
SettingsOn24 on every domain controller.
LogMaxBytes1073741824, which is 1 GB.
The other DCs are the real test

CON-DC-01 shows 24 whatever happens, because step 3 set it directly. The other domain controllers only get the settings through the policy. If one shows fewer than 24, wait five minutes and run steps 5 and 6 again.

What you can now see

Open Event Viewer › Windows Logs › Security on a domain controller and filter by event ID.

Event IDWhat happened
4625A sign-in failed.
4740An account was locked out.
4720A user account was created.
4728, 4732, 4756Someone was added to a security group.
5136An object in the directory was changed.
4769A Kerberos service ticket was requested.
4688A program started.

Things to know

  • Any audit setting not in the list is switched off. When a policy supplies audit settings, Windows clears the rest first.
  • The log fills faster than before. If it stops reaching back far enough, raise MaxSize in the policy or send the events to a log collector.
  • To change a setting later, edit the policy in Group Policy Management under Computer Configuration › Policies › Windows Settings › Security Settings › Advanced Audit Policy Configuration.

Done when

Check

Every domain controller shows 24 settings and a 1 GB Security log, and a failed sign-in appears in the log as event 4625.

Your progress is kept in this browser only.