TExcelTAD
Home › Windows & Active Directory Security › Auditing ACLs and AD CS Continuously

Auditing ACLs and AD CS Continuously

An AD that was cleaned up last year is not clean today. Every new product installation, delegation request, migration script and certificate template adds permissions, and the attack-path, DCSync, GPO and AD CS lessons showed that a single ACE in the wrong place can be a path to Tier 0. The defence is not a one-time review but a routine: export the security descriptors of the objects that matter, check them against rules, and diff them against the last export so every new permission on a Tier 0 object is seen within a day. This lesson builds that routine on SDDL, the text form of security descriptors that every AD tool can export.

SDDL in five minutes

A security descriptor in SDDL (Security Descriptor Definition Language) looks like O:DAG:DAD:(A;;GA;;;DA)(OA;;CR;00299570-…;;S-1-5-21-…-1105): O: owner, G: primary group, D: the DACL as a list of ACEs. Each ACE is (type;flags;rights;object type;inherited object type;trustee):

Part Common values
type A allow, D deny, OA object-specific allow (a right on one attribute, property set or extended right), OD object deny
flags CI container inherit, IO inherit only, ID inherited
rights GA generic all, GW generic write, WD write DACL, WO write owner, WP write property, CR control access (extended right), CC create child, RP read property
object type a GUID: an attribute (bf9679c0-0de6-11d0-a285-00aa003049e2 = member), or an extended right (00299570-246d-11d0-a768-00aa006e0529 = reset password, 1131f6ad-… = replicate secrets, 0e10c968-78fb-11d2-90d4-00c04f79dc55 = certificate enrollment)
trustee a SID or an alias: DA Domain Admins, EA Enterprise Admins, BA Administrators, SY SYSTEM, AU Authenticated Users, WD Everyone, DU Domain Users, PS the object itself

Exports come from (Get-Acl "AD:<DN>").Sddl with the AD module, dsacls, or the attack-path collectors. .NET's ACL classes don't run on Linux, so the script below parses SDDL with a regular expression, which is also a good way to learn the format.

The audit

powershell · try it yourself
$objects = [ordered]@{
  'CN=AdminSDHolder,CN=System'      = 'O:DAG:DAD:(A;;GA;;;DA)(A;;GA;;;EA)(A;;GA;;;SY)(A;;RP;;;AU)(OA;;WP;bf9679c0-0de6-11d0-a285-00aa003049e2;;S-1-5-21-1-2-3-1188)'
  'DC=corp,DC=lab,DC=test'          = 'O:DAG:DAD:(A;;GA;;;DA)(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;ED)(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;S-1-5-21-1-2-3-1150)(A;;RP;;;AU)'
  'CN=Tier0-Admins,OU=Tier0'        = 'O:DAG:DAD:(A;;GA;;;DA)(OA;;CR;00299570-246d-11d0-a768-00aa006e0529;;S-1-5-21-1-2-3-1120)(A;;RP;;;AU)'
  'CN=WebServer-Lab (template)'     = 'O:S-1-5-21-1-2-3-1201G:DAD:(A;;GA;;;EA)(OA;;CR;0e10c968-78fb-11d2-90d4-00c04f79dc55;;DU)(A;;WP;;;DU)'
}
$names = @{ 'DA' = 'Domain Admins'; 'EA' = 'Enterprise Admins'; 'SY' = 'SYSTEM'; 'AU' = 'Authenticated Users'; 'ED' = 'Enterprise DCs'
            'DU' = 'Domain Users'; 'S-1-5-21-1-2-3-1188' = 'Helpdesk-Ops'; 'S-1-5-21-1-2-3-1150' = 'svc-backup'
            'S-1-5-21-1-2-3-1120' = 'IT-Helpdesk'; 'S-1-5-21-1-2-3-1201' = 'carol' }
$tier0 = 'DA', 'EA', 'SY', 'ED', 'BA'
$guid = @{ 'bf9679c0-0de6-11d0-a285-00aa003049e2' = 'write member'; '1131f6ad-9c07-11d1-f79f-00c04fc2dcd2' = 'replicate secrets'
           '00299570-246d-11d0-a768-00aa006e0529' = 'reset password'; '0e10c968-78fb-11d2-90d4-00c04f79dc55' = 'enroll' }
