So, hello everybody. We are very excited to be here. And welcome to the session Breaching AWS Accounts Through Shadow Resources. And in this session we will demonstrate several vulnerabilities that we found on AWS. The most severe of these vulnerabilities could allow an attacker to add an admin role to another account. So let's start. Let's start by discussing the most debatable topic on AWS which is AWS account ID. So, each AWS account has a unique identifier associated with it. 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. And along the history of AWS we have many different opinion whether it is a secret or not. Although AWS in their documentation states that this account ID should be shared carefully, they do not consider this a secret. But we as security practitioners, security researchers, know that attacker could achieve problematic things only by knowing this account ID. So, what is the right answer? Are AWS account IDs secret or not? We hope that by the end of this session we will have more solid opinion about this. So, let us introduce ourselves. My name is Yakir Kotkoda and here with me are Michael Kaczynski and Ofik Itach. We are all security researchers from Aqua Security and we are focusing in our daily on cloud vulnerabilities, open source vulnerabilities and more. Let me go over the agenda. 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. 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. So, let's first talk how our journey began. 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. Although the user did not explicitly ask AWS to do so, this is how the service operates. We have decided to name this kind of resources that spawned automatically without the user intervention a shadow resource. So, let's explain this term. When we refer to shadow resources, we are mainly first to resources that generated automatically or semi-automatically by AWS. Most of the time they spawn without user intervention and they might go unnoticed by the account owner. And the great example for this is just the S3 bucket that we saw that the cloud formation service creates for the user. Now, let's align some first, some common knowledge about S3 bucket, which is one of the first services by AWS. This service has some special uniqueness. First of all, S3 bucket name must be globally unique across all AWS. For example, if you create an S3 bucket called coolbucket1, no one else on AWS could claim this name. It will be available only under your account. So, let's set up a view and talk about our first vulnerability on cloud formation. So, first of all, what is cloud formation? Cloud formation is an infrastructure as code service by AWS similar to the telephone project. A user will define a template file that contain AWS resources. Then the user store this template file locally or in S3 bucket. 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. Now, I want us to understand what's happened behind the scenes when the user upload the template file to this service. So, first, the user clicks on the upload template file under the GUI. And we need to remember that every operation on AWS is eventually an API request. So, the create upload bucket API request will be invoked. The cloud formation service will try to create an S3 bucket. Then it will return the bucket name. And then the put object API request will upload the template file to the cloud formation service. Then we will have a lot of API requests. 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. Now, I want us to focus on the bucket naming pattern of this S3 bucket. So, it will consist of three different parts. The first one is a prefix, which is a constant string and it will remain the same. In this case, it is CF template. Then we have the hash, which is a unique identifier per account. And then a region, which will be related to where the user initiate the cloud formation service. So, now let's visualize this. 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. 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. So, we have here a semi-predictable bucket name. So, what if an attacker open or claim this bucket before the user? So, if a user, if an attacker does so, this technique is called bucket name squatting or bucket sniping. You can read a great blog by Oren McKay about this technique. Now, let's explain this. So, we have here the user with the cloud formation service on a specific region. And then the, an attacker on a new region. And what the attacker did here is that he creates a bucket under his account with the hash of the user. We will talk about this later. The prefix and the region. 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. But, it will receive an error. 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. And a DOS scenario is fine, but it isn't enough for a DEF concession. So, let's escalate it. What if an attacker opened a bucket for public access? 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. First of all, the attacker needs to allow public access because it's blocked by default. And then, in order to allow cross-account access, the attacker needs to define a resource-based policy. 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. Of course, this is just a POC and this is very, very dangerous. So, after the attacker does so, now an interesting thing will happen. The cloud formation service of the victim will succeed interact with the attacker claim bucket. So, whenever the user upload a template file, it will be dropped to the attacker S3 bucket. So, we have here a way to enumerate different secrets and resources that the user wrote in their template file. So, this is an information disclosure scenario. But, if an attacker already has access to this template file, what if an attacker modified it? 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. 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. 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. So, now let's visualize this. Here we have the user and the attacker account. 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. And a Lambda that will backdoor any file that dropped to this S3 bucket. So, whenever the user creates a stack, the cloud formation service uploads the victim template to the attacker S3 bucket. Then the Lambda will be triggered and gets the template file from the attacker claim bucket. Then the Lambda will perform a resource injection and here we have a new resource. It's an admin role that can be assumed by the attacker. Then the Lambda will inject this backdoor template file to the S3 bucket. And as I said before, we have here some time of check, time of use issue. So, the user needs to deploy the template file. So, the user click on the submit stack. 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. So, we have here an admin role from external accounts that the attacker can claim. So, actually it's, which, which means an account takeover. Okay. But there are some important point to mention. 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. And we can assume that user that use the cloud formation service via the GUI have such privilege. And even if they do not have high privilege, it's still possible to modify what exists in the template file. 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. So, now let's see a really quick POC of this. Here we have the victim account that try to use the cloud formation service via the GUI and upload the template file. 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. And this is what caused the time of check time of use issue. As we can see here, we have the attacker S3 bucket with the template file of the user and the attacker can modify it. 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. And we can see also that this all can be assumed from external account. In this case, the attacker account. 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. Which is one of the most severe thing that we can receive in the cloud, right? Thank you Akir for showing us such a cool technique. But before we continue, let's not ignore the elephant in the room. 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. But when we look at the bucket name, it's definitely not predictable, right? It's due to the hash in the middle. So, we knew we had to address this problem. The first attempt that we did was actually trying to enumerate and calculate every possible hash. But we quickly realized it's just not doable to the amount of option that we had. Then we thought maybe we can reverse the hash or something like that. Akir said that the hash is unique per account. So, maybe it's based on the account ID or other unique identifier in the account. But after many unsuccessful attempts, we left that technique. Then we decided to turn to open source. In open source, we saw this code. And in this code we saw that there is some cases, there is a code that shows that the bucket is actually randomized. The hash is actually randomized. And what that actually means is it's, we can't predict the hash. So, our technique is not going to work in the real world. 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. We have a really nice technique. We managed to remote account takeover. But we don't have how to use it in the real world. But as good researchers, we thought about a solution. We used the greatest tool known to us, which is the search tool. We used GitHub search and we used source graph search and we managed to find over a thousand buckets. Some of them with the hash that we mentioned. All of them with the hash that we mentioned. And it gave us the ability to hack, like, a couple of big organizations. But we didn't stop there. 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. 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. So, we decided to shift our whole research and turn to find more bucket patterns. We used the open source and look for more bucket patterns. We used AWS documentation and SDK. We even started calling and trying to press nearly every possible button in AWS GUI. And we even created a tool, an open source tool that you can all play with it after this talk. It lets you debug AWS like you're debugging network buckets. And it shows the inner API calls made by AWS which is kind of nice. So, let's see how it works. In one screen, we initiate an API call. This API call in this scenario is the upload template that Kir talked about before. In the other screen, we use Wireshark with our plug-in. We wrote a plug-in for Wireshark. And we just starting to capture API calls that we made. 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. But this API call is undocumented. And the equivalent to that API call is actually five different API calls made by the inner services of AWS. One of them is the create bucket that Kir told you before and it also calculates the hash. So, we have here an undocumented API call used by AWS to create buckets. 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. Because as a reminder, some of the buckets came from open source projects. So, we need to understand which bucket is related to what service. And we also need to understand if any of the services is exploitable. So, you are probably wondering what is the answer for those questions. And the answer was, we managed to find five different vulnerabilities within AWS. Some of them by just using the account ID. So, let's talk about the common steps that we need to take that is common to all the vulnerabilities that we found. As Kir said before, we need to create a bucket name before the user. We also need to open the bucket to the world and we need to put lambda or something to monitor the bucket. And when a file is dropped to the bucket, we can change it. It's the same technique. So, let's explore our second vulnerability for today. In AWS glue. This one is really strong. Because you only need the account ID to exploit a remote account. And just a reminder, account ID is not a secret by AWS, right? So, what is AWS glue? AWS glue is a service for data engineers. This is basically used for data manipulation. To trigger the vulnerability, the user needs to create a job in glue. When you do so, a bucket is automatically configured with a predictable name. There, files of glue will be stored. So, if a bucket is predictable, we can take it before the user. And that's exactly what we did. Our user creates a job. When he creates a job, a script is dropped to our bucket. We have our lambda that changes the file. And when the user runs the job, he gets the modified script. And voila. We have a remote code execution on the remote account. So, you are probably wondering, what are the privileges of the AWS glue service? So, it's actually configured by the user that triggers the job. Most of the time, it will be a default service role that you get when you use AWS glue for the first time. And that role is pretty interesting. Because it has a lot of enumeration potential on the account and also it has some write potential in the account. So, you could probably escalate from here. But it's not the topic for our talk. Another cool anecdote about this vulnerability is actually invisible. And I will explain. When the user tries to get the script and look at the script, he actually gets the original script. Even though it's already modified. And when he runs it, he actually runs the modified script. This is just due to a bug in the AWS glue. But it's still cool. So, let's see the full POC. We recorded that on February. Here you can see a user creating a glue job. When you press the save button, the files are dropped to the attacker bucket. And that's what also gives us the time to modify the script. Because if we are automating this, the Lambda takes just a couple of milliseconds to modify the to inject the code there. In this POC, we just put a print for POC purposes. And as you can see, when the user tries to get the script, he gets the original script. 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. So, now let's explore the third vulnerability for today in EMR, which is another service of AWS. This one is also kind of cool because it, again, it's only the account ID. That's what we were looking for. And it has a cool post exploitation technique. So, EMR, it's a service for data consumption used by data scientists. Another data service. To trigger the vulnerability, the user needs to create a studio. And when you do so, a bucket is automatically configured. And that's where we come to the picture. Again, we open the bucket before the user. When the user creates a studio, he actually stores Jupyter notebooks to our bucket. And in our bucket, we have our Lambda that changes the code. And in Jupyter notebook, you can inject JavaScript. So, we decided to inject JavaScript here and it acts like stored XSS. 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. A quick disclaimer about this vulnerability. It's not a zero shot. It means that the vulnerability, when the user configures the page, he actually needs to do some changes because he gets an error. But the error is really vague. And when I see an error like this as a user, I do one of two things. Either I change the role or I use the policy that is recommended by AWS. In both cases, the vulnerability is going to work. This is due to inconsistent in AWS. The policy that they recommend is actually lacking a string condition that's supposed to protect you from such an attack. But they forgot it. Now Michael will show you a couple of more vulnerabilities and will show you how our technique applies on open source projects. Thank you. All right. So, thank you Ofek. So nowadays everyone loves AI and machine learning. And we could not miss a chance to talk about this on our lecture. Let's discuss the rest of the vulnerabilities and start from AWS SageMaker. So SageMaker is a tool in AWS that is designed to build, train and deploy machine learning models. Canvas is part of the AWS SageMaker ecosystem and it's a very cool no code drag and drop interface. 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. So let's go over the full attack scenario. 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. 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. 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. So it may lead to inaccurate models and all of this can happen without the user even knowing that something has changed. And to our next vulnerability on AWS is on CodeStar. So CodeStar is a tool that provides a unified user interface to easily manage software development activities. 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. So this is essentially a denial of service attack since the attacker prevents the user from using CodeStar on a specific region. And there's one more vulnerability on service catalog. 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. 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. 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. So here you can see an example of a project that checks if the bucket exists. 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. And there's another example of a project that tries to verify that the bucket exists and it tries to list the bucket. 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. And also as part of our investigation we found services that could be vulnerable in the past. These services created predictable bucket names. For instance Athena once created a bucket with the name AWS Athena query results dash account ID dash region. 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. All right. So we discussed vulnerabilities in AWS services and open source projects as well. Now let's explore how we can elevate what we've learned so far to the next level. So we wanted to increase the chances of a victim to be compromised. 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. And we are proud to produce uh, to introduce a new technique we named bucket monopoly. So in previous vulnerabilities we targeted specific regions of other accounts. We could check if a bucket already, already exists and if not we could claim it before the victim. However as you all know AWS has multiple regions. So instead of focusing on a single region we could claim all possible regions that the user has not claimed yet. This strategy increases the likelihood of an unsuspecting victim interacting with an attacker on S3 bucket. But since we have several vulnerable services let's create all of the buckets in all of the possible services. This is practically a land mine. The victim is surrounded by malicious buckets belonging to different services. Whenever the victim will use a new service from uh, the six services we presented on any new region it will be immediately compromised. Let's explain step by step how to perform this kind of attack. First of all we must identify predictable bucket name. After finding these buckets we need to verify that the associated services that create these kinds of buckets are indeed vulnerable. Secondly we must recognize what is the unique identifier. And the last step which is the easy one we need to claim all the bucket names across all regions. So we showed you several ways how to find these kinds of buckets. 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. And it could be achieved by using the GitHub regex search. We could read AWS documentation as well. And we could use, we could crawl AWS services with tools like TrailShark that Ofig just showed you before. Next the second step is to understand what is the unique identifier inside the bucket name. It might be a random hash and it will require further instigation. It could also be account ID or some kind of other public metadata information. If it's a hash we could search on GitHub and on source graph to find leaked hashes and then target them. And if it's an account ID there are multiple ways to find them. So the first method is to use GitHub. We could search the GitHub regex search for specific patterns. 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. So Jerome Brown did it and he extracted nearly 197 thousand unique account IDs. We could also extract the account ID out of the AWS access key ID. Nice article by Tal Berry who showed how to do it. And lastly there are valuable lists out there of known AWS accounts which includes account IDs of numerous large organizations and vendors. And the last step is to monopolize. 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. 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. Now let's talk a little bit about disclosure and timeline. So we reported these vulnerabilities at the middle of February and AWS immediately started fixing them. We got a final confirmation that the vulnerabilities were fixed at the end of June and the general approach here was consistent. 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. 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. So to conclude what we've seen up until now. We have identified six vulnerabilities in AWS that might enable an attacker to exploit organization. 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. 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. 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. 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. 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. It's very simple. 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. It's a simple solution and it's great to check if you haven't been exploited. Sorry, this command. And the expected bucket owner header is also valuable for open source projects as well to verify that no one has claimed the bucket. And lastly, name your S3 bucket with some kind of a random number or a string making the bucket name less predictable. So, after everything we've demonstrated, do you still believe account ID is not a secret? Thank you. We have short time for questions and you're welcome to follow us on Twitter. All right. Questions anyone? All right. We can. So, do I policy to prevent a lot of these attacks? So, you can use them. As I showed you before, the, sorry, the, thank you. So, you should, we showed you several ways. 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. 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. Right. Because you might also delete the bucket and then someone can create it. So, it's like a dangling resource as well. All right. Yeah, I think I'm going to have to go back through and double check my... Thank you. My deny policies. Right. All right. Thank you very much for attending.