WriteCertificateNameFlag

Summary

FSProtect ACL Alias

WriteCertificateNameFlag

AD Alias

Write msPKI-Certificate-Name-Flag

Affected Object Types

Certificate Templates

Exploitation Certainty

Likely

AD Attribute

msPKI-Certificate-Name-Flag

AD Attribute Guid

ea1dddc4-60ff-416e-8cc0-17cee534bce7

AD Right

WriteProperty

Description

The WriteCertificateNameFlag permission in Active Directory allows an account to modify the msPKI-Certificate-Name-Flag attribute on certificate templates. This attribute is crucial for PKI security as it controls several aspects of certificate enrollment, particularly how subject names are generated, validated, and included in certificates. When properly configured by administrators WriteCertificateNameFlag permissions, these settings ensure certificate identities reflect organizational structures, contain accurate user information, comply with naming policies, and maintain strong identity assurance throughout the certificate lifecycle all essential for secure authentication and encrypted communications across enterprise resources.

However, if misconfigured, the WriteCertificateNameFlag permission can introduce significant security vulnerabilities. An attacker with this permission could modify the certificate template to enable the "Enrollee supplies subject" flag. When this flag is active, users can request certificates with any subject name they choose, regardless of their actual identity. This could allow an attacker to impersonate other entities, including trusted services or privileged users, by obtaining certificates with their identities. Such exploitation could lead to man-in-the-middle attacks, unauthorized authentication, and compromise of encrypted communications across the organization's infrastructure.

Identification

PowerShell

Active Directory Module

Using the ActiveDirectory PowerShell module, you can enumerate WriteCertificateNameFlag entries.

1. Find-WriteCertificateNameFlag function

2. Scan all templates in the domain

3. Scan a specified template

.NET Directory Services

By leveraging PowerShell’s built-in .NET DirectoryServices namespace, you can enumerate WriteCertificateNameFlag entries without relying on any external modules or dependencies.

1. Find-WriteCertificateNameFlagSimple function

2. Scan all domain templates

3. Scan a specific template

Active Directory Services Interface

1. Open Active Directory Services Interface (ADSI Edit).

2. Right-click ADSI Edit and select Connect to... from the context menu.

3. Select Configuration in Select a well-known Naming Context and click OK.

4. Go to Configuration > Services > Public Key Services > Certificate Templates.

5. In the Certificate Templates list, double-click the Certificate Template.

6. In the Properties window, navigate to the Security tab.

7. Click on the Advanced button to open the Advanced Security Settings dialog.

8. In the Advanced Security Settings window, locate and select the relevant Access Control Entry (ACE) for the user or group you wish to configure.

9. Click Edit to modify the selected ACE.

10. In the permissions list, locate and check the option Write msPKI-Certificate-Name-Flag.

11. Click OK to save your changes and close the dialogs.

Exploitation

When a certificate template includes both authentication and enrollment permissions, enabling supply alternative subject makes it vulnerable to ESC01 a common misconfiguration in Active Directory Certificate Services (AD CS).

ESC01 allows low-privileged users to request authentication certificates for other users, including domain admins, by specifying arbitrary subject names (e.g., UPN or SAN). This can lead to privilege escalation and full domain compromise.

This permission can be exploitable on Windows systems with certify and rubeus, while on Linux systems, tools such as certipy can be effectively used for exploitation.Certify, Rubeus, Certipy

The following examples demonstrate exploitation on Windows and Linux environments.

Windows

First, modify the certificate template's msPKI-Certificate-Name-Flag attribute using PowerShell:

After modifying the template, request a certificate with an impersonated subject:

After running Certify, save the issued certificate as a PEM file. Then use OpenSSL to convert it to PFX format.

Then use the certificate to authenticate as the target user and dump the NTLM hash.

For example:

Using the Administrator account SID

Linux

First, modify the certificate template's msPKI-Certificate-Name-Flag attribute using BloodyAD:

For example:

After setting the flag, the attacker can actively enroll a certificate from the CA using Linux tools. This results in a .pfx certificate file that can be used for authentication and impersonation.

For example:

Retrieve the NTLM hash

For example:

Important Note

After you have obtained the certificate, you can impersonate any user with this certificate.

Mitigation

1. Open Active Directory Services Interface (ADSI Edit).

2. Right-click ADSI Edit and select Connect to... from the context menu.

3. Select Configuration in Select a well-known Naming Context and click OK.

4. Go to Configuration > Services > Public Key Services > Certificate Templates.

5. In the Certificate Templates list, double-click the Certificate Template.

6. In the Properties window, navigate to the Security tab.

7. Click on the Advanced button to open the Advanced Security Settings dialog.

8. In the Advanced Security Settings window, locate and select the relevant Access Control Entry (ACE) for the user or group you wish to configure.

9. Click Edit to modify the selected ACE.

10. In the permissions list, locate and remove the option Write msPKI-Certificate-Name-Flag.

11. Click OK to save your changes and close the dialogs.

Detection

Adding new Access Control Entries to Active Directory objects changes the ntSecurityDescriptor attribute of the objects themselves. These changes can be detected with the 5136 and 4662 Event IDs to identify dangerous modifications.

Event ID
Description
Fields/Attributes
References

5136

A directory service object was modified.

ntSecurityDescriptor

https://learn.microsoft.com/en-us/windows/security/threat-protection/auditing/event-5136

4662

An operation was performed on an object.

AccessList, AccessMask

https://learn.microsoft.com/en-us/windows/security/threat-protection/auditing/event-4662

4886

Certificate Services received a certificate request.

CertificateTemplate, Requester

https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/dn319076(v=ws.11)

4887

Certificate Services approved a certificate request and issued a certificate.

CertificateTemplate, Requester

https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/dn319076(v=ws.11)

References

Last updated

Was this helpful?