$dangerous = 'GA', 'GW', 'WD', 'WO', 'WP'

function Get-Aces([string]$sddl) {
  $owner = if ($sddl -match '^O:([^G]+)G:') { $Matches[1] } else { '?' }
  $aces = foreach ($m in [regex]::Matches($sddl, '\(([^;]*);([^;]*);([^;]*);([^;]*);([^;]*);([^)]*)\)')) {
    [pscustomobject]@{ Type = $m.Groups[1].Value; Rights = $m.Groups[3].Value; Object = $m.Groups[4].Value; Trustee = $m.Groups[6].Value }
  }
  return $owner, $aces
}

foreach ($dn in $objects.Keys) {
  $owner, $aces = Get-Aces $objects[$dn]
  $out = @()
  if ($tier0 -notcontains $owner) { $out += "owner is $($names[$owner]) (owners can rewrite the DACL)" }
  foreach ($a in $aces) {
    if ($tier0 -contains $a.Trustee) { continue }
    $rights = for ($i = 0; $i -lt $a.Rights.Length; $i += 2) { $a.Rights.Substring($i, 2) }
    $what = if ($a.Object) { $guid[$a.Object] } else { ($rights | Where-Object { $dangerous -contains $_ }) -join '+' }
    $bad = ($rights | Where-Object { $dangerous -contains $_ }) -or ($a.Object -and $guid[$a.Object] -ne 'enroll')
    if ($dn -like '*template*' -and $guid[$a.Object] -eq 'enroll' -and $a.Trustee -eq 'DU') { $out += 'Domain Users may enroll (check ESC1/ESC2 conditions)' }
    elseif ($bad) { $out += "$($names[$a.Trustee]) has $what" }
  }
  "== $dn"
  if ($out) { $out | ForEach-Object { "   FINDING $_" } } else { '   ok' }
}
== CN=AdminSDHolder,CN=System
   FINDING Helpdesk-Ops has write member
== DC=corp,DC=lab,DC=test
   FINDING svc-backup has replicate secrets
== CN=Tier0-Admins,OU=Tier0
   FINDING IT-Helpdesk has reset password
== CN=WebServer-Lab (template)
   FINDING owner is carol (owners can rewrite the DACL)
   FINDING Domain Users may enroll (check ESC1/ESC2 conditions)
   FINDING Domain Users has WP

Each finding is one of the attack paths of the earlier lessons, now caught at the source. The help-desk operations group can write the member attribute through AdminSDHolder, and SDProp copies that ACE to every protected group and account within an hour, so that one ACE gives membership control of Domain Admins. svc-backup can replicate secrets. The help desk can reset Tier 0 admins' passwords. The web-server template is owned by carol and writable by Domain Users (ESC4), on top of being enrollable by them.

Diffing exports

A rule set catches known-bad patterns; a diff catches everything new. Store each day's export (object DN → SDDL) and compare the ACE sets:

powershell · try it yourself
$yesterday = @{ 'CN=Tier0-Admins,OU=Tier0' = 'O:DAG:DAD:(A;;GA;;;DA)(A;;RP;;;AU)'
                'DC=corp,DC=lab,DC=test'   = 'O:DAG:DAD:(A;;GA;;;DA)(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;ED)(A;;RP;;;AU)' }
$today     = @{ 'CN=Tier0-Admins,OU=Tier0' = 'O:DAG:DAD:(A;;GA;;;DA)(OA;;CR;00299570-246d-11d0-a768-00aa006e0529;;S-1-5-21-1-2-3-1120)(A;;RP;;;AU)'
                'DC=corp,DC=lab,DC=test'   = 'O:DAG:DAD:(A;;GA;;;DA)(OA;;CR;1131f6ad-9c07-11d1-f79f-00c04fc2dcd2;;ED)(A;;RP;;;AU)' }
