WEBVTT

00:00.000 --> 00:04.660
William Taylor is a security consultant with a background in embedded engineering and DevOps.

00:04.660 --> 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.

00:14.320 --> 00:18.460
The title of the talk is Unexpected Leaks in AWS Transit Gateways.

00:18.460 --> 00:20.980
Please give William a warm welcome.

00:26.020 --> 00:27.520
Thanks, everybody.

00:27.520 --> 00:28.280
Hello.

00:28.960 --> 00:29.500
Wow.

00:29.500 --> 00:32.560
Final talk on the final day of the conference.

00:32.580 --> 00:36.000
Excellent effort for making it this far.

00:36.100 --> 00:39.740
You're all looking way fresher than I feel.

00:39.740 --> 00:44.780
But my voice only has to survive for another 20 minutes or so.

00:44.980 --> 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.

00:52.520 --> 00:58.000
So I'm going to be talking about leaky AWS Transit Gateways.

00:58.000 --> 01:02.340
I'm going to be walking through a security assessment that I did earlier this year.

01:02.340 --> 01:06.540
We're going to be looking at some of the issues that I found in that assessment.

01:06.640 --> 01:11.200
And we're going to try and look through some of the lessons learned from that.

01:11.540 --> 01:13.500
So a very brief introduction.

01:13.500 --> 01:14.340
My name is Will.

01:14.340 --> 01:17.180
I'm a security consultant at Winsecure.

01:17.180 --> 01:20.500
I'm based in New York, as you can tell from the accent.

01:20.800 --> 01:26.760
I have a few areas of interest, including mobile and Kubernetes security.

01:28.880 --> 01:33.060
And, more poignantly for this talk, cloud security.

01:33.860 --> 01:38.140
Let's take a look at the scenario that we're going to be walking through.

01:38.560 --> 01:45.580
So one of our clients, they have a new deployment of sensitive compute resources.

01:45.580 --> 01:53.820
The idea of this project that they're doing is no one will have direct access to the compute instances.

01:53.820 --> 01:55.880
It's all obfuscated from them.

01:55.880 --> 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.

02:09.800 --> 02:19.040
So one of the key design aims of this project was the isolation of that compute.

02:19.040 --> 02:22.420
So it's sensitive, and they want it to be completely separate.

02:22.420 --> 02:23.960
No one is talking directly to it.

02:23.960 --> 02:25.100
No one can access it.

02:25.100 --> 02:29.020
That's the primary security concern of this project.

02:29.540 --> 02:37.680
Having just said that, the new deployment is temporarily connected to the old deployment.

02:37.680 --> 02:39.240
So this is a transition phase.

02:39.320 --> 02:42.280
They're designing a new deployment in a new region.

02:42.340 --> 02:44.540
But the old deployment is still running.

02:46.100 --> 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.

02:59.480 --> 03:04.400
So there needs to be some controlled, limited communication between them.

03:04.400 --> 03:06.280
So this is a transition phase.

03:06.420 --> 03:08.640
But in the roadmap, that is one to two years.

03:08.640 --> 03:11.580
So this is going to be the situation for quite a while.

03:11.860 --> 03:13.260
And this is where we come in.

03:13.260 --> 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.

03:23.100 --> 03:28.620
Let's look at the design of this project so we can see what we're dealing with.

03:28.620 --> 03:31.520
Here's our isolated account.

03:31.660 --> 03:33.860
And we have our VPC.

03:34.280 --> 03:36.800
And in our VPC, we have our subnets.

03:36.800 --> 03:39.000
And these are our compute subnets.

03:39.000 --> 03:45.300
So when someone wants some new resources, this is where our EC2s get deployed.

03:45.360 --> 03:50.000
And as well as our compute subnets, here we have our egress subnets.

03:50.000 --> 03:56.560
So if stuff does need to be, traffic does need to go out, it goes through these egress subnets.

03:58.540 --> 04:02.940
Each one of those in its own availability zone within the wider region.

04:04.580 --> 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.

04:13.360 --> 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.

04:22.860 --> 04:24.540
But we're not talking about that today.

04:24.540 --> 04:28.600
What we're interested in is this legacy account.

