AD CS "Certified Pre-Owned" Cheatsheet
AD CS "Certified Pre-Owned" Cheatsheet
Table of Contents
1. Background & Key Concepts
Active Directory Certificate Services (AD CS) is Microsoft's PKI implementation that integrates with Active Directory forests. It provides encryption, digital signatures, and — critically — user and machine authentication to AD. Although not installed by default, AD CS is widely deployed and is often misconfigured in ways that allow domain-level compromise.
Core Certificate Fields
| Field | Description |
|---|---|
| Subject | Owner of the certificate (identity being certified). |
| SubjectAlternativeName (SAN) | One or more alternate names for the subject. Critically abused in ESC1/ESC6. |
| Extended Key Usages (EKUs) | OIDs that define what the certificate can be used for (e.g., authentication, code signing). |
| Issuer | The Certificate Authority (CA) that signed and issued the certificate. |
| NotBefore / NotAfter | Validity window of the certificate. |
| Basic Constraints | Indicates whether the certificate is a CA or end-entity certificate. |
| Signature | Signed by the issuing CA's private key to prove authenticity. |
Key AD CS Containers (LDAP)
2. Authentication EKU OIDs
The following EKU OIDs, when present in a certificate, permit authentication to Active Directory. This is the core of most AD CS abuse scenarios.
| Description | OID | Notes |
|---|---|---|
| Client Authentication | 1.3.6.1.5.5.7.3.2 | Most common auth EKU. |
| PKINIT Client Authentication | 1.3.6.1.5.2.3.4 | Must be added manually; not in default AD CS. |
| Smart Card Logon | 1.3.6.1.4.1.311.20.2.2 | Used for smart card / PKINIT auth. |
| Any Purpose | 2.5.29.37.0 | Allows any usage including auth. |
| No EKU (SubCA) | — | Subordinate CA cert; can authenticate. |
| Certificate Request Agent | 1.3.6.1.4.1.311.20.2.1 | Allows enrolling on behalf of others (ESC3). |
Check EKUs on a Certificate (PowerShell)
Check EKUs with certutil
3. Certificate Enrollment Methods
Clients can request certificates from an Enterprise CA via several interfaces. Each interface represents a potential attack surface.
| Method | Protocol | URL / Interface |
|---|---|---|
| DCOM (default) | MS-WCCE | COM interfaces on the CA server |
| RPC / Named Pipes | MS-ICPR | Named pipes or TCP/IP |
| Web Enrollment | HTTP/HTTPS | http://<CA>/certsrv/ |
| Certificate Enrollment Web Service (CES) | MS-WSTEP (SOAP) | https://<CES>/<CA>_CES_Kerberos/service.svc |
| Network Device Enrollment (NDES) | SCEP | http://<NDES>/CertSrv/mscep/ |
GUI Enrollment
Command-Line Enrollment
Convert PEM to PFX (OpenSSL)
4. AD CS Enumeration
Thorough enumeration of CAs and certificate templates is the foundation of any AD CS assessment. The primary tools are Certify, certutil, and PSPKIAudit.
Enumerate Certificate Authorities
Enumerate Certificate Templates
LDAP Query for ESC1-Vulnerable Templates
View CA Security Descriptor (Remote Registry)
5. Certificate Theft
THEFT1 Export via Crypto APIs
If a private key is marked exportable, it can be extracted directly. For non-exportable keys, Mimikatz can patch CAPI/CNG in memory to force exportability.
THEFT2 User Certificate Theft via DPAPI
User private keys are stored DPAPI-encrypted under %APPDATA%\Microsoft\Crypto\RSA\<User SID>\. Decryption requires the user's DPAPI master key.
THEFT3 Machine Certificate Theft via DPAPI
Machine private keys are stored under %ALLUSERSPROFILE%\Application Data\Microsoft\Crypto\RSA\MachineKeys\. The DPAPI_SYSTEM LSA secret (accessible only as SYSTEM) is required for decryption.
THEFT4 Finding Certificate Files on Disk
Certificates are sometimes left on file systems, shares, or source code repositories. Common file extensions to search for are listed below.
| Extension | Contents |
|---|---|
.pfx / .p12 | Certificate + private key (PKCS#12). Usually password-protected. |
.pem | Base64-encoded certificate and/or private key. |
.key | Private key only. |
.crt / .cer | Certificate only (no private key). |
.jks / .keystore | Java Keystore — may contain certs and private keys. |
.csr | Certificate Signing Request — no cert or key. |
THEFT5 NTLM Credential Theft via PKINIT
When a TGT is obtained via PKINIT (certificate-based Kerberos), the KDC embeds the account's NTLM hash in the PAC. This hash can be extracted and used for pass-the-hash or cracking.
6. Account Persistence
PERSIST1 User Account Persistence via Certificate Request
Request a certificate for the current user from a template that allows domain authentication. The certificate remains valid (and usable for authentication) even after a password reset.
PERSIST2 Machine Account Persistence via Certificate Request
Enroll the machine account in a certificate template that allows Domain Computers. Persistence survives system reimages (if the machine account name is reused) and password rotations.
PERSIST3 Account Persistence via Certificate Renewal
Renew a certificate before it expires to silently extend access without requesting a new certificate (which would leave additional artifacts on the CA).
7. Domain Escalation
ESC1 Misconfigured Template — Enrollee Supplies Subject
A template is vulnerable when: low-privileged users can enroll, no manager approval is required, an auth EKU is present, and the CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT flag is set. This allows any enrollee to specify an arbitrary SAN (e.g., a Domain Admin UPN).
ESC2 Misconfigured Template — Any Purpose / No EKU
A template with the Any Purpose EKU or no EKU (SubCA) and low-privileged enrollment rights. Even without CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT, these certs can authenticate to AD as the requesting user, and can be used as a Certificate Request Agent (see ESC3).
ESC3 Misconfigured Enrollment Agent Template
A template with the Certificate Request Agent EKU (1.3.6.1.4.1.311.20.2.1) and no enrollment agent restrictions allows a low-privileged user to request certificates on behalf of any other user.
ESC4 Vulnerable Certificate Template Access Control
If a low-privileged user has WriteDACL, WriteOwner, or WriteProperty rights on a template object, they can reconfigure it to be vulnerable (e.g., add CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT or a dangerous EKU).
ESC5 Vulnerable PKI AD Object Access Control
Write access to other AD CS-related objects (e.g., the Enterprise CA object, the NTAuthCertificates object, or the PKI container itself) can allow an attacker to compromise the entire PKI.
ESC6 EDITF_ATTRIBUTESUBJECTALTNAME2 Flag on CA
When this flag is set on a CA, any certificate request can include a user-specified SAN, regardless of template settings. Combined with any enrollable auth template, this allows domain escalation.
ESC7 Vulnerable Certificate Authority Access Control
Principals with Manage CA rights can change CA settings (e.g., enable ESC6). Principals with Issue and Manage Certificates rights can approve pending certificate requests, bypassing manager approval requirements.
ESC8 NTLM Relay to AD CS HTTP Endpoints
If the AD CS web enrollment endpoint (/certsrv/) is accessible and does not require HTTPS or EPA, an attacker can relay NTLM authentication from a privileged account (e.g., a DC) to obtain a certificate for that account.
8. Domain Persistence
DPERSIST1 Certificate Forgery with Stolen CA Private Key
If a CA's private key is not hardware-protected, it can be extracted via DPAPI. The stolen key can then be used with ForgeCert to forge certificates for any principal in the domain. Forged certificates cannot be revoked as long as the CA certificate is valid.
DPERSIST2 Trusting Rogue CA Certificates
An attacker with sufficient privileges can add a rogue CA certificate to the NTAuthCertificates AD object and the enterprise trust stores, allowing them to issue certificates that AD will trust for authentication.
DPERSIST3 Malicious Misconfigurations for Future Escalation
An attacker with CA or template write access can introduce misconfigurations (e.g., enable EDITF_ATTRIBUTESUBJECTALTNAME2, weaken template ACLs) that can be exploited later, even after losing initial access.
9. Defensive Guidance
Preventive Controls
| ID | Control | Key Action / Command |
|---|---|---|
| PREVENT1 | Treat CAs as Tier 0 Assets | Apply DC-level security controls to all CA servers and subordinate CAs. |
| PREVENT2 | Harden CA Settings | certutil -config "CA\NAME" -setreg policy\EditFlags -EDITF_ATTRIBUTESUBJECTALTNAME2; restrict "Manage CA" and "Issue and Manage Certificates" rights. |
| PREVENT3 | Audit Published Templates | Remove unused templates from all CAs. Use Certify.exe find or certutil -TCAInfo. |
| PREVENT4 | Harden Template Settings | Disable "Supply in the request"; enable manager approval; restrict enrollment to least-privilege groups; minimise EKUs. |
| PREVENT5 | Audit NTAuthCertificates | certutil -viewdelstore "ldap:///CN=NtAuthCertificates..."; remove unnecessary CA certs. |
| PREVENT6 | Secure Private Key Storage | Use HSMs for CA keys; enable TPM attestation for client keys; enable Credential Guard. |
| PREVENT7 | Enforce Strict User Mappings | Set HKLM\SYSTEM\CurrentControlSet\Services\Kdc\UseSubjectAltName = 0 on DCs to disable SAN-based mapping. |
| PREVENT8 | Harden HTTP Enrollment Endpoints | Require HTTPS + EPA on /certsrv/; disable if not needed; restrict access to authorised hosts. |
Disable SAN Mapping (PREVENT7)
Audit NTAuthCertificates (PREVENT5)
Detective Controls — Windows Event IDs
| Event ID | Description | Relevant Technique |
|---|---|---|
4886 | Certificate Services received a certificate request. | PERSIST1, PERSIST2, ESC1–ESC8 |
4887 | Certificate Services approved a certificate request and issued a certificate. | PERSIST1, PERSIST2, ESC1–ESC8 |
4888 | Certificate Services denied a certificate request. | PERSIST1, PERSIST2 |
4870 | Certificate Services revoked a certificate. | Incident Response |
4882 | The security permissions for Certificate Services were changed. | ESC4, ESC5, ESC7 |
4898 | Certificate Services loaded a template. | ESC4, DPERSIST3 |
4768 | A Kerberos authentication ticket (TGT) was requested. | THEFT5, PERSIST1, ESC1 |
4769 | A Kerberos service ticket was requested. | PERSIST2 (S4U2Self) |
4776 | The computer attempted to validate the credentials for an account. | THEFT5 (NTLM from PKINIT) |
5136 | A directory service object was modified. | ESC4, ESC5, DPERSIST2, DPERSIST3 |
Detective Controls Summary
| ID | Control | What to Monitor |
|---|---|---|
| DETECT1 | Monitor Certificate Enrollments | Event IDs 4886, 4887 on CA servers; alert on unusual template usage or high-volume requests. |
| DETECT2 | Monitor Certificate Authentication | Event ID 4768 with Pre-Authentication Type: 16 (PKINIT); alert on cert auth for sensitive accounts. |
| DETECT3 | Monitor CA Backup Events | Event IDs 4876, 4877 on CA servers; unexpected backups may indicate key theft attempts. |
| DETECT4 | Monitor Template Modifications | Event ID 4898 (template loaded) and 5136 (AD object modified) for certificate template objects. |
| DETECT5 | Monitor DPAPI Key Reads | Audit access to %APPDATA%\Microsoft\Crypto\ and %ALLUSERSPROFILE%\...\MachineKeys\. |
| DETECT6 | Use Honey Credentials | Deploy honey certificates with auth EKUs; alert on any authentication attempt using them. |
| DETECT7 | Miscellaneous | Monitor for certutil.exe invocations with -dspublish, -setreg, or -backup flags. |
10. Tool Reference
| Tool | Purpose | Key Commands |
|---|---|---|
| Certify | AD CS enumeration and certificate requests (C#, GhostPack) | cas, find, find /vulnerable, request, approve |
| Rubeus | Kerberos abuse toolkit; supports PKINIT certificate auth (C#, GhostPack) | asktgt /certificate:..., s4u, describe |
| SharpDPAPI | DPAPI decryption; extracts user and machine certificates (C#, GhostPack) | certificates, certificates /machine, masterkeys |
| ForgeCert | Forge certificates using a stolen CA private key (C#, GhostPack) | /CA:ca.pfx /SubjectAltName:user@domain /OutFile:forged.pfx |
| Mimikatz | Credential extraction; CAPI/CNG patching; DPAPI operations | crypto::capi, crypto::cng, crypto::certificates, dpapi::masterkey |
| Kekeo | Kerberos manipulation; PKINIT to NTLM hash extraction | tgt::pac, tgt::ask |
| PSPKIAudit | PowerShell AD CS auditing tool (GhostPack) | Invoke-PKIAudit |
| certutil.exe | Built-in Windows CA management and certificate utility | -TCAInfo, -v -dstemplate, -dump -v cert.pfx, -setreg, -backup |
| certreq.exe | Built-in Windows certificate request tool | -submit, -renew, -retrieve |
| Seatbelt | Host enumeration and triage (C#, GhostPack) | dir, FindInterestingFiles |
| impacket-ntlmrelayx | NTLM relay attacks; supports AD CS web enrollment relay (ESC8) | -t http://<adcs>/certsrv/certfnsh.asp --adcs |
| openssl | Certificate format conversion (PEM ↔ PFX) | pkcs12 -in cert.pem -export -out cert.pfx |
Comments
Post a Comment