WEBVTT

00:00.000 --> 00:04.460
...researcher at Datadog where he specializes in offensive AWS security.

00:04.460 --> 00:10.460
He's known for finding multiple zero-day vulnerabilities in AWS services and regularly publishing on new attack techniques.

00:10.460 --> 00:16.380
The title of Nick's talk is Kicking in the Door to the Cloud Exploiting Cloud Provider Vulnerabilities for Initial Access.

00:16.380 --> 00:18.240
Please give a warm welcome for Nick.

00:22.180 --> 00:24.220
Hey everyone, thank you so much for being here.

00:24.220 --> 00:28.300
Welcome to my talk on exploiting AWS vulnerabilities for initial access.

00:28.440 --> 00:33.060
Mike just gave me a great introduction so I don't want to try and follow it up.

00:33.060 --> 00:34.440
Just two things to note.

00:34.500 --> 00:41.080
If you've seen me before at most recently DEF CON Mainstage or Black Hat, this is the same talk.

00:41.120 --> 00:44.260
DEF CON is a limited time, so I definitely don't want to waste yours.

00:44.260 --> 00:47.120
Or we could also free up some space perhaps for folks still online.

00:47.120 --> 00:51.860
So again, if you recognize me from recent events, this is the same talk.

00:51.860 --> 00:54.880
Second thing, I don't know about you, my eyes are not very good anymore.

00:54.880 --> 00:58.580
And we're going to be looking at a bunch of IEM policies so we can exploit them.

00:58.580 --> 01:01.320
They tend to be kind of small and hard to show on a slide.

01:01.320 --> 01:07.880
So that QR code will take you to this slide deck so that you can follow along on your phone or mobile device of your choosing.

01:08.700 --> 01:15.600
With all that out of the way, listen, breaking into AWS accounts is a topic that is near and dear to my heart.

01:15.600 --> 01:17.720
And I'm sure it is for many of you as well.

01:17.780 --> 01:27.780
But I think if we're being completely honest with ourselves, the traditional methods of gaining access to AWS environments are boring.

01:27.780 --> 01:38.840
If we were to poll the audience for real-world cloud breaches and security incidents, I guarantee 95% of scenarios will fall into one of three categories.

01:38.840 --> 01:45.860
They were either caused by a leaked access key, an exposed S3 bucket, or an exploited EC2 instance.

01:45.860 --> 01:51.780
These are the stereotypical ways that adversaries gain access to AWS environments and resources.

01:51.780 --> 01:55.860
And to be clear, these are very real risks that we do have to contend with.

01:55.860 --> 01:57.460
But this is cloud village.

01:57.460 --> 01:59.560
This is nothing you haven't seen before.

01:59.560 --> 02:01.880
And again, these are boring.

02:02.040 --> 02:14.680
What we're going to be doing instead is kicking in the door to the cloud, breaking into USP1, and exploiting vulnerabilities in AWS services themselves, particularly by taking advantage of pre-existing trust.

02:14.680 --> 02:15.900
What do I mean by that?

02:15.900 --> 02:25.160
Well, a common design pattern within AWS is to have IEM roles in your account that have a trust relationship back to some AWS service.

02:25.160 --> 02:31.580
This enables that service to take action and perform functionality in your account.

02:31.740 --> 02:45.980
What we're going to be doing today is finding vulnerabilities in those AWS services so we can hijack that trust relationship, gain access to victim AWS accounts, so that from there we can access resources, escalate privileges, move laterally, and more.

02:45.980 --> 02:51.660
In this session, we're going to describe how trust is established between IEM roles and AWS services.

02:51.660 --> 02:59.240
We're then going to dive deep on two vulnerabilities, as well as a general misconfiguration that would allow us to hijack those roles.

02:59.240 --> 03:01.380
And finally, we're going to talk prevention options.

03:01.380 --> 03:11.980
In the absolute worst-case scenario of an attacker having a cross-tenant AWS zero-day, like we'll demonstrate in this talk, what options do we have to potentially mitigate that attack vector?

