๐Ÿ›๏ธActive Directory Certificate Services (ADCS)

Introduction to ADCS

Active Directory Certificate Services (ADCS) is the role that handles certificate issuance for users, computers, and services in the Active Directory network. When misconfigured, this service can present vulnerabilities that attackers could exploit to escalate privileges or access sensitive information.

Common ADCS Vulnerabilities

  • Certificate Issuance Privilege Delegation: If certain users have permissions to issue certificates for others, an attacker could abuse these privileges to obtain elevated permissions.

  • Certificate Template Misconfiguration: Incorrect configurations in certificate templates could allow an attacker to request a certificate on behalf of another user, including one with elevated privileges.

  • NTLM Relaying over HTTP: If ADCS accepts NTLM authentication instead of Kerberos, an attacker could redirect requests to gain access.

Main Components

  • CA (Certification Authority): Issues and manages certificates. There can be multiple CAs in a hierarchy.

  • Certificate Templates: Define configuration, permissions, and requirements for issuing certificates.

  • CES (Certificate Enrollment Server): Allows certificate renewal through HTTPS requests.

  • Certificate Enrollment Policy Web Server: Provides information about certificate enrollment policies.

  • CA Web Enrollment: Allows hosts outside the domain or with other operating systems to renew certificates.

  • NDES (Network Device Enrollment Service): Allows network devices to obtain certificates without connection.

X.509 Certificate Formats

  • PEM: Base64-encoded DER certificate; can store multiple keys without password protection.

  • DER: Certificate in raw binary format.

  • PFX/P12 (PKCS#12): Stores private keys with password protection.

  • P7B (PKCS#7): Stores certificate chains but not private keys.

Main Certificate Attributes

  • Subject: Entity to which the certificate is issued.

  • Issuer: Usually the CA.

  • SAN: Subject Alternative Name.

  • Validity Period: Certificate validity period.

  • EKU (Extended Key Use): Defines specific uses of the certificate.

  • OID (Object Identifier): Indicates the purpose or usage scenario of the certificate.

OID
Certificate Usage

1.3.6.1.5.5.7.3.1

Server Authentication

1.3.6.1.5.5.7.3.2

Client Authentication

1.3.6.1.5.5.7.3.3

Code Signing

1.3.6.1.5.5.7.3.4

Secure Email

CSR (Certificate Signing Request) Process

  1. Client sends a certificate request (CSR).

  2. CA verifies client permissions to issue the requested certificate.

  3. If permissions match, CA generates and signs the certificate with its private key.

  4. Signed certificate is returned to the client.

Checking Misconfigured Templates

We'll use Certipy for privilege escalation with ADCS.

GitHub Repository: ly4k/Certipy

To check for misconfigured templates that we can abuse:

Common Issues and Solutions

KDC_ERR_PADATA_TYPE_NOSUPP Error

This error occurs when attempting to authenticate with a user's PFX certificate, indicating that the KDC doesn't support the provided authentication type.

Common Causes:

  • Domain controller doesn't have a certificate installed for smart cards

  • DC lacks "Domain Controller", "Domain Controller Authentication", or another certificate with Server Authentication EKU

  • Wrong CA is being queried or proper CA cannot be contacted

Solution: Use PassTheCert to authenticate to LDAP via SChannel:

ESC Attack Techniques

ESC1 - Domain Users Enrollment

Certificate request with alternative SAN.

Standard Users

Certificate Authentication:

Domain Computers (Machine Account)

When ESC1 is only available through Domain Computers:

ESC2

Certificate request with alternative SAN:

Authentication:

Verification:

ESC3

Request certificate and then impersonate administrator:

ESC4

Modify vulnerable template:

ESC5

Request and approve certificate:

ESC6

Certificate request with alternative UPN:

ESC7

Prerequisites: User must have "Manage CA" and "Manage Certificates" access rights, and SubCA template must be enabled.

ESC8

NTLM Relay attack:

Possible follow-up attacks:

DCSync Attack (if Domain Admin privileges):

Silver Ticket (using machine account NTLM hash):

ESC9

Requirements: GenericWrite or GenericAll over account A to compromise account B.

ESC10

Case 1: Standard Account Compromise

Case 2: Machine Account Compromise

ESC11

RPC-based relay attack:

Follow ESC8 steps after successful relay.

ESC13

Policy-based certificate template exploitation:

Use certificate with Pass-the-Certificate for TGT with additional group privileges.

ESC14

Scenario A: Write altSecurityIdentities on Target

X509 Parser Script (x509.py):

ESC15

Description: Certificate template allows authentication via Client Authentication EKU with altSecurityIdentities configured to use non-compliant Subject Alternative Name (SAN) values.

Requirements: Access to an account with certificate enrollment permissions, vulnerable certificate template with Client Authentication EKU, and permissive SAN configuration.

Detection

First, identify vulnerable templates using Certipy:

Look for templates that allow:

  • Client Authentication in Extended Key Usage (EKU)

  • ENROLLEE_SUPPLIES_SUBJECT flag set

  • No manager approval required

  • Certificate Request Agent not required

Method 1: UPN Impersonation with Password Change (Destructive)

This method involves changing the target administrator's password, making it detectable but straightforward:

Method 2: On-Behalf-Of Request (Stealthy)

This method is more stealthy as it doesn't modify the administrator's password:

Method 3: Direct Certificate Authentication

Alternative approach using certificate for direct LDAP authentication:

Note: ESC15 vulnerabilities typically arise from misconfigured certificate templates that allow Subject Alternative Name spoofing combined with Client Authentication capabilities. Always verify the specific template configuration and adjust the exploitation approach accordingly.

ESC16

Security Extension disabled on CA.

Scenario A: UPN Manipulation

Requirements: StrongCertificateBindingEnforcement = 1 (Compatibility) or 0 (Disabled) on DCs, and attacker has write access to victim's UPN.

Tools and Resources

Primary Tools

  • Certipy: Main tool for ADCS enumeration and exploitation

  • PassTheCert: Certificate-based authentication when PKINIT is not supported

  • PowerView: Domain enumeration and computer account management

  • BloodHound: Active Directory relationship mapping

  • Coercer: Authentication coercion attacks

Useful References

Notes and Best Practices

  1. Always save original configurations when modifying templates (ESC4, ESC7)

  2. Revert changes after successful exploitation to minimize detection

  3. Handle timeouts - If receiving "NETBIOS connection timeout" errors, retry the commands

  4. Certificate validation - Ensure proper certificate validation when authenticating

  5. Privilege verification - Always verify obtained privileges match expected access levels

Last updated