Fix ESC1 false negatives in template enumeration - #317
Merged
Merged
Conversation
Owner
|
Absolutely incredible PR and code change, thank you! The code fails a formatting check - I'll be very happy to merge once formatted with Black! :) |
Contributor
Author
|
Thanks for the feedback! I’ve formatted the code with Black, and the PR should now pass the formatting check. |
Owner
|
Thank you! :) Apologies for the delay |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR improves ESC1 detection in Certipy 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: Certificate Templates Structure) 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, Certipy 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
certipy/commands/find.py, the functioncan_user_enroll_in_templatedoes 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 (or All-Extended-Rights) 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
certipy/lib/security.py(ActiveDirectorySecurity parser)has_standard_control_accesswhen a standardACCESS_ALLOWED_ACEhas the Control Access bit (0x00000100) set.certipy/commands/find.py(can_user_enroll_in_template)ObjectTypeis the Enroll GUID (detected via presence of Enroll inextended_rightsand the EXTENDED_RIGHT bit).has_standard_control_accessflag).What this means
Enrollment rights are now determined exactly per MS-CRTD:
ACCESS_ALLOWED_OBJECT_ACE+ Control Access + Enroll GUID.ACCESS_ALLOWED_ACE(standard) + Control Access bit.This aligns Certipy’s behavior with the spec and eliminates the observed false negatives for templates that rely on a standard Control Access grant.
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.
TestCase1
TestCase2
TestCase3
TestCase4
Reproduction:
Run






certipy findusing the modified version of Certipy (this branch).Run the same command using the original Certipy release for comparison.




For the vulnerable cases where the original Certipy 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 Certipy.