03:12.520 --> 03:18.140
Worth noting, most of the vulnerabilities we're going to be talking about today have since been fixed by AWS.

03:18.200 --> 03:25.580
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:25.600 --> 03:34.000
With that out of the way, to get us started on the topic of abusing pre-existing trust, we should probably talk how that trust is established.

03:34.100 --> 03:39.680
In AWS, every IEM role has a role trust policy.

03:39.680 --> 03:45.420
And this policy determines who or what is permitted to assume a role.

03:45.420 --> 03:49.520
There are a number of identities that can be permitted via trust policy.

03:49.520 --> 03:52.960
IEM users, roles, AWS organizations, and more.

03:53.320 --> 04:00.760
But where I think this is particularly interesting is when we authorize an AWS service to have the ability to assume a role.

04:00.840 --> 04:04.620
To demonstrate this, we're going to be using Lambda as an example.

04:05.200 --> 04:12.600
What you may be able to see there on the right side of the slide is the default trust policy associated with the role used by Lambda.

04:12.680 --> 04:18.120
If you create a Lambda function today, this is the role trust policy that will be automatically created for you.

04:18.120 --> 04:23.000
And what it says is that we're going to allow the Lambda service to assume this role.

04:23.180 --> 04:32.920
The way this works in principle is every time your Lambda function runs, the Lambda service assumes that role in your account and does whatever it is you want it to do.

04:32.920 --> 04:35.120
Now, this behavior is really interesting.

04:35.120 --> 04:39.780
Because if we think about it, I already said this is the default trust policy.

04:39.780 --> 04:45.140
So, theoretically, the overwhelming majority of Lambda functions use this very same policy.

04:45.140 --> 04:48.700
And if we read it, it just authorizes the Lambda service.

04:48.700 --> 04:51.180
It's not tied to someone's specific account.

04:51.400 --> 04:59.360
So, could we get a little sneaky and create a Lambda function in our account, but point to or reference a role in someone else's?

04:59.860 --> 05:02.940
Preferably one that we don't have legitimate access to.

05:03.240 --> 05:10.780
Could we cause this Lambda service to assume the role in the victim account and access resources or do things that are beneficial for us?

05:10.840 --> 05:16.180
Well, the good news or bad news, depending on your perspective, is there is something that's supposed to stop this.

05:16.180 --> 05:17.600
That's called pass rule.

05:17.680 --> 05:24.800
Any time you provide an IEM role to an AWS service, you are interacting with pass rule.

05:24.800 --> 05:34.980
One of the core rules of which is you can only, quoting, you can only use the pass rule permission to pass an IEM role to a service that shares the same AWS account.

05:35.020 --> 05:40.140
If you try to pass a role outside of your account, well, you'll almost always get an error.

05:40.140 --> 05:42.240
Cross-account pass rule is not allowed.

05:42.240 --> 05:52.300
Now, this is a very important security boundary in AWS because without it, theoretically, we could just arbitrarily assume a role into anybody's account and access all the resources associated with those roles.

05:52.300 --> 05:55.700
So this is going to be the target of the first part of our talk today.

05:55.700 --> 06:06.780
Finding a vulnerability in the pass rule implementation that would allow us to weaponize an AWS service against a role that trusts it so that from there, we can access all the resources associated with it.

06:06.780 --> 06:11.340
So this first vulnerability is a confused deputy vuln in AWS AppSync.

06:11.340 --> 06:17.100
If you're not familiar with AppSync, AppSync is a managed GraphQL service offered by AWS.

06:17.160 --> 06:20.880
It allows you to quickly and scalably build GraphQL APIs.

06:21.080 --> 06:24.280
The way that it works is very similar to what I described with Lambda.

06:24.280 --> 06:32.640
You create an AppSync API, automatically as a part of your data source, it'll create a role for you that has a trust relationship back to the AppSync service.

