Skip to content
Access control Write-up Advanced

Certifried: Active Directory Domain Privilege Escalation (CVE-2022–26923)

A low-privileged domain user could create a machine account, clear its service principal names, and set its DNS host name to match the domain controller's. By requesting a certificate from the Machine template, the attacker obtained a certificate that the KDC mapped to the domain controller account, allowing them to authenticate as the DC and escalate to domain administrator.

Oliver Lyak Follow

Published on research.ifcr.dk

In this blog post, we’ll dive into a recently patched Active Directory Domain Privilege Escalation vulnerability that I reported through ZDI to Microsoft.

Oliver Lyak, on research.ifcr.dk

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 11 min read.

Context

This is a write-up of an Active Directory domain privilege escalation vulnerability that I reported through ZDI to Microsoft, tracked as CVE-2022-26923 and patched in the May 2022 Security Updates. In essence, the vulnerability allowed a low-privileged user to escalate privileges to domain administrator in a default Active Directory environment with the Active Directory Certificate Services (AD CS) server role installed. At Institute For Cyber Risk, we see AD CS environments on almost every engagement; it is rare to see large and medium-sized Active Directory environments without AD CS installed.

AD CS is Microsoft's public key infrastructure (PKI) implementation. It integrates tightly with Active Directory and enables the issuing of X.509 certificates that can be used for encryption, message signing and authentication. A certificate binds an identity (the subject) to a public/private key pair, and an application can use that key pair as proof of the identity of the user. Certificate Authorities (CAs) issue the certificates.

At a high level, a client generates a public/private key pair and places the public key in a certificate signing request (CSR) along with details such as the subject and the certificate template name. The client sends the CSR to the Enterprise CA. The CA checks whether the client is allowed to request certificates, looks up the certificate template AD object named in the CSR, and checks whether the template's permissions allow the authenticating account to obtain a certificate. If so, the CA generates a certificate using the template's settings (EKUs, cryptography settings, issuance requirements and so on) plus the information supplied in the CSR where the template allows it, signs the certificate with its private key and returns it to the client.

Users request certificates based on predefined templates. A template specifies the settings for the final certificate: whether it can be used for client authentication, which properties must be defined, who is allowed to enrol, and so on. This write-up focuses only on the client authentication aspect of AD CS.

Setup

For the examples I created the domain CORP.LOCAL with AD CS installed, and a default, low-privileged user named JOHN. The CA is named CORP-DC-CA. I used Certipy to request certificates and authenticate with them.

By default, domain users can enrol in the User certificate template and domain computers can enrol in the Machine certificate template. Both templates allow client authentication, so an issued certificate can be used to authenticate against the KDC through the PKINIT Kerberos extension.

In the first example I request a certificate from CORP-DC-CA based on the User template and then use the issued certificate john.pfx to authenticate against the KDC. When authenticating with a certificate, Certipy tries to request a Kerberos TGT and retrieve the NT hash of the account.

Finding it

Why does AD CS have different templates for users and computers? In short, user accounts have a User Principal Name (UPN), whereas computer accounts do not. When a certificate is requested based on the User template, the UPN of the user account is embedded in the certificate for identification. When the certificate is used for authentication, the KDC tries to map the UPN from the certificate to a user. The msPKI-Certificate-Name-Flag property of the User template specifies SubjectAltRequireUpn (CT_FLAG_SUBJECT_ALT_REQUIRE_UPN).

Per MS-ADTS (3.1.1.5.1.3 Uniqueness Constraints), the UPN must be unique, so two users cannot share a UPN. If I try to change the UPN of Jane to [redacted], I get a constraint violation, because that UPN is already used by John.

Computer accounts have no UPN, so what do they use for certificate authentication? The Machine template specifies SubjectAltRequireDns (CT_FLAG_SUBJECT_ALT_REQUIRE_DNS) instead. I created a new machine account, requested a certificate and authenticated with it. The certificate was issued with the DNS host name [redacted].local, and the computer account JOHNPC$ has that value in its dNSHostName property.

Looking at the permissions of the JOHNPC object, John, as the creator of the machine account, has the "Validated write to DNS host name" permission. Microsoft describes this as a "Validated write permission to enable setting of a DNS host name attribute that is compliant with the computer name and domain name." So what does "compliant with the computer name and domain name" mean?

As John I updated the DNS host name of JOHNPC to [redacted].local. There were no issues or constraint violations, and the SAM Account Name of JOHNPC was still JOHNPC$. Requesting a certificate again produced one with the DNS host name [redacted].local. So the DNS host name in the issued certificate is derived from the dNSHostName property, and the creator of the machine account can write that property.

The next observation was that MS-ADTS (3.1.1.5.1.3 Uniqueness Constraints) nowhere states that the dNSHostName property of a computer account must be unique. The domain controller's own account, DC$, has dNSHostName set to DC.CORP.LOCAL.

