1 00:00:00,000 --> 00:00:04,660 William Taylor is a security consultant with a background in embedded engineering and DevOps. 2 00:00:04,660 --> 00:00:14,320 And in this talk, looking to create a case study concerning Transit Gateway and AWS, where security consultants were able to communicate freely across an apparent network boundary. 3 00:00:14,320 --> 00:00:18,460 The title of the talk is Unexpected Leaks in AWS Transit Gateways. 4 00:00:18,460 --> 00:00:20,980 Please give William a warm welcome. 5 00:00:26,020 --> 00:00:27,520 Thanks, everybody. 6 00:00:27,520 --> 00:00:28,280 Hello. 7 00:00:28,960 --> 00:00:29,500 Wow. 8 00:00:29,500 --> 00:00:32,560 Final talk on the final day of the conference. 9 00:00:32,580 --> 00:00:36,000 Excellent effort for making it this far. 10 00:00:36,100 --> 00:00:39,740 You're all looking way fresher than I feel. 11 00:00:39,740 --> 00:00:44,780 But my voice only has to survive for another 20 minutes or so. 12 00:00:44,980 --> 00:00:51,360 Not used to holding a microphone, so if I keep moving it away from me, I'm going to start throwing things if you can't hear. 13 00:00:52,520 --> 00:00:58,000 So I'm going to be talking about leaky AWS Transit Gateways. 14 00:00:58,000 --> 00:01:02,340 I'm going to be walking through a security assessment that I did earlier this year. 15 00:01:02,340 --> 00:01:06,540 We're going to be looking at some of the issues that I found in that assessment. 16 00:01:06,640 --> 00:01:11,200 And we're going to try and look through some of the lessons learned from that. 17 00:01:11,540 --> 00:01:13,500 So a very brief introduction. 18 00:01:13,500 --> 00:01:14,340 My name is Will. 19 00:01:14,340 --> 00:01:17,180 I'm a security consultant at Winsecure. 20 00:01:17,180 --> 00:01:20,500 I'm based in New York, as you can tell from the accent. 21 00:01:20,800 --> 00:01:26,760 I have a few areas of interest, including mobile and Kubernetes security. 22 00:01:28,880 --> 00:01:33,060 And, more poignantly for this talk, cloud security. 23 00:01:33,860 --> 00:01:38,140 Let's take a look at the scenario that we're going to be walking through. 24 00:01:38,560 --> 00:01:45,580 So one of our clients, they have a new deployment of sensitive compute resources. 25 00:01:45,580 --> 00:01:53,820 The idea of this project that they're doing is no one will have direct access to the compute instances. 26 00:01:53,820 --> 00:01:55,880 It's all obfuscated from them. 27 00:01:55,880 --> 00:02:09,800 Users will go into a user interface, whatever service or application they want to run, type in some stuff, and then those resources will be provisioned in the background and deployed into this AWS account. 28 00:02:09,800 --> 00:02:19,040 So one of the key design aims of this project was the isolation of that compute. 29 00:02:19,040 --> 00:02:22,420 So it's sensitive, and they want it to be completely separate. 30 00:02:22,420 --> 00:02:23,960 No one is talking directly to it. 31 00:02:23,960 --> 00:02:25,100 No one can access it. 32 00:02:25,100 --> 00:02:29,020 That's the primary security concern of this project. 33 00:02:29,540 --> 00:02:37,680 Having just said that, the new deployment is temporarily connected to the old deployment. 34 00:02:37,680 --> 00:02:39,240 So this is a transition phase. 35 00:02:39,320 --> 00:02:42,280 They're designing a new deployment in a new region. 36 00:02:42,340 --> 00:02:44,540 But the old deployment is still running. 37 00:02:46,100 --> 00:02:59,120 And so if you already have some compute running in the old deployment, and then maybe there's an update and it needs more compute, maybe some of that is issued automatically into the new region. 38 00:02:59,480 --> 00:03:04,400 So there needs to be some controlled, limited communication between them. 39 00:03:04,400 --> 00:03:06,280 So this is a transition phase. 40 00:03:06,420 --> 00:03:08,640 But in the roadmap, that is one to two years. 41 00:03:08,640 --> 00:03:11,580 So this is going to be the situation for quite a while. 42 00:03:11,860 --> 00:03:13,260 And this is where we come in. 43 00:03:13,260 --> 00:03:21,960 So with Secure, we're hired to do a security assessment, to look at those security controls and see if they're effective in their aims. 44 00:03:23,100 --> 00:03:28,620 Let's look at the design of this project so we can see what we're dealing with. 45 00:03:28,620 --> 00:03:31,520 Here's our isolated account. 46 00:03:31,660 --> 00:03:33,860 And we have our VPC. 47 00:03:34,280 --> 00:03:36,800 And in our VPC, we have our subnets. 48 00:03:36,800 --> 00:03:39,000 And these are our compute subnets. 49 00:03:39,000 --> 00:03:45,300 So when someone wants some new resources, this is where our EC2s get deployed. 50 00:03:45,360 --> 00:03:50,000 And as well as our compute subnets, here we have our egress subnets. 51 00:03:50,000 --> 00:03:56,560 So if stuff does need to be, traffic does need to go out, it goes through these egress subnets. 52 00:03:58,540 --> 00:04:02,940 Each one of those in its own availability zone within the wider region. 53 00:04:04,580 --> 00:04:13,360 Now, so for most of the communication that those compute instances might need to do, they'll talk to AWS private link endpoints. 54 00:04:13,360 --> 00:04:22,860 So if they need any other AWS resources, or if they do need to talk to the internet for whatever reason, private link endpoints is where the majority of stuff is going to go. 55 00:04:22,860 --> 00:04:24,540 But we're not talking about that today. 56 00:04:24,540 --> 00:04:28,600 What we're interested in is this legacy account. 57 00:04:28,780 --> 00:04:33,360 So we have new one on the left, and on the right, the legacy account. 58 00:04:33,360 --> 00:04:38,580 Same idea, compute being deployed in there across various subnets. 59 00:04:39,060 --> 00:04:45,420 And the way that we're going to connect the new and the old is with transit gateways. 60 00:04:45,420 --> 00:04:55,260 So here we have a transit gateway, and the transit gateway attachments are attached to each of the egress subnets. 61 00:04:55,620 --> 00:04:58,640 Then there's a second transit gateway. 62 00:04:58,660 --> 00:05:00,660 Those two appear for traffic to go across. 63 00:05:00,660 --> 00:05:04,420 And then finally, the traffic goes into the legacy account. 64 00:05:04,420 --> 00:05:08,880 So now we can see how the new and the old are going to be connected. 65 00:05:09,240 --> 00:05:14,940 Finally on this diagram, and most importantly, we have the network access control lists. 66 00:05:14,940 --> 00:05:18,400 So these are in the egress subnets. 67 00:05:18,660 --> 00:05:27,840 And the way these have been set up is very granular for each of the subnets in the legacy account. 68 00:05:27,840 --> 00:05:33,100 There's a specific rule for that subnet explicitly denying all traffic. 69 00:05:33,120 --> 00:05:36,880 There also happens to be a deny all, a sort of a catch all. 70 00:05:36,880 --> 00:05:41,520 But the principle behind it is, by default, everything is blocked. 71 00:05:41,520 --> 00:05:44,700 But you have each of those rules for each of those subnets. 72 00:05:44,700 --> 00:05:57,700 And then if there does need to be communication between the two, that particular rule for that particular subnet, that can be switched around to allow communication across the two accounts. 73 00:06:00,800 --> 00:06:03,400 So we have our design. 74 00:06:03,400 --> 00:06:07,480 So it's fairly clear what the expected operation is here. 75 00:06:07,480 --> 00:06:14,040 So part of the assessment, we have deployed an EC2 into the compute egress. 76 00:06:14,040 --> 00:06:16,740 Into the compute subnet, I should say. 77 00:06:17,340 --> 00:06:24,460 We deployed it using the same technique that the customers of this account would use. 78 00:06:24,580 --> 00:06:27,840 So using that user interface, it gets deployed automatically. 79 00:06:28,140 --> 00:06:35,440 And then if we try and communicate with anything in the legacy account, it's just going to hit those knuckles and it's not going to go any further. 80 00:06:35,440 --> 00:06:36,920 So nice and simple. 81 00:06:38,080 --> 00:06:42,260 So on our test, what's the easiest way to test for this? 82 00:06:42,260 --> 00:06:49,460 We just run a simple nmap scan against one of those EC2s running in the legacy account. 83 00:06:49,460 --> 00:06:55,900 So we had all the private IP addresses for those EC2s in the old account. 84 00:06:56,040 --> 00:07:02,040 So we pick one of those, run an nmap scan, and the host subnet. 85 00:07:02,040 --> 00:07:06,700 It can hit it, it can enumerate all ports and communicate with it. 86 00:07:06,700 --> 00:07:08,220 So that's a bit weird. 87 00:07:08,220 --> 00:07:12,280 Let's check the subnet, run an nmap scan against the whole subnet. 88 00:07:12,340 --> 00:07:13,520 Same thing. 89 00:07:13,520 --> 00:07:16,560 All hosts, all ports being enumerated. 90 00:07:16,900 --> 00:07:22,680 Finally, just for good luck, we're going to run it against all the IPs known in that legacy account. 91 00:07:22,680 --> 00:07:24,820 And just all hosts are up. 92 00:07:24,820 --> 00:07:29,420 We can talk to every single EC2, enumerate all the ports. 93 00:07:29,700 --> 00:07:33,180 This isn't what the expected outcome was. 94 00:07:34,960 --> 00:07:38,700 So, now we can move on to the investigation. 95 00:07:38,700 --> 00:07:40,580 Let's try and find out what's going on. 96 00:07:40,580 --> 00:07:43,580 The design seems to make sense on the surface. 97 00:07:43,980 --> 00:07:47,120 We can see how the traffic is supposed to be flowing. 98 00:07:47,300 --> 00:07:50,480 But the evidence very much proves otherwise. 99 00:07:50,480 --> 00:07:52,300 So, what's going on? 100 00:07:52,820 --> 00:07:56,500 First thing we do, we look at the AWS account. 101 00:07:56,680 --> 00:08:00,640 Maybe that test EC2 has been deployed somewhere else somehow. 102 00:08:00,640 --> 00:08:02,540 Maybe it's been deployed to the legacy account. 103 00:08:03,000 --> 00:08:06,600 But no, it's all been in the right place, as expected. 104 00:08:06,720 --> 00:08:10,720 Are there any other strange resources in that account or something strange? 105 00:08:10,720 --> 00:08:11,780 I can't see anything. 106 00:08:11,820 --> 00:08:15,680 Everything seems to be matching the diagram that we've just looked at. 107 00:08:16,600 --> 00:08:20,020 We also have access to the infrastructure as code. 108 00:08:20,020 --> 00:08:22,520 So, we could look through that to see if there are any clues. 109 00:08:22,820 --> 00:08:26,340 But again, everything seems to be supporting the expectation. 110 00:08:26,420 --> 00:08:29,900 The diagram that we looked at seems to match the infrastructure as code. 111 00:08:29,900 --> 00:08:36,740 We can explicitly see those transit gateway attachments being attached to those egress subnets. 112 00:08:36,980 --> 00:08:40,760 So, everything seems to be as expected. 113 00:08:41,780 --> 00:08:43,440 So, the NACLs. 114 00:08:43,440 --> 00:08:44,600 It's got to be the NACLs, right? 115 00:08:44,600 --> 00:08:49,160 Because that's the network protection that's in place. 116 00:08:49,160 --> 00:08:53,160 That's what we're using to try and control our traffic flow. 117 00:08:53,160 --> 00:08:54,440 So, we take a look at them. 118 00:08:54,440 --> 00:08:59,000 Is there a sneaky allow all rule with a high priority in there or something? 119 00:08:59,000 --> 00:09:01,040 Couldn't see anything like that. 120 00:09:01,040 --> 00:09:03,620 Checking through all the rules all makes sense. 121 00:09:03,620 --> 00:09:08,920 And we can see there's a rule explicitly denying a certain IP. 122 00:09:09,060 --> 00:09:12,220 And then we can scan that IP and we can connect to it. 123 00:09:12,220 --> 00:09:16,700 So, it's like these NACLs just aren't doing anything. 124 00:09:17,420 --> 00:09:18,900 Time for a Google. 125 00:09:19,540 --> 00:09:23,560 So, go to the internet and start searching around. 126 00:09:23,560 --> 00:09:26,280 Try to see if anyone's done anything similar. 127 00:09:26,280 --> 00:09:29,140 See if anyone's got any similar experiences. 128 00:09:29,140 --> 00:09:33,540 We found a blog post on an AWS support forum. 129 00:09:34,880 --> 00:09:40,660 Now, this person is doing something very similar to the design that we looked at before. 130 00:09:40,660 --> 00:09:44,180 So, they have multiple subnets split by availability zone. 131 00:09:44,180 --> 00:09:46,780 Two subnets in each availability zone. 132 00:09:46,880 --> 00:09:54,640 And then by their testing and the documentation, it's impossible to link two or more subnets to a transit gateway attachment. 133 00:09:54,640 --> 00:09:59,920 Now, what these people are trying to do in their projects, they actually wanted the scenario that we have. 134 00:09:59,920 --> 00:10:08,220 They wanted all the subnets to be connected to that transit gateway to be able to do whatever they want to do, send the traffic. 135 00:10:08,540 --> 00:10:12,520 So, we're achieving what they want to achieve, and they're confused why they can't do it. 136 00:10:13,120 --> 00:10:14,660 What are the responses? 137 00:10:15,720 --> 00:10:21,220 The subnet association is simply the subnet within the entire availability zone. 138 00:10:21,840 --> 00:10:24,080 The entire availability zone. 139 00:10:24,080 --> 00:10:28,040 That's the clue that's going to tell us what went wrong. 140 00:10:29,460 --> 00:10:32,960 Let's go back and look at our diagram. 141 00:10:32,960 --> 00:10:34,720 So, this is what we had before. 142 00:10:35,200 --> 00:10:42,740 But from what we've just learned on the previous slide, there's something that should be slightly different in our diagram. 143 00:10:42,740 --> 00:10:50,180 It actually makes more sense to depict the transit gateway attachments here, on the availability zone. 144 00:10:50,780 --> 00:11:00,480 Now, if our transit gateway attachments are attached here on the availability zone, then those egress subnets, they're not doing anything. 145 00:11:00,480 --> 00:11:02,100 They basically don't exist. 146 00:11:02,740 --> 00:11:09,100 Now, our traffic is just going straight from our compute network to the gateway attachment, straight across. 147 00:11:09,160 --> 00:11:09,660 So, there we go. 148 00:11:09,660 --> 00:11:15,680 Now, we can clearly see why we're able to hit all of those EC2s in the legacy account. 149 00:11:15,680 --> 00:11:35,960 So, the compute subnets, they did have the NACLs, but anyone who's ever deployed anything in AWS knows that the NACLs, by default, are just set to allow all, and quite often you'll find them stay that way, because a lot of people use security groups, and so just leave the NACLs alone. 150 00:11:35,960 --> 00:11:46,660 But in this particular project, the NACLs are critical, but they were placed in the egress subnets, which are now gone, so now we just have allow all in the background there. 151 00:11:48,120 --> 00:11:49,300 What's the fix? 152 00:11:49,300 --> 00:11:51,580 How can we stop this happening? 153 00:11:51,580 --> 00:12:00,020 There's always a caveat when talking about fixes, because it's very dependent on the client's needs, a particular project. 154 00:12:00,260 --> 00:12:08,520 There might be a reason why they're doing something in a particular way, but there's a very clear thing that we need to apply. 155 00:12:08,520 --> 00:12:13,240 Those NACLs should be in the compute subnet. 156 00:12:14,360 --> 00:12:27,920 There is actually, in the documentation, there's sort of a throwaway line that does mention that the NACL should be applied where the compute is living, so that was one of the mistakes that was made in the design. 157 00:12:27,920 --> 00:12:32,500 And also, if you are using NACLs, then don't use the default ones. 158 00:12:32,500 --> 00:12:36,740 They should always be actively set, not just using the default. 159 00:12:37,760 --> 00:12:43,540 Maybe VPC peering is an alternative, but that's a different technology, it's a different approach. 160 00:12:43,580 --> 00:12:45,800 They might be able to do the same thing they want to do. 161 00:12:45,800 --> 00:12:47,900 Maybe they want to use transit gateways. 162 00:12:48,240 --> 00:12:55,760 Maybe you want separate compute and egress VPCs, rather than trying to have the subnets as the network separator. 163 00:12:55,760 --> 00:12:58,480 The subnets are more commonly the logical separator. 164 00:12:58,480 --> 00:13:01,260 Maybe separate them into different VPCs. 165 00:13:02,800 --> 00:13:06,840 The exact solution, that would depend on the client and what they want to achieve. 166 00:13:06,840 --> 00:13:08,520 But those NACLs, that's the key one. 167 00:13:08,520 --> 00:13:11,200 If you are going to use NACLs, make sure they are set properly. 168 00:13:12,320 --> 00:13:14,520 So the conclusion, the lessons learned. 169 00:13:14,520 --> 00:13:16,160 What do we take away from this? 170 00:13:16,520 --> 00:13:18,320 Strong design, strong start. 171 00:13:18,400 --> 00:13:22,780 So this client, they did design with security in mind, which is excellent. 172 00:13:22,780 --> 00:13:31,000 They weren't just thinking about it as an afterthought, they were thinking about it, how they were going to protect their system, and they did security design review. 173 00:13:31,000 --> 00:13:31,920 Again, very valuable. 174 00:13:31,920 --> 00:13:37,260 Someone looked at it and was like, yep, this makes sense, this seems to do what we want it to do. 175 00:13:38,460 --> 00:13:45,220 But this use case really shows how crucial it is to do that practical testing. 176 00:13:45,320 --> 00:13:52,640 Because everything on paper, everyone was thinking it's all fine, and then two minutes of practical testing, we can see that it's not actually the case. 177 00:13:53,000 --> 00:13:55,120 Everything was completely open. 178 00:13:57,060 --> 00:13:59,100 Dangers of dodgy documentation. 179 00:13:59,340 --> 00:14:01,340 I think that's a little unfair. 180 00:14:01,720 --> 00:14:04,560 I mainly kept that line in because I really like alliteration. 181 00:14:05,120 --> 00:14:14,920 But one of the things in the documents about Transit Gateways, they talk about how it's attached to one of the subnets, and that's what it appears to be. 182 00:14:15,300 --> 00:14:21,280 And then because of that, that sort of implies that the original design we looked at is the right way around. 183 00:14:21,280 --> 00:14:23,460 It's the right way how everything is set up. 184 00:14:24,260 --> 00:14:30,560 But again, if you read the documentation carefully, it does say that it's different, which is why I say it's a little bit unfair what I'm saying. 185 00:14:30,620 --> 00:14:37,540 But the takeaway is, if you're just relying on the documentation, the documentation could be wrong, it could be incomplete, it could be confusing. 186 00:14:37,600 --> 00:14:41,020 So it's great, but just never rely on it too much. 187 00:14:41,620 --> 00:14:43,460 So one final slide. 188 00:14:44,220 --> 00:14:49,120 So I've walked through this use case, but it's far from being unique. 189 00:14:49,120 --> 00:14:50,440 This happens all the time. 190 00:14:50,440 --> 00:14:56,020 So some slightly different examples of when testing revealed strange behaviors. 191 00:14:56,020 --> 00:14:59,700 There was another AWS account with EC2 deployment. 192 00:14:59,700 --> 00:15:04,220 All these EC2s had public IPs, and the security groups were set to allow all. 193 00:15:04,220 --> 00:15:07,040 By design, that was necessary for their function. 194 00:15:07,040 --> 00:15:08,640 They wanted high throughput. 195 00:15:08,820 --> 00:15:15,260 So they were using IP tables within TCP connections to protect those exposed EC2s. 196 00:15:16,440 --> 00:15:17,920 799 of them. 197 00:15:17,920 --> 00:15:18,460 Fine. 198 00:15:18,460 --> 00:15:20,220 Couldn't connect one. 199 00:15:20,220 --> 00:15:22,260 You could connect scanning with an Nmap. 200 00:15:22,260 --> 00:15:26,100 I could hit port 22, port 111, connect on SSH. 201 00:15:26,800 --> 00:15:37,180 And it turned out it was just this tiny error in the initialization script where that IP tables rule, there was no catch to see if it was successful or not. 202 00:15:37,180 --> 00:15:43,040 It just ran, just a simple bash script, and then if for whatever reason it failed, it just carried on and nothing had happened. 203 00:15:43,040 --> 00:15:47,360 So on this particular instance, that IP table rule wasn't set. 204 00:15:47,360 --> 00:15:48,660 It remained open. 205 00:15:48,660 --> 00:15:54,700 So doing that security assessment, it all seemed fine, but because we tested it, we found that one that was the exception. 206 00:15:56,100 --> 00:15:57,360 So just AWS. 207 00:15:58,240 --> 00:16:01,740 Occasionally, Azure will throw up weird things at you. 208 00:16:02,000 --> 00:16:05,060 So we had an Azure account. 209 00:16:05,060 --> 00:16:11,400 We had sensitive compute, and they had a large number of network security groups to control the traffic in and out. 210 00:16:11,400 --> 00:16:14,880 So there were individual IPs, individual ports. 211 00:16:14,880 --> 00:16:16,160 They had loads of them. 212 00:16:18,100 --> 00:16:22,020 But then they also had this thing called a service tag. 213 00:16:22,020 --> 00:16:25,780 Now, I'm giving the shortest introduction to service tags. 214 00:16:25,780 --> 00:16:38,520 Last year, a good friend and colleague of mine, Alan Mehta, who is in the audience today, gave a great talk at Cloud Village about it, so I encourage you to check that out and speak with him for more information about the service tags. 215 00:16:38,520 --> 00:16:43,160 But basically what it means is if you set service tag rather than an IP, 216 00:16:46,420 --> 00:16:54,520 the compute in your network can talk directly to any Azure compute instance with a public IP. 217 00:16:54,520 --> 00:16:58,180 Because Azure Cloud Service Tag basically means all of those IPs. 218 00:16:58,940 --> 00:17:03,180 So it permits that outbound connection, and suddenly you've got that outbound role. 219 00:17:03,320 --> 00:17:12,200 And again, the design was done initially with the great intentions, but then they threw in this service tag that they didn't really understand because very few people do. 220 00:17:12,200 --> 00:17:14,920 And outbound. 221 00:17:16,100 --> 00:17:17,680 And that's me. 222 00:17:17,820 --> 00:17:19,580 Thank you very much for listening. 223 00:17:19,580 --> 00:17:20,460 Thank you. 224 00:17:20,460 --> 00:17:21,480 Applause.