06:32.760 --> 06:39.400
Then, every time your AppSync API runs, the AppSync service assumes that role and does whatever it is it's supposed to do.

06:39.400 --> 06:46.280
And also, like Lambda, if you try to pass a role outside of your account, you get the error message, cross-account pass rule is not allowed.

06:46.560 --> 06:48.260
Now, this is Cloud Village.

06:48.260 --> 06:51.920
I'm sure many of you are already trying to think of ways to bypass this control.

06:52.040 --> 06:59.000
Perhaps some weird encoding schemes, maybe something like HTTP request smuggling, or maybe something even more exotic.

06:59.060 --> 07:08.300
These are all great ideas, and I strongly encourage you to try them in your own time, but we actually found a much simpler approach to get past this control.

07:08.300 --> 07:11.220
Through the power of Spongebob memes.

07:11.720 --> 07:16.260
See, under normal circumstances, the AWS API is case-sensitive.

07:16.260 --> 07:20.580
And what we mean by that is it expects parameters in a very particular casing.

07:20.580 --> 07:24.600
If you don't meet that expectation, you'll almost always get an error.

07:24.600 --> 07:37.820
So as a 100% unrelated API, just to demonstrate this behavior, here we're performing secrets manager create secret, and that API expects a name parameter with a capital N.

07:37.820 --> 07:43.540
If you pass it in that format, 200 OK, you created a secret, everything worked normally.

07:43.760 --> 07:53.660
But if we were to change the casing on that parameter in any way, in this particular case we made it all uppercase, we pass that to the API, well, it gets mad.

07:53.660 --> 07:56.260
400 bad requests, member must not be null.

07:56.260 --> 08:01.160
The reason for this is we didn't actually pass the parameter it was looking for.

08:01.260 --> 08:09.180
It might be the right alphabetical characters, but it's not what it's specifically looking for, and so it rightfully so throws an error.

08:09.320 --> 08:18.140
While this may sound like a weirdly specific thing to point out and almost obvious, the reason I am is because by comparison, AppSync was an oddity.

08:18.240 --> 08:20.760
It was not case sensitive.

08:20.880 --> 08:26.180
You could pass arbitrary parameters in mixed casing, and it would take it totally fine.

08:26.340 --> 08:30.660
Presumably somewhere on the back end it was normalizing these values in some way.

08:31.420 --> 08:39.200
Now, the parameter you would use to pass a role to the AppSync service was ServiceRoleArn, capital R, capital A.

08:39.200 --> 08:44.300
If you try to pass a role outside of your account, once again, cross-account pass role is not allowed.

08:44.700 --> 09:03.100
But, if you change the casing on that parameter in any way, in this case we've put it all to lowercase, and we try to pass a role outside of our AWS account, for some unknown reason, whatever filtering, allowlisting, or checking that was supposed to occur either didn't happen at all or completely failed.

09:03.100 --> 09:13.380
And so by changing that casing on a parameter, we were able to break a major security boundary in AWS through Spongebob memes.

09:13.660 --> 09:22.860
With this capability, we now could pass arbitrary IAM role arms to the AppSync service for it to try and assume.

09:22.860 --> 09:36.100
To put this another way, any legitimate role in any AWS account that used AppSync was now a target for us that we could assume into and access whatever resources were associated with it.

09:36.100 --> 09:49.280
This is an example of a cross-service confused deputy attack where a lower-privileged entity, us, was able to trick or coerce a higher-privileged entity, the AppSync service, to do something on our behalf.

09:49.280 --> 09:56.500
In this scenario, that was to assume a role in a victim account and carry out whatever API operation we asked it to perform.

09:56.500 --> 09:59.360
That's how we're able to do things like... oh, shoot.

09:59.360 --> 10:10.640
Really quick, I did want to stress, the thing that makes this possible, the thing that enables this attack, is this pre-existing trust between that IAM role and the AppSync service.

10:10.660 --> 10:23.560
Because the role trusts AppSync, and because we are weaponizing AppSync against it, this is the trust avenue that we are taking advantage of to assume that role and perform that API call.

