[00:04.220 --> 00:10.300] So, hello everybody. We are very excited to be here. And welcome to the session [00:10.300 --> 00:15.300] Breaching AWS Accounts Through Shadow Resources. And in this session we will [00:15.300 --> 00:19.960] demonstrate several vulnerabilities that we found on AWS. The most severe of [00:19.960 --> 00:23.480] these vulnerabilities could allow an attacker to add an admin role to another [00:23.480 --> 00:30.600] account. So let's start. Let's start by discussing the most debatable topic on [00:30.600 --> 00:38.100] AWS which is AWS account ID. So, each AWS account has a unique identifier [00:38.100 --> 00:45.180] associated with it. This identifier consists of 12 digits and the most [00:45.180 --> 00:51.440] important thing about this is that some treat it as a secret and some don't. And [00:51.440 --> 00:56.280] along the history of AWS we have many different opinion whether it is a secret [00:56.280 --> 01:03.940] or not. Although AWS in their documentation states that this account ID should be [01:03.940 --> 01:08.980] shared carefully, they do not consider this a secret. But we as security [01:08.980 --> 01:12.740] practitioners, security researchers, know that attacker could achieve [01:12.740 --> 01:18.960] problematic things only by knowing this account ID. So, what is the right answer? [01:19.120 --> 01:24.940] Are AWS account IDs secret or not? We hope that by the end of this session we will [01:24.940 --> 01:31.920] have more solid opinion about this. So, let us introduce ourselves. My name is [01:31.920 --> 01:38.500] Yakir Kotkoda and here with me are Michael Kaczynski and Ofik Itach. We are all [01:38.500 --> 01:43.200] security researchers from Aqua Security and we are focusing in our daily on cloud [01:43.200 --> 01:47.820] vulnerabilities, open source vulnerabilities and more. Let me go over the [01:47.820 --> 01:52.080] agenda. We will introduce something that's called shadow resources and what they [01:52.080 --> 01:59.100] are, then several vulnerabilities that we found on AWS and an open source tool that we [01:59.100 --> 02:04.360] developed during our research that helped us to find more vulnerabilities. After [02:04.360 --> 02:09.140] this we will introduce a new technique called bucket monopoly that help us emphasize [02:09.140 --> 02:14.360] the risk of our findings and we will end our session by suggesting some [02:14.360 --> 02:21.860] mitigations and recommendation. So, let's first talk how our journey began. While we [02:21.860 --> 02:28.800] worked with the AWS management console, which is the GUI of AWS, we noticed that when a [02:28.800 --> 02:35.580] user use the cloud formation service and upload a template file, AWS behind the [02:35.580 --> 02:42.300] scenes creates an S3 bucket for the user. Although the user did not explicitly ask AWS to [02:42.300 --> 02:47.900] do so, this is how the service operates. We have decided to name this kind of resources [02:47.900 --> 02:53.520] that spawned automatically without the user intervention a shadow resource. So, let's [02:53.520 --> 02:59.380] explain this term. When we refer to shadow resources, we are mainly first to resources that [02:59.380 --> 03:07.200] generated automatically or semi-automatically by AWS. Most of the time they spawn without [03:07.200 --> 03:14.080] user intervention and they might go unnoticed by the account owner. And the great example [03:14.080 --> 03:19.380] for this is just the S3 bucket that we saw that the cloud formation service creates for the [03:19.380 --> 03:27.360] user. Now, let's align some first, some common knowledge about S3 bucket, which is one of the [03:27.360 --> 03:35.240] first services by AWS. This service has some special uniqueness. First of all, S3 bucket [03:35.240 --> 03:42.140] name must be globally unique across all AWS. For example, if you create an S3 bucket called [03:42.660 --> 03:49.020] coolbucket1, no one else on AWS could claim this name. It will be available only under your [03:49.020 --> 03:56.080] account. So, let's set up a view and talk about our first vulnerability on cloud formation. So, [03:56.080 --> 04:01.640] first of all, what is cloud formation? Cloud formation is an infrastructure as code service by [04:01.640 --> 04:08.380] AWS similar to the telephone project. A user will define a template file that contain AWS [04:08.380 --> 04:15.880] resources. Then the user store this template file locally or in S3 bucket. And then the user [04:15.880 --> 04:22.840] will create a stack based on this template file and when the user will deploy this stack, the [04:22.840 --> 04:29.180] cloud formation service deploys the resources that exist under this template file. Now, I [04:29.180 --> 04:33.180] want us to understand what's happened behind the scenes when the user upload the template file [04:33.180 --> 04:41.740] to this service. So, first, the user clicks on the upload template file under the GUI. And we [04:41.740 --> 04:49.400] need to remember that every operation on AWS is eventually an API request. So, the create upload [04:49.400 --> 04:55.440] bucket API request will be invoked. The cloud formation service will try to create an S3 [04:55.440 --> 05:03.160] bucket. Then it will return the bucket name. And then the put object API request will upload [05:03.180 --> 05:10.600] the template file to the cloud formation service. Then we will have a lot of API requests. But in [05:10.600 --> 05:15.960] the end, the user will submit the stack which will cause the cloud formation service to deploy [05:15.960 --> 05:23.060] all the AWS resources that exist under this template file. Now, I want us to focus on the [05:23.060 --> 05:29.960] bucket naming pattern of this S3 bucket. So, it will consist of three different parts. The first [05:29.960 --> 05:37.060] one is a prefix, which is a constant string and it will remain the same. In this case, it is CF [05:37.060 --> 05:45.400] template. Then we have the hash, which is a unique identifier per account. And then a region, which [05:45.400 --> 05:51.000] will be related to where the user initiate the cloud formation service. So, now let's visualize [05:51.000 --> 05:59.200] this. So, basically, when a user uses the cloud formation service via the AWS GUI, AWS behind the [05:59.200 --> 06:05.120] scenes creates an S3 bucket with this pattern. And when the user will try to create another cloud [06:05.120 --> 06:10.440] formation service in a new region for the first time, the cloud formation service creates an S3 [06:10.440 --> 06:18.420] bucket with the same prefix, with the same hash, but with a different region. So, we have here a [06:18.420 --> 06:27.400] semi-predictable bucket name. So, what if an attacker open or claim this bucket before the user? [06:28.100 --> 06:35.020] So, if a user, if an attacker does so, this technique is called bucket name squatting or bucket [06:35.020 --> 06:41.560] sniping. You can read a great blog by Oren McKay about this technique. Now, let's explain this. So, [06:41.560 --> 06:47.160] we have here the user with the cloud formation service on a specific region. And then the, an [06:47.160 --> 06:53.640] attacker on a new region. And what the attacker did here is that he creates a bucket under his [06:53.640 --> 06:59.280] account with the hash of the user. We will talk about this later. The prefix and the region. So, [06:59.280 --> 07:05.560] whenever the user will try to use the cloud formation service in this region for the first time, [07:05.560 --> 07:11.580] the cloud formation service will try to interact with the attacker claim bucket. But, it will [07:11.580 --> 07:18.860] receive an error. So, basically, we have here a way to prevent the other user from using the cloud [07:18.860 --> 07:28.080] formation service on a specific region which can be considered as a DOS scenario. And a DOS scenario [07:28.080 --> 07:35.660] is fine, but it isn't enough for a DEF concession. So, let's escalate it. What if an attacker [07:35.660 --> 07:43.080] opened a bucket for public access? So, the reason why the cloud formation service got an error [07:43.080 --> 07:49.400] before is because the attacker needs still to define some settings on their S3 bucket. First of [07:49.400 --> 07:56.240] all, the attacker needs to allow public access because it's blocked by default. And then, in [07:56.240 --> 08:04.560] order to allow cross-account access, the attacker needs to define a resource-based policy. In this [08:04.560 --> 08:11.200] case, we have a very permissive bucket policy that allows any principal on AWS to perform any [08:11.200 --> 08:16.600] action on the S3 bucket of the attacker. Of course, this is just a POC and this is very, very [08:16.600 --> 08:23.480] dangerous. So, after the attacker does so, now an interesting thing will happen. The cloud [08:23.480 --> 08:29.680] formation service of the victim will succeed interact with the attacker claim bucket. So, whenever [08:29.680 --> 08:36.240] the user upload a template file, it will be dropped to the attacker S3 bucket. So, we have here a [08:36.240 --> 08:42.120] way to enumerate different secrets and resources that the user wrote in their template file. So, [08:42.120 --> 08:51.040] this is an information disclosure scenario. But, if an attacker already has access to this [08:51.040 --> 08:58.060] template file, what if an attacker modified it? So, if an attacker does so, this is called [08:58.060 --> 09:03.440] resource injection in cloud formation templates and it's a great technique that's published [09:03.440 --> 09:10.580] already by Rhinolab and also credited to Matthew Filler about this. And all the idea behind this [09:10.580 --> 09:16.440] technique is some time of check, time of issue behavior that the cloud formation service has by [09:16.900 --> 09:22.920] default that allow an attacker a windows of opportunity to modify templates file before the [09:22.920 --> 09:28.320] cloud formation service try to deploy them. So, it's possible for attacker to modify this [09:28.320 --> 09:33.860] template file and actually do it manually or with Lambda that will backdoor this template [09:33.860 --> 09:41.880] automatically. So, now let's visualize this. Here we have the user and the attacker account. The [09:41.880 --> 09:47.320] attacker is in external account and the attacker create an S3 bucket that the cloud formation [09:47.320 --> 09:52.340] service of the victim will try to use. And a Lambda that will backdoor any file that dropped to [09:52.340 --> 10:00.800] this S3 bucket. So, whenever the user creates a stack, the cloud formation service uploads the [10:00.800 --> 10:07.320] victim template to the attacker S3 bucket. Then the Lambda will be triggered and gets the [10:08.260 --> 10:13.680] template file from the attacker claim bucket. Then the Lambda will perform a resource [10:13.680 --> 10:21.660] injection and here we have a new resource. It's an admin role that can be assumed by the attacker. [10:22.340 --> 10:30.560] Then the Lambda will inject this backdoor template file to the S3 bucket. And as I said before, we [10:30.560 --> 10:36.720] have here some time of check, time of use issue. So, the user needs to deploy the template file. [10:36.720 --> 10:41.480] So, the user click on the submit stack. And then the previously vulnerable cloud formation [10:41.480 --> 10:48.320] service will attempt to get the backdoor template file from the attacker S3 bucket and deploy this [10:48.320 --> 10:54.260] malicious role under the victim account. So, we have here an admin role from external accounts [10:54.260 --> 11:04.250] that the attacker can claim. So, actually it's, which, which means an account takeover. Okay. [11:06.390 --> 11:13.490] But there are some important point to mention. In order to add or inject an admin role to another [11:13.490 --> 11:19.910] account, the initiator of the cloud formation service, which is an AWS user or a service role, [11:19.910 --> 11:26.010] needs to have some, needs to have some high privilege. And we can assume that user that use the [11:26.010 --> 11:31.370] cloud formation service via the GUI have such privilege. And even if they do not have high [11:31.370 --> 11:38.450] privilege, it's still possible to modify what exists in the template file. And of course, the [11:38.450 --> 11:43.570] attacker needs to wait for the victim to use the cloud formation service in a new region for the [11:43.570 --> 11:50.310] first time. So, now let's see a really quick POC of this. Here we have the victim account that [11:50.310 --> 11:55.710] try to use the cloud formation service via the GUI and upload the template file. Behind the [11:55.710 --> 12:00.310] scenes, the cloud, the template file already dropped to the attacker claim bucket and the user [12:00.310 --> 12:04.990] still needs to define stack name, privilege and more. And this is what caused the time of check [12:04.990 --> 12:10.810] time of use issue. As we can see here, we have the attacker S3 bucket with the template file of [12:10.810 --> 12:16.390] the user and the attacker can modify it. Meanwhile, the attacker deploys the stack and we can [12:16.390 --> 12:22.770] see that we have under this deployment an attacker user which is a really privileged role, an [12:22.770 --> 12:28.490] admin role. And we can see also that this all can be assumed from external account. In this [12:29.190 --> 12:34.690] case, the attacker account. So, all attacker needs to do is to assume this role, find the [12:34.690 --> 12:41.030] related account ID of the user on the CloudWatch logs and then the attacker has an admin role on [12:41.030 --> 12:45.250] the victim account. Which is one of the most severe thing that we can receive in the cloud, [12:45.250 --> 12:59.400] right? Thank you Akir for showing us such a cool technique. But before we continue, let's not [12:59.400 --> 13:10.460] ignore the elephant in the room. Akir showed us previously a way to, sorry, a way to [13:11.100 --> 13:17.360] previously Akir showed us a way to, he showed us that the bucket name needs to be [13:17.360 --> 13:23.400] predictable. But when we look at the bucket name, it's definitely not predictable, right? It's [13:23.400 --> 13:29.320] due to the hash in the middle. So, we knew we had to address this problem. The first attempt [13:29.320 --> 13:38.720] that we did was actually trying to enumerate and calculate every possible hash. But we [13:38.720 --> 13:45.240] quickly realized it's just not doable to the amount of option that we had. Then we thought [13:45.240 --> 13:50.340] maybe we can reverse the hash or something like that. Akir said that the hash is unique [13:50.340 --> 13:56.220] per account. So, maybe it's based on the account ID or other unique identifier in the [13:56.220 --> 14:06.300] account. But after many unsuccessful attempts, we left that technique. Then we decided to turn [14:06.300 --> 14:14.660] to open source. In open source, we saw this code. And in this code we saw that there is some [14:14.660 --> 14:20.560] cases, there is a code that shows that the bucket is actually randomized. The hash is [14:20.560 --> 14:33.320] actually randomized. And what that actually means is it's, we can't predict the hash. So, our [14:33.320 --> 14:45.640] technique is not going to work in the real world. But as good researchers, we were sad about [14:45.640 --> 14:50.600] this because we know that our technique is not going to work and we had to rethink about [14:50.600 --> 14:56.880] everything that we came so far. We have a really nice technique. We managed to remote account [14:56.880 --> 15:06.420] takeover. But we don't have how to use it in the real world. But as good researchers, we thought [15:06.420 --> 15:14.560] about a solution. We used the greatest tool known to us, which is the search tool. We used [15:14.560 --> 15:22.680] GitHub search and we used source graph search and we managed to find over a thousand buckets. [15:22.680 --> 15:27.940] Some of them with the hash that we mentioned. All of them with the hash that we mentioned. And [15:27.940 --> 15:36.820] it gave us the ability to hack, like, a couple of big organizations. But we didn't stop there. [15:37.180 --> 15:44.280] Doing our searches, we actually find that there is cases where the account, where the bucket [15:44.280 --> 15:52.660] name of some services is actually created by just using account ID. So, we thought about [15:53.650 --> 16:02.920] maybe instead of trying to find a mysterious hash or trying to understand this randomized string, [16:02.920 --> 16:11.300] maybe we can just use the account ID instead and find new vulnerability that the bucket name [16:11.300 --> 16:21.540] actually contains the account ID. So, we decided to shift our whole research and turn to find more [16:21.540 --> 16:28.960] bucket patterns. We used the open source and look for more bucket patterns. We used AWS [16:28.960 --> 16:35.500] documentation and SDK. We even started calling and trying to press nearly every possible button [16:35.500 --> 16:44.540] in AWS GUI. And we even created a tool, an open source tool that you can all play with it after [16:44.540 --> 16:54.480] this talk. It lets you debug AWS like you're debugging network buckets. And it shows the inner [16:54.480 --> 17:03.860] API calls made by AWS which is kind of nice. So, let's see how it works. In one screen, we initiate [17:03.860 --> 17:13.520] an API call. This API call in this scenario is the upload template that Kir talked about before. In [17:13.520 --> 17:21.420] the other screen, we use Wireshark with our plug-in. We wrote a plug-in for Wireshark. And we [17:21.420 --> 17:30.220] just starting to capture API calls that we made. And what is interesting about what we seen using [17:30.220 --> 17:38.380] this tool is actually when we initiate the API call in the GUI, it's actually one API call. But this [17:38.380 --> 17:45.900] API call is undocumented. And the equivalent to that API call is actually five different API calls [17:45.900 --> 17:52.680] made by the inner services of AWS. One of them is the create bucket that Kir told you before and it [17:52.680 --> 17:57.880] also calculates the hash. So, we have here an undocumented API call used by AWS to create [17:57.880 --> 18:07.200] buckets. So, all of the techniques that I mentioned before gave us around hundreds of buckets and we [18:07.200 --> 18:14.920] understand that we have tons of work to do. Because as a reminder, some of the buckets came from [18:14.920 --> 18:20.500] open source projects. So, we need to understand which bucket is related to what service. And we [18:20.500 --> 18:29.200] also need to understand if any of the services is exploitable. So, you are probably wondering what is [18:29.200 --> 18:35.440] the answer for those questions. And the answer was, we managed to find five different [18:35.440 --> 18:45.200] vulnerabilities within AWS. Some of them by just using the account ID. So, let's talk about the [18:45.200 --> 18:52.460] common steps that we need to take that is common to all the vulnerabilities that we found. As [18:52.460 --> 18:57.420] Kir said before, we need to create a bucket name before the user. We also need to open the bucket [18:57.420 --> 19:04.060] to the world and we need to put lambda or something to monitor the bucket. And when a file is [19:04.060 --> 19:10.920] dropped to the bucket, we can change it. It's the same technique. So, let's explore our second [19:10.920 --> 19:17.960] vulnerability for today. In AWS glue. This one is really strong. Because you only need the account [19:17.960 --> 19:31.500] ID to exploit a remote account. And just a reminder, account ID is not a secret by AWS, right? So, what [19:31.500 --> 19:38.680] is AWS glue? AWS glue is a service for data engineers. This is basically used for data [19:38.680 --> 19:45.380] manipulation. To trigger the vulnerability, the user needs to create a job in glue. When you do [19:45.380 --> 19:51.980] so, a bucket is automatically configured with a predictable name. There, files of glue will be [19:51.980 --> 20:00.780] stored. So, if a bucket is predictable, we can take it before the user. And that's exactly what we [20:00.780 --> 20:08.200] did. Our user creates a job. When he creates a job, a script is dropped to our bucket. We have our [20:08.200 --> 20:16.600] lambda that changes the file. And when the user runs the job, he gets the modified script. And [20:16.600 --> 20:26.710] voila. We have a remote code execution on the remote account. So, you are probably wondering, [20:26.710 --> 20:36.810] what are the privileges of the AWS glue service? So, it's actually configured by the user that triggers [20:36.810 --> 20:46.490] the job. Most of the time, it will be a default service role that you get when you use AWS glue for [20:46.490 --> 20:53.390] the first time. And that role is pretty interesting. Because it has a lot of enumeration [20:53.390 --> 21:01.990] potential on the account and also it has some write potential in the account. So, you could [21:01.990 --> 21:08.910] probably escalate from here. But it's not the topic for our talk. Another cool anecdote about this [21:08.910 --> 21:17.610] vulnerability is actually invisible. And I will explain. When the user tries to get the script and [21:17.610 --> 21:24.790] look at the script, he actually gets the original script. Even though it's already modified. And [21:24.790 --> 21:31.250] when he runs it, he actually runs the modified script. This is just due to a bug in the AWS [21:31.250 --> 21:39.370] glue. But it's still cool. So, let's see the full POC. We recorded that on February. Here you [21:39.370 --> 21:49.390] can see a user creating a glue job. When you press the save button, the files are dropped to the [21:49.390 --> 21:56.470] attacker bucket. And that's what also gives us the time to modify the script. Because if we are [21:56.470 --> 22:03.130] automating this, the Lambda takes just a couple of milliseconds to modify the to inject the code [22:03.130 --> 22:14.110] there. In this POC, we just put a print for POC purposes. And as you can see, when the user tries [22:14.110 --> 22:21.510] to get the script, he gets the original script. And when he runs the script, if we look at the [22:21.510 --> 22:36.980] logs, you can see that the script is actually modified and we got remote code execution. So, now [22:36.980 --> 22:47.480] let's explore the third vulnerability for today in EMR, which is another service of AWS. This one [22:47.480 --> 22:55.420] is also kind of cool because it, again, it's only the account ID. That's what we were looking for. And [22:55.420 --> 23:05.540] it has a cool post exploitation technique. So, EMR, it's a service for data consumption used by [23:05.540 --> 23:12.720] data scientists. Another data service. To trigger the vulnerability, the user needs to create a [23:12.720 --> 23:18.500] studio. And when you do so, a bucket is automatically configured. And that's where we come to [23:18.500 --> 23:25.520] the picture. Again, we open the bucket before the user. When the user creates a studio, he actually [23:25.520 --> 23:32.860] stores Jupyter notebooks to our bucket. And in our bucket, we have our Lambda that changes the code. [23:32.860 --> 23:41.540] And in Jupyter notebook, you can inject JavaScript. So, we decided to inject JavaScript here and it [23:41.540 --> 23:51.560] acts like stored XSS. When the user tried to open his EMR, his service, he gets the modified Jupyter [23:51.560 --> 23:58.740] notebook and every time he will go to the notebook, he will be redirected to a fake login page [23:58.740 --> 24:07.900] created by us. A quick disclaimer about this vulnerability. It's not a zero shot. It means that [24:07.900 --> 24:15.480] the vulnerability, when the user configures the page, he actually needs to do some changes because [24:15.480 --> 24:22.740] he gets an error. But the error is really vague. And when I see an error like this as a user, I do [24:22.740 --> 24:31.760] one of two things. Either I change the role or I use the policy that is recommended by AWS. In [24:31.760 --> 24:40.260] both cases, the vulnerability is going to work. This is due to inconsistent in AWS. The policy [24:40.260 --> 24:47.000] that they recommend is actually lacking a string condition that's supposed to protect you from [24:47.000 --> 24:53.840] such an attack. But they forgot it. Now Michael will show you a couple of more vulnerabilities [24:54.410 --> 24:59.800] and will show you how our technique applies on open source projects. Thank you. [25:05.870 --> 25:12.910] All right. So, thank you Ofek. So nowadays everyone loves AI and machine learning. And we could not [25:12.910 --> 25:17.590] miss a chance to talk about this on our lecture. Let's discuss the rest of the vulnerabilities and [25:17.590 --> 25:24.530] start from AWS SageMaker. So SageMaker is a tool in AWS that is designed to build, train and [25:24.530 --> 25:32.850] deploy machine learning models. Canvas is part of the AWS SageMaker ecosystem and it's a very cool [25:32.850 --> 25:39.410] no code drag and drop interface. We discovered that when a user creates a Canvas instance for the [25:39.410 --> 25:46.470] first time on a specific region, then a bucket with the name SageMaker dash region dash account ID [25:46.470 --> 25:53.550] is created and the S3 bucket will store files that are utilized by the service. So let's go over [25:53.550 --> 25:59.630] the full attack scenario. So the attacker has claimed the bucket before the user and then the [25:59.630 --> 26:06.110] user opens Canvas and it will create a data set and uploads the files. On the background the [26:06.110 --> 26:11.070] files will be uploaded to the attacker controller S3 bucket and then the attacker could get the [26:11.070 --> 26:16.370] data set and we will have data leakage. But if that's not enough, the attacker could [26:16.370 --> 26:22.270] also manipulate the data set and then SageMaker will use the manipulated data set and we have [26:22.270 --> 26:28.430] data manipulation. So it may lead to inaccurate models and all of this can happen without the [26:28.430 --> 26:35.010] user even knowing that something has changed. And to our next vulnerability on AWS is on [26:35.010 --> 26:41.270] CodeStar. So CodeStar is a tool that provides a unified user interface to easily manage [26:41.270 --> 26:46.350] software development activities. So the service was deprecated just I think two weeks [26:46.350 --> 26:51.790] ago and in this scenario the attacker has claimed the bucket again before the user and when [26:51.890 --> 26:58.670] a user tries to create a CodeStar project on a region, then CodeStar on the background will [26:58.670 --> 27:05.010] try to create a bucket and it will fail and it will return the user an error. So this is [27:05.010 --> 27:10.010] essentially a denial of service attack since the attacker prevents the user from using CodeStar [27:10.010 --> 27:16.750] on a specific region. And there's one more vulnerability on service catalog. We won't [27:16.750 --> 27:21.230] elaborate about it right now but we're going to publish a blog in the next few hours so you [27:21.230 --> 27:30.910] could see it there. So after we talked about the vulnerabilities in AWS, on our research we [27:30.910 --> 27:35.510] also identified that this attack vector affects many open source projects as well apparently. [27:36.030 --> 27:42.190] And many open source projects create S3 buckets as part of functionality and the consequences [27:42.190 --> 27:48.730] change depending on the project but some projects are vulnerable and could allow an attacker [27:48.730 --> 27:55.470] to gain full access to all of the files in the bucket. So here you can see an example of a [27:55.470 --> 28:02.270] project that checks if the bucket exists. And this check is wrong since an attacker could claim [28:02.270 --> 28:07.090] the bucket and the project will print to the screen that the bucket already exists but it will [28:07.090 --> 28:13.650] continue running without any problems. And there's another example of a project that tries to [28:13.650 --> 28:19.690] verify that the bucket exists and it tries to list the bucket. But this check is also wrong [28:19.690 --> 28:26.510] since an attacker could claim the bucket, open it for public access, set permissive policy and [28:26.510 --> 28:34.430] by doing so it will allow the victim to list using the AWS S3LS command to list the bucket and [28:34.430 --> 28:42.550] again the script will continue running without any failure. And also as part of our investigation [28:42.550 --> 28:47.910] we found services that could be vulnerable in the past. These services created predictable [28:47.910 --> 28:53.950] bucket names. For instance Athena once created a bucket with the name AWS Athena query [28:53.950 --> 29:01.790] results dash account ID dash region. This bucket is not created anymore and when we [29:01.790 --> 29:07.230] encountered it Athena did not seem to be vulnerable and now this bucket is created by the user [29:07.230 --> 29:13.470] specification. All right. So we discussed vulnerabilities in AWS services and open source [29:13.470 --> 29:18.330] projects as well. Now let's explore how we can elevate what we've learned so far to the next [29:18.330 --> 29:24.690] level. So we wanted to increase the chances of a victim to be compromised. It would be [29:24.690 --> 29:29.330] important to us to show that this attack vector is not just theoretical but it's also practical [29:29.810 --> 29:35.370] and effective on real world scenarios. And we are proud to produce uh, to introduce a new [29:35.370 --> 29:40.270] technique we named bucket monopoly. So in previous vulnerabilities we targeted specific [29:40.270 --> 29:45.630] regions of other accounts. We could check if a bucket already, already exists and if not we [29:45.630 --> 29:51.150] could claim it before the victim. However as you all know AWS has multiple regions. So [29:51.150 --> 29:55.650] instead of focusing on a single region we could claim all possible regions that the user has [29:55.650 --> 30:01.890] not claimed yet. This strategy increases the likelihood of an unsuspecting victim interacting [30:01.890 --> 30:08.630] with an attacker on S3 bucket. But since we have several vulnerable services let's create all [30:08.630 --> 30:14.450] of the buckets in all of the possible services. This is practically a land mine. The victim [30:14.450 --> 30:20.350] is surrounded by malicious buckets belonging to different services. Whenever the victim will [30:20.350 --> 30:26.310] use a new service from uh, the six services we presented on any new region it will be [30:26.310 --> 30:35.090] immediately compromised. Let's explain step by step how to perform this kind of attack. First [30:35.090 --> 30:40.230] of all we must identify predictable bucket name. After finding these buckets we need to [30:40.230 --> 30:43.970] verify that the associated services that create these kinds of buckets are indeed [30:43.970 --> 30:49.670] vulnerable. Secondly we must recognize what is the unique identifier. And the last step [30:49.670 --> 30:55.710] which is the easy one we need to claim all the bucket names across all regions. So we showed [30:55.710 --> 31:00.270] you several ways how to find these kinds of buckets. We start reconnaissance by looking for [31:00.270 --> 31:06.650] bucket names that contains a prefix or a postfix alongside with an identifier like account ID [31:06.650 --> 31:12.470] or a hash. And it could be achieved by using the GitHub regex search. We could read AWS [31:12.470 --> 31:17.590] documentation as well. And we could use, we could crawl AWS services with tools like [31:17.590 --> 31:22.950] TrailShark that Ofig just showed you before. Next the second step is to understand what is [31:22.950 --> 31:28.890] the unique identifier inside the bucket name. It might be a random hash and it will require [31:28.890 --> 31:33.930] further instigation. It could also be account ID or some kind of other public metadata [31:33.930 --> 31:40.250] information. If it's a hash we could search on GitHub and on source graph to find leaked [31:40.250 --> 31:44.450] hashes and then target them. And if it's an account ID there are multiple ways to find [31:44.450 --> 31:50.110] them. So the first method is to use GitHub. We could search the GitHub regex search for [31:50.110 --> 31:55.450] specific patterns. We could also leverage the gray head warfare platform which is a [31:55.450 --> 31:59.330] platform that collects publicly accessible S3 buckets and then we could extract the account [31:59.330 --> 32:06.190] ID out of the bucket. So Jerome Brown did it and he extracted nearly 197 thousand unique [32:06.190 --> 32:11.630] account IDs. We could also extract the account ID out of the AWS access key ID. Nice [32:11.630 --> 32:17.150] article by Tal Berry who showed how to do it. And lastly there are valuable lists out there [32:17.150 --> 32:22.110] of known AWS accounts which includes account IDs of numerous large organizations and [32:22.110 --> 32:27.750] vendors. And the last step is to monopolize. So attacker utilize the understanding of [32:27.750 --> 32:32.830] naming conventions and account IDs to strategically create S3 buckets with predictable [32:32.830 --> 32:38.550] names across all AWS regions where these buckets do not exist yet. Then the attacker [32:38.550 --> 32:43.890] will open the bucket for public access, set permissive policy and by doing so they [32:43.890 --> 32:50.590] position themselves to intercept the victim future interactions with these buckets. Now [32:50.590 --> 32:54.770] let's talk a little bit about disclosure and timeline. So we reported these vulnerabilities [32:54.770 --> 32:59.830] at the middle of February and AWS immediately started fixing them. We got a final [32:59.830 --> 33:05.410] confirmation that the vulnerabilities were fixed at the end of June and the general [33:05.410 --> 33:11.850] approach here was consistent. So AWS will either add some kind of a random sequence or a [33:11.850 --> 33:17.670] number to the bucket and then create it or they will prompt the user to choose a new bucket [33:17.670 --> 33:22.830] name thereby they will ignore the already claimed bucket. AWS also indicated that they [33:22.830 --> 33:26.850] confirmed the results of each team investigation and they will contact customers [33:26.850 --> 33:33.170] directly in the event that they were affected. So to conclude what we've seen up until now. [33:33.170 --> 33:38.150] We have identified six vulnerabilities in AWS that might enable an attacker to exploit [33:38.150 --> 33:42.810] organization. We explained how these vulnerabilities occur and we presented a new [33:42.810 --> 33:47.690] attack vector called shadow resources as well as the technique we named bucket monopoly. [33:47.690 --> 33:52.830] While the vulnerabilities we mentioned were already mitigated by AWS this attack vector [33:52.830 --> 33:58.210] can still be applicable to other AWS services and many, many open source projects as you [33:58.210 --> 34:03.610] just saw. So to prevent an entity that assumes a role accessing a bucket you do not trust [34:04.110 --> 34:09.610] you can define a scoped policy that contains the AWS resource account condition. So this [34:09.610 --> 34:15.730] approach will prevent the user in your account to access and write data to buckets that [34:15.730 --> 34:22.090] are located on accounts you do not trust. We also recommend verifying that the owner of [34:22.090 --> 34:28.150] the S3 bucket using the expected bucket owner header to ensure that the buckets that are [34:28.150 --> 34:33.570] used by your services are indeed under your account. It's very simple. You can just take [34:33.570 --> 34:38.890] each one of your buckets, the cloud formation, the glue, the EMR and the rest of them and [34:38.890 --> 34:43.670] for each region check that no one has claimed your bucket. It's a simple solution and it's [34:43.670 --> 34:52.030] great to check if you haven't been exploited. Sorry, this command. And the expected bucket [34:52.030 --> 34:56.130] owner header is also valuable for open source projects as well to verify that no one has [34:56.130 --> 35:07.070] claimed the bucket. And lastly, name your S3 bucket with some kind of a random number or a [35:07.070 --> 35:16.950] string making the bucket name less predictable. So, after everything we've demonstrated, do [35:16.950 --> 35:21.810] you still believe account ID is not a secret? Thank you. We have short time for questions and [35:21.810 --> 35:48.280] you're welcome to follow us on Twitter. All right. Questions anyone? All right. We can. [35:54.300 --> 36:05.140] So, do I policy to prevent a lot of these attacks? So, you can use them. As I showed you [36:05.140 --> 36:16.460] before, the, sorry, the, thank you. So, you should, we showed you several ways. I think the [36:16.460 --> 36:22.340] resource account condition should be fine to prevent all your roles and users that are [36:22.340 --> 36:27.060] assuming this role from accessing buckets you do not trust. I mean, for specific roles that need [36:27.060 --> 36:34.300] to access some kinds of buckets, you just, I mean, by default, I recommend adding these like [36:34.300 --> 36:41.300] section to making sure that the buckets you try to access or your services, et cetera, will not [36:42.340 --> 36:48.240] access buckets that you do not own or maybe someone else owns. Right. Because you might also [36:48.240 --> 36:55.860] delete the bucket and then someone can create it. So, it's like a dangling resource as well. All [36:55.860 --> 36:59.740] right. Yeah, I think I'm going to have to go back through and double check my... Thank you. My [36:59.740 --> 37:06.380] deny policies. Right. All right. Thank you very much for attending.