Active Directory Certificate Services (AD CS) Compromise
Introduction
Active Directory Certificate Services (AD CS) is a Microsoft role that enables organisations to build and manage a Public Key Infrastructure (PKI). AD CS is often used to issue and manage certificates for secure communication, authentication, and encryption within a Windows environment. While AD CS is a powerful tool for securing an enterprise, misconfigurations or improper implementation can make it a prime target for attackers.
An AD CS compromise occurs when attackers exploit vulnerabilities, misconfigurations, or design flaws in the PKI infrastructure to escalate privileges, impersonate users or devices, and establish persistent access within a network. This tactic is classified under the Credential Access, Privilege Escalation, and Persistence tactics in the MITRE ATT&CK Framework (e.g., T1552.003).
How Active Directory Certificate Services Works
Certificate Authority (CA):
AD CS acts as a Certificate Authority that issues and manages certificates based on predefined templates.
Certificate Templates:
Templates define the rules for certificate issuance, including permissions, key usage, and subject details.
Authentication and Security:
Certificates issued by AD CS can be used for authentication, encrypting communications, signing emails, and more.
Integration with Active Directory:
AD CS integrates tightly with Active Directory, allowing seamless use of certificates for domain accounts and resources.
How Attackers Exploit AD CS
Misconfigured Certificate Templates:
Templates with overly permissive configurations (e.g., allowing enrollment by unauthorised users or services) can be abused to issue certificates for privilege escalation.
Escalation via Certificate Requests:
Attackers forge certificate requests to impersonate privileged accounts, such as domain administrators.
NTLM Relay Attacks:
Vulnerabilities like CVE-2022-26923 allow attackers to abuse the AD CS Enrollment Web Service to relay NTLM authentication and obtain certificates.
Persistent Access:
Certificates are long-lived compared to passwords and can be reused by attackers to maintain access, even if credentials are rotated.
Service Account Exploitation:
Attackers compromise service accounts with certificate enrollment privileges and use them to request malicious certificates.
Certificate Theft:
Once a certificate and private key are stolen, attackers can impersonate legitimate users or services.
Risks of AD CS Compromise
Privilege Escalation:
Certificates can grant attackers elevated privileges within the domain.
Lateral Movement:
Stolen certificates allow attackers to access other resources or impersonate users.
Persistence:
Certificates provide long-term access, bypassing password expiration policies and multifactor authentication (MFA).
Stealthy Attacks:
Certificates can be used to establish encrypted channels, making attacker activity harder to detect.
Indicators of AD CS Compromise
Unusual Certificate Requests:
Certificates requested by unauthorised accounts or for privileged templates.
Misconfigured Templates:
Templates allowing enrollment by non-administrative users or accounts.
Excessive Access to AD CS Servers:
Unauthorised users accessing the Certificate Authority (CA) server or enrollment web services.
Use of Stolen Certificates:
Authentication or encryption activity involving certificates not typically used by the legitimate account.
Detection Techniques
Monitor Certificate Issuance:
Track certificate requests and issuance using AD CS logs (Event ID 4886, 4887, 4888, etc.).
Event ID 39: Event generated when no strong certificate mappings can be found, and the certificate does not have a new Security Identifier (SID) extension that the Key Distribution Centre (KDC) could validate.
Event ID 40: Event generated when a certificate is supplied that was issued to the user before the user existed in Active Directory, and no strong mapping is found.
Event ID 41: Event generated when a certificate is supplied where the SID contained in the new extension of the user's certificate does not match the user’s SID, implying that the certificate was issued to another user.
Event ID 1102: Event generated when the Security audit log is cleared. To avoid detection, malicious actors may clear this audit log to remove any evidence of their activities. Can assist in identifying if an AD CS CA has been compromised.
Event ID 4674: Event generated when an attempt is made to perform privileged operations on a protected subsystem object after the object is already opened.
Event ID 4768: Event generated when a TGT is requested. The ‘PreAuthType’ of ‘16’ indicates that a certificate was used in the TGT request.
Event ID 4886: Event generated when AD CS receives a certificate request. This may indicate if malicious actors attempted to elevate privileges by requesting an authentication certificate for a privileged user.
Event ID 4887: Event generated when AD CS approves a certificate request and issues a certificate. This may be used to indicate when malicious actors successfully escalated privileges using AD CS.
Event ID 4899: Event generated when a certificate template is updated. This may occur when malicious actors attempt to modify a certificate template to introduce additional features that may make it vulnerable to privilege escalation.
Event ID 4900: Event generated when security settings on a Certificate Services template are updated. This may occur when the Access Control List on the template has been modified to potentially introduce vulnerable conditions, such as modification of enrolment rights to a certificate template.
AD CS event auditing is not enabled by default. Follow these steps to configure audit logging for AD CS:
Enable ‘Audit object access’ for Certificate Services in Group Policy for AD CS CAs. This can be found within the ‘Advanced Audit Policy Configuration’ within Security Settings.
Within the CA properties, the Auditing tab shows configurations of events to log. Enable all available options.
Detect Misconfigured Templates:
Audit certificate templates for permissions and key usages that could allow abuse:
Analyse NTLM Relay Attacks:
Monitor network traffic and logs for NTLM relay activity targeting AD CS Enrollment Web Services.
Track Certificate Usage:
Use SIEM tools to identify authentication activity involving unusual certificates.
Mitigation Strategies
Harden Certificate Templates:
Review and restrict permissions on certificate templates to limit who can enrol for certificates.
Enable Enhanced Key Usage (EKU):
Configure templates to restrict certificates to specific purposes, reducing the attack surface.
Audit AD CS Configurations:
Regularly review CA configurations, template permissions, and enrollment methods.
Implement Strong Access Controls:
Restrict access to AD CS servers, enrollment services, and certificate templates.
Monitor Certificate Revocation:
Use Certificate Revocation Lists (CRLs) to invalidate compromised certificates.
The following security controls should be implemented to mitigate an ESC1 AD CS compromise:
Remove the Enrolee Supplies Subject flag. Do not allow users to provide their own SAN in the certificate signing request for templates configured for client authentication. Templates configured with the Enrolee Supplies Subject flag allow a user to provide their own SAN.
Restrict standard user object permissions on certificate templates. Standard user objects should not have write permissions on certificate templates. User objects with write permissions may be able to change enrolment permissions or configure additional settings to make the certificate template vulnerable.
Remove vulnerable AD CS CA configurations. Ensure that the CA is not configured with the EDITF_ATTRIBUTESUBJECTALTNAME2 flag. When configured, this allows a SAN to be provided on any certificate template.
Require CA Certificate Manager approval for certificate templates that allow the SAN to be supplied. This ensures certificate templates that require CA certificate manager approval are not issued automatically when requested; instead, they must be approved using certificate manager before the certificate is issued.
Remove EKUs that enable user authentication. This prevents malicious actors from exploiting the certificate to authenticate as other users.
Limit access to AD CS CA servers to only privileged users that require access. This may be a smaller subset of privileged users than the Domain Admins security group and reduces the number of opportunities for malicious actors to gain access to CA servers.
Restrict privileged access pathways to AD CS CA servers to jump servers and secure admin workstations using only the ports and services that are required for administration. AD CS servers are classified as ‘Tier 0’ assets within Microsoft’s ‘Enterprise Access Model’.
Only use AD CS CA servers for AD CS and do not install any non-security-related services or applications. This reduces the attack surface of AD CS CA servers as there are fewer services, ports and applications that may be vulnerable and used to compromise an AD CS CA server.
Encrypt and securely store backups of AD CS CA servers and limit access to only Backup Administrators. Backups of AD CS CA servers need to be afforded the same security as the actual AD CS CA servers. Malicious actors may target backup systems to gain access to critical and sensitive computer objects, such as AD CS CA servers.
Centrally log and analyse AD CS CA server logs in a timely manner to identify malicious activity. If malicious actors gain privileged access to a CA server, this activity should be identified as soon as possible to respond and limit the impact.
Apply Patches:
Ensure your environment is protected against vulnerabilities like CVE-2022-26923.
Example Threat Hunting Queries
Identify Misconfigured Templates in AD CS:
Monitor Certificate Requests in Logs:
Look for Event ID 4886 for certificate requests and 4887 for issued certificates in the Certificate Services logs.
AD CS provides critical infrastructure for secure authentication and encryption, but misconfigurations or vulnerabilities can make it a target for attackers. A compromised AD CS environment can lead to privilege escalation, lateral movement, and persistent access, often with minimal detection. By hardening configurations, monitoring certificate activity, and addressing vulnerabilities, organisations can significantly reduce the risks associated with AD CS compromise.
KQL Detection Queries
Detecting potential compromise of Active Directory Certificate Services (AD CS) requires monitoring certificate issuance, template misuse, unauthorised access to AD CS services, and suspicious certificate requests. This detection can be achieved by querying logs from Windows Event Logs (Certificate Services logs) and Active Directory in Microsoft Sentinel using KQL.
Query to detect potential compromises in Active Directory Certificate Services (AD CS):
Query performs the following steps:
Defines the time range for the query to look back over the past 7 days.
Identifies suspicious certificate requests by looking for Event ID 4886 and summarising the data based on the requester and certificate template.
Identifies certificate issuance events by looking for Event ID 4887 and summarising the data based on the issuer and certificate template.
Combines the results to identify potential compromises by matching suspicious certificate requests with issuance events.
Splunk Detection Queries
To detect Active Directory Certificate Services (AD CS) compromise in Splunk, you can focus on Windows Security logs and Certificate Services logs for suspicious certificate requests, template abuse, and unauthorized access to Certificate Authority (CA) servers. Below is a Splunk query to detect suspicious AD CS activity.
Splunk Query to Detect AD CS Compromise
Query Breakdown
Target Events:
4886: Certificate request.
4887: Certificate issued.
4888: Certificate revoked.
4889: Certificate denied.
Field Parsing:
Extract key fields like
RequestorName
,TemplateName
, andCertificateSerialNumber
.Use
mvindex
to clean up usernames if they include domain prefixes.
Summarize Events:
Groups events by
EventCode
and aggregates key details likeTemplates
,Requestors
, andSerialNumbers
.
Filter Suspicious Activity:
Focuses on templates associated with high privileges (e.g., "Admin" or "DomainAdmin").
Assign Suspicious Scores:
Assigns a "High" score to requests using sensitive templates for easy prioritization.
Output Key Details:
Displays computers, event descriptions, templates, and requestors for SOC investigation.
Reference
Last updated