1 00:00:00,000 --> 00:00:04,460 ...researcher at Datadog where he specializes in offensive AWS security. 2 00:00:04,460 --> 00:00:10,460 He's known for finding multiple zero-day vulnerabilities in AWS services and regularly publishing on new attack techniques. 3 00:00:10,460 --> 00:00:16,380 The title of Nick's talk is Kicking in the Door to the Cloud Exploiting Cloud Provider Vulnerabilities for Initial Access. 4 00:00:16,380 --> 00:00:18,240 Please give a warm welcome for Nick. 5 00:00:22,180 --> 00:00:24,220 Hey everyone, thank you so much for being here. 6 00:00:24,220 --> 00:00:28,300 Welcome to my talk on exploiting AWS vulnerabilities for initial access. 7 00:00:28,440 --> 00:00:33,060 Mike just gave me a great introduction so I don't want to try and follow it up. 8 00:00:33,060 --> 00:00:34,440 Just two things to note. 9 00:00:34,500 --> 00:00:41,080 If you've seen me before at most recently DEF CON Mainstage or Black Hat, this is the same talk. 10 00:00:41,120 --> 00:00:44,260 DEF CON is a limited time, so I definitely don't want to waste yours. 11 00:00:44,260 --> 00:00:47,120 Or we could also free up some space perhaps for folks still online. 12 00:00:47,120 --> 00:00:51,860 So again, if you recognize me from recent events, this is the same talk. 13 00:00:51,860 --> 00:00:54,880 Second thing, I don't know about you, my eyes are not very good anymore. 14 00:00:54,880 --> 00:00:58,580 And we're going to be looking at a bunch of IEM policies so we can exploit them. 15 00:00:58,580 --> 00:01:01,320 They tend to be kind of small and hard to show on a slide. 16 00:01:01,320 --> 00: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. 17 00:01:08,700 --> 00: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. 18 00:01:15,600 --> 00:01:17,720 And I'm sure it is for many of you as well. 19 00:01:17,780 --> 00: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. 20 00:01:27,780 --> 00: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. 21 00:01:38,840 --> 00:01:45,860 They were either caused by a leaked access key, an exposed S3 bucket, or an exploited EC2 instance. 22 00:01:45,860 --> 00:01:51,780 These are the stereotypical ways that adversaries gain access to AWS environments and resources. 23 00:01:51,780 --> 00:01:55,860 And to be clear, these are very real risks that we do have to contend with. 24 00:01:55,860 --> 00:01:57,460 But this is cloud village. 25 00:01:57,460 --> 00:01:59,560 This is nothing you haven't seen before. 26 00:01:59,560 --> 00:02:01,880 And again, these are boring. 27 00:02:02,040 --> 00: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. 28 00:02:14,680 --> 00:02:15,900 What do I mean by that? 29 00:02:15,900 --> 00: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. 30 00:02:25,160 --> 00:02:31,580 This enables that service to take action and perform functionality in your account. 31 00:02:31,740 --> 00: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. 32 00:02:45,980 --> 00:02:51,660 In this session, we're going to describe how trust is established between IEM roles and AWS services. 33 00:02:51,660 --> 00: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. 34 00:02:59,240 --> 00:03:01,380 And finally, we're going to talk prevention options. 35 00:03:01,380 --> 00: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? 36 00:03:12,520 --> 00:03:18,140 Worth noting, most of the vulnerabilities we're going to be talking about today have since been fixed by AWS. 37 00:03:18,200 --> 00: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. 38 00:03:25,600 --> 00: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. 39 00:03:34,100 --> 00:03:39,680 In AWS, every IEM role has a role trust policy. 40 00:03:39,680 --> 00:03:45,420 And this policy determines who or what is permitted to assume a role. 41 00:03:45,420 --> 00:03:49,520 There are a number of identities that can be permitted via trust policy. 42 00:03:49,520 --> 00:03:52,960 IEM users, roles, AWS organizations, and more. 43 00:03:53,320 --> 00: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. 44 00:04:00,840 --> 00:04:04,620 To demonstrate this, we're going to be using Lambda as an example. 45 00:04:05,200 --> 00: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. 46 00:04:12,680 --> 00:04:18,120 If you create a Lambda function today, this is the role trust policy that will be automatically created for you. 47 00:04:18,120 --> 00:04:23,000 And what it says is that we're going to allow the Lambda service to assume this role. 48 00:04:23,180 --> 00: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. 49 00:04:32,920 --> 00:04:35,120 Now, this behavior is really interesting. 50 00:04:35,120 --> 00:04:39,780 Because if we think about it, I already said this is the default trust policy. 51 00:04:39,780 --> 00:04:45,140 So, theoretically, the overwhelming majority of Lambda functions use this very same policy. 52 00:04:45,140 --> 00:04:48,700 And if we read it, it just authorizes the Lambda service. 53 00:04:48,700 --> 00:04:51,180 It's not tied to someone's specific account. 54 00:04:51,400 --> 00: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? 55 00:04:59,860 --> 00:05:02,940 Preferably one that we don't have legitimate access to. 56 00:05:03,240 --> 00: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? 57 00:05:10,840 --> 00:05:16,180 Well, the good news or bad news, depending on your perspective, is there is something that's supposed to stop this. 58 00:05:16,180 --> 00:05:17,600 That's called pass rule. 59 00:05:17,680 --> 00:05:24,800 Any time you provide an IEM role to an AWS service, you are interacting with pass rule. 60 00:05:24,800 --> 00: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. 61 00:05:35,020 --> 00:05:40,140 If you try to pass a role outside of your account, well, you'll almost always get an error. 62 00:05:40,140 --> 00:05:42,240 Cross-account pass rule is not allowed. 63 00:05:42,240 --> 00: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. 64 00:05:52,300 --> 00:05:55,700 So this is going to be the target of the first part of our talk today. 65 00:05:55,700 --> 00: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. 66 00:06:06,780 --> 00:06:11,340 So this first vulnerability is a confused deputy vuln in AWS AppSync. 67 00:06:11,340 --> 00:06:17,100 If you're not familiar with AppSync, AppSync is a managed GraphQL service offered by AWS. 68 00:06:17,160 --> 00:06:20,880 It allows you to quickly and scalably build GraphQL APIs. 69 00:06:21,080 --> 00:06:24,280 The way that it works is very similar to what I described with Lambda. 70 00:06:24,280 --> 00: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. 71 00:06:32,760 --> 00: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. 72 00:06:39,400 --> 00: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. 73 00:06:46,560 --> 00:06:48,260 Now, this is Cloud Village. 74 00:06:48,260 --> 00:06:51,920 I'm sure many of you are already trying to think of ways to bypass this control. 75 00:06:52,040 --> 00:06:59,000 Perhaps some weird encoding schemes, maybe something like HTTP request smuggling, or maybe something even more exotic. 76 00:06:59,060 --> 00: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. 77 00:07:08,300 --> 00:07:11,220 Through the power of Spongebob memes. 78 00:07:11,720 --> 00:07:16,260 See, under normal circumstances, the AWS API is case-sensitive. 79 00:07:16,260 --> 00:07:20,580 And what we mean by that is it expects parameters in a very particular casing. 80 00:07:20,580 --> 00:07:24,600 If you don't meet that expectation, you'll almost always get an error. 81 00:07:24,600 --> 00: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. 82 00:07:37,820 --> 00:07:43,540 If you pass it in that format, 200 OK, you created a secret, everything worked normally. 83 00:07:43,760 --> 00: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. 84 00:07:53,660 --> 00:07:56,260 400 bad requests, member must not be null. 85 00:07:56,260 --> 00:08:01,160 The reason for this is we didn't actually pass the parameter it was looking for. 86 00:08:01,260 --> 00: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. 87 00:08:09,320 --> 00: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. 88 00:08:18,240 --> 00:08:20,760 It was not case sensitive. 89 00:08:20,880 --> 00:08:26,180 You could pass arbitrary parameters in mixed casing, and it would take it totally fine. 90 00:08:26,340 --> 00:08:30,660 Presumably somewhere on the back end it was normalizing these values in some way. 91 00:08:31,420 --> 00:08:39,200 Now, the parameter you would use to pass a role to the AppSync service was ServiceRoleArn, capital R, capital A. 92 00:08:39,200 --> 00:08:44,300 If you try to pass a role outside of your account, once again, cross-account pass role is not allowed. 93 00:08:44,700 --> 00: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. 94 00:09:03,100 --> 00: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. 95 00:09:13,660 --> 00:09:22,860 With this capability, we now could pass arbitrary IAM role arms to the AppSync service for it to try and assume. 96 00:09:22,860 --> 00: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. 97 00:09:36,100 --> 00: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. 98 00:09:49,280 --> 00: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. 99 00:09:56,500 --> 00:09:59,360 That's how we're able to do things like... oh, shoot. 100 00:09:59,360 --> 00: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. 101 00:10:10,660 --> 00: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. 102 00:10:23,560 --> 00: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. 103 00:10:35,480 --> 00: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. 104 00:10:46,680 --> 00:10:53,260 But because of this vulnerability, it assumes the role in the victim account and performs whatever we want it to perform. 105 00:10:53,420 --> 00:10:58,780 Whatever identity policies are associated with that role are all available for us to take advantage of. 106 00:10:58,780 --> 00: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. 107 00:11:08,760 --> 00: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. 108 00:11:24,500 --> 00:11:31,460 Next, before we dive into our second vulnerability, we need to learn a few things about assumeRole with WebIdentity. 109 00:11:31,680 --> 00:11:39,700 Up until this point, we've been learning about plain assumeRole, which is typically used for AWS-to-AWS role assumption. 110 00:11:39,960 --> 00: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. 111 00:11:50,340 --> 00: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. 112 00:11:57,760 --> 00:11:58,720 What do you do? 113 00:11:58,720 --> 00:12:02,620 Well, one option is to use assumeRole with WebIdentity. 114 00:12:02,620 --> 00: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. 115 00:12:11,060 --> 00: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. 116 00:12:17,960 --> 00:12:22,020 Think Facebook, Google, Amazon, GitHub, and things like that. 117 00:12:22,100 --> 00:12:28,920 Your external identities, whether they are human or machine, interact with this identity provider to generate a token. 118 00:12:28,940 --> 00:12:36,380 That token is then passed into the assumeRole with WebIdentity call to authorize you to assume a role in an account. 119 00:12:36,920 --> 00:12:43,400 Now, before we dive into this next point, I really want to stress assumeRole with WebIdentity is a general design pattern. 120 00:12:43,400 --> 00:12:48,900 It's used by a number of technologies, some native to AWS and some completely external. 121 00:12:48,900 --> 00: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. 122 00:12:58,720 --> 00:13:02,200 A variety of services will exhibit this exact same behavior. 123 00:13:02,560 --> 00:13:07,680 Like I said before, every IAM role has a role trust policy. 124 00:13:07,680 --> 00: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. 125 00:13:16,420 --> 00:13:24,040 And what it says is that we're going to allow the GitHub identity provider to assumeRole with WebIdentity. 126 00:13:24,240 --> 00:13:31,380 And that's a really scary thought, because if we think about it, the GitHub identity provider is public. 127 00:13:31,380 --> 00:13:33,840 It's global, in a sense. 128 00:13:33,840 --> 00: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. 129 00:13:48,400 --> 00:13:55,240 If you had this trust policy on a role in your account, anybody in the world could have assumed it. 130 00:13:55,400 --> 00: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. 131 00:14:08,500 --> 00:14:12,220 Again, assumeRole with WebIdentity is a general design pattern. 132 00:14:12,440 --> 00:14:18,480 The specific condition you will need will differ depending on what service you're using and what options you have. 133 00:14:18,480 --> 00: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. 134 00:14:28,060 --> 00: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. 135 00:14:41,840 --> 00:14:46,480 The good news, though, to this situation is AWS actually did something about it. 136 00:14:46,480 --> 00:14:49,660 Last year, this particular attack was very much in vogue. 137 00:14:49,660 --> 00:14:56,900 A number of security researchers, including my own colleague Christoph, identified this misconfiguration and sounded the alarm about it. 138 00:14:56,900 --> 00: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. 139 00:15:05,020 --> 00:15:09,180 Now, in response to this raised awareness, AWS did something good. 140 00:15:09,360 --> 00:15:16,300 They made it so that this once optional condition is now mandatory. 141 00:15:16,300 --> 00:15:22,660 You can no longer create a trust policy tied to the GitHub identity provider that does not include a condition. 142 00:15:22,660 --> 00:15:23,740 And so, that's great. 143 00:15:23,740 --> 00:15:26,420 That theoretically closes the loophole for any new roles. 144 00:15:26,420 --> 00:15:27,240 Fantastic. 145 00:15:27,240 --> 00:15:34,680 But, it's really important to stress they only did that for GitHub actions. 146 00:15:34,680 --> 00:15:42,380 Any of the other services that are similarly affected by this very same misconfiguration were slash are still vulnerable. 147 00:15:42,380 --> 00:15:45,620 So, again, strongly encourage you to audit your roles. 148 00:15:45,980 --> 00: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. 149 00:15:52,720 --> 00:15:55,800 The service I'd like to take a look at is Amazon Cognito. 150 00:15:55,800 --> 00:16:02,040 If you're not familiar, Cognito is essentially a sign-in as a service offering from AWS. 151 00:16:02,040 --> 00:16:04,920 It allows you to securely store user credentials. 152 00:16:05,020 --> 00: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. 153 00:16:10,520 --> 00:16:11,920 They'll take care of that for you. 154 00:16:12,640 --> 00: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. 155 00:16:25,940 --> 00: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. 156 00:16:34,540 --> 00: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. 157 00:16:45,440 --> 00:16:51,620 The good news about Cognito is it seems the developers foresaw the very same attack we did with GitHub actions. 158 00:16:51,740 --> 00:17:00,600 In particular, they, by default, out of the box, include a condition which restricts which identity pool can assume the role. 159 00:17:00,600 --> 00:17:03,240 And so this effectively mitigates the attack. 160 00:17:03,560 --> 00:17:09,640 If that condition is not present for any reason, well, once again, anybody can assume that role. 161 00:17:09,740 --> 00:17:13,240 And we're going to be talking about some reasons why it wasn't present in just a little bit. 162 00:17:13,520 --> 00: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. 163 00:17:24,200 --> 00: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. 164 00:17:29,600 --> 00:17:33,800 So for our purposes, we're going to refer to this as the Variant 1 Vulnerable Trust Policy. 165 00:17:33,940 --> 00:17:34,840 Why Variant 1? 166 00:17:34,840 --> 00:17:36,360 Because there's a Variant 2 as well. 167 00:17:36,360 --> 00: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. 168 00:17:44,340 --> 00:17:48,440 And that is the AMR, or the Authentication Methods References. 169 00:17:48,560 --> 00:17:51,520 This value can be authenticated or unauthenticated. 170 00:17:51,580 --> 00:17:54,840 And you might be wondering, could we have assumed a role if that condition was present? 171 00:17:54,840 --> 00:17:56,620 Well, yeah, absolutely. 172 00:17:56,660 --> 00:18:01,220 All that condition is doing is checking if you are authenticated to an identity pool. 173 00:18:01,280 --> 00:18:04,820 Not that you are authenticated to a specific identity pool. 174 00:18:04,860 --> 00:18:08,640 And since we can bring our own identity pool, we can configure it however we like. 175 00:18:08,640 --> 00:18:15,020 We can add that authentication component, or get rid of it, depending on what is needed to satisfy that condition. 176 00:18:16,160 --> 00:18:18,700 You might have noticed I called this a misconfiguration. 177 00:18:18,720 --> 00:18:20,140 That's because it totally is. 178 00:18:20,300 --> 00: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. 179 00:18:30,560 --> 00: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. 180 00:18:40,080 --> 00:18:43,880 And so at this point, you're probably thinking, well, Nick, I was promised a second vulnerable. 181 00:18:44,040 --> 00:18:45,640 You're calling this a misconfiguration. 182 00:18:45,640 --> 00:18:46,640 What gives? 183 00:18:46,780 --> 00: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. 184 00:18:55,120 --> 00:19:00,880 See, earlier this year, when we noticed this capability in Cognito, one of the first questions we had was, okay, cool. 185 00:19:00,880 --> 00:19:03,360 I wonder how common this misconfiguration is. 186 00:19:03,360 --> 00: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. 187 00:19:14,060 --> 00: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. 188 00:19:22,700 --> 00: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. 189 00:19:34,940 --> 00:19:37,620 That left us with a little over 8,000 results. 190 00:19:37,780 --> 00:19:40,460 We then tried to assume each role twice. 191 00:19:40,520 --> 00:19:43,200 Once authenticated, once unauthenticated. 192 00:19:43,200 --> 00:19:48,060 We let our automation run and pretty much immediately it was clear something was horribly wrong. 193 00:19:48,060 --> 00:19:50,700 Remember, this was across all of public GitHub. 194 00:19:50,700 --> 00:19:53,740 Across teams, organizations, individuals and companies. 195 00:19:53,780 --> 00: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? 196 00:20:03,040 --> 00: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. 197 00:20:13,480 --> 00:20:19,160 Now, what made these roles so strange was that they all ended in either auth role or unauth role. 198 00:20:19,260 --> 00:20:26,120 And additionally, they appear to have a timestamp dating back to 2018 or 2019, or they had a six digit integer . 199 00:20:26,620 --> 00:20:28,500 Presumably, these were the newer ones. 200 00:20:28,900 --> 00:20:33,440 To make things even weirder, we actually found three roles that belonged to AWS themselves. 201 00:20:33,480 --> 00:20:37,100 And so it wasn't clear what was going on that was making these roles vulnerable. 202 00:20:37,100 --> 00:20:43,380 Using Sourcegraph, we were able to find the name of the file where these roles were being found. 203 00:20:43,380 --> 00:20:49,420 And again, the overwhelming majority were found in a file called teamproviderinfo.json. 204 00:20:49,420 --> 00: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. 205 00:20:56,140 --> 00:20:59,280 It turns out it was AWS Amplify. 206 00:20:59,680 --> 00: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. 207 00:21:09,540 --> 00: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. 208 00:21:17,260 --> 00:21:19,580 And unfortunately, they didn't just do it once. 209 00:21:19,620 --> 00:21:20,940 They actually did it twice. 210 00:21:21,220 --> 00: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. 211 00:21:27,140 --> 00:21:31,980 Essentially, what it does is it will obfuscate a lot of the underlying infrastructure. 212 00:21:32,080 --> 00: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. 213 00:21:38,740 --> 00:21:41,640 Your developers don't even need to know what Cognito is. 214 00:21:41,640 --> 00:21:47,580 By using Amplify, Amplify will go in, create those Cognito resources, configure them, and so on. 215 00:21:50,880 --> 00: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. 216 00:21:59,400 --> 00:22:03,200 And that's because the Amplify CLI is open source. 217 00:22:03,200 --> 00:22:08,640 And by digging through the commit history, we can actually see how and when these vulnerabilities were introduced. 218 00:22:09,020 --> 00:22:15,180 I do want to be respectful for time, since we did start a little bit late, to quickly summarize this. 219 00:22:15,180 --> 00:22:20,400 The Variant 2 issue was introduced in July of 2018. 220 00:22:20,400 --> 00:22:28,040 A little over a year later, on August 8th, 2019, they sort of fixed the issue, seemingly unintentionally. 221 00:22:28,200 --> 00:22:34,880 Essentially, what occurred here was they seemingly unintentionally made a fix so that no future roles would be misconfigured. 222 00:22:34,880 --> 00:22:41,550 However, any that had already been created were still vulnerable, and we could still assume them like we did in 2024. 223 00:22:42,500 --> 00:22:49,100 In July of 2020, the Variant 1 vulnerable trust policy was introduced to the Amplify CLI and Studio. 224 00:22:49,520 --> 00:22:58,420 We disclosed this in January, and by February and April, AWS introduced comprehensive fixes to both of these variants. 225 00:22:58,560 --> 00:23:01,640 In particular, they went a little bit above and beyond what they did with GitHub. 226 00:23:02,900 --> 00:23:07,920 They did the same thing where you can no longer create trust policies that are vulnerable to this misconfiguration. 227 00:23:07,920 --> 00:23:09,420 The API will actually reject it. 228 00:23:09,420 --> 00:23:16,880 But also, they made changes to STS itself to prevent you from being able to assume a vulnerable role. 229 00:23:16,920 --> 00: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. 230 00:23:25,900 --> 00: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, 231 00:23:38,200 --> 00:23:38,880 and more. 232 00:23:39,020 --> 00:23:44,960 Now, speaking of picking things for time, we'll actually make this a little bit of a choose-your-own-adventure. 233 00:23:45,100 --> 00: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? 234 00:23:55,180 --> 00:23:56,120 Which would you prefer? 235 00:23:56,120 --> 00:23:57,560 Show of hands for the Amplify Vuln? 236 00:23:57,560 --> 00:24:00,340 Keep it down if you'd rather do the defense side. 237 00:24:03,460 --> 00:24:08,040 I'm seeing more hands down, so I guess we'll go with the defense side. 238 00:24:08,280 --> 00:24:11,380 Just know you can actually still exploit this today. 239 00:24:11,380 --> 00:24:12,260 It is more difficult. 240 00:24:12,260 --> 00:24:17,980 It does require an additional misconfigured resource, but the Amplify Vuln is still there. 241 00:24:17,980 --> 00: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. 242 00:24:28,760 --> 00:24:33,940 But, let's talk a little bit about what we can do to prevent cross-tenant attacks in AWS. 243 00:24:34,100 --> 00: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. 244 00:24:43,440 --> 00:24:49,340 The way that we would do this is we would attach these as conditions on our role trust policies. 245 00:24:49,340 --> 00:24:52,180 Now, definitely note, these are not included by default. 246 00:24:52,180 --> 00:24:56,320 If you created an instance profile tomorrow, this wouldn't be automatically attached. 247 00:24:56,320 --> 00: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. 248 00:25:04,980 --> 00:25:10,060 From some nominal testing, it appears that EC2, Lambda, and AppSync all work totally fine. 249 00:25:10,380 --> 00:25:14,260 Again, definitely strongly encourage you to test this before you try pushing to production. 250 00:25:14,500 --> 00: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. 251 00:25:31,880 --> 00:25:35,940 What's super cool about this is we actually got to test this in real life. 252 00:25:35,940 --> 00: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. 253 00:25:47,760 --> 00:25:50,000 And indeed, it did successfully block us. 254 00:25:50,040 --> 00: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. 255 00:25:59,100 --> 00:26:02,460 The other reason I like these is from a defense-in-depth perspective. 256 00:26:02,580 --> 00:26:08,540 If pass rule says, under no circumstance should someone be able to assume a role cross-tenant in AWS, well, great. 257 00:26:08,540 --> 00: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. 258 00:26:18,620 --> 00:26:24,300 So quickly in conclusion, we took a look today at how confused deputy attacks can weaponize cloud services against us. 259 00:26:24,300 --> 00: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. 260 00:26:32,740 --> 00:26:35,040 Again, strongly encourage you to audit your roles. 261 00:26:35,040 --> 00:26:36,760 It's a very easy mistake to make. 262 00:26:36,760 --> 00:26:38,060 Amazon made it twice. 263 00:26:38,240 --> 00: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. 264 00:26:45,680 --> 00:26:50,560 If you enjoyed this talk, you can find more of our research at securitylabs.datadoghq.com. 265 00:26:50,560 --> 00:26:54,740 If you have any questions, feel free to come find me after or reach out on social media. 266 00:26:54,740 --> 00:26:55,660 My name is Nick Frechette. 267 00:26:55,660 --> 00:26:56,760 Thank you all so much.