Exploitation

Step 1: try to point the machine account at the domain controller

I changed the dNSHostName property of JOHNPC to DC.CORP.LOCAL. This time I got an error saying "An operations error occurred", which is different from the constraint violation seen when changing a UPN to another user's UPN.

What happened: when the dNSHostName of JOHNPC was changed from [redacted].local to [redacted].local, the servicePrincipalName property of JOHNPC was updated to reflect the new value. Per MS-ADTS (3.1.1.5.1.3 Uniqueness Constraints), servicePrincipalName is checked for uniqueness. Updating dNSHostName to [redacted].local made the domain controller try to update servicePrincipalName to include RestrictedKrbHost/[redacted].local and HOST/[redacted].local, which conflict with the domain controller's own servicePrincipalName. So updating dNSHostName indirectly caused a constraint violation through the automatic SPN update.

Step 2: understand the SPN validation

The permissions of JOHNPC also give John, as the creator of the machine account, the "Validated write to service principal name" permission. Microsoft describes it as a "Validated write permission to enable setting of the SPN attribute which is compliant to the DNS host name of the computer." So updated servicePrincipalName values must be compliant with dNSHostName.

Only two values are updated and checked when dNSHostName changes: RestrictedKrbHost/[redacted].local and HOST/[redacted].local, which contain the dNSHostName value. The other two values, RestrictedKrbHost/JOHNPC and HOST/JOHNPC, contain the sAMAccountName value without the trailing $. Only the servicePrincipalName values that contain the dNSHostName value must be compliant with it.

Step 3: delete the DNS-derived SPNs, then set the duplicate host name

Can the servicePrincipalName values that contain the dNSHostName be deleted? Yes. With those values gone, updating dNSHostName of JOHNPC to [redacted].local no longer forces the domain controller to update servicePrincipalName, because none of the remaining values contain the dNSHostName value.

I updated the dNSHostName property of JOHNPC to [redacted].local. It succeeded: dNSHostName was set to [redacted].local and servicePrincipalName was unaffected, so no constraint violation occurred. JOHNPC now has the same dNSHostName as the domain controller DC$.

Step 4: request a certificate and authenticate

I requested a certificate for JOHNPC using the Machine template, which embeds the dNSHostName property as identification. The certificate was issued with the DNS host name [redacted].local. Authenticating with it also succeeded, and Certipy retrieved the NT hash for dc$. As a proof of concept, that NT hash can be used to perform a DCSync attack and dump the hashes of all users.

Why the KDC mapped the certificate to the domain controller

PKINIT is the Kerberos extension that allows certificates for initial authentication. To use a certificate for Kerberos authentication, it must be configured with the "Client Authentication" EKU and some identification of the account. The Windows implementation is described in MS-PKCA, which specifies how the KDC maps a certificate to an account (MS-PKCA 3.1.5.2.1).

First the account is looked up based on the principal name in the AS-REQ, for example [redacted]. Then, depending on the account's userAccountControl property, the KDC validates the mapping from either the SAN DNSName or the SAN UPNName in the certificate. If the WORKSTATION_TRUST_ACCOUNT (domain computer) or SERVER_TRUST_ACCOUNT (domain controller) bit is set, the KDC validates the mapping from the DNSName; otherwise it validates from the UPNName. The DNSName mapping is described in MS-PKCA 3.1.5.2.1.1.

The KDC must confirm that the sAMAccountName of the looked-up account matches the computer name in the DNSName field terminated with $, and that the DNS domain name in the DNSName field matches the DNS domain name of the realm. For the computer account JOHNPC$ in [redacted], a valid mapping requires the DNSName [redacted].local, that is <computername>.<domain>, where <computername> is the sAMAccountName without the trailing $.

So during PKINIT authentication we supply a principal name such as johnpc$@[redacted] and a certificate whose DNSName is [redacted].local. The KDC looks up the account from the principal name; because johnpc$ is a computer account, it splits the DNSName into a computer name part and a realm part, then validates that the computer name part matches the sAMAccountName terminated with $ and that the realm part matches the domain. If both match, the mapping is valid. The dNSHostName property is not used for the certificate mapping at all; it is only used when the certificate is requested.

Root cause

The design flaw is the gap between two checks. The CA derives the DNSName in the certificate from the writable dNSHostName property, and the KDC validates the DNSName against the sAMAccountName of the account named in the AS-REQ. Nothing enforces that dNSHostName is unique across the directory, and the creator of a machine account holds the validated write permissions over both dNSHostName and servicePrincipalName. The only obstacle was the automatic SPN update colliding with the domain controller's SPNs, and that obstacle disappears once the DNS-derived SPN values are deleted, because only SPN values containing the dNSHostName value are checked for compliance with it.

Impact

