WEBVTT

00:00.500 --> 00:02.380
Good afternoon DEF CON.

00:02.380 --> 00:03.920
Thank you so much for being here.

00:03.920 --> 00:08.720
Welcome to my talk on exploiting AWS service vulnerabilities for initial access.

00:08.880 --> 00:10.560
My name is Nick Furchette.

00:10.560 --> 00:15.760
I'm a security researcher over at Datadog where I specialize in AWS offensive security.

00:15.760 --> 00:23.780
So finding ways to more effectively attack AWS environments and then hopefully how do we detect that behavior or potentially prevent it entirely.

00:23.860 --> 00:29.240
As a result of that research sometimes I find vulnerabilities in the underlying AWS services.

00:29.260 --> 00:31.340
Some of which we're going to be talking about today.

00:31.700 --> 00:41.520
Uh in my free time I'm the creator and maintainer of Hacking the Cloud which is an open source encyclopedia of offensive security techniques that you can use in cloud hacking adventures.

00:41.580 --> 00:45.520
Uh 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:51.940
Now breaking into AWS accounts is a topic that's near and dear to my heart.

00:51.940 --> 00:54.520
And I'm sure it is for many of you as well.

00:54.520 --> 01:04.000
But I think if we're being honest with ourselves the traditional methods for gaining access to AWS environments are boring.

01:04.000 --> 01:15.580
If we were to poll the audience for real world AWS breaches, compromises and other security incidents I guarantee 95% of scenarios would fall into one of three categories.

01:15.740 --> 01:22.880
They were either caused by a leaked access key, an exposed S3 bucket or an exploited EC2 instance.

01:23.000 --> 01:28.840
These are the stereotypical ways that adversaries gain access to AWS accounts.

01:28.840 --> 01:39.020
And to be clear these are very real risks that we do have to contend with but it's nothing you haven't seen before and again these methods are boring.

01:39.120 --> 01:47.040
What we're going to be doing instead is kicking it in the door to the cloud and exploiting vulnerabilities in AWS services to get initial access.

01:47.040 --> 01:51.220
Particularly by abusing pre-existing trust.

01:51.340 --> 02:02.740
What I mean by that is a common design pattern in AWS is to have IAM roles in your account that have a trust relationship back to some AWS service.

02:02.740 --> 02:09.420
This enables that service to perform actions and uh do functionality in your account.

02:09.580 --> 02:21.920
Today we're going to look at some vulnerabilities that would allow us to hijack that trust relationship and gain access to victim accounts so that from there we can escalate privileges, move laterally, access resources and more.

02:21.980 --> 02:28.920
In this session we're going to talk a little bit about how trust is established between IAM roles and AWS services.

02:28.980 --> 02:36.200
Then we're going to dive deep on two vulnerabilities as well as a more general misconfiguration that would allow us to take advantage of this.

02:36.200 --> 02:39.420
And finally we're going to discuss prevention options.

02:39.420 --> 02:48.980
In the absolute worst case scenario of an adversary having a cross tenant zero day in AWS, what options do we have to try and mitigate some of these attacks?

02:49.340 --> 02:56.560
Now it's worth noting that the majority of vulnerabilities we're going to be talking about today have been remediated by AWS.

02:56.760 --> 03:04.520
So think of this more from the perspective of what can we learn from these vulnerabilities that we can apply to better attack or defend cloud environments.

03:05.060 --> 03:11.780
To get us started on the topic of abusing pre-existing trust, we should probably talk about how that trust is established.

03:12.200 --> 03:18.840
In AWS, every IAM role is going to have a role trust policy.

03:18.840 --> 03:24.780
And this policy determines who or what is permitted to assume a role.

03:24.980 --> 03:27.820
Trust policies can trust a variety of identities.

03:27.820 --> 03:33.280
Users, roles, AWS organizations, uh identity providers and many others.

03:33.280 --> 03:38.760
But where I think it's most interesting is when they trust an AWS service itself.

03:39.000 --> 03:46.100
What you see here on the slide is the default trust policy that is associated with roles for the Lambda service.

03:46.180 --> 03:52.320
If you were to create a Lambda function today, the role that would be created for you would have this very same trust policy.

03:52.320 --> 04:00.040
And what it says is that we're going to allow the Lambda service to assume role with web, or sorry, to assume role.

04:00.320 --> 04:11.680
Now, the way this works in practice is every time your Lambda function runs, the Lambda service assumes that role in your account and does whatever it is that you want it to do.

04:11.840 --> 04:16.020
This behavior introduces some really interesting questions.

04:16.020 --> 04:24.040
Since I already said that this is the default policy, theoretically the majority of roles using Lambda wouldn't have it.

04:24.040 --> 04:30.040
And since the trust policy just says that it trusts Lambda, could I do something a little bit sneaky?

04:30.280 --> 04:36.960
Could I create a Lambda function in my account but point to or reference a role in a different AWS account?

04:36.980 --> 04:40.460
Preferably one that I don't have legitimate access to.

04:40.720 --> 04:50.100
Uh could we cause that Lambda service to assume that role in the victim account and carry out whatever operations would be beneficial to us as adversaries?

04:50.200 --> 04:55.300
Well, the good news or bad news depending on your perspective is there is something that stops this.

04:55.300 --> 04:56.760
And that's called pass role.