04:28.780 --> 04:33.360
So we have new one on the left, and on the right, the legacy account.

04:33.360 --> 04:38.580
Same idea, compute being deployed in there across various subnets.

04:39.060 --> 04:45.420
And the way that we're going to connect the new and the old is with transit gateways.

04:45.420 --> 04:55.260
So here we have a transit gateway, and the transit gateway attachments are attached to each of the egress subnets.

04:55.620 --> 04:58.640
Then there's a second transit gateway.

04:58.660 --> 05:00.660
Those two appear for traffic to go across.

05:00.660 --> 05:04.420
And then finally, the traffic goes into the legacy account.

05:04.420 --> 05:08.880
So now we can see how the new and the old are going to be connected.

05:09.240 --> 05:14.940
Finally on this diagram, and most importantly, we have the network access control lists.

05:14.940 --> 05:18.400
So these are in the egress subnets.

05:18.660 --> 05:27.840
And the way these have been set up is very granular for each of the subnets in the legacy account.

05:27.840 --> 05:33.100
There's a specific rule for that subnet explicitly denying all traffic.

05:33.120 --> 05:36.880
There also happens to be a deny all, a sort of a catch all.

05:36.880 --> 05:41.520
But the principle behind it is, by default, everything is blocked.

05:41.520 --> 05:44.700
But you have each of those rules for each of those subnets.

05:44.700 --> 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.

06:00.800 --> 06:03.400
So we have our design.

06:03.400 --> 06:07.480
So it's fairly clear what the expected operation is here.

06:07.480 --> 06:14.040
So part of the assessment, we have deployed an EC2 into the compute egress.

06:14.040 --> 06:16.740
Into the compute subnet, I should say.

06:17.340 --> 06:24.460
We deployed it using the same technique that the customers of this account would use.

06:24.580 --> 06:27.840
So using that user interface, it gets deployed automatically.

06:28.140 --> 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.

06:35.440 --> 06:36.920
So nice and simple.

06:38.080 --> 06:42.260
So on our test, what's the easiest way to test for this?

06:42.260 --> 06:49.460
We just run a simple nmap scan against one of those EC2s running in the legacy account.

06:49.460 --> 06:55.900
So we had all the private IP addresses for those EC2s in the old account.

06:56.040 --> 07:02.040
So we pick one of those, run an nmap scan, and the host subnet.

07:02.040 --> 07:06.700
It can hit it, it can enumerate all ports and communicate with it.

07:06.700 --> 07:08.220
So that's a bit weird.

07:08.220 --> 07:12.280
Let's check the subnet, run an nmap scan against the whole subnet.

07:12.340 --> 07:13.520
Same thing.

07:13.520 --> 07:16.560
All hosts, all ports being enumerated.

07:16.900 --> 07:22.680
Finally, just for good luck, we're going to run it against all the IPs known in that legacy account.

07:22.680 --> 07:24.820
And just all hosts are up.

07:24.820 --> 07:29.420
We can talk to every single EC2, enumerate all the ports.

07:29.700 --> 07:33.180
This isn't what the expected outcome was.

07:34.960 --> 07:38.700
So, now we can move on to the investigation.

07:38.700 --> 07:40.580
Let's try and find out what's going on.

07:40.580 --> 07:43.580
The design seems to make sense on the surface.

07:43.980 --> 07:47.120
We can see how the traffic is supposed to be flowing.

07:47.300 --> 07:50.480
But the evidence very much proves otherwise.

07:50.480 --> 07:52.300
So, what's going on?

07:52.820 --> 07:56.500
First thing we do, we look at the AWS account.

07:56.680 --> 08:00.640
Maybe that test EC2 has been deployed somewhere else somehow.

08:00.640 --> 08:02.540
Maybe it's been deployed to the legacy account.

08:03.000 --> 08:06.600
But no, it's all been in the right place, as expected.

08:06.720 --> 08:10.720
Are there any other strange resources in that account or something strange?

08:10.720 --> 08:11.780
I can't see anything.

08:11.820 --> 08:15.680
Everything seems to be matching the diagram that we've just looked at.

08:16.600 --> 08:20.020
We also have access to the infrastructure as code.