10:23.560 --> 10:35.480
For a practical example of how we'd exploit this as an adversary, we would create our own attacker-controlled AppSync API, configure it, set the schema, decide what API call we wanted to make, and so on.

10:35.480 --> 10:46.560
We then perform that pass-role bypass to specify the victim role we want to assume, and then, under normal circumstances, the AppSync service would assume the role in our account and do whatever.

10:46.680 --> 10:53.260
But because of this vulnerability, it assumes the role in the victim account and performs whatever we want it to perform.

10:53.420 --> 10:58.780
Whatever identity policies are associated with that role are all available for us to take advantage of.

10:58.780 --> 11:08.320
So, for instance, we can do something like this in this screenshot, where we're dumping the contents of a DynamoDB table cross-tenant in AWS by invoking the DynamoDB scan operation.

11:08.760 --> 11:23.860
If you'd like to learn more about this vulnerability, 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 how we think about approaching this type of research.

11:24.500 --> 11:31.460
Next, before we dive into our second vulnerability, we need to learn a few things about assumeRole with WebIdentity.

11:31.680 --> 11:39.700
Up until this point, we've been learning about plain assumeRole, which is typically used for AWS-to-AWS role assumption.

11:39.960 --> 11:50.060
Now, while assumeRole is great, it does have a little bit of a limitation, and that is that it requires the entity doing the role assumption to originate from AWS.

11:50.340 --> 11:57.760
And unfortunately, there's a variety of use cases in which you might want to have someone from outside your cloud have the ability to assume a role.

11:57.760 --> 11:58.720
What do you do?

11:58.720 --> 12:02.620
Well, one option is to use assumeRole with WebIdentity.

12:02.620 --> 12:11.060
The idea here is that you sort of offload the responsibility of authenticating or authorizing a user to an identity provider of your choosing.

12:11.060 --> 12:17.960
This can be a private identity provider, one that you or your organization own and maintain, or it can be a public identity provider.

12:17.960 --> 12:22.020
Think Facebook, Google, Amazon, GitHub, and things like that.

12:22.100 --> 12:28.920
Your external identities, whether they are human or machine, interact with this identity provider to generate a token.

12:28.940 --> 12:36.380
That token is then passed into the assumeRole with WebIdentity call to authorize you to assume a role in an account.

12:36.920 --> 12:43.400
Now, before we dive into this next point, I really want to stress assumeRole with WebIdentity is a general design pattern.

12:43.400 --> 12:48.900
It's used by a number of technologies, some native to AWS and some completely external.

12:48.900 --> 12:58.720
We're going to be focusing in on GitHub Actions because it is a common use case, but I really want to stress, we're not isolated to just GitHub.

12:58.720 --> 13:02.200
A variety of services will exhibit this exact same behavior.

13:02.560 --> 13:07.680
Like I said before, every IAM role has a role trust policy.

13:07.680 --> 13:16.420
And what you see here on the slide is the most basic, bare-bones, simple trust policy you could possibly have when using assumeRole with WebIdentity.

13:16.420 --> 13:24.040
And what it says is that we're going to allow the GitHub identity provider to assumeRole with WebIdentity.

13:24.240 --> 13:31.380
And that's a really scary thought, because if we think about it, the GitHub identity provider is public.

13:31.380 --> 13:33.840
It's global, in a sense.

13:33.840 --> 13:48.400
There's nothing stopping someone from creating their own GitHub account, creating their own GitHub action to generate a token signed by that very same identity provider, passing that in to the assumeRole with WebIdentity goal, and now they can assume a role in your account.

13:48.400 --> 13:55.240
If you had this trust policy on a role in your account, anybody in the world could have assumed it.

13:55.400 --> 14:08.500
That is why any time you use assumeRole with WebIdentity with an identity provider that is, in a sense, public or global, you need to have a condition which restricts who specifically is permitted to assume that role.