04:56.880 --> 05:04.360
Any time you are providing a role to an AWS service for it to assume it, you're interacting with pass role.

05:04.360 --> 05:10.840
One of the core rules of which is that you can only pass a role within your same AWS account.

05:10.920 --> 05:17.640
If you try to pass a role outside of it, you get the error message , access denied, cross account pass role is not allowed.

05:17.740 --> 05:29.740
Now, this is a very important security boundary in AWS because without it, theoretically we could just arbitrarily assume role into pretty much any account and access any of the resources associated with it.

05:29.740 --> 05:33.080
So this is going to be the goal for the first part of our session today.

05:33.080 --> 05:42.680
Finding a vulnerability in the pass role implementation to allow us to weaponize a service against roles that trust it and access resources in victim accounts.

05:42.920 --> 05:47.700
So the first vulnerability is a confused deputy vuln in AWS AppSync.

05:47.900 --> 05:53.160
If you're not familiar with AppSync, AppSync is a managed GraphQL service offered by AWS.

05:53.240 --> 05:57.760
And it allows you to quickly and easily build GraphQL APIs.

05:58.040 --> 06:07.780
The way that it works is pretty similar to what I described with Lambda, where you first create an AppSync API in your account, configure it, set your schema, and so on.

06:07.780 --> 06:15.800
And then as a part of setting your data source, a role will be created for you that by default has a trust policy back to the AppSync service.

06:16.000 --> 06:23.540
Then, when your AppSync API is run, the AppSync service assumes that role and does whatever that API is supposed to do.

06:23.600 --> 06:29.160
And again, if you try to pass a role outside of your account, cross account pass role is not allowed.

06:29.320 --> 06:36.200
Now, I recognize this is DEF CON and I'm sure many of you are already trying to come up with ways that we can bypass this control.

06:36.340 --> 06:43.340
Things like unique encoding schemes, maybe something like HTTP request smuggling or maybe even something more exotic.

06:43.440 --> 06:51.200
These are all great ideas and I strongly encourage you to pursue them, but we actually found a much simpler approach to get around this.

06:51.220 --> 06:54.080
Through the power of Spongebob memes.

06:54.880 --> 07:00.080
See, under normal circumstances, the AWS API is typically case sensitive.

07:00.080 --> 07:07.740
And what I mean by that is, if you pass a parameter to the AWS API, it expects it in a very particular casing format.

07:07.740 --> 07:11.100
If you don't meet that expectation, you'll get an error.

07:11.120 --> 07:19.020
So to demonstrate this with a completely unrelated API, here we're performing secrets manager create secret.

07:19.020 --> 07:22.980
And that API expects a name parameter with a capital N.

07:23.000 --> 07:28.920
So long as you pass it in that format, 200 OK, everything works, you created a secret.

07:29.240 --> 07:38.780
However, if we were to deviate from that format in any way, in this case we've put it to all uppercase, we try to pass that to the API, it complains.

07:38.780 --> 07:41.620
400 bad requests, member must not be null.

07:41.860 --> 07:46.340
The reason for this is, well we didn't pass the parameter it was looking for.

07:46.340 --> 07:53.740
It might be the right alphabetical characters, but it's not the specific one and so it rightfully so throws an error.

07:54.020 --> 08:02.360
While this may sound like a fairly obvious thing to point out, the reason it matters is that by comparison, the AppSync API was a bit of an oddity.

08:02.360 --> 08:04.460
It was not case sensitive.

08:04.460 --> 08:10.520
We could pass arbitrary parameters of mixed casing and the API would take it totally fine.

08:10.520 --> 08:15.320
Presumably somewhere on the back end it was normalizing these values in some way.

08:15.520 --> 08:25.600
Now, the parameter you would use to pass a role ARN to the AppSync service was called service role ARN, capital R, capital A.

08:25.620 --> 08:31.160
If you try to pass a role outside of your account, once again, cross account pass role is not allowed.

08:31.580 --> 08:48.140
But, if we change the casing on that parameter in any way, even on just a single character, in this case we made it all lowercase, and we try to pass a role outside of our account, for some unknown reason, whatever filtering or allow listing or checking that was supposed to occur,

08:48.140 --> 08:51.040
either didn't happen at all or completely failed.

08:51.080 --> 08:59.880
And so by changing the casing on a parameter, we were able to now arbitrarily specify roles for the AppSync service to try and assume.

08:59.880 --> 09:05.760
And so, we were able to break a major security boundary in AWS with Spongebob memes.

09:06.500 --> 09:18.440
To put this in another, in another context, what this allowed us to do, was to target any role that legitimately used the AppSync service in any AWS account.

09:18.440 --> 09:25.820
We could now provide that role to the service and arbitrarily assume it and access whatever resources were associated with it.

09:25.820 --> 09:40.180
This is an example of a cross service confused depi attack, where a lower privileged entity, in this case us, was able to trick or coerce a higher privileged entity, in this case the AppSync service, to do something on our behalf.

09:40.180 --> 09:43.960
And this scenario, that was assuming a role in a victim account.

09:43.960 --> 09:56.120
It's really important to stress, the thing that makes this possible, the thing that enables this attack, is that pre-existing trust relationship between those IAM roles and the AppSync service.

09:56.180 --> 10:05.420
Because the roles trust AppSync and because we found a way to weaponize that service against them, this is the path that allows us to assume those roles in victim accounts.