A low-privileged user can escalate to domain administrator in a default Active Directory environment with AD CS installed, by creating a machine account, giving it the domain controller's DNS host name, obtaining a certificate for it and authenticating as the domain controller. With the resulting NT hash of dc$, a DCSync attack dumps the hashes of all users. The attack requires the ability to create a machine account; the MS-DS-Machine-Account-Quota attribute defaults to 10.

Fix

Microsoft patched the vulnerability in the May 2022 Security Updates by introducing a new Object ID (OID) in new certificates to further fingerprint the user: the user's objectSid (SID) is embedded within the new szOID_NTDS_CA_SECURITY_EXT (1.3.6.1.4.1.311.25.2) OID. Certificate templates with the new CT_FLAG_NO_SECURITY_EXTENSION (0x80000) flag set in the msPKI-Enrollment-Flag attribute will not embed the new OID and are therefore still vulnerable to this attack. It is unlikely that this flag is set, but you should be aware of the implications of turning it on. Furthermore, the "Validated write to DNS host name" permission now only allows setting a dNSHostName attribute that matches the SAM Account Name of the account; however, with a generic write permission over the computer account it is still possible to create a duplicate dNSHostName value.

An attempt to exploit the vulnerability against a patched domain controller returns KDC_ERR_CERTIFICATE_MISMATCH during Kerberos authentication if the certificate has the szOID_NTDS_CA_SECURITY_EXT OID. I also tried authenticating with Schannel against LDAPS to check whether the vulnerability was only patched in the Kerberos implementation; that method cannot bypass the security update. There might be other interesting cases, since the dNSHostName property can still be duplicated and embedded in the certificate. To check whether a CA is vulnerable, request a certificate and check whether the user's SID is embedded in it. Both the KDC and the CA server must be patched to fully mitigate the vulnerability.

The patch also brings an end to the ESC6 attack described in Will Schroeder and Lee Christensen's whitepaper, but the ESC1 attack still works, since the new OID is not embedded in certificates based on templates with the ENROLLEE_SUPPLIES_SUBJECT flag specified.

If the patch cannot be installed, you can harden the AD CS environment by restricting certificate enrolment. Separately, you can change the MS-DS-Machine-Account-Quota attribute to 0; it determines how many computer accounts a user may create in a domain and defaults to 10. This is not a mitigation of the vulnerability, since an attacker might compromise an existing machine account, for instance by compromising a workstation with KrbRelay.

Certipy was updated alongside this write-up with functionality to easily create a new machine account with the DNS host name [redacted].local and then request a certificate.

Variants to test

  1. Request a certificate from a template that allows client authentication and check whether the issued certificate contains the szOID_NTDS_CA_SECURITY_EXT OID with the account's SID.
  2. Create a machine account, delete the servicePrincipalName values containing the dNSHostName, and set dNSHostName to the domain controller's host name. A successful write with no constraint violation is the precondition for the attack.
  3. Request a Machine template certificate for that account and authenticate with the domain controller's principal name. A returned TGT and the dc$ NT hash confirm the escalation; KDC_ERR_CERTIFICATE_MISMATCH indicates a patched KDC.
  4. Try the same certificate against LDAPS with Schannel. I also tried authenticating with Schannel against LDAPS; that method cannot bypass the security update.
  5. Check templates with ENROLLEE_SUPPLIES_SUBJECT for the ESC1 case, which the patch does not address.

Disclosure timeline

  • Dec 14, 2021: Vulnerability reported to Zero Day Initiative
  • Dec 17, 2021: Case assigned
  • Dec 31, 2021: Case investigated
  • Jan 11, 2022: Case contracted
  • Jan 20, 2022: Case reviewed
  • Jan 21, 2022: Vendor disclosure, tracked as ZDI-CAN-16168
  • May 10, 2022: Patch released by Microsoft

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 23 min read.

What happened, in plain words

Imagine a large office building where every employee has a badge. The badge is issued by a reception desk, and the security guard at the door trusts whatever the badge says. One day someone works out that the reception desk will happily print a badge saying "I am the building manager" if you fill in the form in a particular way, and the guard at the door has no way to tell that badge apart from the real manager's. That is roughly what this vulnerability was.

The building here is an Active Directory domain, the reception desk is a certificate authority, the badge is a digital certificate, and the guard is the Kerberos key distribution centre. A normal, low-privileged user could end up with the digital equivalent of the domain administrator's badge.

This is a write-up of an Active Directory domain privilege escalation vulnerability that I reported through ZDI to Microsoft. It is tracked as CVE-2022-26923 and was patched in the May 2022 Security Updates. In essence, the vulnerability allowed a low-privileged user to escalate privileges to domain administrator in a default Active Directory environment with the Active Directory Certificate Services (AD CS) server role installed. At Institute For Cyber Risk, we see AD CS environments on almost every engagement; it is rare to see large and medium-sized Active Directory environments without AD CS installed.

A few words before we start, because the rest of the article leans on them.

