githubEdit

Windows PrivEsc with AD CS

We may be able to compromise Active Directory with vulnerable AD CS configurations or templates.

Enumerate Certificate Templates

Certificate templates are the rule set for AD CS. It contains CA name, CA permissions, etc. Some attributes are related to vulnerabilities to privilege escalation. To enumerate them, we can use Certify or Certipy.

certipy find -u user@example.local -p password -dc-ip <target-ip> -stdout
certipy find -vulnerable -u user@example.local -p password -dc-ip <target-ip> -stdout

Certify.exe find /vulnerable

ESC1

Requirements to Attack

Attribute
Value
Description

msPKI-Certificate-Name-Flag

CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT (0x00000001)

If the flag is present, a requester can specify the SAN(Subject Alternative Name).

msPKI-enrollment-flag

None

Authorized Signature Required

0

It's not required.

pKIExtendedKeyUsage

Client Authentication, PKINIT Client Authentication, Smart Card Login, Any Purpose, or no EKU (SubCA)

Enrollment Permissions

Low-level domain users such as Authenticated Users

Low-priivileged users can request a certificate with the template.

Manager approval

Disabled

Exploit

Reference: HackTricksarrow-up-right

Request the certificate specifying the altname as a Domain Admin such as localadmin then impersonate an administrator.

Then transform .pem to .pfx using openssl.

After that we can request TGT using Rubeus.

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. Or if we outputs as .kirbi, crack it by john.

  • Crack TGT

Please see Kerberos TGT Crackingarrow-up-right.

  • Pass-The-Ticket

ESC2

Requirements to Attack

Attribute
Value
Description

msPKI-Certificate-Name-Flag

CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT (0x00000001)

If the flag is present, a requester can specify the SAN(Subject Alternative Name).

msPKI-enrollment-flag

None

Authorized Signature Required

0

It's not required.

pKIExtendedKeyUsage

Any Purpose EKUs or no EKU (SubCA)

Enrollment Permissions

Low-level domain users such as Authenticated Users

Low-priivileged users can request a certificate with the template.

Manager approval

Disabled

Exploit

The following LDAP query when run against the AD Forest’s configuration schema can be used to enumerate templates matching this scenario.

ESC3

To abuse this for privilege escalation, a CAs requires at least two templates conditions.

Requirements to Attack (Condition 1)

Attribute
Value
Description

Authorized Signature Required

0

It's not required.

pKIExtendedKeyUsage

Certificate Request Agent EKU

The Certificate Request Agent OID (1.3.6.1.4.1.311.20.2.1), known as Enrollment Agent, allows for requesting other certificate templates on behalf of other principals.

Enrollment Permissions

Low-level domain users such as Authenticated Users

Low-priivileged users can request a certificate with the template.

Enrollment Agent Restrictions

Not implemented

Manager approval

Disabled

Requirements to Attack (Condition 2)

Attribute
Value
Description

Authorized Signature Required

1

It's required.

Schema Version

1 or is greater than 2

Application Policies

Certificate Request Agent EKU

pKIExtendedKeyUsage

Certificate Request Agent EKU

Client Authentication

Enrollment Permissions

Low-level domain users such as Authenticated Users

Low-priivileged users can request a certificate with the template.

Enrollment Agent Restrictions

Not implemented

Manager approval

Disabled

Exploit

We can request an enrollment agent certificate (Condition 1).

Then issue a certificate request on behalf of another to a template that allows for domain authentication (Condition 2).

Ask TGT to authenticate as the "On Behalf Of" user.

ESC4

Requirements to Attack

Attribute
Value
Description

Access Control rights

Users have Full Control or Write permission.

Object Control Permissions

Users have Owner, FullControl, WriteOwner, WriteDacl or WriteProperty permission.

ESC6

Requirements to Attack

Attribute
Value
Description

EDITF_ATTRIBUTESUBJECTALTNAME2 flag

Enabled

If this flag is set on the CA, any request (including when the subject is built from Active Directory) can have user defined values in the SAN (subject alternative name.)

Exploit

First off, check if the EDITF_ATTRIBUTESUBJECTALTNAME2 flag is set on the CA.

If set, abuse it by using /altname flag with any template (e.g. User) that allows for domain auth.

ESC7

Requirements to Attack

Attribute
Value
Description

CA Permissions

Low-privileged users have ManageCA (aka CA Administrator) permissions or ManageCertificates (aka Certificate Manager/Officer).

The ManageCA permission grants a principal the ability to perform "Administrative" CA actions, including the modification of persistent configuration data. This includes the EDITF_ATTRIBUTESUBJECTALTNAME2 flag.

Exploit

At first we need to know the CA Name so run the following command then check the output.

Then add new officer to the CA. Replace victim-ca with actual name found.

Next, enable the template on the CA.

Request the certificate for the template such as SubCA.

If failed, we can issue the request with the request ID.

Now we have administrator.pfx. Using this, we can retrieve the hash.

Crack the hash and get the administrator’s password or execute pass-the-hash attack.

ESC8

AD CS supports several HTTP-based enrollment methods via additional AD CS server roles that administrators can install. These HTTP-based certificate enrollement interfaces are all vulnerable NTLM relay attacks.

Exploit

Enumerate enabled HTTP AD CS endpoints with Certify.

To parse and list the CES endpoints in their AD object in the msPKI-Enrollment-Servers, execute the following command.

Privilege Escalation with Microsoft Management Console (MMC)

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. Request a New “Malicious” Certificate with 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.

2. Impersonate User using the 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.exearrow-up-right is useful to do for that. For details, see Privilege Escalation with Kerberosarrow-up-right.

    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.

Add Computer and PrivEsc

1. Add Computer to the Domain

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

3. Request Certificates

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.

4. Authenticate using PFX

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

Then using/cracking it to authenticate as Administrator.

Option: Authenticate over LDAP

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

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 PassTheCertarrow-up-right, we can spawn shell as Administrator via Schannel against LDAP(S).

References

Back to topMade with Material for MkDocsarrow-up-right

Last updated