10:06.200 --> 10:12.640
Now, if you've ever done cross tenant attacks in AWS, you know that assuming a role is only half the battle.

10:12.640 --> 10:15.280
From here, we have to actually do something useful.

10:15.360 --> 10:27.060
If we were in a scenario where, say, we had a vulnerability similar to this, but we were limited to something like S3 list buckets as the only API call we could make, well yeah, it's not great.

10:27.060 --> 10:33.720
Um, I wouldn't be very happy of it if I was a defender, but at the end of the day, there's very little risk that could be demonstrated there.

10:34.040 --> 10:39.500
The good news for us is that in this scenario, the AppSync service is more than happy to provide.

10:39.620 --> 10:44.520
In particular, AppSync allows you to run arbitrary AWS API calls.

10:44.520 --> 10:51.700
So you now have the full spectrum of API calls that you can invoke at your choosing.

10:52.400 --> 11:00.120
Now for a step by step practical example of how we'd exploit this, as an attacker, we'd create our own AppSync API.

11:00.120 --> 11:03.780
Configure it, set the schema, create our data sources and so on.

11:03.840 --> 11:09.340
Then we would perform that pass role bypass to specify what role in the victim account we want to assume.

11:09.360 --> 11:14.740
And then, under normal circumstances, the AppSync service would assume the role in our account.

11:14.740 --> 11:22.560
But because of this vulnerability, it now assumes the role in the victim account and carries out whatever API operation we asked it to perform.

11:22.920 --> 11:35.160
The neat thing about this, from a attacker's perspective, is if you've ever done pentesting or red teaming in AWS, you know that one of the challenges you have is that you're trying to find credentials with access to things that you care about.

11:35.160 --> 11:41.920
And if you can't find them immediately, how can you move laterally, escalate privileges, find other credentials and things like that?

11:41.920 --> 11:43.480
It becomes a bit of a hassle.

11:43.720 --> 11:50.680
By comparison, with confused deputy attacks, you can just land as the identity of a production application.

11:50.800 --> 11:56.080
If there's a production AppSync API, it has privileges to do whatever that service needs to do.

11:56.080 --> 12:02.040
Whether that is upload S3, write to DynamoDB, read from RDS or anything else.

12:02.160 --> 12:09.420
Because we land as that role, we have access to whatever privileges are associated with it, and these tend to be fairly beneficial.

12:09.420 --> 12:16.280
So no need for weird bloodhound-esque lateral movement paths, you just pass that role and yow you're in.

12:16.460 --> 12:27.360
That's how we can do things like this in this screenshot, where we dump the contents of a DynamoDB table, cross tenant in AWS, by asking it to perform the DynamoDB scan operation.

12:27.980 --> 12:42.300
If you're interested in this vulnerability and you'd like to learn more, AWS did release a security bulletin for it, and in addition we have a blog post with a ton of additional information on conducting confused deputy attacks in AWS and some things to look out for.

12:42.300 --> 12:47.000
Um, the respective QR codes with the arrows will take you to each of those.

12:47.740 --> 12:55.540
Now, before we get to our next vulnerability, it's important that we learn a few things about assume role with web identity.

12:55.940 --> 13:04.280
Up until this point, we've been talking about plain assume role, which is typically used for AWS to AWS role assumption.

13:04.480 --> 13:12.820
As an example, if you have an AWS account and you would like me to assume a role in that account to do something, we'd probably end up using assume role.

13:13.160 --> 13:23.120
Now, while this is great, it does have sort of a limitation, in that it requires the entity doing the role assumption to originate from AWS.

13:23.520 --> 13:31.820
And unfortunately, there are a variety of use cases in which you might want to have an identity from outside Amazon have the ability to assume role in your account.

13:32.020 --> 13:32.840
What do you do?

13:32.840 --> 13:36.180
Well, that's where assume role with web identity comes in.

13:36.180 --> 13:45.580
The core idea here is that you essentially offload the responsibility of authorizing that role assumption onto an identity provider of your choosing.

13:45.580 --> 13:52.960
This can be a private identity provider, one that you or your company own and maintain, or it can be a public identity provider.

13:52.960 --> 13:57.760
Think things like Facebook, Amazon, Google, GitHub, and many others.

13:58.180 --> 14:13.020
The sort of core idea here is that your external users, whether they be human or machine, interact with the identity provider to generate a JWT, they pass that into the assume role with web identity call, and this enables them to assume a role in your account.

14:13.100 --> 14:19.700
Now, before we go any further, I really want to stress that assume role with web identity is a general design pattern.

14:19.760 --> 14:27.140
A variety of technologies and services, both native to AWS and outside of it, will use this general design pattern.

14:27.220 --> 14:39.600
In the next couple slides, we're going to use GitHub actions as an example, just to sort of explain how this works and talk a little bit more about the underpinnings, but really want to stress, this is not limited to just GitHub actions.

14:40.560 --> 14:56.920
To one common problem with CIC pipelines, particularly if they're outside of your cloud provider, if you're using something like GitHub actions, well, how do you authenticate to an S3 bucket if you wanted to upload, say, some sort of build artifact or logs or anything else?

14:56.920 --> 14:59.340
Well, we could use assume role with web identity.

14:59.440 --> 15:06.620
To set this up, we initially create a trust relationship between our AWS account and an identity provider.

