1 00:00:00,000 --> 00:00:04,880 All right. I'd like to welcome our next speaker. Matt's going to be speaking to us today about 2 00:00:04,880 --> 00:00:09,760 hiding in plain sight, disguising HTTPS traffic with domain fronting. Take it away, Matt. 3 00:00:10,540 --> 00:00:19,340 Thank you. Hi. My name is Matt. I'm a software developer. Come here my first time at 4 00:00:19,340 --> 00:00:25,060 DEF CON. Can everyone hear me up the back? I heard there's some sound issues, but lots of 5 00:00:25,060 --> 00:00:29,880 thumbs in the air. Thanks very much. Cool. So a lot of us have probably heard about domain 6 00:00:29,880 --> 00:00:36,440 fronting. It got a fair bit of attention recently when Signal Messenger made some noise when I 7 00:00:36,440 --> 00:00:41,740 think Google said, hey, we're going to put an end to this. So there was lots of questions about 8 00:00:41,740 --> 00:00:48,360 what is it? There was an academic paper floating around, which I don't really understand how to 9 00:00:48,360 --> 00:00:54,980 read papers like that. So I asked my friend to help me out, and he explained it to me, and I 10 00:00:54,980 --> 00:00:59,860 sort of figured it out. So I thought, let's bring it here and explain it. 11 00:00:59,880 --> 00:01:07,600 So in simple terms, to maybe people who don't even necessarily know what TLS is, or just have 12 00:01:07,600 --> 00:01:16,060 rough understanding, so I will be maybe to some people going to a basic level. That way, more 13 00:01:16,060 --> 00:01:24,680 people can understand. So hopefully we get the right balance. So what is it? I put on my 14 00:01:24,680 --> 00:01:29,680 dictionary writer hat and sort of tried to come up with a dictionary definition, and it's 15 00:01:30,440 --> 00:01:36,100 abusing an implementation detail of shared infrastructure to disguise the true destination of a 16 00:01:36,100 --> 00:01:44,100 HTTPS transaction. So there's a few key words in here. Implementation detail is one big one. And 17 00:01:44,100 --> 00:01:53,680 shared infrastructure is another. And we'll go into why these parts are important later. And 18 00:01:53,680 --> 00:01:59,660 HTTPS. As far as I know, there's probably not really any other protocols that share a shared 19 00:01:59,680 --> 00:02:05,220 infrastructure. There's a lot of different paths to different things within the same place that 20 00:02:05,220 --> 00:02:11,140 connections get terminated at. Domain formatting is not new. It's been around for quite a while. It 21 00:02:11,140 --> 00:02:16,700 didn't do an exhaustive search, but it has, this is the oldest thing I could find that uses it. 22 00:02:16,800 --> 00:02:24,900 It's some kind of proxy that's written in Python, and it's some, the code of GitHub, the commit 23 00:02:24,900 --> 00:02:29,660 message says abstract host substitution. Maybe that's the old name for it. So it's kind of a 24 00:02:31,460 --> 00:02:37,580 new thing. Cool. So let's look at some of the advantages of domain fronting. What? Sorry. I 25 00:02:38,280 --> 00:02:43,160 messed that up. Sorry. Uses of domain fronting. I mentioned signal messenger. They primarily 26 00:02:43,160 --> 00:02:48,800 seem to use that for bypassing censorship. Blanton seems to do the same. I think that's some 27 00:02:48,800 --> 00:02:58,320 kind of a VPN. And then there's Meek Client, which is an OBFS proxy for Tor. I presume pretty 28 00:02:58,320 --> 00:02:59,640 much everybody here has heard of Tor. I don't know if you've heard of Tor. I don't know if you've 29 00:02:59,640 --> 00:03:06,900 heard of Tor, which is usually used for, you guessed it, bypassing censorship. But also for 30 00:03:06,900 --> 00:03:15,220 evading detection. So the OBFS proxy, there's different plug-ins for Tor, basically, that let 31 00:03:15,220 --> 00:03:21,820 you pretend you're different types of traffic. All kinds of interesting ones. I wish I could go 32 00:03:21,820 --> 00:03:29,620 into them today, but that's a huge rabbit warren. And then malware. So, you know, there's a lot of 33 00:03:29,640 --> 00:03:29,660 things going on. I'm not sure what that is. But, you're not going to be able to get away with this. 34 00:03:29,660 --> 00:03:31,460 So, let's get a look at some of the advantages. Okay. There will be bypassing censorship. Obviously, 35 00:03:31,480 --> 00:03:35,600 censorship isn't just a country saying, no, you can't go to this website. That's also 36 00:03:36,440 --> 00:03:42,980 corporations saying, no, you're not going to Facebook at work. And also evading detection. Malware 37 00:03:42,980 --> 00:03:51,300 doesn't want to be going to, hey, you just got hacked.com. And so, advantages. Why is it useful? 38 00:03:51,300 --> 00:03:57,780 useful? Well, it can't be detected without breaking TLS. Someone has to actually perform 39 00:03:57,780 --> 00:04:01,620 some kind of a man in the middle attack in order to be able to see that you're doing that. 40 00:04:03,200 --> 00:04:12,500 So one potential case here would be if I'm in a corporate network which doesn't want to 41 00:04:13,050 --> 00:04:21,280 invade the privacy of their staff by intercepting their TLS communications, I won't be able to 42 00:04:21,300 --> 00:04:26,920 tell that this is happening. So maybe a piece of malware could use it to evade my firewall from 43 00:04:26,920 --> 00:04:31,940 detecting it. It uses existing infrastructure on the server side. So when I've been playing 44 00:04:31,940 --> 00:04:41,220 around with this, it's mostly CDNs like CloudFront and not CloudFlare anymore and not Google 45 00:04:41,220 --> 00:04:47,000 Cloud anymore either. And it's compatible with anything that can be tunneled over HTTPS. So if 46 00:04:47,000 --> 00:04:51,160 you can think of a way of tunneling your traffic over HTTPS, you could use domain fronting 47 00:04:51,160 --> 00:04:58,920 to send that traffic around. And it's very simple and easy. It sounds complicated, but once you 48 00:04:59,420 --> 00:05:03,680 realize how simple it is, you'll just walk away and go, cool, I'm going to go do that at home. 49 00:05:03,760 --> 00:05:10,800 It'll take you five minutes. Okay, where is it not useful? Bypassing censorship where the TLS 50 00:05:10,800 --> 00:05:15,860 is man in the middle. So if I break your TLS session, I can see you doing this. I said that 51 00:05:15,860 --> 00:05:21,140 before. And it's not useful for hiding web traffic in a normal web browser. So it's not useful for 52 00:05:21,140 --> 00:05:25,120 hiding web traffic in a normal web browser. But you can do it in a normal web browser, but each 53 00:05:25,120 --> 00:05:30,380 web page you go to is going to load things from all kinds of different places. You need to find 54 00:05:30,380 --> 00:05:38,480 suitable domains to hide behind and not every web site would have domains that match. So yeah, 55 00:05:38,520 --> 00:05:44,620 it needs to be on a shared infrastructure. And the front domain for that destination needs to be 56 00:05:44,620 --> 00:05:51,120 known. So I'll explain what I mean by front domain a bit later when I go into the demo. So first, it's 57 00:05:54,580 --> 00:06:01,100 And the security is void. The reason for that is you need to 58 00:06:01,100 --> 00:06:05,140 basically trust a different certificate to where you're 59 00:06:05,140 --> 00:06:10,740 actually talking to. Again, we'll see more in the demo. So 60 00:06:10,740 --> 00:06:17,320 how does it work? Well, let's go back to the days of HTTP 1.0. 61 00:06:17,320 --> 00:06:21,780 And obviously when your web browser was doing, you're trying 62 00:06:21,780 --> 00:06:27,140 to browse to www.mywebsite.com and you do a DNS lookup, your 63 00:06:27,140 --> 00:06:30,180 DNS server returns the server address and you connect to that 64 00:06:30,180 --> 00:06:33,620 web server and say, hey, get me the home page and it returns it. 65 00:06:33,920 --> 00:06:38,200 The problem here, of course, is we needed one IP address per 66 00:06:38,200 --> 00:06:41,380 domain we were hosting. So if you wanted to host both, you 67 00:06:41,380 --> 00:06:44,480 know, website A.com and website B.com, you needed to 68 00:06:44,480 --> 00:06:47,240 have two different IP addresses and some of us couldn't do 69 00:06:47,240 --> 00:06:52,020 that. Or, you know, and then we obviously want many millions of 70 00:06:52,020 --> 00:06:55,620 websites. Maybe we would run out of IPv4 even faster than we 71 00:06:56,280 --> 00:07:01,960 currently are. So they introduced the host header. So 72 00:07:02,660 --> 00:07:05,620 basically that just changed this sequence diagram slightly. 73 00:07:06,500 --> 00:07:09,120 Well, not at all really. It just added this extra piece of 74 00:07:09,120 --> 00:07:14,000 information on the second green arrow here where we just specify, 75 00:07:14,180 --> 00:07:17,100 hey, I want to go to website A or website B. That way, that 76 00:07:17,100 --> 00:07:21,460 way we could share that IP address across both of them. But 77 00:07:21,460 --> 00:07:24,060 it's 2018 and we encrypt web traffic, or we're supposed to. 78 00:07:24,500 --> 00:07:30,800 So, you know, we, this thing called TLS, I guess was its 79 00:07:30,800 --> 00:07:35,040 original name. Sorry, SSL was its original name and now known 80 00:07:35,040 --> 00:07:43,040 as TLS. Basically it just takes HTTP as it was, wraps it in a 81 00:07:43,040 --> 00:07:46,640 secure layer that validates, you know, where, where you're 82 00:07:46,640 --> 00:07:49,820 talking to. In some cases it can validate you yourself if you 83 00:07:49,820 --> 00:07:55,060 decide to do bi-directional authentication. You know, am I 84 00:07:55,060 --> 00:07:57,420 talking to my bank or am I talking to someone that claims to 85 00:07:57,420 --> 00:08:00,560 be my bank? You know, it takes care of that for you. And it 86 00:08:00,560 --> 00:08:04,980 encrypts the traffic between you and the server, as we know. And 87 00:08:04,980 --> 00:08:08,560 without, without changing the protocol. So as the application 88 00:08:08,560 --> 00:08:11,460 developer, it doesn't matter if I'm using HTTP or if I'm doing 89 00:08:11,460 --> 00:08:16,460 IMAP or POP or whatever, you know, TLS was designed to just go 90 00:08:16,460 --> 00:08:23,000 over the top. However, sorry, just getting ahead of myself 91 00:08:23,000 --> 00:08:28,740 here. So TLS handshake is pretty complicated and I don't 92 00:08:28,740 --> 00:08:32,800 understand anything but the first two that's happening there. 93 00:08:33,340 --> 00:08:36,360 And, and I don't, and it's not, not relevant for domain 94 00:08:36,360 --> 00:08:39,540 fronting. Basically what happens here is I use TLS 95 00:08:39,540 --> 00:08:43,100 handshake, your, your client says, hey, I want to talk TLS. 96 00:08:43,440 --> 00:08:46,420 And then the server goes, sure, I am TLS. And then the server goes, 97 00:08:46,420 --> 00:08:46,440 TLS. And then the server goes, sure, I am TLS. And then the 98 00:08:46,460 --> 00:08:46,840 server goes, sure, I am TLS. And then the server goes, sure, 99 00:08:46,840 --> 00:08:48,040 what happens first is they lock your bank, definitely your 100 00:08:48,040 --> 00:08:53,340 bank, not someone else. And they do some kind of special packet 101 00:08:53,340 --> 00:08:58,000 dance. And arrive at some encryption keys that they both 102 00:08:58,000 --> 00:09:05,640 agree on. And from there, everything gets encrypted. 103 00:09:05,820 --> 00:09:07,760 Right? So it's it's a layers, it's hidden from me as the 104 00:09:07,760 --> 00:09:11,340 application developer. But everything from that point is 105 00:09:11,340 --> 00:09:13,420 encrypted. And as the application developer it just 106 00:09:13,420 --> 00:09:16,440 looks like the same protocol that I came up with back in the 107 00:09:16,440 --> 00:09:23,940 HTTP. So forget about all that stuff that I don't know. And we pretend it's not there and 108 00:09:23,940 --> 00:09:31,380 just focus on the first couple of messages. Now, if I'm sitting on a network watching your 109 00:09:31,380 --> 00:09:35,860 traffic, okay, so maybe I'm at your Starbucks Wi-Fi, maybe I'm your ISP, maybe I'm a 110 00:09:35,860 --> 00:09:43,340 government, maybe I'm your sysadmin at your company, I can't see what's happening down the 111 00:09:43,340 --> 00:09:52,980 bottom here. That part's encrypted, obviously. But what I can see is at these first few 112 00:09:52,980 --> 00:09:57,160 messages are unencrypted. The client hello actually has a part at the beginning that says, 113 00:09:57,840 --> 00:10:04,480 hey, I want to go to Google.com. And the reason for that is because at the beginning, when 114 00:10:04,480 --> 00:10:13,320 we look back at our HTTP 1.0 versus HTTP 1.1, is, you know, the first message is encrypted. 115 00:10:13,340 --> 00:10:22,900 I've totally messed this up, I'm sorry. So the reason for this is when I say, hey, I want to 116 00:10:22,900 --> 00:10:31,840 talk TLS, the server immediately needs to know who it is representing. So if I have website A 117 00:10:31,840 --> 00:10:36,860 and website B both on the same server and my client says, hey, I want to talk TLS, I need to 118 00:10:36,860 --> 00:10:43,320 send it back a certificate to say, hey, I'm website A or website B. So I'm not going to be able to 119 00:10:44,200 --> 00:10:48,580 use my website A or website B. And so, that meant TLS had to be extended slightly to identify 120 00:10:50,840 --> 00:10:55,640 which server we were talking about. Now, am I talking to Google.com, am I talking to Yahoo.com. 121 00:10:55,980 --> 00:11:06,300 So that got, it's an SNI extension, so I, I think, when did the Xbox 360 come out? That didn't 122 00:11:06,300 --> 00:11:11,280 support it. I just know that if you, if you want to support Xbox 360, it doesn't support this, you 123 00:11:11,280 --> 00:11:16,260 have one IP per. So that's roughly how long ago it got introduced, but it wasn't a standard 124 00:11:16,260 --> 00:11:24,420 thing. So say I'm on your network, I'm sniffing your traffic and I'm watching you use HTTPS. I 125 00:11:24,420 --> 00:11:29,140 can see that you're going to google.com because it's sitting there in that very first message 126 00:11:29,140 --> 00:11:41,260 that you send in your TCP session to Google. So just to recap that, the answer to that is 127 00:11:41,280 --> 00:11:49,820 the entire contents of the HTTP session are encrypted, which is all that stuff. For web 128 00:11:49,820 --> 00:11:55,820 developers, maybe early on, certainly early on in my web development career, none of this was 129 00:11:55,820 --> 00:12:00,200 clear to me, like where all this stuff went. It just somehow magically arrived and then you got 130 00:12:00,200 --> 00:12:05,560 it from dollar post in PHP somewhere. And then what's not encrypted is the domain name of the 131 00:12:05,560 --> 00:12:10,000 server we're talking to. That's exposed by SNI. So that's how you're, even though you're using 132 00:12:10,000 --> 00:12:11,260 HTTPS, you're not going to be able to access it. So that's how you're going to be able to 133 00:12:11,260 --> 00:12:11,500 access it. And then you're going to have the IP address and you're going to be able to use a 134 00:12:11,500 --> 00:12:15,880 TLS certificate to see what your ISP can see, what you're looking at. And the service 135 00:12:15,880 --> 00:12:21,820 certificate also is encrypted. And I can't remember, but I think TLS 1.3 is supposed to 136 00:12:21,820 --> 00:12:31,240 encrypt the service certificate. Anyone here? No? No. It does. Thanks. Cool. So let's take a 137 00:12:31,240 --> 00:12:36,480 look at HTTPS stacks. So with domain fronting, what's important about, or what makes it work, 138 00:12:36,480 --> 00:12:42,380 work is the implementation of the HTTPS stacks and how they usually get shared across 139 00:12:43,020 --> 00:12:48,580 customers, say if you're using Amazon CloudFront. So very simple single server stack, like 140 00:12:48,580 --> 00:12:54,560 let's say I'm, when I was 14, I used to run a web server under my desk which was just 141 00:12:54,560 --> 00:13:00,660 Apache. And it basically, it's this first thing on the left. So, sorry, first thing on the 142 00:13:00,660 --> 00:13:06,620 left is a client and then we got the web server which is like Apache and whatever. And 143 00:13:06,620 --> 00:13:13,500 that pulls stuff from an origin. And that's generic because the origin can be a file system, it 144 00:13:13,500 --> 00:13:19,020 could be a Rails application, it could be a Django application, it doesn't matter. It's, this 145 00:13:19,020 --> 00:13:26,740 is just to show the separation of concerns. So you see this web server is responsible for 146 00:13:26,740 --> 00:13:30,640 HTTP, TLS and caching. And this is just to show the separation of concerns. So this is 147 00:13:30,660 --> 00:13:39,520 what we do. And when you're running one website, it's all pretty simple. And yet what we 148 00:13:39,520 --> 00:13:45,520 like to do, usually for performance reasons though, is delegate the TLS. So TLS is, you 149 00:13:45,520 --> 00:13:51,400 know, reasonably heavy on the CPU. And perhaps what you're doing in your application might be 150 00:13:51,400 --> 00:14:00,260 very heavy on the memory. So we, often we split this out. And this is often what's happening at 151 00:14:00,660 --> 00:14:01,080 the end of the day. And so it's a, it's a, it's a little bit like a, you know, a, a, you know, 152 00:14:01,080 --> 00:14:04,540 it's, it's a little bit like a cloud front or a Google Cloud where they have lots of customers 153 00:14:04,540 --> 00:14:08,980 and they want to have a very fast end point with an IP that lots of many, lots of customers use 154 00:14:09,600 --> 00:14:15,780 that just does the job of terminating those TLS connections and getting them to the next link in 155 00:14:15,780 --> 00:14:24,920 in the chain which is the next web server that goes and then fetches the content. And so when 156 00:14:24,920 --> 00:14:34,040 we delegated it this is where I can steal that little NSA graphic I love. So this is how I 157 00:14:34,560 --> 00:14:38,880 think Heroku kind of works. That's a shared infrastructure provider. I haven't tried if 158 00:14:38,880 --> 00:14:42,620 domain fronting works through Heroku yet. That's probably something I'll do right after this. 159 00:14:43,360 --> 00:14:49,080 But you basically you talk to that reverse proxy whose job is hey let's terminate TLS here and 160 00:14:49,080 --> 00:14:58,040 then it goes to something else whose job is look at the host header in the request and route it 161 00:14:58,040 --> 00:15:07,080 to whichever one the host header matches. So what happens in these CDN networks often is the 162 00:15:07,080 --> 00:15:12,480 reverse proxy decides what certificate to send back to the client based on the SNI 163 00:15:12,480 --> 00:15:16,740 header. That thing you saw in my Wireshark screen shot. And then the next link of the chain 164 00:15:16,740 --> 00:15:23,100 decides where to send it based on the host header. Which they don't always have to match. And 165 00:15:23,100 --> 00:15:29,380 in domain fronting they basically we deliberately make sure they don't match. So if we were to 166 00:15:29,380 --> 00:15:35,060 make I'm sorry this is way too small to see on the screen. But if we were to make a request to 167 00:15:35,060 --> 00:15:42,460 www.good.com and say in the SNI header hey I want the certificate for good.com. And then we 168 00:15:42,480 --> 00:15:50,700 get my TLS session established. And then I say okay get me the home page and the host is www.evil.com. 169 00:15:50,980 --> 00:15:58,320 And what will end up happening is if that reverse proxy that should satisfy the TLS session then 170 00:15:58,320 --> 00:16:04,640 the router would look at the host header and go ah I want to go to evil.com. And this seems to be 171 00:16:04,640 --> 00:16:09,380 roughly how it works behind the scenes at Amazon. Unfortunately I don't work there. I don't know 172 00:16:09,380 --> 00:16:12,460 anyone that does. I wish I would love to know why it works. So I'm going to show you how it works. 173 00:16:12,480 --> 00:16:25,280 There. So I've already ruined that one. And again remembering what we saw in the Wireshark I 174 00:16:25,280 --> 00:16:31,040 would only see if I'm sniffing the network I would only see the packets going to good.com. Why 175 00:16:31,040 --> 00:16:36,700 does it work? An anonymous Google software engineer said it worked because of a quirk of our 176 00:16:36,700 --> 00:16:42,460 software stack. And Google has since done what they can to get rid of domain fronting. So I'm 177 00:16:42,480 --> 00:16:46,240 going to show you how it works. Okay. So it highly depends on implementation. In order for it 178 00:16:46,240 --> 00:16:53,580 to work the shared infrastructure must not check for a mismatch between SNI header and host 179 00:16:53,580 --> 00:16:58,580 header. Apparently that's what Cloudflare does to stop it. And it kind of makes sense to do 180 00:16:58,580 --> 00:17:08,220 that. And also HCP requests must be routed separately to how TLS, the TLS. So both those 181 00:17:08,220 --> 00:17:12,460 layers need to be dealt with separately. Okay. So I'm going to show you how it works. An 182 00:17:12,480 --> 00:17:18,080 example. So to put it together what do we need to actually do? All we need to do is connect like 183 00:17:18,080 --> 00:17:24,300 normal to one host. And set the host header to another and they've got to be on the same 184 00:17:24,300 --> 00:17:30,020 infrastructure that can route between them. So we find evil.com needs to be accessible via the 185 00:17:30,020 --> 00:17:35,180 same infrastructure as something innocent looking. And the infrastructure needs to have the 186 00:17:35,180 --> 00:17:42,460 right implementation quirks. So let's say there's plenty of websites online that don't have the 187 00:17:42,480 --> 00:17:49,280 same infrastructure. So let's say I'm on a popular CDN like jQuery is on a CDN and that same CDN I 188 00:17:49,280 --> 00:17:57,460 could go and sign up for myself and put my malware command and control server behind that CDN. 189 00:17:57,560 --> 00:18:06,980 Which would allow me to use somebody else's domain who uses that same CDN to go there. And I 190 00:18:06,980 --> 00:18:12,460 keep giving away the. So I'm going to go ahead and show you how it works. So I'm going to go 191 00:18:12,480 --> 00:18:18,920 to find them. There's loads of websites there. If we go to say Alexa top 500 we should be able to 192 00:18:18,920 --> 00:18:26,300 just do reverse DNS look ups to you know google.com points to this whatever. This customer is using 193 00:18:26,300 --> 00:18:32,840 Akamai. I think Facebook uses Akamai. Also would be another good one to try. And they're easy 194 00:18:32,840 --> 00:18:42,460 to find and sign up for. So what makes some domains better than others? It depends really on 195 00:18:42,480 --> 00:18:45,940 what we're trying to do. If we're evading detection like malware we want to have something that 196 00:18:45,940 --> 00:18:52,200 looks pretty business as usual you know. If I'm in a company that sells apples it probably doesn't 197 00:18:52,200 --> 00:18:58,880 look very suspicious if I'm going to fruit.com. Or maybe something innocuous you know. If I'm if 198 00:18:58,880 --> 00:19:04,380 I've infiltrated a company and I'm trying to exfiltrate some data and that company is also a 199 00:19:04,380 --> 00:19:12,260 marketing company that uploads a lot to YouTube maybe I could hide my stuff through youtube.com. If I'm in maybe a 200 00:19:12,480 --> 00:19:12,640 website that has a lot of data or that is a very good example. So yeah that's one way to find us. 201 00:19:12,640 --> 00:19:18,880 So the other thing is that if I'm in a country that blocks blocks access to sites which is signals 202 00:19:18,880 --> 00:19:23,940 problem is they were they were in a country which was blocking blocking their messenger and they 203 00:19:23,940 --> 00:19:31,040 also apparently block websites. They chose a web an eCommerce website which they thought would be 204 00:19:31,040 --> 00:19:39,080 would would have collateral damage. So if that country were to block that site that would that would 205 00:19:42,480 --> 00:19:48,720 as a whole, so perhaps be a reason why that wouldn't get 206 00:19:48,720 --> 00:19:50,840 blocked. And then maybe you could do a combination of all. 207 00:19:50,920 --> 00:19:53,100 You can find something that looks like business as usual, 208 00:19:53,260 --> 00:19:56,500 it's innocuous and it's got collateral damage, probably a 209 00:19:56,500 --> 00:20:02,380 really good one to go with. So I've talked a lot and I'm going 210 00:20:02,380 --> 00:20:08,580 to keep talking. But instead of boring slides, let's fire up 211 00:20:08,580 --> 00:20:11,460 this SSH session and I'm going to try and talk and hold the 212 00:20:11,460 --> 00:20:34,660 mic at the same time. One second. Alright, so what we're 213 00:20:34,660 --> 00:20:38,320 going to start with is I have a root shell here and I'm going to 214 00:20:38,320 --> 00:20:41,440 start off a TCP dump. So you can see, I'm going to start off with 215 00:20:43,360 --> 00:20:44,640 a TCP dump. So I'm going to start off with a TCP dump. So 216 00:20:44,640 --> 00:20:48,020 this is just an empty EC2 instance in Amazon. So there 217 00:20:48,020 --> 00:20:54,660 should be hopefully no other traffic on 443. So this command 218 00:20:54,660 --> 00:20:59,580 here, for those not familiar with TCP dump, takes network 219 00:20:59,580 --> 00:21:02,500 traffic that's going through your network card and logs it 220 00:21:02,500 --> 00:21:06,100 somewhere. And I'll just briefly go over the arguments 221 00:21:06,100 --> 00:21:11,440 here. Minus C4 means stop after I've seen four packets. And C4 222 00:21:11,460 --> 00:21:15,540 means stop. So there's three for the TCP handshake and then the 223 00:21:15,540 --> 00:21:19,040 fourth packet is our first message from client to server, 224 00:21:19,160 --> 00:21:23,560 which is our client hello, which has the SNI header in it. Minus A 225 00:21:23,560 --> 00:21:27,960 means give me ASCII output, show it straight to the terminal. N 226 00:21:27,960 --> 00:21:30,220 is like a performance optimization, like don't do a 227 00:21:30,220 --> 00:21:36,480 reverse lookup to the IP address. And I, our interface, F0 228 00:21:36,480 --> 00:21:40,480 and then we're looking for TCP port 443. So let's run that and 229 00:21:40,480 --> 00:21:41,440 then switch to another packet. And then I'm going to start a 230 00:21:41,460 --> 00:21:48,720 screen. And then we're just going to run a curl to pixum.photos. 231 00:21:48,740 --> 00:21:52,180 It's like lorem ipsum but for pictures. So curl minus S just 232 00:21:52,180 --> 00:21:56,900 means shut up, don't do anything except get that and give me the 233 00:21:56,900 --> 00:22:00,160 output to stand it out. And then we're going to pipe that to MD5 234 00:22:00,160 --> 00:22:02,900 some so we can look at, okay, what was the content I actually 235 00:22:02,900 --> 00:22:07,560 saw? So the content I actually saw in this case, or the hash of 236 00:22:07,560 --> 00:22:11,440 it, is, you know, C8E, EAD. So we're going to look at, okay, 237 00:22:11,460 --> 00:22:15,160 so the purpose of this is just basically go get me this web 238 00:22:15,160 --> 00:22:19,940 page, make a hash of it so I've got an idea of what I saw. And 239 00:22:19,940 --> 00:22:23,560 then let's get another web page. So in this case, protect your 240 00:22:23,560 --> 00:22:28,580 privacy now.com. And obviously different hash. So these are the 241 00:22:28,580 --> 00:22:32,940 two hashes. And then what we're going to do is take a look at 242 00:22:32,940 --> 00:22:37,840 when I do a domain fronting, which one I get. So hopefully 243 00:22:37,840 --> 00:22:38,600 this makes sense. 244 00:22:41,840 --> 00:22:49,460 Now just realize I've messed up my TCP dump. Okay. So only the 245 00:22:49,460 --> 00:22:54,200 first curl request got shown up, only the first curl request got 246 00:22:54,200 --> 00:22:58,120 dumped here because it stopped after four packets. So you can 247 00:22:58,120 --> 00:23:02,940 see right here, this is my SNI header that says, hey, I'm going 248 00:23:02,940 --> 00:23:07,380 to picsum.photos. And then let's run the TCP dump again and 249 00:23:08,900 --> 00:23:11,440 switch to the other screen and run, I'll just run this curl 250 00:23:11,460 --> 00:23:14,080 command here. So when I'm going to protectyourprivacynow.com, 251 00:23:14,610 --> 00:23:19,500 you can see on the other side, you've got in the same, roughly 252 00:23:19,500 --> 00:23:25,700 the same place, I'm going to protectyourprivacynow.com. All 253 00:23:25,700 --> 00:23:31,160 right. And it's in my history because I was testing it out. 254 00:23:32,820 --> 00:23:38,100 Cool. So basically, let's do some domain fronting and turn 255 00:23:38,100 --> 00:23:41,440 over to, let's get TCP dump running. Okay. So basically, 256 00:23:41,460 --> 00:23:45,980 what we're going to do is we're going to run this again. Okay. 257 00:23:46,080 --> 00:23:52,260 So all we've done here is we're still establishing our TLS 258 00:23:52,260 --> 00:23:56,820 connection with protectyourprivacynow.com. So you 259 00:23:56,820 --> 00:23:59,320 can see that most of this curl command is just the same as the 260 00:23:59,320 --> 00:24:03,000 one above it. The only difference here is we're telling 261 00:24:03,000 --> 00:24:07,000 curl with the minus H flag, change the host header to 262 00:24:07,000 --> 00:24:11,440 picsum.photos. And so when I run this, I'm going to run this 263 00:24:11,440 --> 00:24:15,740 again. So the MD5 sum of what came back is actually picsum.photos. 264 00:24:16,040 --> 00:24:19,960 But if I go and look at the other side where I've dumped the 265 00:24:19,960 --> 00:24:24,900 packets, it actually just shows protectyourprivacynow.com. So 266 00:24:24,900 --> 00:24:26,880 when I said it was really easy and you can go and do it in five 267 00:24:27,320 --> 00:24:41,420 minutes at home, there it is. Cool. So I'm going to run this 268 00:24:41,440 --> 00:24:45,980 again. Cool. So there's a few risks here. Obviously, one of 269 00:24:45,980 --> 00:24:51,500 them is the reliability. When I tried going to protectyourprivacynow.com, 270 00:24:51,600 --> 00:24:55,160 I don't know that they're going to keep it on that same CDN as 271 00:24:55,680 --> 00:25:01,220 picsum.photos. They could change that at any time and they could 272 00:25:01,220 --> 00:25:07,460 point it somewhere else. So a potential solution to that is you 273 00:25:07,460 --> 00:25:11,280 could have a list of backup domains. If you were shipping an app that relied on domain fronting, 274 00:25:11,440 --> 00:25:16,440 maybe you want to have a list of other ones that still work. But a bigger problem is you 275 00:25:16,440 --> 00:25:20,840 can't validate that the server is authentic. Because if you're connecting to 276 00:25:22,800 --> 00:25:29,900 protectyourprivacy.com but then really intending to talk to picsum.photos, the server you 277 00:25:29,900 --> 00:25:34,140 validated who you're talking to is protectyourprivacy.com, not the photo site that 278 00:25:34,140 --> 00:25:41,420 you're trying to go to. And also, since you can't validate that the server is authentic, 279 00:25:41,440 --> 00:25:45,140 you're connecting to that place that you didn't set up yourself. They could change that 280 00:25:45,140 --> 00:25:50,720 certificate or CA at any time, so you can't pin it either. Which you'd normally be able to do if it 281 00:25:50,720 --> 00:26:01,020 was a self-signed cert or whatever. So also, the traffic is visible to the infrastructure 282 00:26:01,020 --> 00:26:06,900 provider. So say if you had traffic that you needed to hide from Amazon Cloud Front, for example, 283 00:26:08,240 --> 00:26:11,420 or it was sensitive. Because it was a private server, it could be a private server. So you could 284 00:26:11,420 --> 00:26:14,680 do that. But because you established your connection with site A, that infrastructure 285 00:26:14,680 --> 00:26:22,980 provided just by default is able to see what you did. It's kind of obvious if you're used to using 286 00:26:22,980 --> 00:26:28,560 a CDN, but it's not that obvious sometimes when you do these tricks. I don't know, I guess I 287 00:26:28,560 --> 00:26:35,820 forget about all these sort of things. And sensitive data could be stolen and malicious 288 00:26:35,820 --> 00:26:41,220 payloads could be injected. So basically, just treat it as an unencrypted connection. Encrypt and 289 00:26:41,220 --> 00:26:46,540 sign all your messages. Maybe come up with your own way of validating that you're really talking 290 00:26:46,540 --> 00:26:53,300 to who you think you're talking to. Cool. So I actually saw a DOS attack happen via domain 291 00:26:53,300 --> 00:27:00,840 fronting. It was a combination of some not quite configured correct, not quite correctly configured 292 00:27:00,840 --> 00:27:07,380 infrastructure and domain fronting. So what happened was we had a very, there was a very normal 293 00:27:07,380 --> 00:27:11,200 web server set up. You know, you start with one web server. You refactor the other server. You do a 294 00:27:11,220 --> 00:27:17,780 map to your application and you make it two web servers and then you, you know, you eventually end 295 00:27:17,780 --> 00:27:22,200 up with a cluster of them and then you end up going, okay, we need a CDN. And so it was put 296 00:27:22,200 --> 00:27:30,720 behind a CDN. And so they marked the CDN IPs as trusted proxies to the web server, as you do 297 00:27:30,720 --> 00:27:36,860 because obviously TCP connection hits the CDN endpoint and then the CDN makes another 298 00:27:36,860 --> 00:27:41,200 connection. And then attackers found a nice, slow way to do that. And then they started to use the 299 00:27:41,220 --> 00:27:47,420 web page and they decided to make thousands of requests to it. But they used domain fronting, 300 00:27:47,520 --> 00:27:55,500 which in the case of the CDN that was being used and for some reason was going between two 301 00:27:55,500 --> 00:28:01,280 different IPs. So it was going from one CDN endpoint to another and then to the web server 302 00:28:01,280 --> 00:28:07,200 which it didn't expect. So basically the connection diagram would look like this. A client 303 00:28:07,640 --> 00:28:11,200 way to the left, connects to reverse proxy. That's one TCP. That's the other one. So you get a lot of 304 00:28:11,220 --> 00:28:18,320 connection and the reverse proxy then connects to the web server. So normally because the web 305 00:28:18,320 --> 00:28:24,780 server can only see the connection from 2222, so for those that can't see the IP addresses, 306 00:28:25,080 --> 00:28:31,800 they're a bit small. So the web server sees the reverse proxy's IP address from that actual 307 00:28:31,800 --> 00:28:37,880 TCP. So the reverse proxy usually adds into the X forwarded for header, hey I'm forwarding it 308 00:28:37,880 --> 00:28:46,420 for 1.1.1.1. And the web server knows that because the actual TCP connection comes from 2222 309 00:28:46,860 --> 00:28:59,880 that it can trust that 1111 is really who it's talking to. And that's what I just. So in this 310 00:28:59,880 --> 00:29:07,540 case what was happening was the user was hitting the front domain, the domain fronting domain that 311 00:29:07,540 --> 00:29:07,860 was high. So the user was hitting the front domain, the domain fronting domain that was 312 00:29:07,880 --> 00:29:16,460 hidden behind that added X forwarded for 1111. It got forwarded to the other one which added 313 00:29:16,460 --> 00:29:21,020 another X forwarded for header and then passed it up to the web server who didn't 314 00:29:21,020 --> 00:29:28,420 really understand that there could be more than one. So that allowed, that basically opened up an 315 00:29:28,420 --> 00:29:35,620 IP spoofing vulnerability. Because the web server was thinking that the user's true IP was in 316 00:29:35,620 --> 00:29:37,860 fact the IP of the CDN endpoint and the server was actually trying to go back to the system because the 317 00:29:37,860 --> 00:29:45,480 point. So what we expect to happen usually is that header has one address which is the true IP of 318 00:29:45,480 --> 00:29:50,680 the user or at least that's what the web server was expecting. And that the web server reads 319 00:29:50,680 --> 00:29:56,740 that header and it knows who it's talking to. In actual fact, there was two. It didn't 320 00:29:56,740 --> 00:30:07,240 understand it. And it assumed that the CDN was the real user. It got worse because we had failed 321 00:30:07,240 --> 00:30:11,560 to band configure it and it ended up banding the whole CDN and taking the site out because it 322 00:30:11,560 --> 00:30:20,640 thought the CDN was dosing it. And the root cause, misconfiguration, we'd forgotten, look at 323 00:30:20,640 --> 00:30:27,860 the full list. And because it went through domain fronting, which is a way that it wasn't 324 00:30:27,860 --> 00:30:33,800 expected to work, it invalidated that. That assumption. So in order to plug that, know your 325 00:30:33,800 --> 00:30:37,220 infrastructure. X4 to 4 is actually a de facto standard. You're always going to have to 326 00:30:37,220 --> 00:30:42,400 make sure that your infrastructure provider might do it differently to how you expect. I 327 00:30:42,400 --> 00:30:48,860 think Cloudflare, I think, has an XCF connecting IP or something. It's completely different. 328 00:30:49,220 --> 00:30:55,720 And wherever there's a possibility to get proxied multiple times, make sure that the chain 329 00:30:55,720 --> 00:31:01,560 of your infrastructure, the chain is trusted. So, you know, if you've got a CDN endpoint that 330 00:31:01,560 --> 00:31:07,100 maybe hits another one, that hits a load balancer, that hits another load balancer, it needs 331 00:31:07,220 --> 00:31:12,940 to be able to draw a line between all those endpoints and go, ah, okay, I trust this one, which 332 00:31:12,940 --> 00:31:20,420 trusts that one, and find its way to the true IP. So in that case, Nginx is, I don't know the other 333 00:31:20,420 --> 00:31:26,780 ones, unfortunately, but it's real IP recursive, if you want to Google that. And Cloudflare's 334 00:31:26,780 --> 00:31:33,420 header, connecting IP. So the future of domain fronting, I don't think it will last much longer. 335 00:31:35,600 --> 00:31:37,200 Cloudflare has already said, you know, we're going to have to make sure that we're going to be 336 00:31:37,200 --> 00:31:42,640 able to get rid of it. It can't be relied upon. It's implementation details which could 337 00:31:42,640 --> 00:31:47,960 change. Like I mentioned before, Amazon might just suddenly start doing something differently 338 00:31:47,960 --> 00:31:55,180 one day. Netlify, Beluga, all those CDN providers, whatever you use, they might find a 339 00:31:55,180 --> 00:32:00,560 more efficient way of doing it or decide to get rid of it. Different regions of the world 340 00:32:00,560 --> 00:32:07,000 might use different infrastructure. I think I noticed this when I was in China. I went to 341 00:32:07,000 --> 00:32:10,520 Apple.com and I was like, oh, I wonder where that's going. And I had a look. It was completely 342 00:32:10,520 --> 00:32:15,500 different to the result I was getting from Perth. It was back in my one place and some other CDN 343 00:32:15,500 --> 00:32:21,860 elsewhere. So if you were writing something that needs to be used all over the world, there might 344 00:32:21,860 --> 00:32:27,460 be pointing to different infrastructure. And it's also actively possible, sorry, it's possible to 345 00:32:27,460 --> 00:32:34,340 actively prevent it from working, which is Cloudflare's deliberately doing this by checking for a 346 00:32:34,340 --> 00:32:36,980 mismatch between the SNI and host header. So, you know, it's a little bit of a challenge. But, you 347 00:32:38,160 --> 00:32:42,300 know, it's a nice way of using a SNI header. Or by using SNI for routing the request, if you 348 00:32:42,300 --> 00:32:50,280 remember the several layers of where it decides on its final destination, it could just simply use 349 00:32:50,280 --> 00:32:59,340 the SNI header, which I believe was the intent behind HTTP 2. Seems unwanted. Amazon and Google 350 00:33:00,880 --> 00:33:06,100 have, appear to have responded to pressure against it. Google has already broken it deliberately. 351 00:33:06,420 --> 00:33:06,960 Amazon doesn't want to be a threat to their customers. So, you know, it's a little bit of a 352 00:33:06,960 --> 00:33:12,300 Amazon said they will. And Cloudflare for some reason says it's a risk to their customers. It 353 00:33:12,300 --> 00:33:19,020 would put our traditional customers at risk. I presume that means people behind corporate 354 00:33:19,020 --> 00:33:25,860 firewalls, because those corporate firewalls can't necessarily ban malware traffic if it's 355 00:33:25,860 --> 00:33:33,140 using domain fronting. So domain fronting may be not that useful for making your own personal 356 00:33:33,140 --> 00:33:39,940 HTTPS more private. So a couple more suggestions here. TLS 1.3 has explored the possibility of 357 00:33:39,940 --> 00:33:46,000 encrypting the SNI component. It didn't make it into the spec because it required an extra round 358 00:33:46,000 --> 00:33:51,440 trip in order to, there was actually two proposals. One was an extra round trip to negotiate a key 359 00:33:51,440 --> 00:33:56,500 first. The other one I think was based on a static key. I didn't really pay much attention to it. 360 00:34:03,780 --> 00:34:12,640 However, I did read recently that there was work done on this by Cloudflare I think. And this was 361 00:34:12,640 --> 00:34:17,660 only in the last couple of days I think that came out. Use a conventional tunnel like a VPN if you 362 00:34:17,660 --> 00:34:24,980 set the tunnel up yourself. Tunnel traffic other ways. There's other protocols out there for 363 00:34:24,980 --> 00:34:32,620 achieving this. I've seen some pretty, obviously old school malware command and control, IRC. A 364 00:34:32,620 --> 00:34:33,120 friend of mine did a little bit of research on this. And he said that it's a little bit more 365 00:34:33,140 --> 00:34:38,060 complicated. So I tried to do IP over Facebook Messenger. That was pretty horrible. HTTP over 366 00:34:38,060 --> 00:34:47,580 XMPP. And just coming up with crazy silly ideas can be pretty fun. But I hope you all walk away 367 00:34:47,580 --> 00:34:54,900 from here understanding how SNI facilitates sharing infrastructure that uses TLS. Working around 368 00:34:54,900 --> 00:35:03,080 that problem of needing one IP per host. How third parties can see where your HTTPS traffic is 369 00:35:03,080 --> 00:35:12,140 going without doing a man-in-the-middle attack. How to find domains and actually do domain 370 00:35:12,140 --> 00:35:18,980 fronting yourself. And also how to protect yourself from misconfigurations like what I saw before. 371 00:35:19,900 --> 00:35:28,180 Where basically the infrastructure just didn't do what was expected. Thanks for having me. Any 372 00:35:28,180 --> 00:35:33,060 questions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 00:35:33,080 --> 00:35:36,020 . . . .