start	end	text
0	4660	William Taylor is a security consultant with a background in embedded engineering and DevOps.
4660	14320	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.
14320	18460	The title of the talk is Unexpected Leaks in AWS Transit Gateways.
18460	20980	Please give William a warm welcome.
26020	27520	Thanks, everybody.
27520	28280	Hello.
28960	29500	Wow.
29500	32560	Final talk on the final day of the conference.
32580	36000	Excellent effort for making it this far.
36100	39740	You're all looking way fresher than I feel.
39740	44780	But my voice only has to survive for another 20 minutes or so.
44980	51360	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.
52520	58000	So I'm going to be talking about leaky AWS Transit Gateways.
58000	62340	I'm going to be walking through a security assessment that I did earlier this year.
62340	66540	We're going to be looking at some of the issues that I found in that assessment.
66640	71200	And we're going to try and look through some of the lessons learned from that.
71540	73500	So a very brief introduction.
73500	74340	My name is Will.
74340	77180	I'm a security consultant at Winsecure.
77180	80500	I'm based in New York, as you can tell from the accent.
80800	86760	I have a few areas of interest, including mobile and Kubernetes security.
88880	93060	And, more poignantly for this talk, cloud security.
93860	98140	Let's take a look at the scenario that we're going to be walking through.
98560	105580	So one of our clients, they have a new deployment of sensitive compute resources.
105580	113820	The idea of this project that they're doing is no one will have direct access to the compute instances.
113820	115880	It's all obfuscated from them.
115880	129800	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.
129800	139040	So one of the key design aims of this project was the isolation of that compute.
139040	142420	So it's sensitive, and they want it to be completely separate.
142420	143960	No one is talking directly to it.
143960	145100	No one can access it.
145100	149020	That's the primary security concern of this project.
149540	157680	Having just said that, the new deployment is temporarily connected to the old deployment.
157680	159240	So this is a transition phase.
159320	162280	They're designing a new deployment in a new region.
162340	164540	But the old deployment is still running.
166100	179120	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.
179480	184400	So there needs to be some controlled, limited communication between them.
184400	186280	So this is a transition phase.
186420	188640	But in the roadmap, that is one to two years.
188640	191580	So this is going to be the situation for quite a while.
191860	193260	And this is where we come in.
193260	201960	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.
203100	208620	Let's look at the design of this project so we can see what we're dealing with.
208620	211520	Here's our isolated account.
211660	213860	And we have our VPC.
214280	216800	And in our VPC, we have our subnets.
216800	219000	And these are our compute subnets.
219000	225300	So when someone wants some new resources, this is where our EC2s get deployed.
225360	230000	And as well as our compute subnets, here we have our egress subnets.
230000	236560	So if stuff does need to be, traffic does need to go out, it goes through these egress subnets.
238540	242940	Each one of those in its own availability zone within the wider region.
244580	253360	Now, so for most of the communication that those compute instances might need to do, they'll talk to AWS private link endpoints.
253360	262860	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.
262860	264540	But we're not talking about that today.
264540	268600	What we're interested in is this legacy account.
268780	273360	So we have new one on the left, and on the right, the legacy account.
273360	278580	Same idea, compute being deployed in there across various subnets.
279060	285420	And the way that we're going to connect the new and the old is with transit gateways.
285420	295260	So here we have a transit gateway, and the transit gateway attachments are attached to each of the egress subnets.
295620	298640	Then there's a second transit gateway.
298660	300660	Those two appear for traffic to go across.
300660	304420	And then finally, the traffic goes into the legacy account.
304420	308880	So now we can see how the new and the old are going to be connected.
309240	314940	Finally on this diagram, and most importantly, we have the network access control lists.
314940	318400	So these are in the egress subnets.
318660	327840	And the way these have been set up is very granular for each of the subnets in the legacy account.
327840	333100	There's a specific rule for that subnet explicitly denying all traffic.
333120	336880	There also happens to be a deny all, a sort of a catch all.
336880	341520	But the principle behind it is, by default, everything is blocked.
341520	344700	But you have each of those rules for each of those subnets.
344700	357700	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.
360800	363400	So we have our design.
363400	367480	So it's fairly clear what the expected operation is here.
367480	374040	So part of the assessment, we have deployed an EC2 into the compute egress.
374040	376740	Into the compute subnet, I should say.
377340	384460	We deployed it using the same technique that the customers of this account would use.
384580	387840	So using that user interface, it gets deployed automatically.
388140	395440	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.
395440	396920	So nice and simple.
398080	402260	So on our test, what's the easiest way to test for this?
402260	409460	We just run a simple nmap scan against one of those EC2s running in the legacy account.
409460	415900	So we had all the private IP addresses for those EC2s in the old account.
416040	422040	So we pick one of those, run an nmap scan, and the host subnet.
422040	426700	It can hit it, it can enumerate all ports and communicate with it.
426700	428220	So that's a bit weird.
428220	432280	Let's check the subnet, run an nmap scan against the whole subnet.
432340	433520	Same thing.
433520	436560	All hosts, all ports being enumerated.
436900	442680	Finally, just for good luck, we're going to run it against all the IPs known in that legacy account.
442680	444820	And just all hosts are up.
444820	449420	We can talk to every single EC2, enumerate all the ports.
449700	453180	This isn't what the expected outcome was.
454960	458700	So, now we can move on to the investigation.
458700	460580	Let's try and find out what's going on.
460580	463580	The design seems to make sense on the surface.
463980	467120	We can see how the traffic is supposed to be flowing.
467300	470480	But the evidence very much proves otherwise.
470480	472300	So, what's going on?
472820	476500	First thing we do, we look at the AWS account.
476680	480640	Maybe that test EC2 has been deployed somewhere else somehow.
480640	482540	Maybe it's been deployed to the legacy account.
483000	486600	But no, it's all been in the right place, as expected.
486720	490720	Are there any other strange resources in that account or something strange?
490720	491780	I can't see anything.
491820	495680	Everything seems to be matching the diagram that we've just looked at.
496600	500020	We also have access to the infrastructure as code.
500020	502520	So, we could look through that to see if there are any clues.
502820	506340	But again, everything seems to be supporting the expectation.
506420	509900	The diagram that we looked at seems to match the infrastructure as code.
509900	516740	We can explicitly see those transit gateway attachments being attached to those egress subnets.
516980	520760	So, everything seems to be as expected.
521780	523440	So, the NACLs.
523440	524600	It's got to be the NACLs, right?
524600	529160	Because that's the network protection that's in place.
529160	533160	That's what we're using to try and control our traffic flow.
533160	534440	So, we take a look at them.
534440	539000	Is there a sneaky allow all rule with a high priority in there or something?
539000	541040	Couldn't see anything like that.
541040	543620	Checking through all the rules all makes sense.
543620	548920	And we can see there's a rule explicitly denying a certain IP.
549060	552220	And then we can scan that IP and we can connect to it.
552220	556700	So, it's like these NACLs just aren't doing anything.
557420	558900	Time for a Google.
559540	563560	So, go to the internet and start searching around.
563560	566280	Try to see if anyone's done anything similar.
566280	569140	See if anyone's got any similar experiences.
569140	573540	We found a blog post on an AWS support forum.
574880	580660	Now, this person is doing something very similar to the design that we looked at before.
580660	584180	So, they have multiple subnets split by availability zone.
584180	586780	Two subnets in each availability zone.
586880	594640	And then by their testing and the documentation, it's impossible to link two or more subnets to a transit gateway attachment.
594640	599920	Now, what these people are trying to do in their projects, they actually wanted the scenario that we have.
599920	608220	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.
608540	612520	So, we're achieving what they want to achieve, and they're confused why they can't do it.
613120	614660	What are the responses?
615720	621220	The subnet association is simply the subnet within the entire availability zone.
621840	624080	The entire availability zone.
624080	628040	That's the clue that's going to tell us what went wrong.
629460	632960	Let's go back and look at our diagram.
632960	634720	So, this is what we had before.
635200	642740	But from what we've just learned on the previous slide, there's something that should be slightly different in our diagram.
642740	650180	It actually makes more sense to depict the transit gateway attachments here, on the availability zone.
650780	660480	Now, if our transit gateway attachments are attached here on the availability zone, then those egress subnets, they're not doing anything.
660480	662100	They basically don't exist.
662740	669100	Now, our traffic is just going straight from our compute network to the gateway attachment, straight across.
669160	669660	So, there we go.
669660	675680	Now, we can clearly see why we're able to hit all of those EC2s in the legacy account.
675680	695960	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.
695960	706660	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.
708120	709300	What's the fix?
709300	711580	How can we stop this happening?
711580	720020	There's always a caveat when talking about fixes, because it's very dependent on the client's needs, a particular project.
720260	728520	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.
728520	733240	Those NACLs should be in the compute subnet.
734360	747920	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.
747920	752500	And also, if you are using NACLs, then don't use the default ones.
752500	756740	They should always be actively set, not just using the default.
757760	763540	Maybe VPC peering is an alternative, but that's a different technology, it's a different approach.
763580	765800	They might be able to do the same thing they want to do.
765800	767900	Maybe they want to use transit gateways.
768240	775760	Maybe you want separate compute and egress VPCs, rather than trying to have the subnets as the network separator.
775760	778480	The subnets are more commonly the logical separator.
778480	781260	Maybe separate them into different VPCs.
782800	786840	The exact solution, that would depend on the client and what they want to achieve.
786840	788520	But those NACLs, that's the key one.
788520	791200	If you are going to use NACLs, make sure they are set properly.
792320	794520	So the conclusion, the lessons learned.
794520	796160	What do we take away from this?
796520	798320	Strong design, strong start.
798400	802780	So this client, they did design with security in mind, which is excellent.
802780	811000	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.
811000	811920	Again, very valuable.
811920	817260	Someone looked at it and was like, yep, this makes sense, this seems to do what we want it to do.
818460	825220	But this use case really shows how crucial it is to do that practical testing.
825320	832640	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.
833000	835120	Everything was completely open.
837060	839100	Dangers of dodgy documentation.
839340	841340	I think that's a little unfair.
841720	844560	I mainly kept that line in because I really like alliteration.
845120	854920	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.
855300	861280	And then because of that, that sort of implies that the original design we looked at is the right way around.
861280	863460	It's the right way how everything is set up.
864260	870560	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.
870620	877540	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.
877600	881020	So it's great, but just never rely on it too much.
881620	883460	So one final slide.
884220	889120	So I've walked through this use case, but it's far from being unique.
889120	890440	This happens all the time.
890440	896020	So some slightly different examples of when testing revealed strange behaviors.
896020	899700	There was another AWS account with EC2 deployment.
899700	904220	All these EC2s had public IPs, and the security groups were set to allow all.
904220	907040	By design, that was necessary for their function.
907040	908640	They wanted high throughput.
908820	915260	So they were using IP tables within TCP connections to protect those exposed EC2s.
916440	917920	799 of them.
917920	918460	Fine.
918460	920220	Couldn't connect one.
920220	922260	You could connect scanning with an Nmap.
922260	926100	I could hit port 22, port 111, connect on SSH.
926800	937180	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.
937180	943040	It just ran, just a simple bash script, and then if for whatever reason it failed, it just carried on and nothing had happened.
943040	947360	So on this particular instance, that IP table rule wasn't set.
947360	948660	It remained open.
948660	954700	So doing that security assessment, it all seemed fine, but because we tested it, we found that one that was the exception.
956100	957360	So just AWS.
958240	961740	Occasionally, Azure will throw up weird things at you.
962000	965060	So we had an Azure account.
965060	971400	We had sensitive compute, and they had a large number of network security groups to control the traffic in and out.
971400	974880	So there were individual IPs, individual ports.
974880	976160	They had loads of them.
978100	982020	But then they also had this thing called a service tag.
982020	985780	Now, I'm giving the shortest introduction to service tags.
985780	998520	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.
998520	1003160	But basically what it means is if you set service tag rather than an IP,
1006420	1014520	the compute in your network can talk directly to any Azure compute instance with a public IP.
1014520	1018180	Because Azure Cloud Service Tag basically means all of those IPs.
1018940	1023180	So it permits that outbound connection, and suddenly you've got that outbound role.
1023320	1032200	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.
1032200	1034920	And outbound.
1036100	1037680	And that's me.
1037820	1039580	Thank you very much for listening.
1039580	1040460	Thank you.
1040460	1041480	Applause.