14:08.500 --> 14:12.220
Again, assumeRole with WebIdentity is a general design pattern.

14:12.440 --> 14:18.480
The specific condition you will need will differ depending on what service you're using and what options you have.

14:18.480 --> 14:27.980
To continue using GitHub actions as an example, you need to restrict either the GitHub organization that is permitted to assume it, or the GitHub repo.

14:28.060 --> 14:40.600
If you're a heavy AWS user, I strongly encourage you to audit your roles for this misconfiguration as it can allow basically anybody the ability to assume roles in your account, which I think we can all agree is not good.

14:41.840 --> 14:46.480
The good news, though, to this situation is AWS actually did something about it.

14:46.480 --> 14:49.660
Last year, this particular attack was very much in vogue.

14:49.660 --> 14:56.900
A number of security researchers, including my own colleague Christoph, identified this misconfiguration and sounded the alarm about it.

14:56.900 --> 15:04.680
If you want to learn more about the GitHub action specific scenario, we have a blog post with some more details, and that QR code will take you there.

15:05.020 --> 15:09.180
Now, in response to this raised awareness, AWS did something good.

15:09.360 --> 15:16.300
They made it so that this once optional condition is now mandatory.

15:16.300 --> 15:22.660
You can no longer create a trust policy tied to the GitHub identity provider that does not include a condition.

15:22.660 --> 15:23.740
And so, that's great.

15:23.740 --> 15:26.420
That theoretically closes the loophole for any new roles.

15:26.420 --> 15:27.240
Fantastic.

15:27.240 --> 15:34.680
But, it's really important to stress they only did that for GitHub actions.

15:34.680 --> 15:42.380
Any of the other services that are similarly affected by this very same misconfiguration were slash are still vulnerable.

15:42.380 --> 15:45.620
So, again, strongly encourage you to audit your roles.

15:45.980 --> 15:52.640
What I'd like to do is dive a little bit deeper into one of those services, because it led to something very interesting.

15:52.720 --> 15:55.800
The service I'd like to take a look at is Amazon Cognito.

15:55.800 --> 16:02.040
If you're not familiar, Cognito is essentially a sign-in as a service offering from AWS.

16:02.040 --> 16:04.920
It allows you to securely store user credentials.

16:05.020 --> 16:10.520
But if you don't want to deal with hashing, salting, password reset flows and all that jazz, you can pay Amazon a fee.

16:10.520 --> 16:11.920
They'll take care of that for you.

16:12.640 --> 16:25.880
One of the core features of Cognito is something called an identity pool, which is a resource you can create in your account that you can use to authorize external users generating IEM credentials in your account.

16:25.940 --> 16:34.540
So, for example, if you're building a web app, you want your users to be able to upload files to S3 or perhaps invoke an API gateway using IEM auth.

16:34.540 --> 16:45.360
What you could do is create a Cognito identity pool, allow your external users to interact with it, to generate tokens, then using those, they assume the role in your account and do whatever it is you need them to do.

16:45.440 --> 16:51.620
The good news about Cognito is it seems the developers foresaw the very same attack we did with GitHub actions.

16:51.740 --> 17:00.600
In particular, they, by default, out of the box, include a condition which restricts which identity pool can assume the role.

17:00.600 --> 17:03.240
And so this effectively mitigates the attack.

17:03.560 --> 17:09.640
If that condition is not present for any reason, well, once again, anybody can assume that role.

17:09.740 --> 17:13.240
And we're going to be talking about some reasons why it wasn't present in just a little bit.

17:13.520 --> 17:24.080
So, the way we would do this, very similar to what we described with GitHub actions, the only implementation detail is rather than some public identity provider, we could actually just bring our own identity pool.

17:24.200 --> 17:29.580
That would give us the token we need, we could pass that in to assume our own web identity, and we could assume that role.

17:29.600 --> 17:33.800
So for our purposes, we're going to refer to this as the Variant 1 Vulnerable Trust Policy.

17:33.940 --> 17:34.840
Why Variant 1?