Active Directory is Microsoft's directory service: a database, plus the software around it, that stores every user, every computer and every permission in a Windows network. Think of it as the company's internal phone book and access-control list rolled into one. When you log in to a work laptop, Active Directory is what checks your password and decides what you are allowed to open.

A domain is one such directory, with its own name. In the examples here the domain is called CORP.LOCAL. A domain controller is the server that runs the directory and answers login requests. The domain controller has its own account in the directory, just like a user does.

Privilege escalation means going from a low level of permission to a higher one. A domain administrator is the highest level in a domain: that account can read and change essentially everything, including the password hashes of every user.

Active Directory Certificate Services (AD CS) is Microsoft's public key infrastructure (PKI) implementation. A PKI is a system for issuing and checking digital certificates. AD CS integrates tightly with Active Directory and enables the issuing of X.509 certificates that can be used for encryption, message signing and authentication. A certificate binds an identity (the subject) to a public/private key pair, and an application can use that key pair as proof of the identity of the user. Certificate Authorities (CAs) issue the certificates.

If certificates are new to you, the everyday comparison is a passport. A passport office (the CA) checks who you are and prints a document that other people trust because they recognise the office's stamp. The passport contains your photo and details (the subject) and is hard to forge (the signature). A digital certificate does the same job for computers: it says "this key belongs to this identity" and carries the CA's cryptographic signature so anyone can verify it.

At a high level, a client generates a public/private key pair and places the public key in a certificate signing request (CSR) along with details such as the subject and the certificate template name. The client sends the CSR to the Enterprise CA. The CA checks whether the client is allowed to request certificates, looks up the certificate template AD object named in the CSR, and checks whether the template's permissions allow the authenticating account to obtain a certificate. If so, the CA generates a certificate using the template's settings (EKUs, cryptography settings, issuance requirements and so on) plus the information supplied in the CSR where the template allows it, signs the certificate with its private key and returns it to the client.

A key pair is two mathematically linked keys: one public, which you hand out freely, and one private, which you keep secret. Something signed with the private key can be checked with the public key, and something encrypted with the public key can only be opened with the private key. A CSR is the form you fill in to ask for a certificate; it carries your public key and the details you want on the certificate. A certificate template is a blueprint: it says what a certificate of this kind may contain, what it may be used for, and who is allowed to ask for one.

Users request certificates based on predefined templates. A template specifies the settings for the final certificate: whether it can be used for client authentication, which properties must be defined, who is allowed to enrol, and so on. This write-up focuses only on the client authentication aspect of AD CS, that is, using a certificate to prove who you are when logging in.

Setting up the example

For the examples I created the domain CORP.LOCAL with AD CS installed, and a default, low-privileged user named JOHN. The CA is named CORP-DC-CA. I used Certipy to request certificates and authenticate with them.

Certipy is a tool that talks to AD CS and to the Kerberos login service on your behalf, so you do not have to craft the requests by hand. Kerberos is the login protocol Active Directory uses: instead of sending your password to every server, you ask one central service for a ticket, and you show that ticket to the servers you want to use. The central service is the KDC, the Key Distribution Centre, which runs on the domain controller. The ticket you get first is called a TGT, a Ticket Granting Ticket; it is the proof that you logged in, and you use it to obtain further tickets for individual services.

By default, domain users can enrol in the User certificate template and domain computers can enrol in the Machine certificate template. Both templates allow client authentication, so an issued certificate can be used to authenticate against the KDC through the PKINIT Kerberos extension.

PKINIT is the part of Kerberos that lets you log in with a certificate instead of a password. Enrol simply means "sign up for and receive" a certificate from a template.

In the first example I request a certificate from CORP-DC-CA based on the User template and then use the issued certificate john.pfx to authenticate against the KDC. When authenticating with a certificate, Certipy tries to request a Kerberos TGT and retrieve the NT hash of the account.

A PFX file is a container that holds a certificate together with its private key, usually protected by a password. An NT hash is the way Windows stores a user's password internally: not the password itself, but a value derived from it that the system can check against. If you obtain someone's NT hash, you can often log in as them without ever knowing their password, which is why hashes are treated as secrets.

Finding the flaw

Why does AD CS have different templates for users and computers? In short, user accounts have a User Principal Name (UPN), whereas computer accounts do not. When a certificate is requested based on the User template, the UPN of the user account is embedded in the certificate for identification. When the certificate is used for authentication, the KDC tries to map the UPN from the certificate to a user. The msPKI-Certificate-Name-Flag property of the User template specifies SubjectAltRequireUpn (CT_FLAG_SUBJECT_ALT_REQUIRE_UPN).

A UPN is the login name that looks like an email address, for example [redacted]. It is the name you type at the Windows login screen. The Subject Alternative Name, or SAN, is a field inside a certificate that lists the identities the certificate is valid for; it can hold a UPN, a DNS name, or both. The msPKI-Certificate-Name-Flag is a setting on the template that tells the CA which of those fields it must fill in and require. SubjectAltRequireUpn means: the certificate must carry a UPN in its SAN.

