[00:00.500 --> 00:05.280] Good afternoon DEF CON. Thank you so much for being here. Welcome to my talk on exploiting [00:05.280 --> 00:11.000] AWS service vulnerabilities for initial access. My name is Nick Furchette. I'm a security [00:11.000 --> 00:16.540] researcher over at Datadog where I specialize in AWS offensive security. So finding ways [00:16.540 --> 00:20.960] to more effectively attack AWS environments and then hopefully how do we detect that behavior [00:20.960 --> 00:26.700] or potentially prevent it entirely. As a result of that research sometimes I find vulnerabilities [00:26.700 --> 00:32.040] in the underlying AWS services. Some of which we're going to be talking about today. Uh in [00:32.040 --> 00:36.520] my free time I'm the creator and maintainer of Hacking the Cloud which is an open source [00:36.520 --> 00:41.760] encyclopedia of offensive security techniques that you can use in cloud hacking adventures. Uh [00:41.760 --> 00:45.520] if you'd like a Hacking the Cloud sticker come find me after I have quite a few to give away. [00:47.420 --> 00:52.600] Now breaking into AWS accounts is a topic that's near and dear to my heart. And I'm sure it [00:52.600 --> 00:58.220] is for many of you as well. But I think if we're being honest with ourselves the traditional [00:58.220 --> 01:05.340] methods for gaining access to AWS environments are boring. If we were to poll the audience [01:05.340 --> 01:12.260] for real world AWS breaches, compromises and other security incidents I guarantee 95% of [01:12.260 --> 01:17.900] scenarios would fall into one of three categories. They were either caused by a leaked access [01:17.900 --> 01:25.700] key, an exposed S3 bucket or an exploited EC2 instance. These are the stereotypical ways that [01:25.700 --> 01:32.400] adversaries gain access to AWS accounts. And to be clear these are very real risks that we do [01:32.400 --> 01:37.620] have to contend with but it's nothing you haven't seen before and again these methods are [01:37.620 --> 01:42.680] boring. What we're going to be doing instead is kicking it in the door to the cloud and [01:42.680 --> 01:48.560] exploiting vulnerabilities in AWS services to get initial access. Particularly by abusing [01:48.560 --> 01:57.000] pre-existing trust. What I mean by that is a common design pattern in AWS is to have IAM roles [01:57.000 --> 02:04.160] in your account that have a trust relationship back to some AWS service. This enables that [02:04.160 --> 02:10.440] service to perform actions and uh do functionality in your account. Today we're going to look [02:10.440 --> 02:15.120] at some vulnerabilities that would allow us to hijack that trust relationship and gain access [02:15.120 --> 02:20.160] to victim accounts so that from there we can escalate privileges, move laterally, access [02:20.160 --> 02:24.640] resources and more. In this session we're going to talk a little bit about how trust is [02:24.640 --> 02:30.480] established between IAM roles and AWS services. Then we're going to dive deep on two [02:30.480 --> 02:34.960] vulnerabilities as well as a more general misconfiguration that would allow us to take [02:34.960 --> 02:40.300] advantage of this. And finally we're going to discuss prevention options. In the absolute [02:40.300 --> 02:46.120] worst case scenario of an adversary having a cross tenant zero day in AWS, what options do we [02:46.120 --> 02:52.420] have to try and mitigate some of these attacks? Now it's worth noting that the majority of [02:52.420 --> 02:57.320] vulnerabilities we're going to be talking about today have been remediated by AWS. So think of [02:57.320 --> 03:00.980] this more from the perspective of what can we learn from these vulnerabilities that we can [03:00.980 --> 03:06.700] apply to better attack or defend cloud environments. To get us started on the topic of [03:06.700 --> 03:12.700] abusing pre-existing trust, we should probably talk about how that trust is established. In [03:12.700 --> 03:21.280] AWS, every IAM role is going to have a role trust policy. And this policy determines who or [03:21.280 --> 03:28.480] what is permitted to assume a role. Trust policies can trust a variety of identities. Users, [03:28.480 --> 03:34.500] roles, AWS organizations, uh identity providers and many others. But where I think it's most [03:34.500 --> 03:41.260] interesting is when they trust an AWS service itself. What you see here on the slide is the [03:41.940 --> 03:46.660] default trust policy that is associated with roles for the Lambda service. If you were to [03:46.660 --> 03:50.940] create a Lambda function today, the role that would be created for you would have this very [03:50.940 --> 03:57.180] same trust policy. And what it says is that we're going to allow the Lambda service to assume [03:57.180 --> 04:04.080] role with web, or sorry, to assume role. Now, the way this works in practice is every time your [04:04.080 --> 04:10.160] Lambda function runs, the Lambda service assumes that role in your account and does whatever it [04:10.160 --> 04:16.420] is that you want it to do. This behavior introduces some really interesting questions. Since I [04:16.420 --> 04:22.360] already said that this is the default policy, theoretically the majority of roles using Lambda [04:22.360 --> 04:28.340] wouldn't have it. And since the trust policy just says that it trusts Lambda, could I do [04:28.340 --> 04:33.820] something a little bit sneaky? Could I create a Lambda function in my account but point to or [04:33.820 --> 04:39.020] reference a role in a different AWS account? Preferably one that I don't have legitimate [04:39.020 --> 04:45.600] access to. Uh could we cause that Lambda service to assume that role in the victim account and [04:45.600 --> 04:51.780] carry out whatever operations would be beneficial to us as adversaries? Well, the good news or [04:51.780 --> 04:55.500] bad news depending on your perspective is there is something that stops this. And that's [04:55.500 --> 05:02.400] called pass role. Any time you are providing a role to an AWS service for it to assume it, [05:02.400 --> 05:07.720] you're interacting with pass role. One of the core rules of which is that you can only pass a [05:07.720 --> 05:13.820] role within your same AWS account. If you try to pass a role outside of it, you get the error [05:13.820 --> 05:19.300] message, access denied, cross account pass role is not allowed. Now, this is a very important [05:19.300 --> 05:25.040] security boundary in AWS because without it, theoretically we could just arbitrarily assume [05:25.040 --> 05:30.160] role into pretty much any account and access any of the resources associated with it. So this [05:30.160 --> 05:34.300] is going to be the goal for the first part of our session today. Finding a vulnerability in [05:34.300 --> 05:39.400] the pass role implementation to allow us to weaponize a service against roles that trust it [05:39.400 --> 05:45.120] and access resources in victim accounts. So the first vulnerability is a confused deputy [05:45.120 --> 05:50.900] vuln in AWS AppSync. If you're not familiar with AppSync, AppSync is a managed GraphQL [05:50.900 --> 05:58.720] service offered by AWS. And it allows you to quickly and easily build GraphQL APIs. The way [05:58.720 --> 06:02.900] that it works is pretty similar to what I described with Lambda, where you first create an [06:02.900 --> 06:08.540] AppSync API in your account, configure it, set your schema, and so on. And then as a part of [06:08.540 --> 06:13.900] setting your data source, a role will be created for you that by default has a trust policy back [06:13.900 --> 06:20.260] to the AppSync service. Then, when your AppSync API is run, the AppSync service assumes that [06:20.260 --> 06:25.960] role and does whatever that API is supposed to do. And again, if you try to pass a role outside [06:25.960 --> 06:31.500] of your account, cross account pass role is not allowed. Now, I recognize this is DEF CON [06:31.500 --> 06:35.300] and I'm sure many of you are already trying to come up with ways that we can bypass this [06:35.300 --> 06:41.100] control. Things like unique encoding schemes, maybe something like HTTP request smuggling or [06:41.100 --> 06:46.000] maybe even something more exotic. These are all great ideas and I strongly encourage you to [06:46.000 --> 06:51.660] pursue them, but we actually found a much simpler approach to get around this. Through the [06:51.660 --> 06:59.260] power of Spongebob memes. See, under normal circumstances, the AWS API is typically case [06:59.260 --> 07:05.800] sensitive. And what I mean by that is, if you pass a parameter to the AWS API, it expects it in [07:05.940 --> 07:11.300] a very particular casing format. If you don't meet that expectation, you'll get an error. So [07:11.300 --> 07:17.520] to demonstrate this with a completely unrelated API, here we're performing secrets manager [07:17.520 --> 07:23.800] create secret. And that API expects a name parameter with a capital N. So long as you pass [07:23.800 --> 07:30.900] it in that format, 200 OK, everything works, you created a secret. However, if we were to [07:30.900 --> 07:36.520] deviate from that format in any way, in this case we've put it to all uppercase, we try to pass [07:36.520 --> 07:42.640] that to the API, it complains. 400 bad requests, member must not be null. The reason for this [07:42.640 --> 07:48.620] is, well we didn't pass the parameter it was looking for. It might be the right alphabetical [07:48.620 --> 07:54.420] characters, but it's not the specific one and so it rightfully so throws an error. While this [07:54.420 --> 07:59.160] may sound like a fairly obvious thing to point out, the reason it matters is that by [07:59.160 --> 08:05.260] comparison, the AppSync API was a bit of an oddity. It was not case sensitive. We could pass [08:05.260 --> 08:11.000] arbitrary parameters of mixed casing and the API would take it totally fine. Presumably [08:11.000 --> 08:17.380] somewhere on the back end it was normalizing these values in some way. Now, the parameter you [08:17.380 --> 08:24.720] would use to pass a role ARN to the AppSync service was called service role ARN, capital R, [08:24.720 --> 08:29.900] capital A. If you try to pass a role outside of your account, once again, cross account pass [08:29.900 --> 08:37.300] role is not allowed. But, if we change the casing on that parameter in any way, even on just a [08:37.300 --> 08:42.180] single character, in this case we made it all lowercase, and we try to pass a role outside of [08:42.180 --> 08:47.340] our account, for some unknown reason, whatever filtering or allow listing or checking that was [08:47.340 --> 08:52.320] supposed to occur, either didn't happen at all or completely failed. And so by changing the [08:52.320 --> 08:58.320] casing on a parameter, we were able to now arbitrarily specify roles for the AppSync [08:58.320 --> 09:03.280] service to try and assume. And so, we were able to break a major security boundary in AWS [09:04.090 --> 09:11.560] with Spongebob memes. To put this in another, in another context, what this allowed us to do, [09:11.560 --> 09:18.560] was to target any role that legitimately used the AppSync service in any AWS account. We [09:18.560 --> 09:23.600] could now provide that role to the service and arbitrarily assume it and access whatever [09:23.600 --> 09:29.900] resources were associated with it. This is an example of a cross service confused depi attack, [09:29.900 --> 09:35.200] where a lower privileged entity, in this case us, was able to trick or coerce a higher [09:35.200 --> 09:40.540] privileged entity, in this case the AppSync service, to do something on our behalf. And this [09:40.540 --> 09:46.180] scenario, that was assuming a role in a victim account. It's really important to stress, the [09:46.180 --> 09:50.940] thing that makes this possible, the thing that enables this attack, is that pre-existing [09:50.940 --> 09:57.400] trust relationship between those IAM roles and the AppSync service. Because the roles trust [09:57.400 --> 10:02.100] AppSync and because we found a way to weaponize that service against them, this is the path [10:02.100 --> 10:07.740] that allows us to assume those roles in victim accounts. Now, if you've ever done cross [10:07.740 --> 10:13.400] tenant attacks in AWS, you know that assuming a role is only half the battle. From here, we [10:13.400 --> 10:18.540] have to actually do something useful. If we were in a scenario where, say, we had a [10:18.540 --> 10:23.620] vulnerability similar to this, but we were limited to something like S3 list buckets as the [10:23.620 --> 10:28.780] only API call we could make, well yeah, it's not great. Um, I wouldn't be very happy of it if [10:28.780 --> 10:32.960] I was a defender, but at the end of the day, there's very little risk that could be [10:32.960 --> 10:37.900] demonstrated there. The good news for us is that in this scenario, the AppSync service is [10:37.900 --> 10:43.380] more than happy to provide. In particular, AppSync allows you to run arbitrary AWS [10:43.380 --> 10:50.700] API calls. So you now have the full spectrum of API calls that you can invoke at your [10:50.700 --> 10:57.420] choosing. Now for a step by step practical example of how we'd exploit this, as an attacker, [10:57.420 --> 11:02.860] we'd create our own AppSync API. Configure it, set the schema, create our data sources and [11:02.860 --> 11:07.620] so on. Then we would perform that pass role bypass to specify what role in the victim [11:07.620 --> 11:12.960] account we want to assume. And then, under normal circumstances, the AppSync service would [11:12.960 --> 11:17.600] assume the role in our account. But because of this vulnerability, it now assumes the role [11:17.600 --> 11:23.400] in the victim account and carries out whatever API operation we asked it to perform. The [11:23.400 --> 11:28.020] neat thing about this, from a attacker's perspective, is if you've ever done pentesting or [11:28.020 --> 11:32.180] red teaming in AWS, you know that one of the challenges you have is that you're trying to [11:32.180 --> 11:36.160] find credentials with access to things that you care about. And if you can't find them [11:36.160 --> 11:40.880] immediately, how can you move laterally, escalate privileges, find other credentials and [11:40.880 --> 11:45.780] things like that? It becomes a bit of a hassle. By comparison, with confused deputy [11:45.780 --> 11:51.660] attacks, you can just land as the identity of a production application. If there's a [11:51.660 --> 11:56.500] production AppSync API, it has privileges to do whatever that service needs to do. Whether [11:56.500 --> 12:03.720] that is upload S3, write to DynamoDB, read from RDS or anything else. Because we land as [12:03.720 --> 12:07.820] that role, we have access to whatever privileges are associated with it, and these tend to [12:07.820 --> 12:13.700] be fairly beneficial. So no need for weird bloodhound-esque lateral movement paths, you [12:13.700 --> 12:18.420] just pass that role and yow you're in. That's how we can do things like this in this [12:18.420 --> 12:24.220] screenshot, where we dump the contents of a DynamoDB table, cross tenant in AWS, by asking it [12:24.220 --> 12:29.980] to perform the DynamoDB scan operation. If you're interested in this vulnerability and you'd [12:29.980 --> 12:35.600] like to learn more, AWS did release a security bulletin for it, and in addition we have a [12:35.600 --> 12:40.740] blog post with a ton of additional information on conducting confused deputy attacks in AWS and [12:40.740 --> 12:45.980] some things to look out for. Um, the respective QR codes with the arrows will take you to each [12:45.980 --> 12:51.960] of those. Now, before we get to our next vulnerability, it's important that we learn a few [12:51.960 --> 12:58.060] things about assume role with web identity. Up until this point, we've been talking about [12:58.060 --> 13:05.580] plain assume role, which is typically used for AWS to AWS role assumption. As an example, if [13:05.580 --> 13:09.600] you have an AWS account and you would like me to assume a role in that account to do [13:09.600 --> 13:15.840] something, we'd probably end up using assume role. Now, while this is great, it does have sort [13:15.840 --> 13:22.200] of a limitation, in that it requires the entity doing the role assumption to originate from [13:22.200 --> 13:26.940] AWS. And unfortunately, there are a variety of use cases in which you might want to have an [13:26.940 --> 13:32.380] identity from outside Amazon have the ability to assume role in your account. What do you [13:32.380 --> 13:37.900] do? Well, that's where assume role with web identity comes in. The core idea here is that [13:37.900 --> 13:43.140] you essentially offload the responsibility of authorizing that role assumption onto an [13:43.140 --> 13:48.440] identity provider of your choosing. This can be a private identity provider, one that you [13:48.440 --> 13:53.400] or your company own and maintain, or it can be a public identity provider. Think things [13:53.400 --> 14:00.220] like Facebook, Amazon, Google, GitHub, and many others. The sort of core idea here is that [14:00.220 --> 14:04.640] your external users, whether they be human or machine, interact with the identity provider [14:04.640 --> 14:09.860] to generate a JWT, they pass that into the assume role with web identity call, and this [14:09.860 --> 14:15.020] enables them to assume a role in your account. Now, before we go any further, I really want [14:15.020 --> 14:20.340] to stress that assume role with web identity is a general design pattern. A variety of [14:20.340 --> 14:26.020] technologies and services, both native to AWS and outside of it, will use this general [14:26.020 --> 14:31.540] design pattern. In the next couple slides, we're going to use GitHub actions as an example, [14:31.540 --> 14:35.300] just to sort of explain how this works and talk a little bit more about the underpinnings, but [14:35.300 --> 14:43.540] really want to stress, this is not limited to just GitHub actions. To one common problem with [14:43.540 --> 14:47.520] CIC pipelines, particularly if they're outside of your cloud provider, if you're using [14:47.520 --> 14:52.880] something like GitHub actions, well, how do you authenticate to an S3 bucket if you wanted [14:52.880 --> 14:57.720] to upload, say, some sort of build artifact or logs or anything else? Well, we could use [14:57.720 --> 15:02.360] assume role with web identity. To set this up, we initially create a trust relationship [15:02.360 --> 15:07.680] between our AWS account and an identity provider. Since we're already using GitHub [15:07.680 --> 15:12.980] actions, we might as well use GitHub's provided identity provider. Once that trust is [15:12.980 --> 15:20.120] established, we then create an IEM role. And, like I said before, all roles have a role trust [15:20.120 --> 15:25.320] policy, and in that policy, we specify the identity provider as the entity that's allowed to [15:25.320 --> 15:33.440] assume the role. Then, every time our GitHub action job runs, it will retrieve a JWT that has [15:33.440 --> 15:37.980] been signed by that identity provider, that JWT is passed to an assume role with web [15:37.980 --> 15:42.760] identity call, and thus, that job at that pipeline is able to assume the role in our account [15:43.180 --> 15:48.840] and do whatever it wants to do, whether that is upload something to S3 or call any other API [15:48.840 --> 15:53.460] calls. Now, throughout that explanation, you might have noticed something a little bit scary [15:53.460 --> 15:58.120] and thought, perhaps I misspoke, or maybe I said something wrong. And I assure you, it's just [15:58.120 --> 16:04.640] as scary as it sounds. What you see here is the most basic, bare bones, simple trust policy [16:04.640 --> 16:10.280] you could possibly write when using assume role with web identity. And what it says is that [16:10.280 --> 16:15.080] we're going to allow the GitHub identity provider the ability to assume role with web [16:15.080 --> 16:20.040] identity. And that's a really scary thought, because if we think about it, GitHub's identity [16:20.040 --> 16:26.800] provider is public. It's global. Anybody has access to it. There's nothing stopping someone [16:26.800 --> 16:31.800] from creating their own GitHub account, creating their own GitHub action to generate a JWT [16:31.800 --> 16:37.860] signed by that very same provider, and passing that in to the assume role with web identity [16:37.860 --> 16:44.080] call, allowing them to access those roles in your account. If you had this trust policy on a [16:44.080 --> 16:48.780] role, anybody with access to a GitHub account could have just hijacked it and accessed [16:48.780 --> 16:54.920] anything associated with it. That's why any time you use assume role with web identity, with [16:55.100 --> 17:01.200] a identity provider that is public or global, you need to also have a condition which [17:01.200 --> 17:06.600] restricts specifically who is allowed to assume that role. Again, assume role with web [17:06.600 --> 17:11.540] identity is a general design pattern. The specific condition you'll need will differ depending [17:11.540 --> 17:16.880] on the service and what specific scenario you're in. To continue using GitHub actions as an [17:16.880 --> 17:23.240] example, you need to specify what GitHub repo or what GitHub organization is allowed to [17:23.240 --> 17:29.440] assume that role. If you're a heavy AWS user, strongly encourage you to audit your roles that [17:29.440 --> 17:34.080] use assume role with web identity for this misconfiguration, because again, if you make [17:34.080 --> 17:38.380] this mistake, theoretically anybody could just assume that role in your account, which is [17:38.380 --> 17:45.100] not optimal. Um, now the good news to all this is this attack that I just described was very [17:45.100 --> 17:48.940] much in vogue last year. A number of security researchers, including my own colleague [17:48.940 --> 17:54.160] Christoph, identified that this was a potential issue and raised awareness about it. If you'd [17:54.160 --> 17:57.900] like to le- learn a little bit more about the GitHub specific situation, uh, we have a blog [17:57.900 --> 18:03.900] post with a ton of details and that QR code will take you there. Uh, now to AWS' credit, they [18:03.900 --> 18:08.640] actually did something about this. In particular, they made what was once an optional [18:08.640 --> 18:15.340] condition, now mandatory. You can no longer create a role trust policy for the GitHub identity [18:15.340 --> 18:20.860] provider that doesn't include a condition. And so, that's good. Kudos to AWS, that's a great [18:20.860 --> 18:26.720] change. But, if we were to nitpick it, remember, I said assume role with web identity is used [18:26.720 --> 18:31.300] all over the place in a variety of contexts, and they only fixed it specifically to GitHub [18:31.300 --> 18:36.320] actions. Any of the other technologies or services that have this very same potential [18:36.320 --> 18:41.780] misconfiguration were slash are still vulnerable. So again, definitely encourage you to audit [18:41.780 --> 18:47.120] your roles. There is one such service that I'd like to dive a little bit more deeply on, uh, [18:47.120 --> 18:54.400] and that is Cognito. Uh, Cognito is a sign in as a service offering from AWS. If you want to [18:54.400 --> 18:59.160] store user credentials but you don't want to deal with the hassle of uh, hashing, salting, [18:59.160 --> 19:04.680] and things like that, you can pay Amazon a fee and they'll take care of that for you. One of [19:04.680 --> 19:10.520] the core features of Cognito is something called an identity pool. And an identity pool is a [19:10.520 --> 19:15.660] resource you can create in your account that allows you to distribute short-lived IEM [19:15.660 --> 19:22.680] credentials to your users so that they can assume roles in your account. As an example, say [19:22.680 --> 19:27.260] you're building a web application and you want your users to be able to upload content to S3 [19:27.260 --> 19:32.580] or invoke an API gateway using IEM off, the way you could achieve this is creating a Cognito [19:32.580 --> 19:37.520] identity pool, allowing your users to interact with it, to generate tokens, they would then uh, [19:37.520 --> 19:42.060] through a library in the client pass that to the assume role with web identity call and assume [19:42.060 --> 19:48.060] the role in your account. The good news about Cognito is that they seemingly foresaw the very [19:48.060 --> 19:53.980] same attack that occurred with GitHub actions. They do, by default, include a condition to [19:53.980 --> 20:01.420] defend against it. Specifically, the condition will restrict which identity pool is allowed to [20:01.420 --> 20:07.020] assume a role. And this is very important because if the trust policy looked like this, anyone [20:07.020 --> 20:11.100] in the world would be able to assume that role. And we're gonna talk about some reasons why that [20:11.100 --> 20:17.020] trust policy might look like this in just a little bit. Uh, the way that we can take advantage [20:17.020 --> 20:21.620] of it is slightly different than what we described with GitHub actions. This is mostly an [20:21.620 --> 20:26.860] implementation detail specific to Cognito identity pools. Specifically, what we're gonna do [20:26.860 --> 20:35.460] is use a uh, Cognito offload. Offloads are essentially like the, essentially the step by step [20:35.460 --> 20:42.140] operations uh, that a user would use to generate those credentials. There are two offloads [20:42.140 --> 20:47.400] currently supported, an enhanced offload and a basic offload, sometimes referred to as [20:47.400 --> 20:53.120] classic. We're gonna focus on classic because that allows us to actually specify the role we [20:53.120 --> 20:59.160] wanna assume because the final operation in this chain is assume a role with web identity. Um, [20:59.160 --> 21:03.120] the specific step by steps are as an attacker, we're gonna create our own Cognito identity [21:03.120 --> 21:09.500] pool. We're gonna, going to then perform get ID and get open ID tokens to generate that JWT. [21:09.500 --> 21:14.160] And once we have that JWT, we pass it in an assume role with web identity call and this allows [21:14.160 --> 21:18.780] us to assume the role in the victim account. So for our purposes, for the remainder of this [21:18.780 --> 21:25.240] talk, we'll refer to this as the Variant 1 Vulnerable Trust Policy. A trust policy tied back [21:25.240 --> 21:30.580] to uh, the Cognito service but not including a condition to restrict which identity pool is [21:30.580 --> 21:35.300] allowed to assume it. The reason we call this Variant 1 is because there's a Variant 2 as [21:35.300 --> 21:39.580] well. You might have noticed there's actually two conditions on the default trust policy [21:39.580 --> 21:45.720] associated with roles using Cognito. And this condition is the AMR condition, or the [21:45.720 --> 21:50.340] authentication methods references. And this value can be either authenticated or [21:50.340 --> 21:54.860] unauthenticated. You might wonder, could we assume a role if this condition was set? And [21:54.860 --> 21:59.700] turns out, yeah, absolutely, we totally could. If the value is set to unauthenticated, then [21:59.700 --> 22:04.640] literally everything I just said works completely the same, no changes required. If the value [22:04.640 --> 22:09.400] is authenticated, then we do have to jump through some extra hoops. In particular, in our [22:09.400 --> 22:13.800] attacker controlled account, we have to create a Cognito user pool, configure it alongside [22:13.800 --> 22:18.580] the identity pool, and then from there, basically all the same steps apply with some minor [22:18.580 --> 22:24.780] changes. All this condition is doing is checking that you are authenticated to an identity [22:24.780 --> 22:30.040] pool, not that you are authenticated to a specific identity pool. And since we can just [22:30.040 --> 22:33.480] create our own identity pool, we can configure it however we like, so we can add [22:33.480 --> 22:38.720] authentication if we need to. Now, earlier you might have noticed that I called this a [22:38.720 --> 22:43.840] misconfiguration, and that's because it is. The GitHub action stuff, this Cognito stuff, any [22:43.840 --> 22:48.560] of the other myriad of services which have this very same issue, all of these are [22:49.040 --> 22:53.940] misconfigurations, not a vulnerability. Had you suffered a breach, compromise, or other [22:53.940 --> 22:58.760] security incident as a result of it, well, unfortunately that would be your responsibility as a [22:58.760 --> 23:03.240] part of the AWS shared responsibility model. And so you're probably wondering, well Nick, I [23:03.240 --> 23:07.340] was promised a second vulnerability, you're calling this a misconfiguration, what gives? [23:07.340 --> 23:13.140] Well, uh, this is where things get weird, and we dive into our second vulnerability of the day, [23:13.140 --> 23:19.700] the AWS Amplify service exposing IEM roles to take over. Uh, see earlier this year when we [23:19.700 --> 23:24.860] noticed this capability in Cognito, one of the first questions we had was, okay cool, I wonder [23:24.860 --> 23:30.100] how common this misconfiguration is. And because it could be used for initial access, [23:30.100 --> 23:34.700] literally just assume rolling into victim accounts, we wanted to know if we could use publicly [23:34.700 --> 23:40.740] available data to find vulnerable roles and notify their owners so they could be fixed. To do [23:40.740 --> 23:46.260] this, we used a tool called Sourcegraph. One of the free features of which is essentially like a [23:46.260 --> 23:52.780] Google search, but for public GitHub repos. Uh, we we wrote a regular expression to find IEM [23:52.780 --> 23:58.520] role ARNs. Threw that into Sourcegraph, got back results, deduplicated them, removed like [23:58.520 --> 24:02.380] clearly placeholder ARNs, like account IDs with all one digit or incrementing digits, things [24:02.380 --> 24:08.500] like that. Uh, and that left us with a little over 8,000 results. We then tried to assume each [24:08.500 --> 24:13.540] role twice. Once authenticated and once unauthenticated. And we let our automation run [24:13.540 --> 24:19.440] and pretty much immediately it was clear, something was terribly wrong. Remember, this was [24:19.440 --> 24:25.040] across all of public GitHub. Across teams, organi- organizations, individuals and companies. [24:25.040 --> 24:30.880] So, why was it then that the overwhelming majority of roles that we found to be vulnerable all [24:30.880 --> 24:37.320] had this weirdly specific naming convention? What you see here on the slide are real, re- [24:37.320 --> 24:42.460] real roles that we found in the wild that were vulnerable that we have slightly modified the [24:42.460 --> 24:47.920] names of so as to respect the anonymity of their owners. Now, what made these roles so weird [24:47.920 --> 24:52.940] was that they all ended in either auth role or unauth role. And additionally, they had what [24:52.940 --> 24:58.780] appeared to be either a time stamp dating back to 2018 or 2019 or they had a six digit [24:58.780 --> 25:04.100] integer. Presumably, these were the newer ones. To make things even more weird, as we were [25:04.100 --> 25:10.360] going through the results, we actually found three roles that belonged to AWS themselves. And [25:10.360 --> 25:15.040] so at this point, it wasn't clear if this was some sort of, uh, tutorial gone wrong where [25:15.040 --> 25:20.040] somebody was demoing how to set this up with OIDC, not realizing that it was vulnerable and [25:20.040 --> 25:25.800] letting anybody just assume these roles in anybody's account. Uh, using source graph, we [25:25.800 --> 25:31.220] were able to see the name of the file where these roles were being found. And again, the [25:31.220 --> 25:37.560] overwhelming majority were found in files called team provider info dot Jason. And through [25:37.560 --> 25:43.300] this, this led us ultimately to the culprit. The thing that was causing all these roles to let [25:43.300 --> 25:51.200] anybody assume them. Turns out, it was AWS Amplify. Normally, when we're talking about a [25:51.700 --> 25:56.020] misconfiguration, we're talking about a mistake, misunderstanding, developers moving a little [25:56.020 --> 26:00.280] bit too quickly and breaking things, or not realizing that something is as vulnerable as it [26:00.280 --> 26:07.000] actually was. This was a rare circumstance in which an AWS service itself was exposing IEM [26:07.000 --> 26:11.480] roles, such that anyone could assume them. The vulnerability was not that you could [26:11.480 --> 26:16.340] misconfigure roles, it's that AWS was doing it to you. And fortunately, not just once, they [26:16.340 --> 26:21.980] actually did it twice. If you're not familiar with Amplify, Amplify is a uh, web and mobile [26:21.980 --> 26:26.620] application framework that lets you build these technologies. Uh, one of the core selling [26:26.620 --> 26:32.700] points to Amplify is essentially that uh, by using Amplify, it will abstract away a lot of the [26:32.700 --> 26:37.660] underlying infrastructure. So, if you build a web application and you want your users to be [26:37.660 --> 26:43.160] able to create accounts, sign up, change their password and so on, your developers don't even [26:43.160 --> 26:48.800] need to know what Cognito is. They can simply add authentication through Amplify, and Amplify [26:48.800 --> 26:54.940] goes in, creates Cognito resources, configures them, sets them up, and so on. Key emphasis, [26:54.940 --> 27:01.000] Amplify configures those Cognito resources. Now, there's two ways you can build an Amplify [27:01.000 --> 27:05.360] app or configure them. Uh, they're not mutually exclusive, you can use either or. Uh, there [27:05.360 --> 27:10.700] is the studio, which is the web console portal equivalent, and then there is the CLI, which [27:10.700 --> 27:15.940] you can run from your local machine, or as a part of your CICD pipeline. Now, typically when [27:15.940 --> 27:19.960] we do cloud security research, one of the challenges we often have is, it's not really [27:19.960 --> 27:25.180] clear why this vulnerable behavior is occurring. We might be able to see that something has [27:25.180 --> 27:30.380] security impacts, but it's not clear what exactly happened or why it's doing this. For example, [27:30.380 --> 27:34.820] with the first vulnerability, for some remarkably strange reason, changing the casing on a [27:34.820 --> 27:40.240] JSON parameter let us break a major security boundary in AWS. So we run into these types of [27:40.240 --> 27:44.680] scenarios fairly frequently. What's neat about this Amplify vulnerability, and why it's [27:44.680 --> 27:49.580] personally one of my favorites, is that this is actually a rare instance where we are able to [27:49.580 --> 27:55.440] know not only how did this become vulnerable, but when. That's because the Amplify CLI [27:55.440 --> 28:01.420] written by AWS is actually open source. And by digging through the commit history, we can [28:01.420 --> 28:07.040] see how and when these vulnerabilities were introduced. And we didn't know at the time, but [28:07.040 --> 28:12.740] later on in speaking to AWS employees, we came to find out that the Amplify Studio, the web [28:12.740 --> 28:18.680] console equivalent, actually uses parts of the CLI as libraries. And that's how I can tell [28:18.680 --> 28:24.180] you with confidence that both the Amplify Studio and CLI became vulnerable on or around [28:24.180 --> 28:30.640] July 3rd, 2018 to the Variant 2 Vulnerable Trust Policy, allowing anyone in the world the [28:30.640 --> 28:36.260] ability to assume these roles. What happened here is that any time you create an Amplify [28:36.260 --> 28:41.760] project, two roles are created for your account. An auth role and an unauth role, like we saw [28:41.760 --> 28:48.800] previously. Unfortunately, as a part of this commit, the default trust policy associated with [28:48.800 --> 28:53.880] those roles was set to this, which would allow anybody in the world to assume them. So if you [28:53.880 --> 28:58.240] thought you were building a private, internal only application that required authentication [28:58.240 --> 29:02.440] and you were gatekeeping who could create accounts so that you could protect your stuff, [29:02.440 --> 29:08.300] well, um, sorry, no you weren't. Anybody could just assume those roles and access whatever was [29:08.300 --> 29:14.380] associated with them. Like I said, that was introduced on July 3rd, 2018. A little over a year [29:14.380 --> 29:22.220] later, on August 8th, 2019, AWS sort of fixed this issue. Uh, seemingly unintentionally. What [29:22.220 --> 29:27.500] they did was they set the default effect to a deny and they removed the condition entirely. [29:27.500 --> 29:33.720] This is actually the exact same behavior we see today when creating a new Amplify project. It's [29:33.720 --> 29:38.720] really important to stress, though, that what this change did in August of 2019 was make it so [29:38.720 --> 29:45.120] that no future roles would become misconfigured. Any that had already been created were still [29:45.120 --> 29:52.020] vulnerable and that's how we were able to assume them in 2024. Later on in July of 2020, [29:52.020 --> 29:57.120] variant one was introduced to the Amplify CLI in studio. And this one was a bit more complicated [29:57.120 --> 30:02.440] than the previous one. What happened here was that, uh, like I said previously, you can add [30:02.440 --> 30:08.380] authentication to an Amplify project. If at any time you chose to remove authentication for any [30:08.380 --> 30:13.700] reason, that would introduce the variant one policy. Uh, in speaking to developers who were [30:13.700 --> 30:18.520] affected by this, it seems the most common reason that this occurred was situations in which, [30:18.520 --> 30:25.640] uh, uh, projects started with the built-in Amplify controlled Cognito resources and then at a [30:25.640 --> 30:29.300] point, uh, went to Cognito outside of Amplify or to just a different identity provider [30:29.300 --> 30:34.280] entirely. Regardless of the reason why, what occurred was that a cloud formation template [30:34.280 --> 30:39.540] would run that would start setting the default trust policy to what you see on the slide, [30:39.540 --> 30:45.780] which is totally fine. This is the secure trust policy. However, under the line, uh, under the [30:45.780 --> 30:50.460] condition for the deletion of the authentication configuration, there was a line to delete the [30:50.460 --> 30:55.560] condition off of the trust policy, which left you with this. The variant one vulnerable [30:55.560 --> 31:01.620] policy. Whatever identity permissions were associated with this rule, when this exposure [31:01.620 --> 31:07.260] occurred, it still had access to. So, if your rule could do something like, uh, read from an [31:07.260 --> 31:12.700] S3 bucket, write to a demo deep table, it still had that access. Additionally, at the end of [31:12.700 --> 31:18.540] the day, these are just plain IEM rules. And unfortunately, developers love to over-privilege [31:18.540 --> 31:24.180] their identities. When we were reacting to this vulnerability and notifying customers so [31:24.180 --> 31:28.380] they could mitigate it, we found a number of customers who had highly privileged roles, [31:28.380 --> 31:33.840] including some with S3 full access, Kinesis full access, and more. Unfortunately, as a part [31:33.840 --> 31:37.740] of this vulnerability, now anyone could have just accessed them and then accessed whatever [31:37.740 --> 31:44.120] resources were associated with those accounts. Uh, like I said, that was introduced in [31:44.120 --> 31:48.800] July of 2020, and then between then and when we eventually disclosed in 24, more and more [31:48.800 --> 31:54.000] rules were becoming misconfigured. One thing I'd really like to stress, uh, that makes this [31:54.000 --> 32:00.420] Cognito issue even more extreme, is that Cognito role ARNs are easily discoverable. If we [32:00.420 --> 32:04.400] compare this to the first vulnerability we talked about today, a confused deputy vol in some [32:04.400 --> 32:10.160] AWS service, an adversary still has to contend with the challenge of finding role ARNs. To be [32:10.160 --> 32:15.040] clear, an ARN is not a secret, not in the same way a password or API key is, but it does [32:15.040 --> 32:19.820] represent some level of challenge. They would have to brute force them, enumerate them, [32:19.820 --> 32:23.940] derive them from IAC, pull them out of build logs, rip them out of GitHub like we did, or a [32:23.940 --> 32:29.380] myriad of other ways. Suffice to say, it's something you could do across, say, a small [32:29.380 --> 32:33.820] number of organizations, but not something that you could easily scale to the size of the [32:34.380 --> 32:38.980] internet. By comparison, the whole point of Cognito is that these roles are supposed to be [32:38.980 --> 32:43.410] available to your users. They're basically public. And in addition, they're also [32:43.920 --> 32:47.560] deterministic, in the sense that if you know the unauth role, you now also know the auth role [32:47.560 --> 32:52.100] by default. And so what an adversary could have done is simply taken advantage of the [32:52.840 --> 32:57.700] default domain associated with Amplify apps to suddenly crawl tens of thousands of apps [32:57.700 --> 33:02.980] looking for vulnerable roles. And to be clear, the majority should be fine, but undoubtedly [33:02.980 --> 33:08.320] some number of them were created between July, or sorry, uh, 2018 and 2019, or who have [33:08.320 --> 33:15.180] since changed their authentication configuration since July of 2020. Like I said before, we [33:15.180 --> 33:20.360] did disclose this to AWS in January of this year, and AWS released comprehensive fixes in [33:20.360 --> 33:24.540] February and April. Uh, they did the same thing they did with GitHub Actions, where you can no [33:24.540 --> 33:28.760] longer create these vulnerable trust policies anymore. But in addition, they sort of went [33:28.760 --> 33:35.080] above and beyond. Specific to this Amplify issue, they actually made changes to STS so that [33:35.080 --> 33:41.220] you can no longer assume a role cross-account in AWS. So even if you had a variant 1 or [33:41.220 --> 33:46.180] variant 2 role in your account, somebody from a different account can no longer assume it. [33:46.640 --> 33:50.520] If you'd like to learn more about this vulnerability, AWS did release a security bulletin [33:50.520 --> 33:54.700] for it, and we have a blog post here with a ton of additional content and information on [33:54.700 --> 33:59.100] carrying out these types of attacks, how we found this vulnerability, and more advice on [33:59.100 --> 34:05.640] dealing with assume role with web identity. Really quickly though, I did want to mention, um, [34:05.640 --> 34:10.020] throughout this talk, we have been focused on creating resources in an attacker account so [34:10.020 --> 34:15.420] that we could then victimize a victim account. The reason for doing this is simplicity. If [34:15.420 --> 34:19.560] you own the resource, you can configure it, you can set it up however you like, you know it [34:19.560 --> 34:24.020] will always be available, you can troubleshoot it, but I wanted to mention it's not strictly [34:24.020 --> 34:30.940] required, it's just easier. Specific to the Amplify vulnerability, they fixed cross-account [34:30.940 --> 34:35.400] role assumption using identity pools. It's no longer possible for me to use one of my [34:35.400 --> 34:40.400] identity pools to assume a role in your account. But they didn't do anything about the same [34:40.400 --> 34:45.760] account scenario. And to be clear, I don't really think there's much they could do. Uh, the [34:45.760 --> 34:50.500] reason they were able to block cross-account assume role using this is, well that's, that's a [34:50.500 --> 34:57.180] very weird thing to do. It's very likely zero if any real organizations were doing this in [34:57.180 --> 35:01.060] the wild. And so they said hey, we can just block this off, we can fix this attack vector [35:01.060 --> 35:06.320] and we'll mitigate a lot of the risk. But you can still absolutely do this in the same [35:06.320 --> 35:11.960] account and this is something that you can still take advantage of today. Um, to be clear, [35:11.960 --> 35:16.040] this is more difficult, things are much nicer if you can just bring your own identity pool, [35:16.040 --> 35:20.320] but it's definitely something to be aware of if you are penetration duster, red teamer, or you [35:20.320 --> 35:26.060] simply use Amplify a lot. The way this would work is that if there is a variant one or variant [35:26.060 --> 35:32.280] two role in that account, if there is also a identity pool that is configured with basic [35:32.280 --> 35:37.700] authentication or the basic offload, not necessarily associated with Amplify, just any [35:37.700 --> 35:43.420] cognitive identity pool with that enabled, you as an external adversary can still interact [35:43.420 --> 35:47.980] with that identity pool, generate a JWT, pass it into Sumo with WebIdentity, and still [35:47.980 --> 35:53.100] assume one of those variant one or variant two vulnerable roles. Um, in the bottom left [35:53.100 --> 35:57.140] hand side, there's a QR code that will take you to a Hacking the Cloud article that will walk [35:57.140 --> 36:02.160] you through step by step how you can do this in both authenticated and unauthenticated [36:02.160 --> 36:07.800] environments. With the time we have left, I wanted to talk a little bit about what we can do [36:07.800 --> 36:13.660] to prevent cross tenant attacks in AWS. To be clear, uh, your time is probably much better [36:13.660 --> 36:18.680] spent doing things like deleting old access keys, uh, cleaning up old IM users, following [36:18.680 --> 36:23.220] least privilege, and so on, but if you're already doing all those things, or you have the [36:23.220 --> 36:27.400] technology and processes in place, it might be helpful to know that we do have some controls [36:27.400 --> 36:33.260] that can potentially prevent some of these attacks. In particular, AWS offers us a number [36:33.260 --> 36:39.420] of condition keys that allow us to restrict essentially where an adversary is coming from. [36:39.420 --> 36:44.540] Sort of similar to what we saw with a Sumo with WebIdentity previously. These conditions [36:44.540 --> 36:50.060] allow us to restrict either the ARN, the account, or the organization that is permitted to [36:50.060 --> 36:55.040] assume a role. It's really important to stress, these are not included by default, uh, if you [36:55.040 --> 36:58.820] were to try to create an instance profile today, it wouldn't automatically add one of these, [36:58.820 --> 37:03.080] so you would have to manually attach these conditions to each role you want to assume, or [37:03.080 --> 37:07.960] want to protect, and more importantly, make sure that those services are compatible with [37:07.960 --> 37:13.240] these condition keys. From some nominal testing, EC2, Lambda, AppSync, all work totally [37:13.240 --> 37:18.440] fine, but again, really encourage you to test before you try pushing this into production. To [37:18.440 --> 37:23.580] demonstrate how this would work in practice, uh, using source account as an example and [37:23.580 --> 37:28.880] tying us back to the first, uh, confused deputy attack we had in AWS, uh, by exploiting this [37:28.880 --> 37:33.320] vulnerability, an adversary would be able to assume a role which trusted the absent service. [37:33.320 --> 37:39.740] But if we had set a condition key on that trust policy, limiting what AWS account is permitted [37:39.740 --> 37:45.560] to assume that role, it would successfully block that adversary. The way we know this is back [37:45.560 --> 37:49.180] in the day when this vulnerability was present, we were able to actually test setting that [37:49.180 --> 37:54.740] condition key, and it did successfully block an external adversary. So even in that worst [37:54.740 --> 37:59.600] case scenario of someone having a cross-tenant zero day in AWS, by setting this condition [37:59.600 --> 38:05.280] key, we can block that access. The other reason I like this is from a defense in depth [38:05.280 --> 38:10.660] perspective. If pass rule says, under absolutely no circumstance should someone be able to [38:10.660 --> 38:15.780] assume a role cross-tenant, well great. We broke that with Spongebob memes. So the next time [38:15.780 --> 38:20.640] that happens, or if somebody finds a more inventive way around it, let's have an additional [38:20.640 --> 38:26.100] layer of protection to block these types of attacks. You're also unlikely to run into many [38:26.100 --> 38:31.600] issues. If it works, it's very unlikely to cause, uh, problems. It's, this is more of a static [38:31.600 --> 38:37.000] thing that stays the same over time. So in conclusion, we took a look today at how confused [38:37.000 --> 38:42.500] epi attacks can weaponize cloud services against us. We took a look at a very dangerous [38:42.500 --> 38:47.300] misconfiguration when using assume role with web identity. And again, I strongly encourage you [38:47.300 --> 38:51.800] to audit your roles that use it, because if you make this mistake, theoretically anybody can [38:51.800 --> 38:57.020] assume roles in your account. It's an easy mistake to make. AWS actually made it twice. Um, [38:57.020 --> 39:02.180] and then we also took a look today at how we can use, uh, condition keys to block confused [39:02.180 --> 39:06.580] epi attacks in AWS. If you enjoyed this talk, you can find more of our research at [39:06.580 --> 39:11.380] securitylabs.daydoghq.com. If you have any questions, feel free to find me after or reach out [39:11.380 --> 39:15.220] to me on social media. Again, my name's Nick Furchette. Thank you all so much.