15:06.620 --> 15:11.540
Since we're already using GitHub actions, we might as well use GitHub's provided identity provider.

15:11.940 --> 15:16.600
Once that trust is established, we then create an IEM role.

15:16.600 --> 15:26.500
And, like I said before, all roles have a role trust policy, and in that policy, we specify the identity provider as the entity that's allowed to assume the role.

15:26.940 --> 15:44.900
Then, every time our GitHub action job runs, it will retrieve a JWT that has been signed by that identity provider, that JWT is passed to an assume role with web identity call, and thus, that job at that pipeline is able to assume the role in our account and do whatever it wants to do,

15:44.900 --> 15:49.680
whether that is upload something to S3 or call any other API calls.

15:50.020 --> 15:57.060
Now, throughout that explanation, you might have noticed something a little bit scary and thought, perhaps I misspoke, or maybe I said something wrong.

15:57.060 --> 15:59.680
And I assure you, it's just as scary as it sounds.

16:00.000 --> 16:08.740
What you see here is the most basic, bare bones, simple trust policy you could possibly write when using assume role with web identity.

16:08.800 --> 16:15.900
And what it says is that we're going to allow the GitHub identity provider the ability to assume role with web identity.

16:15.900 --> 16:21.680
And that's a really scary thought, because if we think about it, GitHub's identity provider is public.

16:21.680 --> 16:23.360
It's global.

16:23.440 --> 16:25.280
Anybody has access to it.

16:25.280 --> 16:41.260
There's nothing stopping someone from creating their own GitHub account, creating their own GitHub action to generate a JWT signed by that very same provider, and passing that in to the assume role with web identity call, allowing them to access those roles in your account.

16:41.260 --> 16:50.680
If you had this trust policy on a role, anybody with access to a GitHub account could have just hijacked it and accessed anything associated with it.

16:50.680 --> 17:05.020
That's why any time you use assume role with web identity, with a identity provider that is public or global, you need to also have a condition which restricts specifically who is allowed to assume that role.

17:05.080 --> 17:08.600
Again, assume role with web identity is a general design pattern.

17:08.600 --> 17:14.460
The specific condition you'll need will differ depending on the service and what specific scenario you're in.

17:14.460 --> 17:24.840
To continue using GitHub actions as an example, you need to specify what GitHub repo or what GitHub organization is allowed to assume that role.

17:25.000 --> 17:40.080
If you're a heavy AWS user, strongly encourage you to audit your roles that use assume role with web identity for this misconfiguration, because again, if you make this mistake, theoretically anybody could just assume that role in your account, which is not optimal.

17:40.700 --> 17:46.800
Um, now the good news to all this is this attack that I just described was very much in vogue last year.

17:46.800 --> 17:53.800
A number of security researchers, including my own colleague Christoph, identified that this was a potential issue and raised awareness about it.

17:53.800 --> 18:00.740
If you'd like to le- learn a little bit more about the GitHub specific situation, uh, we have a blog post with a ton of details and that QR code will take you there.

18:01.300 --> 18:05.640
Uh, now to AWS' credit, they actually did something about this.

18:05.640 --> 18:11.200
In particular, they made what was once an optional condition, now mandatory.

18:11.320 --> 18:17.940
You can no longer create a role trust policy for the GitHub identity provider that doesn't include a condition.

18:17.980 --> 18:19.500
And so, that's good.

18:19.500 --> 18:21.820
Kudos to AWS, that's a great change.

18:22.280 --> 18:32.240
But, if we were to nitpick it, remember, I said assume role with web identity is used all over the place in a variety of contexts, and they only fixed it specifically to GitHub actions.

18:32.420 --> 18:39.960
Any of the other technologies or services that have this very same potential misconfiguration were slash are still vulnerable.

18:39.960 --> 18:42.820
So again, definitely encourage you to audit your roles.

18:42.920 --> 18:48.660
There is one such service that I'd like to dive a little bit more deeply on, uh, and that is Cognito.

18:48.700 --> 18:53.340
Uh, Cognito is a sign in as a service offering from AWS.

18:53.340 --> 19:04.120
If you want to store user credentials but you don't want to deal with the hassle of uh, hashing, salting, and things like that, you can pay Amazon a fee and they'll take care of that for you.

19:04.420 --> 19:08.880
One of the core features of Cognito is something called an identity pool.

19:08.880 --> 19:20.560
And an identity pool is a resource you can create in your account that allows you to distribute short-lived IEM credentials to your users so that they can assume roles in your account.

19:20.840 --> 19:35.100
As an example, say you're building a web application and you want your users to be able to upload content to S3 or invoke an API gateway using IEM off, the way you could achieve this is creating a Cognito identity pool, allowing your users to interact with it,

19:35.100 --> 19:43.800
to generate tokens, they would then uh, through a library in the client pass that to the assume role with web identity call and assume the role in your account.

19:44.040 --> 19:50.400
The good news about Cognito is that they seemingly foresaw the very same attack that occurred with GitHub actions.

19:50.400 --> 19:55.380
They do, by default, include a condition to defend against it.

19:55.540 --> 20:02.740
Specifically, the condition will restrict which identity pool is allowed to assume a role.

20:02.740 --> 20:09.440
And this is very important because if the trust policy looked like this, anyone in the world would be able to assume that role.

20:09.440 --> 20:13.940
And we're gonna talk about some reasons why that trust policy might look like this in just a little bit.