17:34.840 --> 17:36.360
Because there's a Variant 2 as well.

17:36.360 --> 17:44.340
You might have noticed, if you have very good vision, that by default on the Cognito Trust Policy, there is a second condition.

17:44.340 --> 17:48.440
And that is the AMR, or the Authentication Methods References.

17:48.560 --> 17:51.520
This value can be authenticated or unauthenticated.

17:51.580 --> 17:54.840
And you might be wondering, could we have assumed a role if that condition was present?

17:54.840 --> 17:56.620
Well, yeah, absolutely.

17:56.660 --> 18:01.220
All that condition is doing is checking if you are authenticated to an identity pool.

18:01.280 --> 18:04.820
Not that you are authenticated to a specific identity pool.

18:04.860 --> 18:08.640
And since we can bring our own identity pool, we can configure it however we like.

18:08.640 --> 18:15.020
We can add that authentication component, or get rid of it, depending on what is needed to satisfy that condition.

18:16.160 --> 18:18.700
You might have noticed I called this a misconfiguration.

18:18.720 --> 18:20.140
That's because it totally is.

18:20.300 --> 18:30.460
Everything we've talked about so far with the Sumo with WebIdentity, the GetUpAction stuff, Cognito stuff, any of the other services that are affected by this very same thing, these are all misconfigurations.

18:30.560 --> 18:39.760
Had you suffered a breach, incident, or other security issue, well, unfortunately, that would have been your responsibility as a part of the AWS Shared Responsibility Model.

18:40.080 --> 18:43.880
And so at this point, you're probably thinking, well, Nick, I was promised a second vulnerable.

18:44.040 --> 18:45.640
You're calling this a misconfiguration.

18:45.640 --> 18:46.640
What gives?

18:46.780 --> 18:55.120
Well, this is where things get weird, and we dive into our second vulnerability, the AWS Amplify service exposing IAM roles to take over.

18:55.120 --> 19:00.880
See, earlier this year, when we noticed this capability in Cognito, one of the first questions we had was, okay, cool.

19:00.880 --> 19:03.360
I wonder how common this misconfiguration is.

19:03.360 --> 19:13.860
And because it could be used for initial access, literally just assume rolling into people's accounts, we wanted to know if we could use publicly available data to find vulnerable roles and notify their owners so it could be fixed.

19:14.060 --> 19:22.680
To do this, we used a tool called Sourcegraph, one of the free features of which is essentially like a Google search for public GitHub repos.

19:22.700 --> 19:34.940
We wrote a regular expression to find IAM role ARNs, threw it into Sourcegraph, we got back results, deduplicated them, removed clearly placeholder ARNs with account IDs of all one digit and incrementing digits, things like that.

19:34.940 --> 19:37.620
That left us with a little over 8,000 results.

19:37.780 --> 19:40.460
We then tried to assume each role twice.

19:40.520 --> 19:43.200
Once authenticated, once unauthenticated.

19:43.200 --> 19:48.060
We let our automation run and pretty much immediately it was clear something was horribly wrong.

19:48.060 --> 19:50.700
Remember, this was across all of public GitHub.

19:50.700 --> 19:53.740
Across teams, organizations, individuals and companies.

19:53.780 --> 20:02.760
So why was it then that the overwhelming majority of roles that we found to be vulnerable all had this weirdly specific naming convention?

20:03.040 --> 20:13.300
What you may or may not be able to see on this slide are real roles that we found in the wild that were vulnerable that we have slightly tweaked the names of so as to respect the anonymity of their owners.

20:13.480 --> 20:19.160
Now, what made these roles so strange was that they all ended in either auth role or unauth role.

20:19.260 --> 20:26.120
And additionally, they appear to have a timestamp dating back to 2018 or 2019, or they had a six digit integer .

20:26.620 --> 20:28.500
Presumably, these were the newer ones.

20:28.900 --> 20:33.440
To make things even weirder, we actually found three roles that belonged to AWS themselves.