08:20.020 --> 08:22.520
So, we could look through that to see if there are any clues.

08:22.820 --> 08:26.340
But again, everything seems to be supporting the expectation.

08:26.420 --> 08:29.900
The diagram that we looked at seems to match the infrastructure as code.

08:29.900 --> 08:36.740
We can explicitly see those transit gateway attachments being attached to those egress subnets.

08:36.980 --> 08:40.760
So, everything seems to be as expected.

08:41.780 --> 08:43.440
So, the NACLs.

08:43.440 --> 08:44.600
It's got to be the NACLs, right?

08:44.600 --> 08:49.160
Because that's the network protection that's in place.

08:49.160 --> 08:53.160
That's what we're using to try and control our traffic flow.

08:53.160 --> 08:54.440
So, we take a look at them.

08:54.440 --> 08:59.000
Is there a sneaky allow all rule with a high priority in there or something?

08:59.000 --> 09:01.040
Couldn't see anything like that.

09:01.040 --> 09:03.620
Checking through all the rules all makes sense.

09:03.620 --> 09:08.920
And we can see there's a rule explicitly denying a certain IP.

09:09.060 --> 09:12.220
And then we can scan that IP and we can connect to it.

09:12.220 --> 09:16.700
So, it's like these NACLs just aren't doing anything.

09:17.420 --> 09:18.900
Time for a Google.

09:19.540 --> 09:23.560
So, go to the internet and start searching around.

09:23.560 --> 09:26.280
Try to see if anyone's done anything similar.

09:26.280 --> 09:29.140
See if anyone's got any similar experiences.

09:29.140 --> 09:33.540
We found a blog post on an AWS support forum.

09:34.880 --> 09:40.660
Now, this person is doing something very similar to the design that we looked at before.

09:40.660 --> 09:44.180
So, they have multiple subnets split by availability zone.

09:44.180 --> 09:46.780
Two subnets in each availability zone.

09:46.880 --> 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.

09:54.640 --> 09:59.920
Now, what these people are trying to do in their projects, they actually wanted the scenario that we have.

09:59.920 --> 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.

10:08.540 --> 10:12.520
So, we're achieving what they want to achieve, and they're confused why they can't do it.

10:13.120 --> 10:14.660
What are the responses?

10:15.720 --> 10:21.220
The subnet association is simply the subnet within the entire availability zone.

10:21.840 --> 10:24.080
The entire availability zone.

10:24.080 --> 10:28.040
That's the clue that's going to tell us what went wrong.

10:29.460 --> 10:32.960
Let's go back and look at our diagram.

10:32.960 --> 10:34.720
So, this is what we had before.

10:35.200 --> 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.

10:42.740 --> 10:50.180
It actually makes more sense to depict the transit gateway attachments here, on the availability zone.

10:50.780 --> 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.

11:00.480 --> 11:02.100
They basically don't exist.

11:02.740 --> 11:09.100
Now, our traffic is just going straight from our compute network to the gateway attachment, straight across.

11:09.160 --> 11:09.660
So, there we go.

11:09.660 --> 11:15.680
Now, we can clearly see why we're able to hit all of those EC2s in the legacy account.

11:15.680 --> 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.

11:35.960 --> 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.

11:48.120 --> 11:49.300
What's the fix?

11:49.300 --> 11:51.580
How can we stop this happening?

11:51.580 --> 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.

12:00.260 --> 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.

12:08.520 --> 12:13.240
Those NACLs should be in the compute subnet.

12:14.360 --> 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.

12:27.920 --> 12:32.500
And also, if you are using NACLs, then don't use the default ones.

12:32.500 --> 12:36.740
They should always be actively set, not just using the default.

12:37.760 --> 12:43.540
Maybe VPC peering is an alternative, but that's a different technology, it's a different approach.

12:43.580 --> 12:45.800
They might be able to do the same thing they want to do.

12:45.800 --> 12:47.900
Maybe they want to use transit gateways.

12:48.240 --> 12:55.760
Maybe you want separate compute and egress VPCs, rather than trying to have the subnets as the network separator.

12:55.760 --> 12:58.480
The subnets are more commonly the logical separator.

12:58.480 --> 13:01.260
Maybe separate them into different VPCs.