20:14.920 --> 20:20.800
Uh, the way that we can take advantage of it is slightly different than what we described with GitHub actions.

20:20.800 --> 20:25.420
This is mostly an implementation detail specific to Cognito identity pools.

20:25.420 --> 20:30.300
Specifically, what we're gonna do is use a uh, Cognito offload.

20:30.300 --> 20:41.160
Offloads are essentially like the, essentially the step by step operations uh, that a user would use to generate those credentials.

20:41.160 --> 20:48.320
There are two offloads currently supported, an enhanced offload and a basic offload, sometimes referred to as classic.

20:48.540 --> 20:58.140
We're gonna focus on classic because that allows us to actually specify the role we wanna assume because the final operation in this chain is assume a role with web identity.

20:58.380 --> 21:03.820
Um, the specific step by steps are as an attacker, we're gonna create our own Cognito identity pool.

21:03.820 --> 21:09.500
We're gonna, going to then perform get ID and get open ID tokens to generate that JWT.

21:09.500 --> 21:16.780
And once we have that JWT, we pass it in an assume role with web identity call and this allows us to assume the role in the victim account.

21:17.120 --> 21:23.680
So for our purposes, for the remainder of this talk, we'll refer to this as the Variant 1 Vulnerable Trust Policy.

21:23.680 --> 21:32.240
A trust policy tied back to uh, the Cognito service but not including a condition to restrict which identity pool is allowed to assume it.

21:32.460 --> 21:35.860
The reason we call this Variant 1 is because there's a Variant 2 as well.

21:35.860 --> 21:41.900
You might have noticed there's actually two conditions on the default trust policy associated with roles using Cognito.

21:41.900 --> 21:48.300
And this condition is the AMR condition, or the authentication methods references.

21:48.300 --> 21:51.300
And this value can be either authenticated or unauthenticated.

21:51.300 --> 21:54.680
You might wonder, could we assume a role if this condition was set?

21:54.680 --> 21:57.120
And turns out, yeah, absolutely, we totally could.

21:57.120 --> 22:03.780
If the value is set to unauthenticated, then literally everything I just said works completely the same, no changes required.

22:04.000 --> 22:08.200
If the value is authenticated, then we do have to jump through some extra hoops.

22:08.200 --> 22:19.680
In particular, in our attacker controlled account, we have to create a Cognito user pool, configure it alongside the identity pool, and then from there, basically all the same steps apply with some minor changes.

22:19.780 --> 22:29.240
All this condition is doing is checking that you are authenticated to an identity pool, not that you are authenticated to a specific identity pool.

22:29.240 --> 22:35.480
And since we can just create our own identity pool, we can configure it however we like, so we can add authentication if we need to.

22:35.640 --> 22:41.060
Now, earlier you might have noticed that I called this a misconfiguration, and that's because it is.

22:41.060 --> 22:51.060
The GitHub action stuff, this Cognito stuff, any of the other myriad of services which have this very same issue, all of these are misconfigurations, not a vulnerability.

22:51.400 --> 23:01.040
Had you suffered a breach, compromise, or other security incident as a result of it, well, unfortunately that would be your responsibility as a part of the AWS shared responsibility model.

23:01.160 --> 23:07.340
And so you're probably wondering, well Nick, I was promised a second vulnerability, you're calling this a misconfiguration, what gives?

23:07.340 --> 23:17.480
Well, uh, this is where things get weird, and we dive into our second vulnerability of the day, the AWS Amplify service exposing IEM roles to take over.

23:17.940 --> 23:27.420
Uh, see earlier this year when we noticed this capability in Cognito, one of the first questions we had was, okay cool, I wonder how common this misconfiguration is.

23:27.420 --> 23:40.340
And because it could be used for initial access, literally just assume rolling into victim accounts, we wanted to know if we could use publicly available data to find vulnerable roles and notify their owners so they could be fixed.

23:40.480 --> 23:43.340
To do this, we used a tool called Sourcegraph.

23:43.340 --> 23:48.700
One of the free features of which is essentially like a Google search, but for public GitHub repos.

23:48.700 --> 23:53.500
Uh, we we wrote a regular expression to find IEM role ARNs.

23:53.500 --> 24:03.280
Threw that into Sourcegraph, got back results, deduplicated them, removed like clearly placeholder ARNs, like account IDs with all one digit or incrementing digits, things like that.

24:03.280 --> 24:06.980
Uh, and that left us with a little over 8,000 results.

24:07.020 --> 24:09.560
We then tried to assume each role twice.

24:09.560 --> 24:12.020
Once authenticated and once unauthenticated.

24:12.020 --> 24:18.320
And we let our automation run and pretty much immediately it was clear, something was terribly wrong.

24:18.460 --> 24:21.280
Remember, this was across all of public GitHub.

24:21.280 --> 24:25.040
Across teams, organi- organizations, individuals and companies.

24:25.040 --> 24:34.480
So, why was it then that the overwhelming majority of roles that we found to be vulnerable all had this weirdly specific naming convention?

24:34.600 --> 24:45.560
What you see here on the slide are real, re- real roles that we found in the wild that were vulnerable that we have slightly modified the names of so as to respect the anonymity of their owners.

24:45.760 --> 24:51.660
Now, what made these roles so weird was that they all ended in either auth role or unauth role.

