00:00:00.000-->00:00:05.839 >>I’d like to introduce first time speaker William Martin in his talk ‘One Click to OWA’ 00:00:05.839-->00:00:10.844 [Applause] >>Thank you, Cars. [Applause]. >> [behind the mic] Let me see if I can maximize it. 00:00:17.584-->00:00:20.654 [Pause with mic interference] cool. >> So as Cars said, my name is William Martin, and er, 00:00:20.654-->00:00:26.560 I’m OSCP, I’m a pen tester for RSM US and I’m based out of Charlotte, and you know first 00:00:26.560-->00:00:31.565 time speaker at DefCon so no pressure. >>[audience member] whoo! >>Oh, thank you. Ah, if 00:00:31.565-->00:00:37.871 you can’t see me back there, I’m the one on the right. [sniggers] and we only get 20 minutes so so 00:00:37.871-->00:00:41.508 we’re kinda blow through this. Ah, we’re gonna talk about basics on Exchange and the 00:00:41.508-->00:00:45.212 various endpoints on Exchange . Ah, we’re going to go through a little bit of multi-factor 00:00:45.212-->00:00:49.383 authentication crash course on how it’s typically set up, uh which will kinda emphasize some 00:00:49.383-->00:00:52.920 gaps that some organizations face. Ah, then I’m going to talk about my favorite attack, which 00:00:52.920-->00:00:57.157 is the NTLM Relay attack, uh we’re going to do a demo and a tool release and and then we’re 00:00:57.157-->00:01:02.029 going to talk about how to fix the things we just broke. So, overall, organizations have been 00:01:02.029-->00:01:05.332 doing a pretty kick-ass job in terms of implementing multi-factor authentication 00:01:05.332-->00:01:10.170 across the board for their externally facing services, like VPNs definitely, our mo desktop 00:01:10.170-->00:01:14.975 services, citrix, um web apps, and email, with an asterix on email, we’re going to get to 00:01:14.975-->00:01:19.980 that one. Um, OWA is typically where we see a lot of two factor being implemented but there’s a 00:01:22.749-->00:01:27.087 little bit of a break in mentality on the goal of multi-factor authentication on 00:01:27.087-->00:01:33.527 OWA. Um, I don’t know about most of you, but, I have email synced to my phone, I have take a 00:01:33.527-->00:01:38.231 gamble at least 60 percent, 70 percent of this room also have that scenario - um, for 00:01:38.231-->00:01:44.171 themselves. Um, but when I was working in an organization I found that I was using 00:01:44.171-->00:01:48.842 multi-factor authentication on our OWA portal, but my phone was syncing just fine with just my 00:01:48.842-->00:01:54.348 username and password, with no other, no other factor, no certification, um, no code, 00:01:54.348-->00:01:59.119 nothing. So that felt a bit weird. It seemed counterintuitive for the point 00:01:59.119-->00:02:05.692 of multi-factor authentication. So, to find out why that gap exists, I realised I had to 00:02:05.692-->00:02:10.163 learn a little bit more about how my phone and my Outlook are connecting to Exchange. And 00:02:10.163-->00:02:15.002 that’s what we’re gonna talk about. So, for those haven’t set up an Exchange server 00:02:15.002-->00:02:19.673 themselves, Exchange, er, has multiple roles in which it can be installed. There’s a mail 00:02:19.673-->00:02:24.911 server role, there’s an edge transport role, um and all these kinda dictate how the server’s 00:02:24.911-->00:02:29.816 going to operate. The role we care about it is called the Client Access Server role. It’s 00:02:29.816-->00:02:34.454 the one we interacts with when talking to our email, that’s things like er auto discover for 00:02:34.454-->00:02:39.526 telling us how to connect to our email, a MAPI in which is how outlook connects in, er and OWA 00:02:39.526-->00:02:44.531 and ECP um which are the focus of this. So, Exchange cas servers run essentially on top 00:02:47.534-->00:02:52.539 of a IAS server, there’s one large web app and accessing them looks a bit like this. So all 00:02:54.808-->00:02:59.813 over https, all over http, just standard web calls. Now, to break down what these little 00:03:02.716-->00:03:07.254 endpoints do, and the various ways you can talk to Exchange, there is PowerShell, which is 00:03:07.254-->00:03:12.859 used by administrators to kinda administer the server itself. Auto discover tells their client 00:03:12.859-->00:03:19.666 how to connect to exchange, MAPI is used by Outlook, RPC is used by old school Outlook, ah, 00:03:19.666-->00:03:24.671 activesync used by your phone typically. Ah, OAB provides your client a way to er download the 00:03:26.706-->00:03:32.412 global address book, so it takes, it kinda eases the burden on Exchange. ECP, is er in 00:03:32.412-->00:03:37.884 addition to OWA which allows a user to kinda change their settings or where you’re going 00:03:37.884-->00:03:43.757 when changing your signature and forwarding rules and what-not um on your OWA and then not to beat 00:03:43.757-->00:03:49.362 a dead horse, OWA itself, the web app lets you to access your email, access your tasks, manage 00:03:49.362-->00:03:54.668 your calendar, um and what-not from the web without having to look, run a thick client. And 00:03:54.668-->00:04:00.941 then finally, EWS or Exchange Web Services, if they soap-based API that allows you to interact 00:04:00.941-->00:04:06.079 with Exchange and make API based calls with your mailbox. So, allows like old school apps or 00:04:06.079-->00:04:11.084 um, or the ma- the Outlook client from MAC is based on EWS. So, the endpoint is what hackers 00:04:14.955-->00:04:20.827 care about are the ones that allow access to the email. So that will be MAPI, RPC, Acce- 00:04:20.827-->00:04:25.832 Activesync, ECP, OWA and EWS. Now, as a pentester, interestingly enough, the ones I 00:04:29.236-->00:04:35.642 find covered by 2 factor authentication most often, are only these two: OWA and Exchange 00:04:35.642-->00:04:41.348 Control Panel. Which leaves at least 4 other ways we can access our email what-not without that 00:04:41.348-->00:04:46.353 code. So, to find out why, I mean, not to get ahead of myself, I’m by far not the first 00:04:48.688-->00:04:52.526 one to find this gap, other have been other security researchers like noblely Black Hill 00:04:52.526-->00:04:56.663 Information Security that have found this kind of gap, this inconsistency on the 00:04:56.663-->00:05:02.569 implementation of multi-factor authentication protecting exchange. And like 2016 20- yes 00:05:02.569-->00:05:06.840 2016 they reported this to Microsoft and said ‘Hey, this is a gap - are you guys going to 00:05:06.840-->00:05:13.713 fix it?’ Microsoft replied, saying No. Because this is not an issue on properly configured 00:05:13.713-->00:05:19.286 systems. So, I took that as, OK it’s, it’s the admin’s fault a check - box wasn’t checked. They 00:05:19.286-->00:05:24.090 didn’t add a route, um some- you know it was just a human error causing this thing, it wasn’t a 00:05:24.090-->00:05:29.863 technological failure. So, because it was so prevalent, I wanted to find out what was 00:05:29.863-->00:05:35.969 causing such a-a pervasive human error, um wha- wha- what would cause all these organizations to 00:05:35.969-->00:05:42.542 see this gap consistently. And answer is - there really isn’t any mention of these other 00:05:42.542-->00:05:47.647 endpoints in those two factor authentication ah protocols implementations. So things like 00:05:47.647-->00:05:52.786 semantic, RSA, um a little bit of Duo in their basic implementation guides they would 00:05:52.786-->00:05:57.791 cover OWA and ECP both of which are the only two web app based protocols. And the reason that 00:05:59.960-->00:06:05.332 is, is because a lot of these protocols are authenticating through something called ADFS or 00:06:05.332-->00:06:10.170 Active Directory Federation Services. Will that be ruining the talk to talk about what that 00:06:10.170-->00:06:16.543 is? Um, in a nutshell, it provides a way for users to authenticate to this one server, 00:06:16.543-->00:06:20.614 through whatever means they choose like multi-factor and then this server will provide 00:06:20.614-->00:06:25.252 that user with a cookie which will vouch to other single silent servers. So when you go 00:06:25.252-->00:06:30.991 a-a protected OWA you’re talking to this other server that says, you know, William logged in, 00:06:30.991-->00:06:37.864 he’s cool, just trust me. That trust gets passed to Exchange and I’m able to log into OWA 00:06:37.864-->00:06:43.470 even though Exchange didn’t handle most of the authentication. So, the issue 00:06:43.470-->00:06:49.142 lies in that, that whole exchange happens over HTTP, happens over like web app based 00:06:49.142-->00:06:54.147 um protocol, um, but EWS and MAPI and RCP and those lower levels can’t handle that kind of 00:06:56.816-->00:07:02.889 interaction, so that causes a bit of an issue. This is what it kinda looks like when you log in 00:07:02.889-->00:07:09.062 to OWA through an ADFS protected setup. Um, you try to access OWA, you get that redirect, 00:07:09.062-->00:07:14.067 saying No contact ADFS first, ADFS is actually the one that authenticates you. It says, hey, 00:07:16.269-->00:07:19.773 log in, maybe use your two factor code, or maybe er, give me your-your certificate, prove 00:07:19.773-->00:07:24.144 who you are. If using multi-factor, it’ll path that code off and say to its 00:07:24.144-->00:07:29.349 multi-factor authentication provider, again like semantic and say, hey, is this code good 00:07:29.349-->00:07:34.821 and it’ll say Yes or No. Anyways, after that’s done, ADFS will pass you back your token or 00:07:34.821-->00:07:39.826 your cookie, you then take that over to OWA and you’re good to go. So, vendors know that 00:07:42.562-->00:07:47.300 solutions aren’t covering these underlying protocols. This is not, they’re not oblivious to 00:07:47.300-->00:07:52.939 this, um the issue is not so much on the vendors themselves, as they’ve stated. It lies on 00:07:52.939-->00:07:57.610 the environment they’re implementing their solution on and to implement their solution 00:07:57.610-->00:08:02.282 properly, they need something called modern authentication - ah, which if you’ve got an 00:08:02.282-->00:08:07.287 Exchange environment on premises take a bit of er er overhead to implement. So, modern 00:08:09.989-->00:08:16.830 authentication, in a nutshell, is Microsoft’s implementation of the OAuth’s protocol and allows 00:08:16.830-->00:08:21.835 Outlook EWS mapping and other protocols to er handle OAuth’s tokens. Now, with OAuth, 00:08:24.371-->00:08:29.109 Exchange is no longer handling the authentication phase of it, even through single sign on like 00:08:29.109-->00:08:33.980 through ADFS, OAuth just passes Exchange her token and says ‘clear you’re good to go’. The 00:08:33.980-->00:08:38.485 OAuth provider is the one that really implements those two factor solutions or whatever 00:08:38.485-->00:08:44.357 else what may it be. Um, but the catch is with mod authentication, you need to 00:08:44.357-->00:08:49.796 implement Azure in some way shape or form. You can’t just spin up a DC on prem, spin up an 00:08:49.796-->00:08:54.801 Exchange server on prem, spin up an ADFS server on prem and be good to go. You have to interact 00:08:54.801-->00:08:59.873 with Office 365 somehow, and it’s that catch that leaves a lot of organizations in the 00:08:59.873-->00:09:04.811 dark. Vulnerable to this kind of um, lack of coverage. So when you’re implemented with Exchange 00:09:08.148-->00:09:13.586 on prem, you need to use something called hybrid modern authentication. It requires an 00:09:13.586-->00:09:19.826 on prem ADFS and it requires you to use Outlook 2013 or later and you’re using Azure to perform 00:09:19.826-->00:09:24.964 all of the token er provisioning. ER, with pure Office 365, guys, when you’re, 00:09:24.964-->00:09:28.802 when you’re using Exchange online, you already support modern Auth because it’s all 00:09:28.802-->00:09:33.973 going through Office 365 anyways, um it just comes down to what kind of multi-factor 00:09:33.973-->00:09:39.879 authentication you want to implement through this now supported protocol. And this is 00:09:39.879-->00:09:44.884 what it looks like when you have a hybrid setup. So, anyways, now we know that the gap that these 00:09:46.920-->00:09:51.524 two factor solutions cause is not a quick, easy fix. And I love that, because it makes it a 00:09:51.524-->00:09:57.564 pain in the ass for my targets to cover theirs. So, while we can, how can we take advantage 00:09:57.564-->00:10:03.303 of this gap? How can we take advantage of this oversight. Well, looking back at those 00:10:03.303-->00:10:08.675 other endpoints you can talk to that are typically unprotected? There’s a common theme amongst 00:10:08.675-->00:10:13.880 three of them. Before doing this research, I didn’t know I didn’t know that three of them use NTLM 00:10:13.880-->00:10:18.885 which is my favourite authentication mechanism. So, [laughter] that’s my point. So 00:10:25.258-->00:10:31.064 also the first meme I’ve ever made. Um, so NTLM attack is my favourite relay until I pop 00:10:31.064-->00:10:36.970 maybe 80 to 90 percent of my internal pentest, um it’s a terribl- it’s an attack as old 00:10:36.970-->00:10:42.642 as time itself, um the cult of the dead clap, uh, the cult of the dead clap were exploiting 00:10:42.642-->00:10:49.182 this as early as 2001. So, for those who don’t know the NTLM relay attack happens through 3 00:10:49.182-->00:10:55.021 messages. It works like this: the victim is somehow tricked to connect to an attacker. And 00:10:55.021-->00:10:58.791 we’ll talk about how they’re tricked in a second. But they connect to an attack and say, 00:10:58.791-->00:11:03.863 hey, i want to log in. Here’ my domain, here’s my username. The attacker that redirects that 00:11:03.863-->00:11:08.935 say’s, ‘okay, I wanna login, here’s my domain and username’ The target server will reply 00:11:08.935-->00:11:13.273 saying: alright cool, if you are really so and so, take the challenge and hash your password 00:11:13.273-->00:11:17.076 with it. We don’t know the password as an attacker, so we’ll pass that right back to 00:11:17.076-->00:11:22.081 the victim. The victim will happily oblige and pass that back. S’now the attacker has the 00:11:24.951-->00:11:29.455 response we path that on to our target server, target server probably says, OK cool, you’ve 00:11:29.455-->00:11:35.261 now authenticated, you are so and so. The attacker gets the session and we kill out victim. 00:11:35.261-->00:11:40.266 We say No, you weren’t able to log in. So, the ways to trigger NTLM authentication are vast, um 00:11:42.735-->00:11:48.141 some of the common ways and favourite ways are UNC links and emails, which if you open an 00:11:48.141-->00:11:53.012 email in Outlook and you click a UNC link, Outlook treats that - it really passes on to Windows 00:11:53.012-->00:11:57.283 and that - And Windows treats that a , like you’re trying to access a network share and per 00:11:57.283-->00:12:01.120 network shares, it will try to authenticate, try to login, try to open that folder for you. 00:12:01.120-->00:12:05.992 Well, if the attacker’s on the other end of that UNC path, it’ll authenticate to them and 00:12:05.992-->00:12:10.997 that triggers the NTLM relay attack. My other favourite way is NTLM, er, ah - sorry, net 00:12:13.233-->00:12:18.771 bios and O and MR poisoning, which, does anyone use responders? Show of hands? Yeah, 00:12:18.771-->00:12:24.077 fair number of us. So, so it never fails to get a hash, um, for those who don’t use 00:12:24.077-->00:12:28.948 Responder, it’s a tool hackers use to abuse how Windows works, when windows asks for a 00:12:28.948-->00:12:33.720 resource, which isn’t available through DNS it will then send a broadcast to the local network 00:12:33.720-->00:12:38.157 saying , hey, has anyone seen, I don’t know, William’s share? And typically there’ll be 00:12:38.157-->00:12:44.130 radio-silence, but an attacker will say, yeah, I’m William’s share. And then the victim will 00:12:44.130-->00:12:50.136 say, oh cool, alright let me log into you. And then, that’s how you get the NTOM hash. Recently 00:12:50.136-->00:12:53.840 I’ve seen some really cool wa-ways to trigger NTLM authentication that I think are 00:12:53.840-->00:12:59.946 worth mentioning. Er, so recently there was a CV pushed out by will Dorman, which he 00:12:59.946-->00:13:04.951 found that Outlook, you could sent an RTF, or a rich text formatted email and when Outlook 00:13:04.951-->00:13:09.222 received that email, it would parse it and if that RTF email had, er I know I’m getting 00:13:09.222-->00:13:15.528 really technical, but if erthat RTF email had a remote resource embedded in it, Outlook would 00:13:15.528-->00:13:19.432 try to unlikely load that that and pass it to Windows and then Windows would authenticate to it 00:13:19.432-->00:13:26.205 if it’s a UNC path um and this is all without user auth- um, intervening without any kind of 00:13:26.205-->00:13:30.243 warnings. So essentially you sent an email, they open it and they - you already get their 00:13:30.243-->00:13:35.815 hash. Um Microsoft patched that one, but er we all know that one patch is everything 00:13:35.815-->00:13:41.954 appropriately so nothing to worry about there. So, um, - there’s a way not patch - 00:13:41.954-->00:13:48.428 difficult to patch by Mike’s fell - Mike you’re in the room? Ah, man, he said he was coming. 00:13:48.428-->00:13:54.300 Alright, so. Long and short, an attacker can modify the details of a Microsoft document and 00:13:54.300-->00:13:59.305 embed UNC path in the settings, so when a Microsoft word opens that document it’ll see a little 00:14:01.340-->00:14:07.380 UNC path in the web settings, it treats that a an external HTML page that you wanna embed in 00:14:07.380-->00:14:12.418 your document so, as always, it’ll try and reach out get that and share it and pass it to 00:14:12.418-->00:14:16.322 Windows and Windows will authenticate. This one there is no user interaction whatsoever 00:14:16.322-->00:14:20.927 outside of opening a document. So, if you find that UNC links are filtered in Kmail and you 00:14:20.927-->00:14:24.831 can’t get like a map go through, you might get like a benign document through their email 00:14:24.831-->00:14:29.836 system and get them to show HTML authentication that way. So now we know these are protect by 00:14:32.739-->00:14:37.744 NTLM and we can relay to NTLM, which one do I attack? Well, a couple years a go, er, SensePost 00:14:39.812-->00:14:44.350 came out with an attack called the Ruler attack. Which took advantage of Outlook rules. In a 00:14:44.350-->00:14:48.855 nutshell, the Outlook thick client on a desktop can be configured to run certain 00:14:48.855-->00:14:54.794 commands a -upon receiving an email, sending an email, upon a certain event happening. And so 00:14:54.794-->00:14:59.432 Ruler found out that if you compromise a users credentials from the outside, you could 00:14:59.432-->00:15:03.836 create a new Outlook rule, sync it up with their server. That rule will then be pushed down to 00:15:03.836-->00:15:10.176 Exchange Outlook clients and then that rule would run upon that event happening. So, um, 00:15:10.176-->00:15:15.681 naturally I thought: great I can get RCE with a relay, let’s let’s use that. That’s what 00:15:15.681-->00:15:21.287 Ruler looks like. Unfortunately, one of the creators of Ruler already had this idea and turns 00:15:21.287-->00:15:28.127 out, to perform the true, true authentic Ruler attack, you have to authenticate to Exchange more 00:15:28.127-->00:15:33.900 than a few times and NT the NTLM relay attack is pretty much a won and done, so you not really 00:15:33.900-->00:15:40.439 gonna get that far using a MAPi or a RCP which is what Ruler is based on. So I just left this 00:15:40.439-->00:15:45.444 guy, Exchange web services which I - 5 already? Chr**t! Alright, which I never heard of until I 00:15:47.613-->00:15:53.920 built this tool, until I ran this attack, so in a nutshell, Exchange web services is just a 00:15:53.920-->00:15:58.925 way to act as exchange to an API and the things we care about is that it’s enabled by default and 00:16:00.993-->00:16:06.666 by on premise exchange it supports NTLM by default and provides access to most things 00:16:06.666-->00:16:09.569 Outlook provides access to. And we don’t have to go through multiple stages of 00:16:09.569-->00:16:14.574 authentication with NTLM on EWS, it’s won and done. So I built a tool called ExchangeRelayx which 00:16:17.243-->00:16:22.849 has these goals in mind. If we pop a user we want them, we wanna to be able to read, send, 00:16:22.849-->00:16:26.185 delete, you know, manage their inbox as they would. We want to be able to download their 00:16:26.185-->00:16:31.257 attachments, er add forwarding rules to kinda backdoor their email. Scrape as much data as we 00:16:31.257-->00:16:35.394 can from that directory and launch phishing from inside their organization. Typically, 00:16:35.394-->00:16:40.633 orgs have great ah attachment filtering on prem on the perimeter but from user to user 00:16:40.633-->00:16:44.537 from inside the organization they have that gap, so if you compromise the exchange of one 00:16:44.537-->00:16:49.308 user you might be able to send users BC and D er malicious attachments without being 00:16:49.308-->00:16:54.313 filtered through. Alright. Now try and power through a demo. [Pause] This demo’s going to a 00:16:58.184-->00:17:03.823 show a OWA that’s protected with 2 factor authentication but is vulnerable to the same gaps we 00:17:03.823-->00:17:08.828 covered. [Pause]. Now being prompted for the code. [Pause and interference on mic]. 00:17:24.911-->00:17:29.081 [Cough] [Long pause] Enter through and there’s your usual, ah, Outlook web interface. You 00:17:29.081-->00:17:35.621 got the emails. You can see that the user we’re on is er William Martin - that’s me. Er, we’ve 00:17:35.621-->00:17:41.928 got folder there on the left called Modern Auth Project. Going to open the user’s Outlook 00:17:41.928-->00:17:46.933 thick client just to demonstrate the same thing. [Pause]. Alright, cool. So we’re actually 00:17:54.373-->00:17:59.011 gonna launch the attack. Tool’s called ExchangeRelayX and right now we’re just going to check if 00:17:59.011-->00:18:03.549 the system is vulnerable. Right now it just reaches out to the mail and says, hey do you 00:18:03.549-->00:18:09.689 support NTLM? And turns out - we do. So let’s build a relay to that NTLM interface, let’s build 00:18:09.689-->00:18:14.694 a relay to Exchange web services. [Pause]. Alright. This is showing sending a sample UNC 00:18:32.678-->00:18:37.683 link to a victim. And we’re masking it as a Youtube link. [Pause] And I’m skipping through 00:18:42.254-->00:18:47.259 some of the loading times in the demo because we’re tight on time. [Pause]. Alright, user 00:18:49.562-->00:18:55.301 gets the er the phishing email - that malicious link in there. They click it and that’s all the 00:18:55.301-->00:18:59.805 user has to do. The attack is now done on their end. Over here we receive the connection, we 00:18:59.805-->00:19:06.178 relayed it back to their Exchange server and we see them popped right there. So, what can 00:19:06.178-->00:19:11.183 we do with this? I tried to build a similar looking OWA for hackers. So, now you see we can 00:19:16.489-->00:19:22.461 open up their email, we still got the same er little folder on the left that they do, and by 00:19:22.461-->00:19:26.899 the way, as we’re reading email and sending email we’re not showing up in their sent folder. 00:19:26.899-->00:19:31.904 >>Man, you’re killing me Cars. >>So, I’m gonna release this tool and you guys can have a lot 00:19:35.574-->00:19:39.779 of fun with it but we kinda have to blow through what you can do. One of the features is that you 00:19:39.779-->00:19:44.784 can - ah, add forwarding rules as well as you can ah unlikely download all of their 00:19:47.153-->00:19:50.956 attachments, so just cycle through inbox, sent folder, everything and just as quickly 00:19:50.956-->00:19:54.994 as you can, download every attachment they’ve ever sent or received. So if you have a user 00:19:54.994-->00:19:59.899 that’s not super technical, maybe their CFO and they get popped, that’s a really bad day. 00:19:59.899-->00:20:04.904 So. [Applause]. Stop applauding we have to move through! So, er how we fixed this you implement 00:20:15.081-->00:20:20.052 modern authentication across your organization - oh man, modern authentication 00:20:20.052-->00:20:24.757 everywhere, er you have to implement Azure with that. RCP won’t be able to support that, 00:20:24.757-->00:20:29.161 same thing with POP3 and IMAP, if you have any 20 10s anywhere this will not work for you you 00:20:29.161-->00:20:34.166 cannot get modern auth with 2010s environment. Um, yeah. Implement MFA everywhere, filter 00:20:37.369-->00:20:43.976 on 1-3-9-4-4-5 and er remember that split tunnel VPNs and IVP6 are typically a gap. Alright, 00:20:43.976-->00:20:48.981 here are the contributors. Sorry for the rush through. [Sigh]. [Applause].