13:02.800 --> 13:06.840
The exact solution, that would depend on the client and what they want to achieve.

13:06.840 --> 13:08.520
But those NACLs, that's the key one.

13:08.520 --> 13:11.200
If you are going to use NACLs, make sure they are set properly.

13:12.320 --> 13:14.520
So the conclusion, the lessons learned.

13:14.520 --> 13:16.160
What do we take away from this?

13:16.520 --> 13:18.320
Strong design, strong start.

13:18.400 --> 13:22.780
So this client, they did design with security in mind, which is excellent.

13:22.780 --> 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.

13:31.000 --> 13:31.920
Again, very valuable.

13:31.920 --> 13:37.260
Someone looked at it and was like, yep, this makes sense, this seems to do what we want it to do.

13:38.460 --> 13:45.220
But this use case really shows how crucial it is to do that practical testing.

13:45.320 --> 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.

13:53.000 --> 13:55.120
Everything was completely open.

13:57.060 --> 13:59.100
Dangers of dodgy documentation.

13:59.340 --> 14:01.340
I think that's a little unfair.

14:01.720 --> 14:04.560
I mainly kept that line in because I really like alliteration.

14:05.120 --> 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.

14:15.300 --> 14:21.280
And then because of that, that sort of implies that the original design we looked at is the right way around.

14:21.280 --> 14:23.460
It's the right way how everything is set up.

14:24.260 --> 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.

14:30.620 --> 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.

14:37.600 --> 14:41.020
So it's great, but just never rely on it too much.

14:41.620 --> 14:43.460
So one final slide.

14:44.220 --> 14:49.120
So I've walked through this use case, but it's far from being unique.

14:49.120 --> 14:50.440
This happens all the time.

14:50.440 --> 14:56.020
So some slightly different examples of when testing revealed strange behaviors.

14:56.020 --> 14:59.700
There was another AWS account with EC2 deployment.

14:59.700 --> 15:04.220
All these EC2s had public IPs, and the security groups were set to allow all.

15:04.220 --> 15:07.040
By design, that was necessary for their function.

15:07.040 --> 15:08.640
They wanted high throughput.

15:08.820 --> 15:15.260
So they were using IP tables within TCP connections to protect those exposed EC2s.

15:16.440 --> 15:17.920
799 of them.

15:17.920 --> 15:18.460
Fine.

15:18.460 --> 15:20.220
Couldn't connect one.

15:20.220 --> 15:22.260
You could connect scanning with an Nmap.

15:22.260 --> 15:26.100
I could hit port 22, port 111, connect on SSH.

15:26.800 --> 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.

15:37.180 --> 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.

15:43.040 --> 15:47.360
So on this particular instance, that IP table rule wasn't set.

15:47.360 --> 15:48.660
It remained open.

15:48.660 --> 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.

15:56.100 --> 15:57.360
So just AWS.

15:58.240 --> 16:01.740
Occasionally, Azure will throw up weird things at you.

16:02.000 --> 16:05.060
So we had an Azure account.

16:05.060 --> 16:11.400
We had sensitive compute, and they had a large number of network security groups to control the traffic in and out.

16:11.400 --> 16:14.880
So there were individual IPs, individual ports.

16:14.880 --> 16:16.160
They had loads of them.

16:18.100 --> 16:22.020
But then they also had this thing called a service tag.

16:22.020 --> 16:25.780
Now, I'm giving the shortest introduction to service tags.

16:25.780 --> 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.

16:38.520 --> 16:43.160
But basically what it means is if you set service tag rather than an IP,

16:46.420 --> 16:54.520
the compute in your network can talk directly to any Azure compute instance with a public IP.

16:54.520 --> 16:58.180
Because Azure Cloud Service Tag basically means all of those IPs.

16:58.940 --> 17:03.180
So it permits that outbound connection, and suddenly you've got that outbound role.

17:03.320 --> 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.

17:12.200 --> 17:14.920
And outbound.

17:16.100 --> 17:17.680
And that's me.

17:17.820 --> 17:19.580
Thank you very much for listening.

17:19.580 --> 17:20.460
Thank you.

17:20.460 --> 17:21.480
Applause.