24:51.660 --> 24:59.680
And additionally, they had what appeared to be either a time stamp dating back to 2018 or 2019 or they had a six digit integer.

24:59.800 --> 25:02.040
Presumably, these were the newer ones.

25:02.420 --> 25:10.080
To make things even more weird, as we were going through the results, we actually found three roles that belonged to AWS themselves.

25:10.240 --> 25:23.300
And so at this point, it wasn't clear if this was some sort of, uh, tutorial gone wrong where somebody was demoing how to set this up with OIDC, not realizing that it was vulnerable and letting anybody just assume these roles in anybody's account.

25:23.480 --> 25:30.520
Uh, using source graph, we were able to see the name of the file where these roles were being found.

25:30.520 --> 25:37.080
And again, the overwhelming majority were found in files called team provider info dot Jason.

25:37.160 --> 25:41.040
And through this, this led us ultimately to the culprit.

25:41.040 --> 25:45.200
The thing that was causing all these roles to let anybody assume them.

25:45.200 --> 25:48.700
Turns out, it was AWS Amplify.

25:49.020 --> 26:01.480
Normally, when we're talking about a misconfiguration, we're talking about a mistake, misunderstanding, developers moving a little bit too quickly and breaking things, or not realizing that something is as vulnerable as it actually was.

26:01.740 --> 26:09.580
This was a rare circumstance in which an AWS service itself was exposing IEM roles, such that anyone could assume them.

26:09.880 --> 26:14.700
The vulnerability was not that you could misconfigure roles, it's that AWS was doing it to you.

26:14.700 --> 26:17.620
And fortunately, not just once, they actually did it twice.

26:17.780 --> 26:25.120
If you're not familiar with Amplify, Amplify is a uh, web and mobile application framework that lets you build these technologies.

26:25.120 --> 26:34.400
Uh, one of the core selling points to Amplify is essentially that uh, by using Amplify, it will abstract away a lot of the underlying infrastructure.

26:34.520 --> 26:44.980
So, if you build a web application and you want your users to be able to create accounts, sign up, change their password and so on, your developers don't even need to know what Cognito is.

26:44.980 --> 26:53.480
They can simply add authentication through Amplify, and Amplify goes in, creates Cognito resources, configures them, sets them up, and so on.

26:53.800 --> 26:57.940
Key emphasis, Amplify configures those Cognito resources.

26:58.320 --> 27:02.320
Now, there's two ways you can build an Amplify app or configure them.

27:02.320 --> 27:04.880
Uh, they're not mutually exclusive, you can use either or.

27:04.880 --> 27:14.620
Uh, there is the studio, which is the web console portal equivalent, and then there is the CLI, which you can run from your local machine, or as a part of your CICD pipeline.

27:14.760 --> 27:23.540
Now, typically when we do cloud security research, one of the challenges we often have is, it's not really clear why this vulnerable behavior is occurring.

27:23.540 --> 27:29.800
We might be able to see that something has security impacts, but it's not clear what exactly happened or why it's doing this.

27:29.800 --> 27:38.440
For example, with the first vulnerability, for some remarkably strange reason, changing the casing on a JSON parameter let us break a major security boundary in AWS.

27:38.880 --> 27:41.820
So we run into these types of scenarios fairly frequently.

27:42.260 --> 27:52.940
What's neat about this Amplify vulnerability, and why it's personally one of my favorites, is that this is actually a rare instance where we are able to know not only how did this become vulnerable, but when.

27:53.000 --> 27:58.960
That's because the Amplify CLI written by AWS is actually open source.

27:59.000 --> 28:05.020
And by digging through the commit history, we can see how and when these vulnerabilities were introduced.

28:05.060 --> 28:17.900
And we didn't know at the time, but later on in speaking to AWS employees, we came to find out that the Amplify Studio, the web console equivalent, actually uses parts of the CLI as libraries.

28:17.900 --> 28:32.680
And that's how I can tell you with confidence that both the Amplify Studio and CLI became vulnerable on or around July 3rd, 2018 to the Variant 2 Vulnerable Trust Policy, allowing anyone in the world the ability to assume these roles.

28:32.680 --> 28:39.340
What happened here is that any time you create an Amplify project, two roles are created for your account.

28:39.340 --> 28:42.760
An auth role and an unauth role, like we saw previously.

28:43.200 --> 28:53.480
Unfortunately, as a part of this commit, the default trust policy associated with those roles was set to this, which would allow anybody in the world to assume them.

28:53.480 --> 29:05.160
So if you thought you were building a private, internal only application that required authentication and you were gatekeeping who could create accounts so that you could protect your stuff, well, um, sorry, no you weren't.

29:05.160 --> 29:09.620
Anybody could just assume those roles and access whatever was associated with them.

29:10.000 --> 29:13.240
Like I said, that was introduced on July 3rd, 2018.

29:13.340 --> 29:19.960
A little over a year later, on August 8th, 2019, AWS sort of fixed this issue.

29:19.960 --> 29:21.780
Uh, seemingly unintentionally.

29:21.780 --> 29:27.500
What they did was they set the default effect to a deny and they removed the condition entirely.

29:27.500 --> 29:33.400
This is actually the exact same behavior we see today when creating a new Amplify project.

29:33.540 --> 29:41.740
It's really important to stress, though, that what this change did in August of 2019 was make it so that no future roles would become misconfigured.

