Fix ESC1 false negatives in template enumeration #33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix ESC1 false negatives in template enumeration
Summary
This PR improves ESC1 detection in PSPKIAudit by addressing false negatives observed in specific template configurations. The change refines the logic that determines whether a template is exploitable for ESC1.
Background
According to Microsoft documentation (MS-CRTD) enrollment permissions for a certificate template are evaluated based on two processing rules:
First rule
ACCESS_ALLOWED_OBJECT_ACE.0x00000100set (Control Access).ObjectTypefield corresponds to the Enroll GUID (0e10c968-78fb-11d2-90d4-00c04f79dc55).Second rule
ACCESS_ALLOWED_ACE.0x00000100set.These rules define how Active Directory evaluates whether a principal can enroll for a certificate. In addition to Microsoft’s specification, further practical details and lab-based examples can be found in my previous articles The Schrödinger’s ESC1 Vulnerability and The Schrödinger’s ESC1 Vulnerability: Benchmark Update, where these conditions were analyzed across different tool implementations.
Problem
In some scenarios, PSPKIAudit failed to flag templates as ESC1-vulnerable even when they were exploitable. This was reproducible in a controlled lab with eight dedicated templates (four vulnerable, four non-vulnerable).
Root Cause
In
PSPKIAudit/Code/Invoke-PKIAudit.ps1, the functionTest-CanLowPrivEnrollInTemplatedoes not implement both enrollment-processing rules defined by Microsoft’s specification (MS-CRTD). The current logic effectively checks only Rule 1 by validating the presence of the Enroll object-specific extended right. Because an ACE with anObjectTypeis, by definition, anACCESS_ALLOWED_OBJECT_ACE, the function implicitly assumes the ACE type and does not verify it explicitly.As a result, Rule 2 is not considered. This omission leads to false negatives in cases where enrollment is legitimately granted through a standard ACE with Control Access.
Solution
Key changes
Implemented MS-CRTD enrollment checks in
PSPKIAudit/Code/Invoke-PKIAudit.ps1Test-CanLowPrivEnrollInTemplateto read the template’s AD ACL by DN and enforce:Replaced low-priv principal regex with non-admin check in
PSPKIAudit/Code/Invoke-PKIAudit.ps1Get-AdminSidsto build an admin SID set (well-known SIDs, Administrator, krbtgt, key admin groups, and all their members).Test-CanLowPrivEnrollInTemplatenow skips ACEs assigned to admin SIDs and evaluates only non-admin principals.Improved DACL rendering for templates in
PSPKIAudit/Code/Invoke-PKIAudit.ps1Get-CertificateTemplateDACLStringto build DACL output from AD (nTSecurityDescriptor), listing entries as “DOMAIN\sam (Allow|Deny) - Rights”.Get-AuditCertificateTemplatecode paths to use the new function, fixing incomplete ACL displays seen withGet-CertificateTemplateAcl.What this means
ACCESS_ALLOWED_OBJECT_ACE+ Control Access + Enroll GUID.ACCESS_ALLOWED_ACE(standard) + Control Access bit.CommonLowprivPrincipals.This aligns PSPKIAudit’s behavior with the spec and eliminates the observed false negatives for templates that rely on a standard Control Access grant or that grant enrollment permissions to a low-privileged principal not listed in
CommonLowprivPrincipals.Testing
Environment: Terraform + GCP lab consisting of a Domain Controller, a Certificate Authority, a Windows Server (for .exe and .ps1 tools), and an Ubuntu machine (for Python tools).
Vulnerable templates: Four vulnerable certificate templates, with screenshots of their security descriptors and the corresponding vulnerable ACEs included.
Reproduction:
Run






Invoke-PKIAuditusing the modified version of PSPKIAudit (this branch).Run the same



Invoke-PKIAuditcommand using the original PSPKIAudit release for comparison.For the vulnerable cases where the original PSPKIAudit failed to detect ESC1 (false negatives), privilege escalation using certipy req and certipy auth was demonstrated to confirm that the templates were indeed exploitable.



Result
All four vulnerable templates are now correctly reported as ESC1 by the modified PSPKIAudit.