Page cover

AD CS (Active Directory Certificate Services) Pentesting

AD CS is Public Key Infrastructure (PKI) implementation. The misconfiguration of certificate templates can be vulnerable to privilege escalation.

We can retrieve certificates information on target Windows machine using certutil.

# Dump general information
certutil -dump

# Dump information about certificate authority
certutil -ca
certutil -catemplates

# List all templates
certutil -template
# specify the template
certutil -template ExampleTemplate
Copied!

Then check if Allow Full Control or Allow Write include the group which current user belongs to. If so, we can modify the template and might be able to escalate privilege.

Get-ChildItem cert:\
Get-ChildItem cert:\CurrentUser\
Get-ChildItem cert:\CurrentUser\My
Get-ChildItem cert:\LocalMachine\
Get-ChildItem cert:\LocalMachine\My
Copied!

We can use Certipy for finding vulnerable templates, requesting TGT, and authentication.

If you get the error like "Kerberos SessionError: KRB_AP_ERR_SKEW(Clock skew too great)", sync the time with AD server.

Now we get the NT hash so we can login the target machine using this hash by Pass-The-Hash.

We can use Certify.exe for enumerating the templates and requesting certificate. It can be downloaded from here.

Now we get the TGT (.kirbi) file. We can use it to the following parts:

  • Crack TGT

  • Pass-The-Ticket

If we find the template which contains vulnerable parameters, we can create a new certificate using the template and can gain access to the Administrator's account. There are some method to create the new one. However, this section provides the easiest way using MMC.

  1. Right-click on the Windows icon, and select Run.

  2. Enter “mmc” (Microsoft Management Console)* in the form and click OK. The console window opens.

  3. In the MMC window, click File → Add/Remote Snap-in..

  4. Add the “Certificates” snap-in in the window then click OK.

  5. Expand the Certificates in the left pane.

  6. Right-click on the Personal and select All Tasks → Request New Certificate.

  7. The Certificate Enrollment window, click Next twice.

  8. In Request Certificates section, click the “More information is required to enroll…”.

  9. In Certificate Properties window, choose types and enter values in the form.

    Subject name:

    • Type: Common name

    • Value: vulncert (specify an arbitrary name)

    Alternative name:

    • Type: User principal name

    • Value: tester@abc.example.com (specify the impersonated name and the target domain)

  10. Add each name and click OK.

  11. Return to the Request Certificates section. Check on the certificate we want to request, then click Enroll.

  12. After finishing, expand Personal → Certificates. We should see the new certificate is added.

  13. Double-click on the certificate. The Certificate window opens.

  14. In the Certificate window, select Details tab and choose Subject Alternative Name. We should see the principal name is our specified name e.g. tester@abc.example.com. If we can, click OK to close the window.

  15. At the end, in the MMC window, right-click on the new certificate which we created and select All Tasks → Export… to export the certificate. The Certificate Export Wizard opens.

  16. In Export Private Key section, select “Yes, export the private key” and click Next.

  17. In Export File Format, it is usually okey the default .PFX format so click Next without any changes.

  18. In Security section, check the Password and enter new password.

  19. In File to Export section, enter the file name and Next.

  20. Finally click Finish then we could export the new malicious certificate.

If we create a new certificate, we can use it to impersonate the privileged user.

  1. Request Kerberos TGT (Ticket Granting Ticket).

    Rubeus.exe is useful to do for that. For details, see Privilege Escalation with Kerberos.

    After that, we should get the TGT (.kirbi file). We can gain access using the TGT by changing the password of the DA account.

  2. Change the Password of the DA (Domain Administrator) Account.

  3. Get the Administrator’s Shell

    Using runas command, we can gain access to the Administrator’s account. Use the new password which we’ve given the previous section in prompt.

We can use the addcomputer (impacket) which is usually used for AD CS (Active Directory Certificate Services) Privilege Escalation.

After adding new computer, we might be able to retrieve certificate using this computer account. At this time, try using alternate UPN (-upn) for administrator because we want to escalate privilege.

If successful, the file which contains certificates and private key (e.g. administrator.pfx) will be saved in current directory.

We might be able to retrieve TGT using the .pfx file as below.

Then using/cracking it to authenticate as Administrator.

Reference: https://offsec.almond.consulting/authenticating-with-certificates-when-pkinit-is-not-supported.html

According to the article above, we may be able to authenticate over some protocols such as LDAP(S). First off, split the administrator.pfx with certificate and private key using two commands below.

After that, using PassTheCert, we can spawn shell as Administrator via Schannel against LDAP(S).

References

Last updated