repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
overview.mdMarkdown155 lines9.8 KiBsource raw download

title: "AD Certificates" section: "Windows" sectionSlug: "windows-hardening" sourcePath: "src/windows-hardening/active-directory-methodology/ad-certificates/README.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/windows-hardening/active-directory-methodology/ad-certificates/README.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: true modified: true license: "CC-BY-NC-4.0"#

AD Certificates#

Introduction#

Components of a Certificate#

Special Considerations#

Certificate Authorities (CAs) in Active Directory (AD)#

AD CS acknowledges CA certificates in an AD forest through designated containers, each serving unique roles:[1]

Certificate Acquisition: Client Certificate Request Flow#

  1. The request process begins with clients finding an Enterprise CA.
  2. A CSR is created, containing a public key and other details, after generating a public-private key pair.
  3. The CA assesses the CSR against available certificate templates, issuing the certificate based on the template's permissions.
  4. Upon approval, the CA signs the certificate with its private key and returns it to the client.[1]

Certificate Templates#

Defined within AD, these templates outline the settings and permissions for issuing certificates, including permitted EKUs and enrollment or modification rights, critical for managing access to certificate services.[1]

Certificate Enrollment#

The enrollment process for certificates is initiated by an administrator who creates a certificate template, which is then published by an Enterprise Certificate Authority (CA). This makes the template available for client enrollment, a step achieved by adding the template's name to the certificatetemplates field of an Active Directory object.[1]

For a client to request a certificate, enrollment rights must be granted. These rights are defined by security descriptors on the certificate template and the Enterprise CA itself. Permissions must be granted in both locations for a request to be successful.[1]

Template Enrollment Rights#

These rights are specified through Access Control Entries (ACEs), detailing permissions like:[1]

Enterprise CA Enrollment Rights#

The CA's rights are outlined in its security descriptor, accessible via the Certificate Authority management console. Some settings even allow low-privileged users remote access, which could be a security concern.[1]

Additional Issuance Controls#

Certain controls may apply, such as:[1]

Methods to Request Certificates#

Certificates can be requested through:[1]

  1. Windows Client Certificate Enrollment Protocol (MS-WCCE), using DCOM interfaces.
  2. ICertPassage Remote Protocol (MS-ICPR), through named pipes or TCP/IP.
  3. The certificate enrollment web interface, with the Certificate Authority Web Enrollment role installed.
  4. The Certificate Enrollment Service (CES), in conjunction with the Certificate Enrollment Policy (CEP) service.
  5. The Network Device Enrollment Service (NDES) for network devices, using the Simple Certificate Enrollment Protocol (SCEP).

Windows users can also request certificates via the GUI (certmgr.msc or certlm.msc) or command-line tools (certreq.exe or PowerShell's Get-Certificate command).

# Example of requesting a certificate using PowerShell
Get-Certificate -Template "User" -CertStoreLocation "cert:\\CurrentUser\\My"

Certificate Authentication#

Active Directory (AD) supports certificate authentication, primarily utilizing Kerberos and Secure Channel (Schannel) protocols.[1]

Kerberos Authentication Process#

In the Kerberos authentication process, a user's request for a Ticket Granting Ticket (TGT) is signed using the private key of the user's certificate. This request undergoes several validations by the domain controller, including the certificate's validity, path, and revocation status. Validations also include verifying that the certificate comes from a trusted source and confirming the issuer's presence in the NTAUTH certificate store. Successful validations result in the issuance of a TGT. The NTAuthCertificates object in AD, found at:

CN=NTAuthCertificates,CN=Public Key Services,CN=Services,CN=Configuration,DC=<domain>,DC=<com>

is central to establishing trust for certificate authentication.[1]

Secure Channel (Schannel) Authentication#

Schannel facilitates secure TLS/SSL connections, where during a handshake, the client presents a certificate that, if successfully validated, authorizes access.[2] The mapping of a certificate to an AD account may involve Kerberos’s S4U2Self function or the certificate’s Subject Alternative Name (SAN), among other methods.[1]

AD Certificate Services Enumeration#

AD's certificate services can be enumerated through LDAP queries, revealing information about Enterprise Certificate Authorities (CAs) and their configurations. This is accessible by any domain-authenticated user without special privileges.[1] Tools like Certify and Certipy are used for enumeration and vulnerability assessment in AD CS environments.[3]

Commands for using these tools include:

# Enumerate trusted root CA certificates, Enterprise CAs and HTTP enrollment endpoints
# Useful flags: /domain, /path, /hideAdmins, /showAllPermissions, /skipWebServiceChecks
Certify.exe cas [/ca:SERVER\ca-name | /domain:domain.local | /path:CN=Configuration,DC=domain,DC=local] [/hideAdmins] [/showAllPermissions] [/skipWebServiceChecks]

# Identify vulnerable certificate templates and filter for common abuse cases
Certify.exe find
Certify.exe find /vulnerable [/currentuser]
Certify.exe find /enrolleeSuppliesSubject   # ESC1 candidates (CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT)
Certify.exe find /clientauth                # templates with client-auth EKU
Certify.exe find /showAllPermissions        # include template ACLs in output
Certify.exe find /json /outfile:C:\Temp\adcs.json

# Enumerate PKI object ACLs (Enterprise PKI container, templates, OIDs) – useful for ESC4/ESC7 discovery
Certify.exe pkiobjects [/domain:domain.local] [/showAdmins]

# Use Certipy for enumeration and identifying vulnerable templates
certipy find -vulnerable -u john@corp.local -p Passw0rd -dc-ip 172.16.126.128

# Enumerate Enterprise CAs and certificate templates with certutil
certutil.exe -TCAInfo
certutil -v -dstemplate

Rubeus can also use a password-protected PFX certificate for PKINIT authentication and request a TGT. The optional /getcredentials switch requests a U2U service ticket and attempts to recover the account NT hash:[4]

Rubeus.exe asktgt /user:<USER> /certificate:C:\temp\leaked.pfx /password:<PFX_PASSWORD> /getcredentials /ptt

References#