Introduce first time speaker William Martin and his talk, One Click. Thank you, Kars. So as Kars said, my name is William Martin. And I'm an OSCP, I'm a pen tester for RSMUS. And I'm based out of Charlotte. And first time presenting at DEF CON, so no pressure. Thank you. If you can't see me back there, I'm the one on the right. And we only got 20 minutes, so we're going to kind of blow through this. We're going to talk about basics on Exchange and the various endpoints on Exchange. We're going to go through a little bit of a multi-factor authentication crash course on how it's typically set up, which will kind of emphasize some gaps that some organizations face. Then we're going to talk about my favorite attack, which is the NTLM relay attack. We're going to do a demo and a tool release, and then we're going to talk about how to fix the things that we just broke. So overall, organizations have been doing a pretty kick-ass job in terms of implementing multi-factor authentication across the board for their externally facing services. Like VPNs, definitely, or remote desktop services, Citrix, web apps, and email, with an asterisk on email, and we're going to get to that one. OWA is typically where we see a lot of two-factor being implemented, but there's a little bit of a break in mentality on the goal for multi-factor authentication on OWA. Um, I don't know about most of you, but I have email synced to my phone. Take a gamble, at least 60%, 70% of this room also have that scenario for themselves. Um, but when I was working in an organization, I found that I was using multi-factor authentication on our OWA portal, but my phone was syncing just fine with just my username and password with no other factor, no certification, no code, nothing. So I thought that was a bit weird. That seemed like it was counterintuitive for the point of multi-factor authentication. So, to find out why that gap exists, I realized I had to learn a little bit more about how my phone and my Outlook were connecting to Exchange. And that's what we're going to talk about. For those who haven't set up an Exchange server themselves, Exchange has multiple roles in which it can be installed. There's a mailbox server role, there's an edge transport role, and all of these kind of dictate how the server is going to operate. The role that we care about is called the client access server role. It's the one that we interact with when we're talking to our email. That's things like Autodiscover for telling us how to connect to our email, Mappy, which is how Outlook connects in, and OWA and ECP, which are the focus of this. So, Exchange Cast servers run essentially on top of an IIS server. There's one large web app. And accessing them looks a bit like this. So, all over HTTPS, all over HTTP, just your standard web calls. Now, to break down what these little endpoints do and the various ways you can talk to Exchange, there is PowerShell, which is used by administrators to kind of administer the server itself. Autodiscover tells your client how to connect to Exchange. Mappy is used by Outlook. RPC is used by old school Outlook. ActiveSync is used by your phone, typically. OAB provides your client a way to download the global address book, so it takes, it kind of eases the burden on Exchange. ECP is in addition to OWA, which allows a user to kind of change their settings. This is where you go into when you're changing your signature, adding forwarding rules and whatnot on your OWA. And then, not to beat a dead horse, OWA itself, the web app that lets you access your email, kind of access your tasks, manage your calendar, and whatnot. from the web without having to run a thick client. And then finally, EWS, or Exchange Web Services. It's a SOAP-based API that allows you to interact with Exchange and make API-based calls to your mailbox. So a lot of old school apps or the Outlook client for Mac is based on EWS. So, the endpoints, because we're hackers, that we care about are the ones that have access to the email. So that would be Mappy, RPC, ActiveSync, ECP, OWA, and EWS. Now, as a pen tester, interestingly enough, the ones that I find covered by two-factor authentication most often are only these two. OWA and Exchange Control Panel, which leaves at least four other ways we can access your email and whatnot without that code. So, to find out why I mean, don't get ahead of myself, I'm by far not the first one to find this gap. There have been other security researchers, like notably Blackhill Information Security, that have found this kind of gap, this inconsistency on the implementation of multi-factor authentication protecting Exchange. And like 2016, they reported this to Microsoft and said, hey, this is a gap, are you guys going to fix it? Microsoft replied saying, no, because this is not an issue on properly configured systems. So I took that as, okay, it's the admin's fault, a checkbox wasn't checked, they didn't add a route, it was just a human error causing this thing, it wasn't a technological failure. But because it was so prevalent, I wanted to find out what was causing such a pervasive human error. Why across all these organizations do we see this gap consistently? And the answer is, there really isn't a mention of these other endpoints in those two-factor authentication protocol implementations. So things like Symantec, RSA, a little bit of Duo, in their basic implementation guides, they would cover OWA and ECP, both of which are the only two web app-based protocols. And the reason that is, is because a lot of these protocols are authenticating through something called ADFS, or Active Directory Federation Services. Without derailing the talk to talk about what that is, in a nutshell, it provides a way for users to authenticate to this one server through whatever means they choose, like multi-factor, and this server will provide that user a cookie which will vouch to other single sign-on services. So when you go to a protected OWA, you're technically talking to this other server, it says, you know, William logged in, he's cool, just trust me. That trust gets passed to Exchange, and I'm able to log into OWA, even though Exchange didn't handle most of the authentication. So the issue lies in that that whole exchange happens over HTTP, happens over that web app-based protocol. But EWS and MAPI and RPC and those lower layer protocols can't handle that kind of interaction. So that causes a bit of an issue. This is what it kind of looks like when you log into OWA through an ADFS protected setup. You try to access OWA, you get that redirect saying, no, contact ADFS first. ADFS is the one that actually authenticates you. It says, hey, log in, maybe use your two-factor code or maybe give me your certificate to prove who you are. If you're using multi-factor, it'll pass that code off and say to its multi-factor authentication provider, again, like Symantec, and say, hey, is this code good? And it will say yes or no. Anyways, after that's done, ADFS will pass you back your token or your cookie. You then take that over to OWA and you're good to go. Vendors know that their solutions aren't covering these underlying protocols. They're not oblivious to this. But the issue is not so much on the vendors themselves as they've stated. It lies on the environment that they're implementing their solution on. And to implement their solution properly, they need something called modern authentication, which if you've got an exchange environment on premises, takes a bit of overhead to implement. So, modern authentication, in a nutshell, is Microsoft's implementation of the OAuth protocol. And it allows Outlook, EWS Mappy, and other protocols to handle OAuth tokens. Now, with OAuth, Exchange is no longer handling the actual authentication phase of it, even through single sign-on like through ADFS. OAuth just passes Exchange their token and says, cool, you're good to go. The OAuth provider is the one that really implements those two-factor solutions or whatever else may be. But the catch is, with modern authentication, you need to implement Azure in some way, shape, or form. You can't just spin up a DC on-prem, spin up an Exchange server on-prem, spin up an ADFS server on-prem, and be good to go. You have to interact with Office 365 somehow. And it's that catch that leaves a lot of organizations in the dark and vulnerable to this kind of a lack of coverage. So, when you implement it with Exchange on-prem, you need to use something called hybrid modern authentication. It requires an on-prem ADFS, and it requires you to use Outlook 2013 or later, and you're using Azure to perform all of the token provisioning. With pure Office 365, guys, when you're using Exchange online, you already support modern auth because it's all going through Office 365 anyways. It just comes down to what kind of multi-factor authentication you want to implement through this now supported protocol. And this is what it looks like when you have a hybrid setup. So, anyways, now we know that the gap that these two-factor solutions cause is not a quick, easy fix. And I love that because it makes it a pain in the ass for my targets to cover theirs. So, while we can, how can we take advantage of this gap? How can we take advantage of this oversight? Well, looking back at those other endpoints that you can talk to that are typically unprotected, there's a common theme amongst three of them. Before doing this research, I didn't know that three of them use NTLM, which is my favorite authentication mechanism. That's my point. So, also the first meme I ever made. So, NTLM relay is my favorite attack and it's how I pop maybe 80-90% of my internal pen tests. It's an attack as old as time itself. The cult of the dead cow were exploiting this as early as 2001. So, for those who don't know, the NTLM relay attack happens through three messages. It works like this. The victim is somehow tricked to connect to an attacker. And we'll talk about how they're tricked in a second. But they connect to an attacker and say, hey, I want to log in. Here's my domain, here's my username. The attacker that redirects that says, hey, I want to log in. Here's my domain and my username. The target server will reply saying, all right, cool, if you're really so and so, take this challenge and hash your password with it. We don't know the password as an attacker, so we'll pass that right back to the victim. The victim will happily oblige and pass that back. So now the attacker has the response. We pass that on to our target server. The target server probably says, okay, cool, you've now authenticated, you are so and so. The attacker gets the session and we kill our victim. We just say, no, you weren't able to log in. The ways to trigger NTLM authentication are vast. Some of the common ways, my favorite ways, are UNC links and emails. Which, if you're opening an email in Outlook and you click a UNC link, Outlook treats that, it really passes it on to us. Windows treats that like you're trying to access a network share. And per network share, it will try to authenticate to it, try to log in, try to open that folder for you. If the attacker is on the other end of that UNC path, it will authenticate to them and that triggers the NTLM relay attack. My other favorite way is NetBIOS and LLMNR poisoning. Anyone here use responder show of hands? Yeah, a fair number of us. So, never fails to get a hash. For those who don't use responder, it's a tool that hackers use to abuse how Windows works. When Windows asks for a resource that isn't available through DNS, it will then send a broadcast to the local network saying, hey, has anyone seen William Share? And typically there will be radio silence. But an attacker will say, yeah, I'm William Share. And then the victim will say, oh, cool, let me log into you. And that's how you get the NTLM hash. Recently I've seen some really cool ways to trigger NTLM authentication that I think are worth mentioning. Recently there was a CVE pushed out by Will Dorman which he found that Outlook, you could send an RTF or a rich text formatted email and when Outlook received that email it would parse it and if that RTF email had a, I know I'm getting really technical, but if that RTF email had a remote resource embedded in it, Outlook would try to automatically load that and it would pass it to Windows and then Windows would authenticate to it. And that's kind of it. if it's a UNC path. And this is all without user intervening and this is without any kind of warnings. So essentially you send an e-mail, they open it and you already got their hash. Microsoft patched that one but we all know that one patches everything appropriately so we have nothing to worry about there. So the other way that is not patched because it's a bit more difficult to patch is by Mike Felch. Mike, you in the room? Oh, man, he said he was coming. All right. So long story short, an attacker can modify the details of a Microsoft document and embed UNC path in the web settings. So when a Microsoft Word opens up that document, it will see a little UNC path in the web settings and it treats that as an external HTML page that you want to embed in your document. And so as always, it will try to reach out and get that. If it's on a share, it passes it to Windows and Windows will authenticate. This one, there is no user interaction whatsoever outside of, oh, my God, I'm going to do this. I'm opening a document. So if you find that UNC links are filtered in e-mail and you can't get a macro through, you might as well get just a benign document through their e-mail system and get them to trigger an NTLM authentication that way. So now that we know that these are protected by NTLM and we can relay to NTLM, which one do we want to attack? Well, a couple years ago, Sense Post came out with an attack called the Ruler attack which took advantage of Outlook rules. In a nutshell, the Outlook thick client on a desktop is going to be able to be configured to run certain commands upon receiving an e-mail, sending an e-mail, upon a certain event happening. And so Ruler found out that if you compromise the user credentials, if you're on the outside, you could create a new Outlook rule, sync it up with their server, that rule will then be pushed down to the Exchange Outlook clients, and then that rule would run upon the event happening. So naturally I thought, great, I can get RCE with a relay. Let's use that. That's what Ruler looks like. Unfortunately, one of the creators of Ruler already had this idea. And it turns out, to perform the true authentic Ruler attack, you need to authenticate to Exchange more than a few times. And the NTLM relay attack is pretty much a one and done. So you're not going to really get that far with using a map or RPC, which is what Ruler is based on. So I just left this guy, Exchange Web Services, which I had five already. Christ! All right. So which one do we want to talk about? Well, we're going to talk about Exchange Web Services, which I had never heard of until I built this, until I ran this attack. So in a nutshell, Exchange Web Services is just a way to access Exchange through an API. And the things we care about is that it's enabled by default. And by on-premise Exchange, it supports NTLM by default. And it provides access to most things Outlook has access to. And we don't have to go through multiple stages of authentication with NTLM on EWS. It's one and done. So I built a tool called Exchange Relay Index, which has these goals in mind. If we pop a user, we want to be able to read, send, delete, manage their inbox as they would. We want to be able to download their attachments, add forwarding rules to kind of backdoor their e-mail, scrape as much data as we can from Active Directory and launch spear phishing from inside the organization. Typically orgs have great attachment filtering on the perimeter. But from user to user from inside the organization, they have that gap. So if you compromise the exchange of one user, you might be able to send users B, C, and D malicious attachments without being filtered through. All right. Now let's try to power through a demo. This demo is going to show an OWA that's protected with two-factor authentication but is vulnerable to the same gaps that we've covered. Now being prompted for the code. Enter it through and there's your usual Outlook web app interface. You've got e-mails. You can see that the user that we're on is William Martin. That's me. We've got a folder over there on the left called Modern Auth Project. Going to open the user's Outlook thick client just to demonstrate the same thing. All right. Cool. So now we're going to launch the attack. The tool is called Exchange Relay X. And right now we're just going to check if the victim is vulnerable. Right now it just reaches out to the mail and says, hey, do you support NTLM? And it turns out we do. So let's build a relay to that NTLM interface. Let's build a relay to Exchange Web Services. All right. We're going to go ahead and test this out. All right. This is showing sending a sample UNC link to a victim. And we're masking it as a YouTube link. And I'm skipping through some of the loading times of the demo because we're tight on time. All right, user gets the phishing e-mail with that malicious link in there. They click it and that's it. That's all the user has to do. The attack is now done on their end. Over here we receive the connection, relate it back to their Exchange Server, and we see them popped right there. So what can we do with this? I tried to build a similar-looking OWA for hackers. So now you see, we can open up their e-mail. We still have the same little folder on the left that they do. And by the way, as we're reading e-mail and as we're sending e-mail, we're not showing up in their sent folder. Man, you're killing me, cars. So I'm going to release this tool and you guys have a lot of fun with it but we have to blow through what you can do. One of the features is that you can add forwarding rules as well as you can automatically download all of their attachments. So it just cycles through inbox, sent folder, everything and just as quickly as it can downloads every attachment they've ever sent or received. So if you have a user that's not super technical, maybe they're a CFO and they get popped, that's a really bad day. So. Stop applauding. We have to move through. So how do we fix this? You have to implement modern authentication across your organization. Aw, man. All right. Modern authentication everywhere. You have to implement Azure with that. RPC won't be able to support that. Same thing with POP3 and IMAP. If you have any 2010s anywhere, this will not work for you. You can't get modern auth with 2010s in the environment. Yeah. Implement MFA everywhere. Filter on 139, 445 and remember that split tunnel VPNs and IPv6 are typically a gap. All right. Here are the contributors. Sorry about the rush through.