Per MS-ADTS (3.1.1.5.1.3 Uniqueness Constraints), the UPN must be unique, so two users cannot share a UPN. If I try to change the UPN of Jane to [redacted], I get a constraint violation, because that UPN is already used by John.

MS-ADTS is Microsoft's published specification of how Active Directory works; it is the rulebook the directory follows. A constraint violation is the directory refusing a change because it would break one of those rules, in this case the rule that no two accounts may share a UPN. The comparison is a company that will not let two employees have the same email address.

Computer accounts have no UPN, so what do they use for certificate authentication? The Machine template specifies SubjectAltRequireDns (CT_FLAG_SUBJECT_ALT_REQUIRE_DNS) instead. I created a new machine account, requested a certificate and authenticated with it. The certificate was issued with the DNS host name [redacted].local, and the computer account JOHNPC$ has that value in its dNSHostName property.

A computer account is the directory entry that represents a machine rather than a person. Its name conventionally ends with a dollar sign, so the computer account for the machine JOHNPC is JOHNPC$. The dNSHostName property is the field that stores the machine's full DNS name, the name other computers use to reach it on the network. SubjectAltRequireDns means: the certificate must carry a DNS name in its SAN instead of a UPN.

Looking at the permissions of the JOHNPC object, John, as the creator of the machine account, has the "Validated write to DNS host name" permission. Microsoft describes this as a "Validated write permission to enable setting of a DNS host name attribute that is compliant with the computer name and domain name." So what does "compliant with the computer name and domain name" mean?

An object here means one entry in the directory, such as a user or a computer. Permissions on an object decide who may read or change which of its fields. A validated write is a special kind of write permission: you may change the field, but the directory checks the new value against a rule before accepting it. The comparison is a form field on a website that rejects anything that does not look like a valid postcode.

As John I updated the DNS host name of JOHNPC to [redacted].local. There were no issues or constraint violations, and the SAM Account Name of JOHNPC was still JOHNPC$. Requesting a certificate again produced one with the DNS host name [redacted].local. So the DNS host name in the issued certificate is derived from the dNSHostName property, and the creator of the machine account can write that property.

The SAM Account Name is the short login name of an account, the one without the domain part; for a computer it is the machine name plus the trailing $. The important finding here is the chain: I can write dNSHostName, and the CA copies dNSHostName into the certificate. Whatever I put in that field ends up on the badge.

The next observation was that MS-ADTS (3.1.1.5.1.3 Uniqueness Constraints) nowhere states that the dNSHostName property of a computer account must be unique. The domain controller's own account, DC$, has dNSHostName set to DC.CORP.LOCAL.

So the rulebook requires UPNs to be unique but says nothing about DNS host names. That is the gap. If I can give my own machine account the same DNS host name as the domain controller, the CA will print me a certificate that says DC.CORP.LOCAL.

Exploitation

Step 1: try to point the machine account at the domain controller

I changed the dNSHostName property of JOHNPC to DC.CORP.LOCAL. This time I got an error saying "An operations error occurred", which is different from the constraint violation seen when changing a UPN to another user's UPN.

Why did I try this? Because the previous step showed that the certificate copies dNSHostName, and the domain controller's own host name is the one worth copying. The error was unexpected, so the next job was to understand it rather than work around it blindly.

What happened: when the dNSHostName of JOHNPC was changed from [redacted].local to [redacted].local, the servicePrincipalName property of JOHNPC was updated to reflect the new value. Per MS-ADTS (3.1.1.5.1.3 Uniqueness Constraints), servicePrincipalName is checked for uniqueness. Updating dNSHostName to [redacted].local made the domain controller try to update servicePrincipalName to include RestrictedKrbHost/[redacted].local and HOST/[redacted].local, which conflict with the domain controller's own servicePrincipalName. So updating dNSHostName indirectly caused a constraint violation through the automatic SPN update.

A service principal name, or SPN, is the name a service advertises so that clients can find it. When you ask Kerberos for a ticket to a particular service, you name the service by its SPN. A computer account normally carries several SPNs built from its host name, such as HOST/... and RestrictedKrbHost/.... The directory keeps these in step with dNSHostName automatically: change the host name, and the SPNs that contain it are rewritten. Because SPNs must be unique, rewriting them to the domain controller's name collides with the domain controller's own SPNs, and the whole change is rejected. The comparison is renaming your desk plate to the manager's name and finding that the building's sign system refuses because the manager already has that plate.

Step 2: understand the SPN validation

The permissions of JOHNPC also give John, as the creator of the machine account, the "Validated write to service principal name" permission. Microsoft describes it as a "Validated write permission to enable setting of the SPN attribute which is compliant to the DNS host name of the computer." So updated servicePrincipalName values must be compliant with dNSHostName.

