TL;DR: The default RD Web configuration allows any domain user to tunnel traffic to any internal host from the internet. RD Web shouldn't be public facing.

Dangerous by Default: RD Web Edition — Abusing RD Web defaults for a BYO-VPN

For a network-focused penetration tester, RD Web sitting on the public internet is the gift that keeps on giving. For those unfamiliar, RD Web Access is a Microsoft Windows Server role that provides a web portal to launch published applications and remote desktops through a web browser. Think of it as Microsoft's answer to Citrix — remote access to work environments through the browser, in a secure way, by only allowing the necessary ports and protocols through without the need for a VPN. Which is funny, because under the hood the default deployment creates an unrestricted tunnel into the network.

This is the first post in a series I'm calling Dangerous by Default — things that ship gift-wrapped for attackers. RD Web is a perfect place to start, as almost everything in this post is the service working exactly like it was designed. I'll even sprinkle in a couple new tools I've built to take advantage of these defaults to BYO-VPN on (approved) client engagements — RDetour and RDRelay.

Pre-Auth Attack Surface

The RD Web login page authenticates directly against internal Active Directory (yes... the actual on-prem domain in most cases.). That means all of the external authentication protections you'd run into spraying an O365 login (such as smart lockout and conditional access) don't apply here. RD Web gives you a direct line into the internal environment, and your login attempts answer to nothing but the on-prem lockout policy.

Metasploit timing-based user enumeration against the RD Web login page

Timing-based user enumeration against the RD Web login page

RD Web is also vulnerable to a well-documented timing-based username enumeration flaw. Valid usernames take measurably longer to respond than invalid ones, which means an unauthenticated attacker can extract the internal domain name and enumerate valid accounts with nothing but a wordlist and a stopwatch. It's a vulnerability that Microsoft doesn't plan on fixing... just another reason this shouldn't be sitting on the internet to begin with.

The Tunnel

Username enumeration and password spraying alone is enough to make me perk up when I see RD Web during an external assessment. But what happens once we're successful at spraying or stuffing credentials against the portal?

In the past, the access I gained here directly determined how deep the compromise went. Either I had full authenticated access to published apps and remote desktop sessions as the compromised user, or I didn't — blocked by MFA, or the account simply didn't have the permissions or published resources to be useful.

RD Web has that look though. The kind of aging, poorly maintained service where you think "surely there's a zero day in here somewhere." So I spent a month or two on and off in my home lab pulling it apart, looking for something worth reporting to Microsoft. I didn't find it. Yet. But the process gave me a much better understanding of how the service actually works under the hood.

Distracted boyfriend meme: pentester looking at default configuration, leaving zero day behind

Once authenticated, RD Web creates a tunnel using the MS-TSGU protocol (RPC over HTTPS on port 443). You authenticate, call TsProxyCreateTunnel, then TsProxyCreateChannel with a host and a port. The gateway opens a TCP socket to that host:port and just relays bytes. Nothing about that pipe is RDP-specific. The gateway doesn't care what goes through it. Ask for port 445 or 389 and it connects.

The only thing controlling where the tunnel can reach is the Resource Authorization Policy (RAP). The default? All hosts, all ports, for Domain Users. That's right... all hosts, all ports, everyone.

MS-TSGU tunnel: Attacker through RD Gateway to any internal host and port

Attacker → RD Gateway → any internal host:port

RDetour

So what have we learned? Once authenticated, we can send arbitrary traffic through this tunnel as long as it conforms to the MS-TSGU protocol's expectations. Enter a pentester's best friend: proxychains. If I could get the tunnel established and route attack tooling from my Kali box through to the internal network via proxychains... now that would be impactful. And it would make me feel like less of a bum for wasting so much time trying to do zero day research.

Enter RDetour. Hand it a gateway and a credential, and it gives you a SOCKS5 proxy into the network behind it.

RDetour tunnel with proxychains routing NetExec, nslookup, and Impacket getTGT through the RD Gateway

RDetour tunnel and proxychains tooling

SCOUT AD domain assessment running through the RDetour tunnel via proxychains

SCOUT AD assessment via LDAP through the tunnel

It's a serial tunnel (one channel at a time) so it works best with single-host tools. That said, I've been able to use NetExec to target entire /24 subnets, send Impacket tooling against the DC, and more. If the RAP is locked down to specific hosts and port 3389, the tunnel stops being useful. Which is the entire remediation.

MFA & RDRelay

Ok but what if MFA is enforced? I spent quite a bit of time on this, testing various theories against a legitimate Duo MFA deployment in my lab.

If MFA is enforced at the remote host level (the RDP session connection), MFA is worthless. The tunnel is already created at that point. We're targeting internal resources as if we plugged our box directly into the internal network. MFA on the workstation never fires because we're never opening an RDP session. Even if the compromised user doesn't have access to any published apps or remote desktops, it doesn't matter. This is post tunnel creation — they may not have RDP access to anything, but we can execute attack traffic directly against the internal network.

If MFA is enforced at the RD Web gateway directly... you got me. That does stop the tunnel from being created. However, MFA fatigue is real. A single mistaken "approve" on a push notification is all it takes. RDetour has a --mfa-fatigue flag that re-arms the push on an interval until someone approves.

$ ./rdetour.py -g rdg.corp.com -u user -d CORP -p 'password' --mfa-fatigue 30
[*] SOCKS5 127.0.0.1:1080 via rdg.corp.com:443 as CORP\user
[mfa] push sent — waiting for approval (attempt 1)
[mfa] denied or timed out — retrying in 30s
[mfa] push sent — waiting for approval (attempt 2)
[mfa] approved — tunnel established

And then there's the phishing angle. If a user can be convinced to log into a convincing-looking RD Web portal, their MFA approval goes right through the relay. That's what RDRelay is for — an Evilginx-style reverse proxy for RD Web. Stand up a lookalike domain, point RDRelay at the real portal, and when the victim logs in you get their credentials and their authenticated session. They approve their own real Duo push, and it passes straight through to the attacker controlled server.

The phishing RD Web login page, visually identical to the real portal

Relayed RD Web login page

RDRelay capturing credentials and session cookies from a relayed RD Web login

RDRelay credential capture and tunnel spawn

Securing RD Web

  • Get it off the internet. Put it behind a VPN with MFA at the edge. This one change kills everything above.
  • If it has to be exposed, fix the RAP. Lock it to specific RDP hosts and port 3389. The default allow-all is what this entire post is about.
  • Put MFA on the gateway, not just the host and understand it only gates the tunnel once.
  • Audit your password spray and account lockout detections. Make sure they're firing on abnormal or malicious behavior against the login page.

If you're a defender: get RD Web off the internet and fix the defaults.

TEST, LEARN, STRENGTHEN, REPEAT!

References