29:41.880 --> 29:48.520
Any that had already been created were still vulnerable and that's how we were able to assume them in 2024.

29:49.120 --> 29:55.620
Later on in July of 2020, variant one was introduced to the Amplify CLI in studio.

29:55.620 --> 29:58.680
And this one was a bit more complicated than the previous one.

29:58.860 --> 30:04.960
What happened here was that, uh, like I said previously, you can add authentication to an Amplify project.

30:04.960 --> 30:11.760
If at any time you chose to remove authentication for any reason, that would introduce the variant one policy.

30:11.760 --> 30:30.280
Uh, in speaking to developers who were affected by this, it seems the most common reason that this occurred was situations in which, uh, uh, projects started with the built-in Amplify controlled Cognito resources and then at a point, uh, went to Cognito outside of Amplify or to just a different identity provider entirely.

30:30.300 --> 30:40.760
Regardless of the reason why, what occurred was that a cloud formation template would run that would start setting the default trust policy to what you see on the slide, which is totally fine.

30:40.760 --> 30:43.240
This is the secure trust policy.

30:43.360 --> 30:54.180
However, under the line, uh, under the condition for the deletion of the authentication configuration, there was a line to delete the condition off of the trust policy, which left you with this.

30:54.180 --> 30:56.500
The variant one vulnerable policy.

30:56.900 --> 31:03.920
Whatever identity permissions were associated with this rule, when this exposure occurred, it still had access to.

31:03.920 --> 31:11.400
So, if your rule could do something like, uh, read from an S3 bucket, write to a demo deep table, it still had that access.

31:11.680 --> 31:15.400
Additionally, at the end of the day, these are just plain IEM rules.

31:15.400 --> 31:19.940
And unfortunately, developers love to over-privilege their identities.

31:20.040 --> 31:32.400
When we were reacting to this vulnerability and notifying customers so they could mitigate it, we found a number of customers who had highly privileged roles, including some with S3 full access, Kinesis full access, and more.

31:32.640 --> 31:41.020
Unfortunately, as a part of this vulnerability, now anyone could have just accessed them and then accessed whatever resources were associated with those accounts.

31:42.000 --> 31:50.720
Uh, like I said, that was introduced in July of 2020, and then between then and when we eventually disclosed in 24, more and more rules were becoming misconfigured.

31:50.960 --> 32:00.000
One thing I'd really like to stress, uh, that makes this Cognito issue even more extreme, is that Cognito role ARNs are easily discoverable.

32:00.080 --> 32:09.860
If we compare this to the first vulnerability we talked about today, a confused deputy vol in some AWS service, an adversary still has to contend with the challenge of finding role ARNs.

32:09.860 --> 32:17.320
To be clear, an ARN is not a secret, not in the same way a password or API key is, but it does represent some level of challenge.

32:17.320 --> 32:25.600
They would have to brute force them, enumerate them, derive them from IAC, pull them out of build logs, rip them out of GitHub like we did, or a myriad of other ways.

32:25.620 --> 32:33.820
Suffice to say, it's something you could do across, say, a small number of organizations, but not something that you could easily scale to the size of the internet.

32:34.380 --> 32:40.220
By comparison, the whole point of Cognito is that these roles are supposed to be available to your users.

32:40.240 --> 32:41.800
They're basically public.

32:41.900 --> 32:48.540
And in addition, they're also deterministic , in the sense that if you know the unauth role, you now also know the auth role by default.

32:48.540 --> 32:59.980
And so what an adversary could have done is simply taken advantage of the default domain associated with Amplify apps to suddenly crawl tens of thousands of apps looking for vulnerable roles.

32:59.980 --> 33:13.080
And to be clear, the majority should be fine, but undoubtedly some number of them were created between July, or sorry, uh, 2018 and 2019, or who have since changed their authentication configuration since July of 2020.

33:13.720 --> 33:21.740
Like I said before, we did disclose this to AWS in January of this year, and AWS released comprehensive fixes in February and April.

33:21.740 --> 33:27.360
Uh, they did the same thing they did with GitHub Actions, where you can no longer create these vulnerable trust policies anymore.

33:27.360 --> 33:30.040
But in addition, they sort of went above and beyond.

33:30.100 --> 33:38.940
Specific to this Amplify issue, they actually made changes to STS so that you can no longer assume a role cross-account in AWS.

33:39.160 --> 33:46.180
So even if you had a variant 1 or variant 2 role in your account, somebody from a different account can no longer assume it.

33:46.640 --> 34:01.480
If you'd like to learn more about this vulnerability, AWS did release a security bulletin for it, and we have a blog post here with a ton of additional content and information on carrying out these types of attacks, how we found this vulnerability, and more advice on dealing with assume role with web identity.

34:02.120 --> 34:12.880
Really quickly though, I did want to mention, um, throughout this talk, we have been focused on creating resources in an attacker account so that we could then victimize a victim account.

34:12.880 --> 34:15.240
The reason for doing this is simplicity.

34:15.240 --> 34:26.260
If you own the resource, you can configure it, you can set it up however you like, you know it will always be available, you can troubleshoot it, but I wanted to mention it's not strictly required, it's just easier.

34:26.560 --> 34:33.120
Specific to the Amplify vulnerability, they fixed cross-account role assumption using identity pools.