Only two values are updated and checked when dNSHostName changes: RestrictedKrbHost/[redacted].local and HOST/[redacted].local, which contain the dNSHostName value. The other two values, RestrictedKrbHost/JOHNPC and HOST/JOHNPC, contain the sAMAccountName value without the trailing $. Only the servicePrincipalName values that contain the dNSHostName value must be compliant with it.

This is the key detail. The SPNs come in two flavours: some are built from the host name, some from the short account name. Only the host-name ones are rewritten and checked when the host name changes. The short-name ones are left alone. So the collision comes only from the host-name SPNs, and if those are not there, there is nothing to collide.

Step 3: delete the DNS-derived SPNs, then set the duplicate host name

Can the servicePrincipalName values that contain the dNSHostName be deleted? Yes. With those values gone, updating dNSHostName of JOHNPC to [redacted].local no longer forces the domain controller to update servicePrincipalName, because none of the remaining values contain the dNSHostName value.

I updated the dNSHostName property of JOHNPC to [redacted].local. It succeeded: dNSHostName was set to [redacted].local and servicePrincipalName was unaffected, so no constraint violation occurred. JOHNPC now has the same dNSHostName as the domain controller DC$.

In other words, I removed the two SPNs that would have been rewritten, then made the change that previously failed. With nothing left to rewrite, there was nothing left to collide, and the directory accepted the duplicate host name.

Step 4: request a certificate and authenticate

I requested a certificate for JOHNPC using the Machine template, which embeds the dNSHostName property as identification. The certificate was issued with the DNS host name [redacted].local. Authenticating with it also succeeded, and Certipy retrieved the NT hash for dc$. As a proof of concept, that NT hash can be used to perform a DCSync attack and dump the hashes of all users.

DCSync is a technique that asks a domain controller to replicate directory data, the way one domain controller syncs with another. If you can make that request with the right permissions, the domain controller hands over the stored password hashes of the accounts. The comparison is convincing the archive clerk that you are a branch office entitled to a full copy of the records.

Why the KDC mapped the certificate to the domain controller

PKINIT is the Kerberos extension that allows certificates for initial authentication. To use a certificate for Kerberos authentication, it must be configured with the "Client Authentication" EKU and some identification of the account. The Windows implementation is described in MS-PKCA, which specifies how the KDC maps a certificate to an account (MS-PKCA 3.1.5.2.1).

An EKU, or Extended Key Usage, is a field in a certificate that says what the certificate may be used for, for example client authentication or server authentication. It is the difference between a passport and a driving licence: both prove identity, but each is only accepted for certain purposes. MS-PKCA is Microsoft's specification of how PKINIT works on Windows.

First the account is looked up based on the principal name in the AS-REQ, for example [redacted]. Then, depending on the account's userAccountControl property, the KDC validates the mapping from either the SAN DNSName or the SAN UPNName in the certificate. If the WORKSTATION_TRUST_ACCOUNT (domain computer) or SERVER_TRUST_ACCOUNT (domain controller) bit is set, the KDC validates the mapping from the DNSName; otherwise it validates from the UPNName. The DNSName mapping is described in MS-PKCA 3.1.5.2.1.1.

An AS-REQ is the first message of a Kerberos login: the client asking the KDC for a TGT and naming the account it wants to log in as. The userAccountControl property is a set of on/off switches stored on every account; the WORKSTATION_TRUST_ACCOUNT and SERVER_TRUST_ACCOUNT switches mark an account as a computer or a domain controller respectively. The KDC reads those switches to decide which field of the certificate to trust.

The KDC must confirm that the sAMAccountName of the looked-up account matches the computer name in the DNSName field terminated with $, and that the DNS domain name in the DNSName field matches the DNS domain name of the realm. For the computer account JOHNPC$ in [redacted], a valid mapping requires the DNSName [redacted].local, that is <computername>.<domain>, where <computername> is the sAMAccountName without the trailing $.

So during PKINIT authentication we supply a principal name such as johnpc$@[redacted] and a certificate whose DNSName is [redacted].local. The KDC looks up the account from the principal name; because johnpc$ is a computer account, it splits the DNSName into a computer name part and a realm part, then validates that the computer name part matches the sAMAccountName terminated with $ and that the realm part matches the domain. If both match, the mapping is valid. The dNSHostName property is not used for the certificate mapping at all; it is only used when the certificate is requested.

This is the second half of the gap. The CA builds the certificate from dNSHostName, which I control. The KDC checks the certificate against the account named in the login request, not against dNSHostName. So I ask to log in as dc$, present a certificate whose DNS name is [redacted].local, and the KDC finds that the name part matches dc$ and the domain part matches the realm. Both checks pass, and the KDC issues a TGT for the domain controller.

Root cause

