1 00:00:04,220 --> 00:00:06,040 So, hello everybody. 2 00:00:06,200 --> 00:00:09,200 We are very excited to be here. 3 00:00:09,200 --> 00:00:13,840 And welcome to the session Breaching AWS Accounts Through Shadow Resources. 4 00:00:14,080 --> 00:00:18,740 And in this session we will demonstrate several vulnerabilities that we found on AWS. 5 00:00:18,960 --> 00:00:24,500 The most severe of these vulnerabilities could allow an attacker to add an admin role to another account. 6 00:00:24,500 --> 00:00:25,460 So let's start. 7 00:00:27,100 --> 00:00:34,460 Let's start by discussing the most debatable topic on AWS which is AWS account ID. 8 00:00:34,620 --> 00:00:39,960 So, each AWS account has a unique identifier associated with it. 9 00:00:40,380 --> 00:00:50,880 This identifier consists of 12 digits and the most important thing about this is that some treat it as a secret and some don't. 10 00:00:51,220 --> 00:00:57,460 And along the history of AWS we have many different opinion whether it is a secret or not. 11 00:00:58,340 --> 00:01:07,540 Although AWS in their documentation states that this account ID should be shared carefully, they do not consider this a secret. 12 00:01:07,640 --> 00:01:16,160 But we as security practitioners, security researchers, know that attacker could achieve problematic things only by knowing this account ID. 13 00:01:16,500 --> 00:01:18,960 So, what is the right answer? 14 00:01:19,120 --> 00:01:22,640 Are AWS account IDs secret or not? 15 00:01:22,640 --> 00:01:27,720 We hope that by the end of this session we will have more solid opinion about this. 16 00:01:28,200 --> 00:01:31,060 So, let us introduce ourselves. 17 00:01:31,060 --> 00:01:37,820 My name is Yakir Kotkoda and here with me are Michael Kaczynski and Ofik Itach. 18 00:01:37,820 --> 00:01:46,120 We are all security researchers from Aqua Security and we are focusing in our daily on cloud vulnerabilities, open source vulnerabilities and more. 19 00:01:46,540 --> 00:01:48,800 Let me go over the agenda. 20 00:01:48,800 --> 00:02:03,180 We will introduce something that's called shadow resources and what they are, then several vulnerabilities that we found on AWS and an open source tool that we developed during our research that helped us to find more vulnerabilities. 21 00:02:03,900 --> 00:02:16,300 After this we will introduce a new technique called bucket monopoly that help us emphasize the risk of our findings and we will end our session by suggesting some mitigations and recommendation. 22 00:02:17,200 --> 00:02:21,280 So, let's first talk how our journey began. 23 00:02:21,480 --> 00:02:38,480 While we worked with the AWS management console, which is the GUI of AWS, we noticed that when a user use the cloud formation service and upload a template file, AWS behind the scenes creates an S3 bucket for the user. 24 00:02:38,860 --> 00:02:45,500 Although the user did not explicitly ask AWS to do so, this is how the service operates. 25 00:02:45,560 --> 00:02:52,700 We have decided to name this kind of resources that spawned automatically without the user intervention a shadow resource. 26 00:02:52,700 --> 00:02:55,140 So, let's explain this term. 27 00:02:55,240 --> 00:03:04,660 When we refer to shadow resources, we are mainly first to resources that generated automatically or semi-automatically by AWS. 28 00:03:05,260 --> 00:03:13,060 Most of the time they spawn without user intervention and they might go unnoticed by the account owner. 29 00:03:13,200 --> 00:03:20,220 And the great example for this is just the S3 bucket that we saw that the cloud formation service creates for the user. 30 00:03:21,440 --> 00:03:29,640 Now, let's align some first, some common knowledge about S3 bucket, which is one of the first services by AWS. 31 00:03:30,420 --> 00:03:33,420 This service has some special uniqueness. 32 00:03:33,420 --> 00:03:38,900 First of all, S3 bucket name must be globally unique across all AWS. 33 00:03:39,660 --> 00:03:47,260 For example, if you create an S3 bucket called coolbucket1, no one else on AWS could claim this name. 34 00:03:47,260 --> 00:03:49,960 It will be available only under your account. 35 00:03:50,440 --> 00:03:55,100 So, let's set up a view and talk about our first vulnerability on cloud formation. 36 00:03:55,760 --> 00:03:58,120 So, first of all, what is cloud formation? 37 00:03:58,480 --> 00:04:04,780 Cloud formation is an infrastructure as code service by AWS similar to the telephone project. 38 00:04:04,940 --> 00:04:09,220 A user will define a template file that contain AWS resources. 39 00:04:09,280 --> 00:04:14,940 Then the user store this template file locally or in S3 bucket. 40 00:04:15,040 --> 00:04:27,920 And then the user will create a stack based on this template file and when the user will deploy this stack, the cloud formation service deploys the resources that exist under this template file. 41 00:04:28,760 --> 00:04:34,540 Now, I want us to understand what's happened behind the scenes when the user upload the template file to this service. 42 00:04:34,540 --> 00:04:41,420 So, first, the user clicks on the upload template file under the GUI. 43 00:04:41,500 --> 00:04:48,060 And we need to remember that every operation on AWS is eventually an API request. 44 00:04:48,060 --> 00:04:52,300 So, the create upload bucket API request will be invoked. 45 00:04:52,380 --> 00:04:56,420 The cloud formation service will try to create an S3 bucket. 46 00:04:56,540 --> 00:04:59,160 Then it will return the bucket name. 47 00:04:59,160 --> 00:05:06,860 And then the put object API request will upload the template file to the cloud formation service. 48 00:05:06,860 --> 00:05:10,100 Then we will have a lot of API requests. 49 00:05:10,240 --> 00:05:20,140 But in the end, the user will submit the stack which will cause the cloud formation service to deploy all the AWS resources that exist under this template file. 50 00:05:20,620 --> 00:05:25,880 Now, I want us to focus on the bucket naming pattern of this S3 bucket. 51 00:05:26,380 --> 00:05:29,520 So, it will consist of three different parts. 52 00:05:29,520 --> 00:05:35,260 The first one is a prefix, which is a constant string and it will remain the same. 53 00:05:35,320 --> 00:05:38,300 In this case, it is CF template. 54 00:05:38,300 --> 00:05:43,540 Then we have the hash, which is a unique identifier per account. 55 00:05:43,540 --> 00:05:49,980 And then a region, which will be related to where the user initiate the cloud formation service. 56 00:05:49,980 --> 00:05:51,940 So, now let's visualize this. 57 00:05:51,940 --> 00:06:01,940 So, basically, when a user uses the cloud formation service via the AWS GUI, AWS behind the scenes creates an S3 bucket with this pattern. 58 00:06:02,100 --> 00:06:15,860 And when the user will try to create another cloud formation service in a new region for the first time, the cloud formation service creates an S3 bucket with the same prefix, with the same hash, but with a different region. 59 00:06:15,920 --> 00:06:20,360 So, we have here a semi -predictable bucket name. 60 00:06:21,340 --> 00:06:27,400 So, what if an attacker open or claim this bucket before the user? 61 00:06:28,100 --> 00:06:35,940 So, if a user, if an attacker does so, this technique is called bucket name squatting or bucket sniping. 62 00:06:35,940 --> 00:06:39,380 You can read a great blog by Oren McKay about this technique. 63 00:06:39,600 --> 00:06:41,180 Now, let's explain this. 64 00:06:41,180 --> 00:06:45,440 So, we have here the user with the cloud formation service on a specific region. 65 00:06:45,740 --> 00:06:49,420 And then the, an attacker on a new region. 66 00:06:49,500 --> 00:06:55,560 And what the attacker did here is that he creates a bucket under his account with the hash of the user. 67 00:06:55,560 --> 00:06:56,900 We will talk about this later. 68 00:06:56,900 --> 00:06:58,600 The prefix and the region. 69 00:06:58,900 --> 00:07:09,920 So, whenever the user will try to use the cloud formation service in this region for the first time, the cloud formation service will try to interact with the attacker claim bucket. 70 00:07:10,300 --> 00:07:12,780 But, it will receive an error. 71 00:07:12,820 --> 00:07:25,500 So, basically, we have here a way to prevent the other user from using the cloud formation service on a specific region which can be considered as a DOS scenario. 72 00:07:26,560 --> 00:07:31,420 And a DOS scenario is fine, but it isn't enough for a DEF concession. 73 00:07:31,420 --> 00:07:33,440 So, let's escalate it. 74 00:07:34,220 --> 00:07:38,420 What if an attacker opened a bucket for public access? 75 00:07:39,800 --> 00:07:48,760 So, the reason why the cloud formation service got an error before is because the attacker needs still to define some settings on their S3 bucket. 76 00:07:48,760 --> 00:07:54,840 First of all, the attacker needs to allow public access because it's blocked by default. 77 00:07:55,220 --> 00:08:03,940 And then, in order to allow cross-account access, the attacker needs to define a resource-based policy. 78 00:08:04,120 --> 00:08:13,800 In this case, we have a very permissive bucket policy that allows any principal on AWS to perform any action on the S3 bucket of the attacker. 79 00:08:13,800 --> 00:08:17,560 Of course, this is just a POC and this is very, very dangerous. 80 00:08:18,020 --> 00:08:22,940 So, after the attacker does so, now an interesting thing will happen. 81 00:08:23,060 --> 00:08:28,720 The cloud formation service of the victim will succeed interact with the attacker claim bucket. 82 00:08:28,720 --> 00:08:34,700 So, whenever the user upload a template file, it will be dropped to the attacker S3 bucket. 83 00:08:34,980 --> 00:08:41,660 So, we have here a way to enumerate different secrets and resources that the user wrote in their template file. 84 00:08:41,720 --> 00:08:45,360 So, this is an information disclosure scenario. 85 00:08:47,560 --> 00:08:54,740 But, if an attacker already has access to this template file, what if an attacker modified it? 86 00:08:55,720 --> 00:09:09,240 So, if an attacker does so, this is called resource injection in cloud formation templates and it's a great technique that's published already by Rhinolab and also credited to Matthew Filler about this. 87 00:09:09,240 --> 00:09:25,560 And all the idea behind this technique is some time of check, time of issue behavior that the cloud formation service has by default that allow an attacker a windows of opportunity to modify templates file before the cloud formation service try to deploy them. 88 00:09:25,560 --> 00:09:34,980 So, it's possible for attacker to modify this template file and actually do it manually or with Lambda that will backdoor this template automatically. 89 00:09:35,300 --> 00:09:37,520 So, now let's visualize this. 90 00:09:39,020 --> 00:09:41,760 Here we have the user and the attacker account. 91 00:09:41,760 --> 00:09:49,500 The attacker is in external account and the attacker create an S3 bucket that the cloud formation service of the victim will try to use. 92 00:09:49,500 --> 00:09:54,020 And a Lambda that will backdoor any file that dropped to this S3 bucket. 93 00:09:54,020 --> 00:10:03,320 So, whenever the user creates a stack, the cloud formation service uploads the victim template to the attacker S3 bucket. 94 00:10:03,320 --> 00:10:11,460 Then the Lambda will be triggered and gets the template file from the attacker claim bucket. 95 00:10:11,820 --> 00:10:17,860 Then the Lambda will perform a resource injection and here we have a new resource. 96 00:10:17,860 --> 00:10:21,660 It's an admin role that can be assumed by the attacker. 97 00:10:22,340 --> 00:10:29,220 Then the Lambda will inject this backdoor template file to the S3 bucket. 98 00:10:29,340 --> 00:10:32,960 And as I said before, we have here some time of check, time of use issue. 99 00:10:32,960 --> 00:10:36,720 So, the user needs to deploy the template file. 100 00:10:36,720 --> 00:10:39,160 So, the user click on the submit stack. 101 00:10:39,160 --> 00:10:50,840 And then the previously vulnerable cloud formation service will attempt to get the backdoor template file from the attacker S3 bucket and deploy this malicious role under the victim account. 102 00:10:51,000 --> 00:10:56,100 So, we have here an admin role from external accounts that the attacker can claim. 103 00:10:56,100 --> 00:11:00,300 So, actually it's, which, which means an account takeover. 104 00:11:03,130 --> 00:11:04,250 Okay. 105 00:11:06,390 --> 00:11:09,350 But there are some important point to mention. 106 00:11:10,110 --> 00:11:23,310 In order to add or inject an admin role to another account, the initiator of the cloud formation service, which is an AWS user or a service role, needs to have some, needs to have some high privilege. 107 00:11:23,630 --> 00:11:29,530 And we can assume that user that use the cloud formation service via the GUI have such privilege. 108 00:11:29,630 --> 00:11:36,070 And even if they do not have high privilege, it's still possible to modify what exists in the template file. 109 00:11:36,910 --> 00:11:44,610 And of course, the attacker needs to wait for the victim to use the cloud formation service in a new region for the first time. 110 00:11:44,830 --> 00:11:47,630 So, now let's see a really quick POC of this. 111 00:11:48,550 --> 00:11:55,210 Here we have the victim account that try to use the cloud formation service via the GUI and upload the template file. 112 00:11:55,210 --> 00:12:03,450 Behind the scenes, the cloud, the template file already dropped to the attacker claim bucket and the user still needs to define stack name, privilege and more. 113 00:12:03,450 --> 00:12:06,450 And this is what caused the time of check time of use issue. 114 00:12:06,950 --> 00:12:13,830 As we can see here, we have the attacker S3 bucket with the template file of the user and the attacker can modify it. 115 00:12:13,950 --> 00:12:23,890 Meanwhile, the attacker deploys the stack and we can see that we have under this deployment an attacker user which is a really privileged role, an admin role. 116 00:12:23,890 --> 00:12:28,130 And we can see also that this all can be assumed from external account. 117 00:12:28,130 --> 00:12:31,230 In this case, the attacker account. 118 00:12:31,270 --> 00:12:41,990 So, all attacker needs to do is to assume this role, find the related account ID of the user on the CloudWatch logs and then the attacker has an admin role on the victim account. 119 00:12:41,990 --> 00:12:46,070 Which is one of the most severe thing that we can receive in the cloud, right? 120 00:12:52,920 --> 00:12:56,560 Thank you Akir for showing us such a cool technique. 121 00:12:56,620 --> 00:13:01,340 But before we continue, let's not ignore the elephant in the room. 122 00:13:02,100 --> 00:13:18,400 Akir showed us previously a way to, sorry, a way to previously Akir showed us a way to, he showed us that the bucket name needs to be predictable. 123 00:13:18,400 --> 00:13:23,000 But when we look at the bucket name, it's definitely not predictable, right? 124 00:13:23,000 --> 00:13:25,120 It's due to the hash in the middle. 125 00:13:25,380 --> 00:13:27,700 So, we knew we had to address this problem. 126 00:13:28,500 --> 00:13:37,320 The first attempt that we did was actually trying to enumerate and calculate every possible hash. 127 00:13:37,440 --> 00:13:43,060 But we quickly realized it's just not doable to the amount of option that we had. 128 00:13:43,880 --> 00:13:48,760 Then we thought maybe we can reverse the hash or something like that. 129 00:13:48,760 --> 00:13:51,540 Akir said that the hash is unique per account. 130 00:13:51,740 --> 00:13:57,180 So, maybe it's based on the account ID or other unique identifier in the account. 131 00:13:57,480 --> 00:14:03,660 But after many unsuccessful attempts, we left that technique. 132 00:14:04,640 --> 00:14:07,940 Then we decided to turn to open source. 133 00:14:08,360 --> 00:14:12,380 In open source, we saw this code. 134 00:14:12,380 --> 00:14:20,120 And in this code we saw that there is some cases, there is a code that shows that the bucket is actually randomized. 135 00:14:20,120 --> 00:14:21,780 The hash is actually randomized. 136 00:14:22,280 --> 00:14:31,320 And what that actually means is it's, we can't predict the hash. 137 00:14:31,620 --> 00:14:37,200 So, our technique is not going to work in the real world. 138 00:14:37,740 --> 00:14:53,100 But as good researchers, we were sad about this because we know that our technique is not going to work and we had to rethink about everything that we came so far. 139 00:14:53,100 --> 00:14:54,860 We have a really nice technique. 140 00:14:54,940 --> 00:14:58,200 We managed to remote account takeover. 141 00:14:58,940 --> 00:15:02,980 But we don't have how to use it in the real world. 142 00:15:02,980 --> 00:15:07,760 But as good researchers, we thought about a solution. 143 00:15:07,760 --> 00:15:14,140 We used the greatest tool known to us, which is the search tool. 144 00:15:14,140 --> 00:15:22,680 We used GitHub search and we used source graph search and we managed to find over a thousand buckets. 145 00:15:22,680 --> 00:15:25,840 Some of them with the hash that we mentioned. 146 00:15:25,840 --> 00:15:27,800 All of them with the hash that we mentioned. 147 00:15:27,800 --> 00:15:33,840 And it gave us the ability to hack, like, a couple of big organizations. 148 00:15:34,780 --> 00:15:36,820 But we didn't stop there. 149 00:15:37,180 --> 00:15:50,240 Doing our searches, we actually find that there is cases where the account, where the bucket name of some services is actually created by just using account ID. 150 00:15:50,500 --> 00:16:14,040 So, we thought about maybe instead of trying to find a mysterious hash or trying to understand this randomized string, maybe we can just use the account ID instead and find new vulnerability that the bucket name actually contains the account ID. 151 00:16:14,080 --> 00:16:23,020 So, we decided to shift our whole research and turn to find more bucket patterns. 152 00:16:23,600 --> 00:16:27,880 We used the open source and look for more bucket patterns. 153 00:16:27,880 --> 00:16:31,340 We used AWS documentation and SDK. 154 00:16:31,520 --> 00:16:37,320 We even started calling and trying to press nearly every possible button in AWS GUI. 155 00:16:37,320 --> 00:16:45,480 And we even created a tool, an open source tool that you can all play with it after this talk. 156 00:16:45,480 --> 00:16:52,140 It lets you debug AWS like you're debugging network buckets. 157 00:16:52,220 --> 00:16:58,840 And it shows the inner API calls made by AWS which is kind of nice. 158 00:16:58,840 --> 00:17:01,420 So, let's see how it works. 159 00:17:01,420 --> 00:17:05,320 In one screen, we initiate an API call. 160 00:17:05,320 --> 00:17:12,520 This API call in this scenario is the upload template that Kir talked about before. 161 00:17:13,100 --> 00:17:17,820 In the other screen, we use Wireshark with our plug-in. 162 00:17:17,820 --> 00:17:20,120 We wrote a plug-in for Wireshark. 163 00:17:20,440 --> 00:17:26,460 And we just starting to capture API calls that we made. 164 00:17:26,460 --> 00:17:36,160 And what is interesting about what we seen using this tool is actually when we initiate the API call in the GUI, it's actually one API call. 165 00:17:36,280 --> 00:17:40,680 But this API call is undocumented. 166 00:17:40,960 --> 00:17:49,140 And the equivalent to that API call is actually five different API calls made by the inner services of AWS. 167 00:17:49,240 --> 00:17:54,280 One of them is the create bucket that Kir told you before and it also calculates the hash. 168 00:17:54,280 --> 00:17:58,820 So, we have here an undocumented API call used by AWS to create buckets. 169 00:17:59,720 --> 00:18:10,400 So, all of the techniques that I mentioned before gave us around hundreds of buckets and we understand that we have tons of work to do. 170 00:18:10,420 --> 00:18:16,720 Because as a reminder, some of the buckets came from open source projects. 171 00:18:16,720 --> 00:18:20,220 So, we need to understand which bucket is related to what service. 172 00:18:20,220 --> 00:18:25,500 And we also need to understand if any of the services is exploitable. 173 00:18:26,580 --> 00:18:31,660 So, you are probably wondering what is the answer for those questions. 174 00:18:31,660 --> 00:18:37,840 And the answer was, we managed to find five different vulnerabilities within AWS. 175 00:18:38,100 --> 00:18:41,180 Some of them by just using the account ID. 176 00:18:43,080 --> 00:18:51,600 So, let's talk about the common steps that we need to take that is common to all the vulnerabilities that we found. 177 00:18:52,220 --> 00:18:56,080 As Kir said before, we need to create a bucket name before the user. 178 00:18:56,080 --> 00:19:02,720 We also need to open the bucket to the world and we need to put lambda or something to monitor the bucket. 179 00:19:02,820 --> 00:19:06,380 And when a file is dropped to the bucket, we can change it. 180 00:19:06,380 --> 00:19:08,060 It's the same technique. 181 00:19:09,440 --> 00:19:12,320 So, let's explore our second vulnerability for today. 182 00:19:12,320 --> 00:19:13,860 In AWS glue. 183 00:19:13,860 --> 00:19:16,120 This one is really strong. 184 00:19:16,120 --> 00:19:22,540 Because you only need the account ID to exploit a remote account. 185 00:19:23,760 --> 00:19:28,880 And just a reminder, account ID is not a secret by AWS, right? 186 00:19:29,860 --> 00:19:32,860 So, what is AWS glue? 187 00:19:32,920 --> 00:19:36,460 AWS glue is a service for data engineers. 188 00:19:36,560 --> 00:19:39,940 This is basically used for data manipulation. 189 00:19:40,360 --> 00:19:44,600 To trigger the vulnerability, the user needs to create a job in glue. 190 00:19:44,680 --> 00:19:50,020 When you do so, a bucket is automatically configured with a predictable name. 191 00:19:50,060 --> 00:19:52,820 There, files of glue will be stored. 192 00:19:53,780 --> 00:19:58,580 So, if a bucket is predictable, we can take it before the user. 193 00:19:59,360 --> 00:20:01,480 And that's exactly what we did. 194 00:20:01,800 --> 00:20:04,180 Our user creates a job. 195 00:20:04,180 --> 00:20:07,760 When he creates a job, a script is dropped to our bucket. 196 00:20:07,760 --> 00:20:10,400 We have our lambda that changes the file. 197 00:20:11,020 --> 00:20:16,140 And when the user runs the job, he gets the modified script. 198 00:20:16,260 --> 00:20:17,700 And voila. 199 00:20:17,700 --> 00:20:21,320 We have a remote code execution on the remote account. 200 00:20:24,790 --> 00:20:32,250 So, you are probably wondering, what are the privileges of the AWS glue service? 201 00:20:32,250 --> 00:20:38,910 So, it's actually configured by the user that triggers the job. 202 00:20:39,390 --> 00:20:47,810 Most of the time, it will be a default service role that you get when you use AWS glue for the first time. 203 00:20:48,410 --> 00:20:51,390 And that role is pretty interesting. 204 00:20:51,390 --> 00:20:59,450 Because it has a lot of enumeration potential on the account and also it has some write potential in the account. 205 00:20:59,450 --> 00:21:03,910 So, you could probably escalate from here. 206 00:21:03,910 --> 00:21:06,790 But it's not the topic for our talk. 207 00:21:06,890 --> 00:21:11,910 Another cool anecdote about this vulnerability is actually invisible. 208 00:21:12,010 --> 00:21:13,470 And I will explain. 209 00:21:14,630 --> 00:21:22,210 When the user tries to get the script and look at the script, he actually gets the original script. 210 00:21:22,210 --> 00:21:24,490 Even though it's already modified. 211 00:21:24,490 --> 00:21:28,470 And when he runs it, he actually runs the modified script. 212 00:21:28,470 --> 00:21:31,750 This is just due to a bug in the AWS glue. 213 00:21:31,750 --> 00:21:33,270 But it's still cool. 214 00:21:34,430 --> 00:21:36,590 So, let's see the full POC. 215 00:21:36,590 --> 00:21:38,870 We recorded that on February. 216 00:21:39,030 --> 00:21:43,770 Here you can see a user creating a glue job. 217 00:21:44,590 --> 00:21:50,910 When you press the save button, the files are dropped to the attacker bucket. 218 00:21:50,910 --> 00:21:55,610 And that's what also gives us the time to modify the script. 219 00:21:55,610 --> 00:22:03,810 Because if we are automating this, the Lambda takes just a couple of milliseconds to modify the to inject the code there. 220 00:22:04,110 --> 00:22:10,770 In this POC, we just put a print for POC purposes. 221 00:22:11,630 --> 00:22:16,990 And as you can see, when the user tries to get the script, he gets the original script. 222 00:22:16,990 --> 00:22:31,090 And when he runs the script, if we look at the logs, you can see that the script is actually modified and we got remote code execution. 223 00:22:36,260 --> 00:22:47,100 So, now let's explore the third vulnerability for today in EMR, which is another service of AWS. 224 00:22:47,100 --> 00:22:53,220 This one is also kind of cool because it, again, it's only the account ID. 225 00:22:53,220 --> 00:22:55,020 That's what we were looking for. 226 00:22:55,020 --> 00:22:59,440 And it has a cool post exploitation technique. 227 00:23:00,580 --> 00:23:06,500 So, EMR, it's a service for data consumption used by data scientists. 228 00:23:06,500 --> 00:23:08,260 Another data service. 229 00:23:09,140 --> 00:23:13,280 To trigger the vulnerability, the user needs to create a studio . 230 00:23:13,460 --> 00:23:17,360 And when you do so, a bucket is automatically configured. 231 00:23:17,400 --> 00:23:19,300 And that's where we come to the picture. 232 00:23:19,300 --> 00:23:22,360 Again, we open the bucket before the user. 233 00:23:22,360 --> 00:23:28,060 When the user creates a studio, he actually stores Jupyter notebooks to our bucket. 234 00:23:28,240 --> 00:23:32,860 And in our bucket, we have our Lambda that changes the code. 235 00:23:32,860 --> 00:23:37,980 And in Jupyter notebook, you can inject JavaScript. 236 00:23:38,160 --> 00:23:43,700 So, we decided to inject JavaScript here and it acts like stored XSS. 237 00:23:43,960 --> 00:24:00,180 When the user tried to open his EMR, his service, he gets the modified Jupyter notebook and every time he will go to the notebook, he will be redirected to a fake login page created by us. 238 00:24:02,700 --> 00:24:04,960 A quick disclaimer about this vulnerability. 239 00:24:05,520 --> 00:24:07,120 It's not a zero shot. 240 00:24:07,120 --> 00:24:16,780 It means that the vulnerability, when the user configures the page, he actually needs to do some changes because he gets an error. 241 00:24:16,780 --> 00:24:18,820 But the error is really vague. 242 00:24:18,980 --> 00:24:24,080 And when I see an error like this as a user, I do one of two things. 243 00:24:24,080 --> 00:24:31,160 Either I change the role or I use the policy that is recommended by AWS. 244 00:24:31,520 --> 00:24:35,240 In both cases, the vulnerability is going to work. 245 00:24:35,380 --> 00:24:38,900 This is due to inconsistent in AWS. 246 00:24:38,980 --> 00:24:48,300 The policy that they recommend is actually lacking a string condition that's supposed to protect you from such an attack. 247 00:24:48,320 --> 00:24:50,160 But they forgot it. 248 00:24:50,640 --> 00:24:58,880 Now Michael will show you a couple of more vulnerabilities and will show you how our technique applies on open source projects. 249 00:24:58,880 --> 00:24:59,800 Thank you. 250 00:25:05,870 --> 00:25:07,010 All right. 251 00:25:07,010 --> 00:25:09,090 So, thank you Ofek. 252 00:25:09,130 --> 00:25:12,290 So nowadays everyone loves AI and machine learning. 253 00:25:12,290 --> 00:25:15,410 And we could not miss a chance to talk about this on our lecture. 254 00:25:15,490 --> 00:25:19,610 Let's discuss the rest of the vulnerabilities and start from AWS SageMaker. 255 00:25:19,990 --> 00:25:26,390 So SageMaker is a tool in AWS that is designed to build, train and deploy machine learning models. 256 00:25:27,030 --> 00:25:35,450 Canvas is part of the AWS SageMaker ecosystem and it's a very cool no code drag and drop interface. 257 00:25:35,510 --> 00:25:52,250 We discovered that when a user creates a Canvas instance for the first time on a specific region, then a bucket with the name SageMaker dash region dash account ID is created and the S3 bucket will store files that are utilized by the service. 258 00:25:52,850 --> 00:25:55,090 So let's go over the full attack scenario. 259 00:25:55,910 --> 00:26:05,030 So the attacker has claimed the bucket before the user and then the user opens Canvas and it will create a data set and uploads the files. 260 00:26:05,270 --> 00:26:13,950 On the background the files will be uploaded to the attacker controller S3 bucket and then the attacker could get the data set and we will have data leakage. 261 00:26:14,070 --> 00:26:23,670 But if that's not enough, the attacker could also manipulate the data set and then SageMaker will use the manipulated data set and we have data manipulation. 262 00:26:24,250 --> 00:26:31,470 So it may lead to inaccurate models and all of this can happen without the user even knowing that something has changed. 263 00:26:32,550 --> 00:26:35,990 And to our next vulnerability on AWS is on CodeStar. 264 00:26:36,270 --> 00:26:43,550 So CodeStar is a tool that provides a unified user interface to easily manage software development activities. 265 00:26:43,870 --> 00:27:04,430 So the service was deprecated just I think two weeks ago and in this scenario the attacker has claimed the bucket again before the user and when a user tries to create a CodeStar project on a region, then CodeStar on the background will try to create a bucket and it will fail and it will return the user an error. 266 00:27:04,550 --> 00:27:11,610 So this is essentially a denial of service attack since the attacker prevents the user from using CodeStar on a specific region. 267 00:27:13,170 --> 00:27:16,370 And there's one more vulnerability on service catalog. 268 00:27:16,370 --> 00:27:22,370 We won't elaborate about it right now but we're going to publish a blog in the next few hours so you could see it there. 269 00:27:24,510 --> 00:27:35,510 So after we talked about the vulnerabilities in AWS, on our research we also identified that this attack vector affects many open source projects as well apparently. 270 00:27:36,030 --> 00:27:51,990 And many open source projects create S3 buckets as part of functionality and the consequences change depending on the project but some projects are vulnerable and could allow an attacker to gain full access to all of the files in the bucket. 271 00:27:52,090 --> 00:27:58,390 So here you can see an example of a project that checks if the bucket exists. 272 00:27:58,570 --> 00:28:09,810 And this check is wrong since an attacker could claim the bucket and the project will print to the screen that the bucket already exists but it will continue running without any problems. 273 00:28:10,770 --> 00:28:18,290 And there's another example of a project that tries to verify that the bucket exists and it tries to list the bucket. 274 00:28:18,290 --> 00:28:38,650 But this check is also wrong since an attacker could claim the bucket, open it for public access, set permissive policy and by doing so it will allow the victim to list using the AWS S3LS command to list the bucket and again the script will continue running without any failure. 275 00:28:40,250 --> 00:28:46,350 And also as part of our investigation we found services that could be vulnerable in the past. 276 00:28:46,350 --> 00:28:48,970 These services created predictable bucket names. 277 00:28:48,970 --> 00:28:57,850 For instance Athena once created a bucket with the name AWS Athena query results dash account ID dash region. 278 00:28:57,970 --> 00:29:08,410 This bucket is not created anymore and when we encountered it Athena did not seem to be vulnerable and now this bucket is created by the user specification. 279 00:29:09,710 --> 00:29:10,250 All right. 280 00:29:10,250 --> 00:29:14,710 So we discussed vulnerabilities in AWS services and open source projects as well. 281 00:29:14,710 --> 00:29:19,070 Now let's explore how we can elevate what we've learned so far to the next level. 282 00:29:19,790 --> 00:29:23,770 So we wanted to increase the chances of a victim to be compromised. 283 00:29:24,210 --> 00:29:32,270 It would be important to us to show that this attack vector is not just theoretical but it's also practical and effective on real world scenarios. 284 00:29:32,290 --> 00:29:37,290 And we are proud to produce uh, to introduce a new technique we named bucket monopoly. 285 00:29:37,830 --> 00:29:41,930 So in previous vulnerabilities we targeted specific regions of other accounts. 286 00:29:41,930 --> 00:29:47,370 We could check if a bucket already, already exists and if not we could claim it before the victim. 287 00:29:47,510 --> 00:29:50,910 However as you all know AWS has multiple regions. 288 00:29:51,110 --> 00:29:56,890 So instead of focusing on a single region we could claim all possible regions that the user has not claimed yet. 289 00:29:57,470 --> 00:30:04,030 This strategy increases the likelihood of an unsuspecting victim interacting with an attacker on S3 bucket. 290 00:30:04,770 --> 00:30:11,310 But since we have several vulnerable services let's create all of the buckets in all of the possible services. 291 00:30:11,970 --> 00:30:14,050 This is practically a land mine. 292 00:30:14,050 --> 00:30:18,290 The victim is surrounded by malicious buckets belonging to different services. 293 00:30:19,210 --> 00:30:28,030 Whenever the victim will use a new service from uh, the six services we presented on any new region it will be immediately compromised. 294 00:30:30,310 --> 00:30:34,110 Let's explain step by step how to perform this kind of attack. 295 00:30:34,690 --> 00:30:38,450 First of all we must identify predictable bucket name. 296 00:30:38,510 --> 00:30:44,810 After finding these buckets we need to verify that the associated services that create these kinds of buckets are indeed vulnerable. 297 00:30:45,370 --> 00:30:48,510 Secondly we must recognize what is the unique identifier. 298 00:30:48,990 --> 00:30:54,130 And the last step which is the easy one we need to claim all the bucket names across all regions. 299 00:30:55,170 --> 00:30:58,230 So we showed you several ways how to find these kinds of buckets. 300 00:30:58,530 --> 00:31:07,830 We start reconnaissance by looking for bucket names that contains a prefix or a postfix alongside with an identifier like account ID or a hash. 301 00:31:08,610 --> 00:31:11,590 And it could be achieved by using the GitHub regex search. 302 00:31:11,590 --> 00:31:13,990 We could read AWS documentation as well. 303 00:31:14,070 --> 00:31:19,990 And we could use, we could crawl AWS services with tools like TrailShark that Ofig just showed you before. 304 00:31:20,530 --> 00:31:25,890 Next the second step is to understand what is the unique identifier inside the bucket name. 305 00:31:26,310 --> 00:31:30,270 It might be a random hash and it will require further instigation. 306 00:31:30,950 --> 00:31:34,730 It could also be account ID or some kind of other public metadata information. 307 00:31:35,530 --> 00:31:41,990 If it's a hash we could search on GitHub and on source graph to find leaked hashes and then target them. 308 00:31:42,150 --> 00:31:45,150 And if it's an account ID there are multiple ways to find them. 309 00:31:45,350 --> 00:31:47,630 So the first method is to use GitHub. 310 00:31:47,990 --> 00:31:51,430 We could search the GitHub regex search for specific patterns. 311 00:31:51,690 --> 00:32:00,830 We could also leverage the gray head warfare platform which is a platform that collects publicly accessible S3 buckets and then we could extract the account ID out of the bucket. 312 00:32:00,910 --> 00:32:07,290 So Jerome Brown did it and he extracted nearly 197 thousand unique account IDs. 313 00:32:07,750 --> 00:32:11,410 We could also extract the account ID out of the AWS access key ID. 314 00:32:11,410 --> 00:32:14,090 Nice article by Tal Berry who showed how to do it. 315 00:32:14,670 --> 00:32:22,970 And lastly there are valuable lists out there of known AWS accounts which includes account IDs of numerous large organizations and vendors. 316 00:32:23,750 --> 00:32:25,850 And the last step is to monopolize. 317 00:32:25,850 --> 00:32:37,930 So attacker utilize the understanding of naming conventions and account IDs to strategically create S3 buckets with predictable names across all AWS regions where these buckets do not exist yet. 318 00:32:37,930 --> 00:32:49,050 Then the attacker will open the bucket for public access, set permissive policy and by doing so they position themselves to intercept the victim future interactions with these buckets. 319 00:32:50,270 --> 00:32:53,150 Now let's talk a little bit about disclosure and timeline. 320 00:32:53,370 --> 00:32:58,690 So we reported these vulnerabilities at the middle of February and AWS immediately started fixing them. 321 00:32:59,210 --> 00:33:07,190 We got a final confirmation that the vulnerabilities were fixed at the end of June and the general approach here was consistent. 322 00:33:07,230 --> 00:33:20,690 So AWS will either add some kind of a random sequence or a number to the bucket and then create it or they will prompt the user to choose a new bucket name thereby they will ignore the already claimed bucket. 323 00:33:20,990 --> 00:33:29,690 AWS also indicated that they confirmed the results of each team investigation and they will contact customers directly in the event that they were affected. 324 00:33:30,390 --> 00:33:33,170 So to conclude what we've seen up until now. 325 00:33:33,170 --> 00:33:39,150 We have identified six vulnerabilities in AWS that might enable an attacker to exploit organization. 326 00:33:39,330 --> 00:33:47,690 We explained how these vulnerabilities occur and we presented a new attack vector called shadow resources as well as the technique we named bucket monopoly. 327 00:33:47,690 --> 00:33:59,270 While the vulnerabilities we mentioned were already mitigated by AWS this attack vector can still be applicable to other AWS services and many, many open source projects as you just saw. 328 00:33:59,430 --> 00:34:09,170 So to prevent an entity that assumes a role accessing a bucket you do not trust you can define a scoped policy that contains the AWS resource account condition. 329 00:34:09,250 --> 00:34:18,530 So this approach will prevent the user in your account to access and write data to buckets that are located on accounts you do not trust. 330 00:34:19,610 --> 00:34:31,530 We also recommend verifying that the owner of the S3 bucket using the expected bucket owner header to ensure that the buckets that are used by your services are indeed under your account. 331 00:34:31,570 --> 00:34:32,670 It's very simple. 332 00:34:32,670 --> 00:34:41,730 You can just take each one of your buckets, the cloud formation, the glue, the EMR and the rest of them and for each region check that no one has claimed your bucket. 333 00:34:41,730 --> 00:34:46,710 It's a simple solution and it's great to check if you haven't been exploited. 334 00:34:48,570 --> 00:34:49,770 Sorry, this command. 335 00:34:49,950 --> 00:34:57,250 And the expected bucket owner header is also valuable for open source projects as well to verify that no one has claimed the bucket. 336 00:34:58,770 --> 00:35:10,030 And lastly, name your S3 bucket with some kind of a random number or a string making the bucket name less predictable. 337 00:35:13,370 --> 00:35:19,230 So, after everything we've demonstrated, do you still believe account ID is not a secret? 338 00:35:19,790 --> 00:35:20,410 Thank you. 339 00:35:20,410 --> 00:35:23,770 We have short time for questions and you're welcome to follow us on Twitter. 340 00:35:26,630 --> 00:35:27,950 All right. 341 00:35:36,380 --> 00:35:38,420 Questions anyone? 342 00:35:39,480 --> 00:35:40,760 All right. 343 00:35:47,080 --> 00:35:48,280 We can. 344 00:35:54,300 --> 00:36:02,000 So, do I policy to prevent a lot of these attacks? 345 00:36:02,000 --> 00:36:03,980 So, you can use them. 346 00:36:04,100 --> 00:36:13,600 As I showed you before, the, sorry, the, thank you. 347 00:36:13,700 --> 00:36:15,880 So, you should, we showed you several ways. 348 00:36:15,880 --> 00:36:25,660 I think the resource account condition should be fine to prevent all your roles and users that are assuming this role from accessing buckets you do not trust. 349 00:36:25,660 --> 00:36:46,120 I mean, for specific roles that need to access some kinds of buckets, you just, I mean, by default, I recommend adding these like section to making sure that the buckets you try to access or your services, et cetera, will not access buckets that you do not own or maybe someone else owns. 350 00:36:46,120 --> 00:36:47,020 Right. 351 00:36:47,020 --> 00:36:52,260 Because you might also delete the bucket and then someone can create it. 352 00:36:52,260 --> 00:36:55,420 So, it's like a dangling resource as well. 353 00:36:55,720 --> 00:36:56,220 All right. 354 00:36:56,220 --> 00:36:59,560 Yeah, I think I'm going to have to go back through and double check my... Thank you. 355 00:36:59,560 --> 00:37:01,240 My deny policies. 356 00:37:01,240 --> 00:37:01,880 Right. 357 00:37:02,680 --> 00:37:04,240 All right. 358 00:37:04,520 --> 00:37:06,380 Thank you very much for attending.