34:33.120 --> 34:38.180
It's no longer possible for me to use one of my identity pools to assume a role in your account.

34:38.680 --> 34:41.440
But they didn't do anything about the same account scenario.

34:41.440 --> 34:45.220
And to be clear, I don't really think there's much they could do.

34:45.220 --> 34:51.720
Uh, the reason they were able to block cross-account assume role using this is, well that's, that's a very weird thing to do.

34:51.720 --> 34:57.700
It's very likely zero if any real organizations were doing this in the wild.

34:57.700 --> 35:03.020
And so they said hey, we can just block this off, we can fix this attack vector and we'll mitigate a lot of the risk.

35:03.100 --> 35:10.180
But you can still absolutely do this in the same account and this is something that you can still take advantage of today.

35:10.440 --> 35:22.280
Um, to be clear, this is more difficult, things are much nicer if you can just bring your own identity pool, but it's definitely something to be aware of if you are penetration duster, red teamer, or you simply use Amplify a lot.

35:22.480 --> 35:40.020
The way this would work is that if there is a variant one or variant two role in that account, if there is also a identity pool that is configured with basic authentication or the basic offload, not necessarily associated with Amplify, just any cognitive identity pool with that enabled,

35:40.020 --> 35:51.460
you as an external adversary can still interact with that identity pool, generate a JWT, pass it into Sumo with WebIdentity, and still assume one of those variant one or variant two vulnerable roles.

35:51.460 --> 36:03.360
Um, in the bottom left hand side, there's a QR code that will take you to a Hacking the Cloud article that will walk you through step by step how you can do this in both authenticated and unauthenticated environments.

36:03.960 --> 36:10.340
With the time we have left, I wanted to talk a little bit about what we can do to prevent cross tenant attacks in AWS.

36:10.720 --> 36:25.020
To be clear, uh, your time is probably much better spent doing things like deleting old access keys, uh, cleaning up old IM users, following least privilege, and so on, but if you're already doing all those things, or you have the technology and processes in place,

36:25.020 --> 36:30.360
it might be helpful to know that we do have some controls that can potentially prevent some of these attacks.

36:30.380 --> 36:39.420
In particular, AWS offers us a number of condition keys that allow us to restrict essentially where an adversary is coming from.

36:39.420 --> 36:43.360
Sort of similar to what we saw with a Sumo with WebIdentity previously.

36:43.420 --> 36:51.120
These conditions allow us to restrict either the ARN, the account, or the organization that is permitted to assume a role.

36:51.220 --> 37:03.000
It's really important to stress, these are not included by default, uh, if you were to try to create an instance profile today, it wouldn't automatically add one of these, so you would have to manually attach these conditions to each role you want to assume,

37:03.000 --> 37:09.080
or want to protect, and more importantly, make sure that those services are compatible with these condition keys.

37:09.080 --> 37:18.000
From some nominal testing, EC2, Lambda, AppSync, all work totally fine, but again, really encourage you to test before you try pushing this into production.

37:18.100 --> 37:33.320
To demonstrate how this would work in practice, uh, using source account as an example and tying us back to the first, uh, confused deputy attack we had in AWS, uh, by exploiting this vulnerability, an adversary would be able to assume a role which trusted the absent service.

37:33.320 --> 37:43.900
But if we had set a condition key on that trust policy, limiting what AWS account is permitted to assume that role, it would successfully block that adversary.

37:43.940 --> 37:53.200
The way we know this is back in the day when this vulnerability was present, we were able to actually test setting that condition key, and it did successfully block an external adversary.

37:53.280 --> 38:02.280
So even in that worst case scenario of someone having a cross-tenant zero day in AWS, by setting this condition key, we can block that access.

38:02.660 --> 38:06.260
The other reason I like this is from a defense in depth perspective.

38:06.260 --> 38:13.480
If pass rule says, under absolutely no circumstance should someone be able to assume a role cross-tenant, well great.

38:13.480 --> 38:15.080
We broke that with Spongebob memes.

38:15.080 --> 38:23.840
So the next time that happens, or if somebody finds a more inventive way around it, let's have an additional layer of protection to block these types of attacks.

38:23.980 --> 38:26.820
You're also unlikely to run into many issues.

38:26.820 --> 38:30.460
If it works, it's very unlikely to cause, uh, problems.

38:30.460 --> 38:33.840
It's, this is more of a static thing that stays the same over time.

38:34.260 --> 38:40.360
So in conclusion, we took a look today at how confused epi attacks can weaponize cloud services against us.

38:40.360 --> 38:45.680
We took a look at a very dangerous misconfiguration when using assume role with web identity.

38:45.680 --> 38:53.360
And again, I strongly encourage you to audit your roles that use it, because if you make this mistake, theoretically anybody can assume roles in your account.

38:53.360 --> 38:54.820
It's an easy mistake to make.

38:54.820 --> 38:56.560
AWS actually made it twice.

38:56.780 --> 39:03.640
Um, and then we also took a look today at how we can use, uh, condition keys to block confused epi attacks in AWS.

39:03.900 --> 39:08.740
If you enjoyed this talk, you can find more of our research at securitylabs.daydoghq.com.

39:08.740 --> 39:12.700
If you have any questions, feel free to find me after or reach out to me on social media.

39:12.700 --> 39:14.140
Again, my name's Nick Furchette.

39:14.140 --> 39:15.220
Thank you all so much.