The design flaw is the gap between two checks. The CA derives the DNSName in the certificate from the writable dNSHostName property, and the KDC validates the DNSName against the sAMAccountName of the account named in the AS-REQ. Nothing enforces that dNSHostName is unique across the directory, and the creator of a machine account holds the validated write permissions over both dNSHostName and servicePrincipalName. The only obstacle was the automatic SPN update colliding with the domain controller's SPNs, and that obstacle disappears once the DNS-derived SPN values are deleted, because only SPN values containing the dNSHostName value are checked for compliance with it.

Impact

A low-privileged user can escalate to domain administrator in a default Active Directory environment with AD CS installed, by creating a machine account, giving it the domain controller's DNS host name, obtaining a certificate for it and authenticating as the domain controller. With the resulting NT hash of dc$, a DCSync attack dumps the hashes of all users. The attack requires the ability to create a machine account; the MS-DS-Machine-Account-Quota attribute defaults to 10.

The fix

Microsoft patched the vulnerability in the May 2022 Security Updates by introducing a new Object ID (OID) in new certificates to further fingerprint the user: the user's objectSid (SID) is embedded within the new szOID_NTDS_CA_SECURITY_EXT (1.3.6.1.4.1.311.25.2) OID. Certificate templates with the new CT_FLAG_NO_SECURITY_EXTENSION (0x80000) flag set in the msPKI-Enrollment-Flag attribute will not embed the new OID and are therefore still vulnerable to this attack. It is unlikely that this flag is set, but you should be aware of the implications of turning it on. Furthermore, the "Validated write to DNS host name" permission now only allows setting a dNSHostName attribute that matches the SAM Account Name of the account; however, with a generic write permission over the computer account it is still possible to create a duplicate dNSHostName value.

An OID, or Object Identifier, is a numeric label for a specific thing in a standard, written as a dotted string of numbers. A SID, or security identifier, is the unique number that identifies an account inside a Windows domain; unlike a name, it cannot be chosen by the person creating the account. The fix adds the account's SID to the certificate, so the KDC can check the certificate against the account's real, unchangeable identity rather than only against a name that can be copied. The comparison is adding a serial number to the badge that the guard can check against the register.

An attempt to exploit the vulnerability against a patched domain controller returns KDC_ERR_CERTIFICATE_MISMATCH during Kerberos authentication if the certificate has the szOID_NTDS_CA_SECURITY_EXT OID. I also tried authenticating with Schannel against LDAPS to check whether the vulnerability was only patched in the Kerberos implementation; that method cannot bypass the security update. There might be other interesting cases, since the dNSHostName property can still be duplicated and embedded in the certificate. To check whether a CA is vulnerable, request a certificate and check whether the user's SID is embedded in it. Both the KDC and the CA server must be patched to fully mitigate the vulnerability.

KDC_ERR_CERTIFICATE_MISMATCH is the error the KDC returns when the certificate does not match the account. Schannel is the Windows component that handles TLS, the encryption used by secure websites and by LDAPS. LDAPS is the encrypted version of LDAP, the protocol used to query and modify the directory. The point of trying Schannel was to check whether the same trick worked over a different login path; it did not.

The patch also brings an end to the ESC6 attack described in Will Schroeder and Lee Christensen's whitepaper, but the ESC1 attack still works, since the new OID is not embedded in certificates based on templates with the ENROLLEE_SUPPLIES_SUBJECT flag specified.

ESC1 and ESC6 are names given in that whitepaper to particular ways of abusing certificate templates. ENROLLEE_SUPPLIES_SUBJECT is a template setting that lets the person requesting the certificate choose the subject written into it, which is dangerous on its own.

If the patch cannot be installed, you can harden the AD CS environment by restricting certificate enrolment. Separately, you can change the MS-DS-Machine-Account-Quota attribute to 0; it determines how many computer accounts a user may create in a domain and defaults to 10. This is not a mitigation of the vulnerability, since an attacker might compromise an existing machine account, for instance by compromising a workstation with KrbRelay.

Harden means reducing the attack surface by tightening settings. The MS-DS-Machine-Account-Quota is the directory setting that says how many computer accounts an ordinary user may create; setting it to 0 stops users creating new ones. KrbRelay is a tool that abuses Kerberos authentication relay to take over an existing machine account, which is why the quota change alone does not close the hole.

Certipy was updated alongside this write-up with functionality to easily create a new machine account with the DNS host name [redacted].local and then request a certificate.

Variants to test

  1. Request a certificate from a template that allows client authentication and check whether the issued certificate contains the szOID_NTDS_CA_SECURITY_EXT OID with the account's SID.
  2. Create a machine account, delete the servicePrincipalName values containing the dNSHostName, and set dNSHostName to the domain controller's host name. A successful write with no constraint violation is the precondition for the attack.
  3. Request a Machine template certificate for that account and authenticate with the domain controller's principal name. A returned TGT and the dc$ NT hash confirm the escalation; KDC_ERR_CERTIFICATE_MISMATCH indicates a patched KDC.
  4. Try the same certificate against LDAPS with Schannel. I also tried authenticating with Schannel against LDAPS; that method cannot bypass the security update.
  5. Check templates with ENROLLEE_SUPPLIES_SUBJECT for the ESC1 case, which the patch does not address.