20:33.480 --> 20:37.100
And so it wasn't clear what was going on that was making these roles vulnerable.

20:37.100 --> 20:43.380
Using Sourcegraph, we were able to find the name of the file where these roles were being found.

20:43.380 --> 20:49.420
And again, the overwhelming majority were found in a file called teamproviderinfo.json.

20:49.420 --> 20:56.140
And this ultimately led us to the culprit that was exposing IAM roles such that anyone in the world can assume them.

20:56.140 --> 20:59.280
It turns out it was AWS Amplify.

20:59.680 --> 21:09.540
Normally, when we're talking about a misconfiguration , we're talking about a mistake, a misunderstanding, developers moving a little bit too quickly or not realizing that something is as exposed as it actually is.

21:09.540 --> 21:16.960
This is a rare circumstance in which an AWS service itself exposed IAM roles such that anyone in the world can assume them.

21:17.260 --> 21:19.580
And unfortunately, they didn't just do it once.

21:19.620 --> 21:20.940
They actually did it twice.

21:21.220 --> 21:26.320
If you're not familiar with Amplify, the way Amplify works is that it's a framework for building web and mobile applications.

21:27.140 --> 21:31.980
Essentially, what it does is it will obfuscate a lot of the underlying infrastructure.

21:32.080 --> 21:37.520
So if you're building a web app, you want users to be able to log in, create accounts, change your password, and so on.

21:38.740 --> 21:41.640
Your developers don't even need to know what Cognito is.

21:41.640 --> 21:47.580
By using Amplify, Amplify will go in, create those Cognito resources, configure them, and so on.

21:50.880 --> 21:59.400
What's neat about this vulnerability, and why it's personally one of my favorites, is this is a rare circumstance where we're actually able to know not only how this vulnerability was introduced, but when.

21:59.400 --> 22:03.200
And that's because the Amplify CLI is open source.

22:03.200 --> 22:08.640
And by digging through the commit history, we can actually see how and when these vulnerabilities were introduced.

22:09.020 --> 22:15.180
I do want to be respectful for time, since we did start a little bit late, to quickly summarize this.

22:15.180 --> 22:20.400
The Variant 2 issue was introduced in July of 2018.

22:20.400 --> 22:28.040
A little over a year later, on August 8th, 2019, they sort of fixed the issue, seemingly unintentionally.

22:28.200 --> 22:34.880
Essentially, what occurred here was they seemingly unintentionally made a fix so that no future roles would be misconfigured.

22:34.880 --> 22:41.550
However, any that had already been created were still vulnerable, and we could still assume them like we did in 2024.

22:42.500 --> 22:49.100
In July of 2020, the Variant 1 vulnerable trust policy was introduced to the Amplify CLI and Studio.

22:49.520 --> 22:58.420
We disclosed this in January, and by February and April, AWS introduced comprehensive fixes to both of these variants.

22:58.560 --> 23:01.640
In particular, they went a little bit above and beyond what they did with GitHub.

23:02.900 --> 23:07.920
They did the same thing where you can no longer create trust policies that are vulnerable to this misconfiguration.

23:07.920 --> 23:09.420
The API will actually reject it.

23:09.420 --> 23:16.880
But also, they made changes to STS itself to prevent you from being able to assume a vulnerable role.

23:16.920 --> 23:25.200
So even if you were an Amplify user, you had a Variant 1 or 2 role in your account, someone from a different AWS account cannot assume that role.

23:25.900 --> 23:38.200
If you would like to learn more about this vulnerability and dive a little bit deeper in some of the things I had to skip over here, definitely check out the security bulletin from AWS, as well as we have a blog post with a ton of additional detail, information,

23:38.200 --> 23:38.880
and more.

23:39.020 --> 23:44.960
Now, speaking of picking things for time, we'll actually make this a little bit of a choose-your-own-adventure.

23:45.100 --> 23:55.100
Would you rather learn how you can prevent confused deputy attacks like the one that I showed, or would you rather learn how you can actually still today exploit the Amplify Vuln?