function Get-AceSet([string]$sddl) { @([regex]::Matches($sddl, '\([^)]*\)') | ForEach-Object Value) }
foreach ($dn in $today.Keys | Sort-Object) {
  $old = Get-AceSet $yesterday[$dn]; $new = Get-AceSet $today[$dn]
  $added = $new | Where-Object { $old -notcontains $_ }
  $removed = $old | Where-Object { $new -notcontains $_ }
  if (-not ($added -or $removed)) { "$dn : unchanged"; continue }
  "$dn :"
  $added | ForEach-Object { "   + $_" }
  $removed | ForEach-Object { "   - $_" }
}
CN=Tier0-Admins,OU=Tier0 :
   + (OA;;CR;00299570-246d-11d0-a768-00aa006e0529;;S-1-5-21-1-2-3-1120)
DC=corp,DC=lab,DC=test : unchanged

The new reset-password ACE on Tier0-Admins appeared overnight; whoever added it should have a change ticket. The directory's own events say the same thing in real time (5136 on nTSecurityDescriptor), and the diff is the safety net when auditing or forwarding failed.

Auditing AD CS continuously

The same routine applies to the PKI, with a few extra objects:

  • certificate templates (DACL, owner, msPKI-Certificate-Name-Flag for enrollee-supplied subject, EKUs, msPKI-Enrollment-Flag for manager approval);
  • the CA's own security (ManageCA, ManageCertificates) and its EditFlags (ESC6);
  • the NTAuthCertificates object and the PKI containers in the Configuration partition (ESC5);
  • whether web enrollment exists and has EPA (ESC8).

Defender tools that run this as a scheduled job and report changes: Locksmith (PowerShell, can also fix), PSPKIAudit, and the AD CS checks of PingCastle and Purple Knight. On the CA, keep auditing on and watch 4899/4900 (template changed / template security changed) and 4882 (CA permissions changed).

How the routine is run

  • Scope: Tier 0 objects first (domain root, AdminSDHolder, privileged groups and their members, DC computer objects, Domain Controllers OU, GPOs linked to it, AD CS objects, Entra Connect accounts), then Tier 1.
  • Frequency: daily export and diff; weekly full rule run and attack-path analysis.
  • Ownership: every finding gets an owner and a deadline; every accepted exception an expiry date.
  • Storage: keep exports read-only and outside the domain they describe, so an intruder can't edit history.

Pitfalls

  • Ignoring inherited ACEs: an ACE on an OU applies to everything below; export with inheritance shown, or evaluate the OU chain.
  • Forgetting owners: the owner can always rewrite the DACL.
  • Counting AdminSDHolder as "safe by design": it is only as safe as its own DACL.
  • Diffing text, not ACEs: reordered but equal ACLs create noise; compare ACE sets as above.

Practice

1. Why is a single ACE on AdminSDHolder worse than the same ACE on Domain Admins?

SDProp copies AdminSDHolder's DACL to every protected object (Domain Admins, Enterprise Admins, Administrators, their members and more) every 60 minutes. One ACE there spreads to all of them and reappears if someone removes it from one group.

2. Decode (OA;;CR;00299570-246d-11d0-a768-00aa006e0529;;S-1-5-21-1-2-3-1120).

Object-specific allow, no inheritance flags, control access right "reset password" (User-Force-Change-Password) for the trustee SID ending in 1120, here IT-Helpdesk.

3. The diff shows an ACE removed from the domain root, nothing added. Is that safe to ignore?

No. Removing an ACE can be harmless cleanup or can break something (or remove an auditing-relevant entry if the change was to the SACL). Every Tier 0 change needs a ticket; investigate who made it (5136) and why.

Test yourself

In SDDL, what does the right WD mean?

  1. Everyone
  2. Write DACL
  3. Write data
  4. Delete

Why diff ACL exports in addition to rule checks?

  1. Rules are always wrong
  2. A diff shows every new permission, including ones no rule anticipated
  3. Diffs are faster
  4. To delete old ACEs

Which CA event records a change to a certificate template's security?

  1. 4886
  2. 4887
  3. 4900
  4. 4769

How often does SDProp apply AdminSDHolder's DACL to protected objects by default?

  1. Every 60 minutes
  2. Once a year
  3. Only at boot
  4. Never