Disclosure timeline

  • Dec 14, 2021: Vulnerability reported to Zero Day Initiative
  • Dec 17, 2021: Case assigned
  • Dec 31, 2021: Case investigated
  • Jan 11, 2022: Case contracted
  • Jan 20, 2022: Case reviewed
  • Jan 21, 2022: Vendor disclosure, tracked as ZDI-CAN-16168
  • May 10, 2022: Patch released by Microsoft

Zero Day Initiative (ZDI) is a programme that receives vulnerability reports and passes them to the affected vendor. Vendor disclosure is the point at which the vendor is formally told about the issue.

Glossary

  • Active Directory: Microsoft's directory service, the database and software that store users, computers and permissions in a Windows network.
  • AD CS (Active Directory Certificate Services): Microsoft's public key infrastructure, the system that issues and manages digital certificates inside a domain.
  • AS-REQ: the first message of a Kerberos login, in which the client asks the KDC for a TGT and names the account it wants to log in as.
  • CA (Certificate Authority): the component that checks a certificate request and signs the resulting certificate.
  • Certificate: a digitally signed document that binds an identity to a public key.
  • Certificate template: a blueprint that defines what a certificate may contain, what it may be used for, and who may request one.
  • Computer account: the directory entry representing a machine, conventionally ending in $.
  • Constraint violation: the directory refusing a change because it would break a uniqueness or format rule.
  • CSR (Certificate Signing Request): the form a client sends to a CA to ask for a certificate, carrying its public key and the details it wants on the certificate.
  • DCSync: a technique that asks a domain controller to replicate directory data, including password hashes, as if it were another domain controller.
  • Domain: one Active Directory directory with its own name, such as CORP.LOCAL.
  • Domain administrator: the highest-privileged account in a domain.
  • Domain controller: the server that runs the directory and answers login requests.
  • dNSHostName: the property on a computer account that stores its full DNS name.
  • EKU (Extended Key Usage): a certificate field that says what the certificate may be used for, such as client authentication.
  • Enrol: to sign up for and receive a certificate from a template.
  • ESC1 / ESC6: names given in the Certified Pre-Owned whitepaper to particular ways of abusing certificate templates.
  • Harden: to reduce attack surface by tightening settings.
  • KDC (Key Distribution Centre): the Kerberos service, running on the domain controller, that issues tickets.
  • Kerberos: the login protocol Active Directory uses, based on tickets rather than sending passwords to every server.
  • Key pair: a public key that can be shared and a private key that must stay secret, linked mathematically.
  • KrbRelay: a tool that abuses Kerberos authentication relay to take over an existing machine account.
  • LDAPS: the encrypted version of LDAP, the protocol used to query and modify the directory.
  • MS-ADTS: Microsoft's published specification of how Active Directory works.
  • MS-PKCA: Microsoft's specification of how PKINIT works on Windows.
  • NT hash: the value Windows derives from a password and stores internally; possessing it often allows logging in as the account.
  • Object: one entry in the directory, such as a user or a computer.
  • OID (Object Identifier): a numeric label for a specific thing in a standard, written as a dotted string of numbers.
  • Permissions: the rules on an object that decide who may read or change which fields.
  • PFX: a file that holds a certificate together with its private key.
  • PKI (Public Key Infrastructure): a system for issuing, distributing and checking digital certificates.
  • PKINIT: the Kerberos extension that allows logging in with a certificate instead of a password.
  • Privilege escalation: moving from a lower level of permission to a higher one.
  • SAM Account Name: the short login name of an account, without the domain part.
  • SAN (Subject Alternative Name): a certificate field listing the identities the certificate is valid for, such as a UPN or a DNS name.
  • Schannel: the Windows component that handles TLS, the encryption used by secure websites and LDAPS.
  • SID (Security Identifier): the unique, unchangeable number that identifies an account in a Windows domain.
  • SPN (Service Principal Name): the name a service advertises so clients can find it, stored on the account and required to be unique.
  • TGT (Ticket Granting Ticket): the first Kerberos ticket, proving you have logged in and used to obtain further tickets.
  • UPN (User Principal Name): the login name that looks like an email address, such as [redacted].
  • userAccountControl: a set of on/off switches stored on every account, marking it as a user, computer or domain controller among other things.
  • Validated write: a write permission where the directory checks the new value against a rule before accepting it.
  • Zero Day Initiative (ZDI): a programme that receives vulnerability reports and passes them to the affected vendor.

More by Oliver Lyak

View all

2 more disclosed reports, best first.

More from Microsoft

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.