23:55.180 --> 23:56.120
Which would you prefer?

23:56.120 --> 23:57.560
Show of hands for the Amplify Vuln?

23:57.560 --> 24:00.340
Keep it down if you'd rather do the defense side.

24:03.460 --> 24:08.040
I'm seeing more hands down, so I guess we'll go with the defense side.

24:08.280 --> 24:11.380
Just know you can actually still exploit this today.

24:11.380 --> 24:12.260
It is more difficult.

24:12.260 --> 24:17.980
It does require an additional misconfigured resource, but the Amplify Vuln is still there.

24:17.980 --> 24:28.520
That QR code, depending on how quickly you can scan it, will walk you through, step-by-step, a Hacking the Cloud article for both authenticated and unauthenticated scenarios.

24:28.760 --> 24:33.940
But, let's talk a little bit about what we can do to prevent cross-tenant attacks in AWS.

24:34.100 --> 24:43.440
Some neat controls that AWS offers us are condition keys that can restrict either the ARN, the account, or the org that is permitted to assume a role.

24:43.440 --> 24:49.340
The way that we would do this is we would attach these as conditions on our role trust policies.

24:49.340 --> 24:52.180
Now, definitely note, these are not included by default.

24:52.180 --> 24:56.320
If you created an instance profile tomorrow, this wouldn't be automatically attached.

24:56.320 --> 25:04.980
So you do have to manually apply these to each role you want to protect, and most crucially, ensure that the service is compatible with them.

25:04.980 --> 25:10.060
From some nominal testing, it appears that EC2, Lambda, and AppSync all work totally fine.

25:10.380 --> 25:14.260
Again, definitely strongly encourage you to test this before you try pushing to production.

25:14.500 --> 25:31.880
Using AWS Source Account as an example, the way that this works is you set this condition on the role trust policy, and an adversary who has a cross-tenant confused deputy vulnerability would be blocked because the account they're originating from does not match that in the condition.

25:31.880 --> 25:35.940
What's super cool about this is we actually got to test this in real life.

25:35.940 --> 25:47.760
Back when the AppSync vulnerability was present and we were able to break into accounts, we were able to test setting the condition on that role trust policy to limit which account was permitted to assume a role.

25:47.760 --> 25:50.000
And indeed, it did successfully block us.

25:50.040 --> 25:58.960
So even in that absolute worst-case scenario of someone having a cross -tenant zero-day in AWS, these condition keys may be able to protect your resources.

25:59.100 --> 26:02.460
The other reason I like these is from a defense-in-depth perspective.

26:02.580 --> 26:08.540
If pass rule says, under no circumstance should someone be able to assume a role cross-tenant in AWS, well, great.

26:08.540 --> 26:18.420
Listen, we broke that with Spongebob memes, so the next time somebody figures that out or finds an even more exotic way to do it, let's have an additional layer of defense to block these types of attacks.

26:18.620 --> 26:24.300
So quickly in conclusion, we took a look today at how confused deputy attacks can weaponize cloud services against us.

26:24.300 --> 26:32.740
We took a look at assume role with WebIdentity and a very dangerous misconfiguration that could cause your roles to be assumable by anyone in the world.

26:32.740 --> 26:35.040
Again, strongly encourage you to audit your roles.

26:35.040 --> 26:36.760
It's a very easy mistake to make.

26:36.760 --> 26:38.060
Amazon made it twice.

26:38.240 --> 26:45.580
And then we also took a look at how we could use conditions to defend ourselves from confused deputy attacks in AWS.

26:45.680 --> 26:50.560
If you enjoyed this talk, you can find more of our research at securitylabs.datadoghq.com.

26:50.560 --> 26:54.740
If you have any questions, feel free to come find me after or reach out on social media.

26:54.740 --> 26:55.660
My name is Nick Frechette.

26:55.660 --> 26:56.760
Thank you all so much.

