1 00:00:00,500 --> 00:00:02,380 Good afternoon DEF CON. 2 00:00:02,380 --> 00:00:03,920 Thank you so much for being here. 3 00:00:03,920 --> 00:00:08,720 Welcome to my talk on exploiting AWS service vulnerabilities for initial access. 4 00:00:08,880 --> 00:00:10,560 My name is Nick Furchette. 5 00:00:10,560 --> 00:00:15,760 I'm a security researcher over at Datadog where I specialize in AWS offensive security. 6 00:00:15,760 --> 00: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. 7 00:00:23,860 --> 00:00:29,240 As a result of that research sometimes I find vulnerabilities in the underlying AWS services. 8 00:00:29,260 --> 00:00:31,340 Some of which we're going to be talking about today. 9 00:00:31,700 --> 00: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. 10 00:00:41,580 --> 00: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. 11 00:00:47,420 --> 00:00:51,940 Now breaking into AWS accounts is a topic that's near and dear to my heart. 12 00:00:51,940 --> 00:00:54,520 And I'm sure it is for many of you as well. 13 00:00:54,520 --> 00:01:04,000 But I think if we're being honest with ourselves the traditional methods for gaining access to AWS environments are boring. 14 00:01:04,000 --> 00: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. 15 00:01:15,740 --> 00:01:22,880 They were either caused by a leaked access key, an exposed S3 bucket or an exploited EC2 instance. 16 00:01:23,000 --> 00:01:28,840 These are the stereotypical ways that adversaries gain access to AWS accounts. 17 00:01:28,840 --> 00: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. 18 00:01:39,120 --> 00: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. 19 00:01:47,040 --> 00:01:51,220 Particularly by abusing pre-existing trust. 20 00:01:51,340 --> 00: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. 21 00:02:02,740 --> 00:02:09,420 This enables that service to perform actions and uh do functionality in your account. 22 00:02:09,580 --> 00: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. 23 00:02:21,980 --> 00: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. 24 00:02:28,980 --> 00: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. 25 00:02:36,200 --> 00:02:39,420 And finally we're going to discuss prevention options. 26 00:02:39,420 --> 00: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? 27 00:02:49,340 --> 00: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. 28 00:02:56,760 --> 00: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. 29 00:03:05,060 --> 00: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. 30 00:03:12,200 --> 00:03:18,840 In AWS, every IAM role is going to have a role trust policy. 31 00:03:18,840 --> 00:03:24,780 And this policy determines who or what is permitted to assume a role. 32 00:03:24,980 --> 00:03:27,820 Trust policies can trust a variety of identities. 33 00:03:27,820 --> 00:03:33,280 Users, roles, AWS organizations, uh identity providers and many others. 34 00:03:33,280 --> 00:03:38,760 But where I think it's most interesting is when they trust an AWS service itself. 35 00:03:39,000 --> 00:03:46,100 What you see here on the slide is the default trust policy that is associated with roles for the Lambda service. 36 00:03:46,180 --> 00: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. 37 00:03:52,320 --> 00: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. 38 00:04:00,320 --> 00: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. 39 00:04:11,840 --> 00:04:16,020 This behavior introduces some really interesting questions. 40 00:04:16,020 --> 00:04:24,040 Since I already said that this is the default policy, theoretically the majority of roles using Lambda wouldn't have it. 41 00:04:24,040 --> 00:04:30,040 And since the trust policy just says that it trusts Lambda, could I do something a little bit sneaky? 42 00:04:30,280 --> 00:04:36,960 Could I create a Lambda function in my account but point to or reference a role in a different AWS account? 43 00:04:36,980 --> 00:04:40,460 Preferably one that I don't have legitimate access to. 44 00:04:40,720 --> 00: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? 45 00:04:50,200 --> 00:04:55,300 Well, the good news or bad news depending on your perspective is there is something that stops this. 46 00:04:55,300 --> 00:04:56,760 And that's called pass role. 47 00:04:56,880 --> 00: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. 48 00:05:04,360 --> 00:05:10,840 One of the core rules of which is that you can only pass a role within your same AWS account. 49 00:05:10,920 --> 00: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. 50 00:05:17,740 --> 00: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. 51 00:05:29,740 --> 00:05:33,080 So this is going to be the goal for the first part of our session today. 52 00:05:33,080 --> 00: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. 53 00:05:42,920 --> 00:05:47,700 So the first vulnerability is a confused deputy vuln in AWS AppSync. 54 00:05:47,900 --> 00:05:53,160 If you're not familiar with AppSync, AppSync is a managed GraphQL service offered by AWS. 55 00:05:53,240 --> 00:05:57,760 And it allows you to quickly and easily build GraphQL APIs. 56 00:05:58,040 --> 00: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. 57 00:06:07,780 --> 00: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. 58 00:06:16,000 --> 00: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. 59 00:06:23,600 --> 00:06:29,160 And again, if you try to pass a role outside of your account, cross account pass role is not allowed. 60 00:06:29,320 --> 00: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. 61 00:06:36,340 --> 00:06:43,340 Things like unique encoding schemes, maybe something like HTTP request smuggling or maybe even something more exotic. 62 00:06:43,440 --> 00: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. 63 00:06:51,220 --> 00:06:54,080 Through the power of Spongebob memes. 64 00:06:54,880 --> 00:07:00,080 See, under normal circumstances, the AWS API is typically case sensitive. 65 00:07:00,080 --> 00: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. 66 00:07:07,740 --> 00:07:11,100 If you don't meet that expectation, you'll get an error. 67 00:07:11,120 --> 00:07:19,020 So to demonstrate this with a completely unrelated API, here we're performing secrets manager create secret. 68 00:07:19,020 --> 00:07:22,980 And that API expects a name parameter with a capital N. 69 00:07:23,000 --> 00:07:28,920 So long as you pass it in that format, 200 OK, everything works, you created a secret. 70 00:07:29,240 --> 00: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. 71 00:07:38,780 --> 00:07:41,620 400 bad requests, member must not be null. 72 00:07:41,860 --> 00:07:46,340 The reason for this is, well we didn't pass the parameter it was looking for. 73 00:07:46,340 --> 00: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. 74 00:07:54,020 --> 00: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. 75 00:08:02,360 --> 00:08:04,460 It was not case sensitive. 76 00:08:04,460 --> 00:08:10,520 We could pass arbitrary parameters of mixed casing and the API would take it totally fine. 77 00:08:10,520 --> 00:08:15,320 Presumably somewhere on the back end it was normalizing these values in some way. 78 00:08:15,520 --> 00: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. 79 00:08:25,620 --> 00:08:31,160 If you try to pass a role outside of your account, once again, cross account pass role is not allowed. 80 00:08:31,580 --> 00: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, 81 00:08:48,140 --> 00:08:51,040 either didn't happen at all or completely failed. 82 00:08:51,080 --> 00: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. 83 00:08:59,880 --> 00:09:05,760 And so, we were able to break a major security boundary in AWS with Spongebob memes. 84 00:09:06,500 --> 00: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. 85 00:09:18,440 --> 00:09:25,820 We could now provide that role to the service and arbitrarily assume it and access whatever resources were associated with it. 86 00:09:25,820 --> 00: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. 87 00:09:40,180 --> 00:09:43,960 And this scenario, that was assuming a role in a victim account. 88 00:09:43,960 --> 00: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. 89 00:09:56,180 --> 00: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. 90 00:10:06,200 --> 00: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. 91 00:10:12,640 --> 00:10:15,280 From here, we have to actually do something useful. 92 00:10:15,360 --> 00: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. 93 00:10:27,060 --> 00: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. 94 00:10:34,040 --> 00:10:39,500 The good news for us is that in this scenario, the AppSync service is more than happy to provide. 95 00:10:39,620 --> 00:10:44,520 In particular, AppSync allows you to run arbitrary AWS API calls. 96 00:10:44,520 --> 00:10:51,700 So you now have the full spectrum of API calls that you can invoke at your choosing. 97 00:10:52,400 --> 00: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. 98 00:11:00,120 --> 00:11:03,780 Configure it, set the schema, create our data sources and so on. 99 00:11:03,840 --> 00:11:09,340 Then we would perform that pass role bypass to specify what role in the victim account we want to assume. 100 00:11:09,360 --> 00:11:14,740 And then, under normal circumstances, the AppSync service would assume the role in our account. 101 00:11:14,740 --> 00: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. 102 00:11:22,920 --> 00: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. 103 00:11:35,160 --> 00: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? 104 00:11:41,920 --> 00:11:43,480 It becomes a bit of a hassle. 105 00:11:43,720 --> 00:11:50,680 By comparison, with confused deputy attacks, you can just land as the identity of a production application. 106 00:11:50,800 --> 00:11:56,080 If there's a production AppSync API, it has privileges to do whatever that service needs to do. 107 00:11:56,080 --> 00:12:02,040 Whether that is upload S3, write to DynamoDB, read from RDS or anything else. 108 00:12:02,160 --> 00: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. 109 00:12:09,420 --> 00:12:16,280 So no need for weird bloodhound-esque lateral movement paths, you just pass that role and yow you're in. 110 00:12:16,460 --> 00: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. 111 00:12:27,980 --> 00: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. 112 00:12:42,300 --> 00:12:47,000 Um, the respective QR codes with the arrows will take you to each of those. 113 00:12:47,740 --> 00: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. 114 00:12:55,940 --> 00: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. 115 00:13:04,480 --> 00: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. 116 00:13:13,160 --> 00: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. 117 00:13:23,520 --> 00: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. 118 00:13:32,020 --> 00:13:32,840 What do you do? 119 00:13:32,840 --> 00:13:36,180 Well, that's where assume role with web identity comes in. 120 00:13:36,180 --> 00: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. 121 00:13:45,580 --> 00: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. 122 00:13:52,960 --> 00:13:57,760 Think things like Facebook, Amazon, Google, GitHub, and many others. 123 00:13:58,180 --> 00: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. 124 00:14:13,100 --> 00: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. 125 00:14:19,760 --> 00:14:27,140 A variety of technologies and services, both native to AWS and outside of it, will use this general design pattern. 126 00:14:27,220 --> 00: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. 127 00:14:40,560 --> 00: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? 128 00:14:56,920 --> 00:14:59,340 Well, we could use assume role with web identity. 129 00:14:59,440 --> 00:15:06,620 To set this up, we initially create a trust relationship between our AWS account and an identity provider. 130 00:15:06,620 --> 00:15:11,540 Since we're already using GitHub actions, we might as well use GitHub's provided identity provider. 131 00:15:11,940 --> 00:15:16,600 Once that trust is established, we then create an IEM role. 132 00:15:16,600 --> 00: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. 133 00:15:26,940 --> 00: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, 134 00:15:44,900 --> 00:15:49,680 whether that is upload something to S3 or call any other API calls. 135 00:15:50,020 --> 00: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. 136 00:15:57,060 --> 00:15:59,680 And I assure you, it's just as scary as it sounds. 137 00:16:00,000 --> 00: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. 138 00:16:08,800 --> 00: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. 139 00:16:15,900 --> 00:16:21,680 And that's a really scary thought, because if we think about it, GitHub's identity provider is public. 140 00:16:21,680 --> 00:16:23,360 It's global. 141 00:16:23,440 --> 00:16:25,280 Anybody has access to it. 142 00:16:25,280 --> 00: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. 143 00:16:41,260 --> 00: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. 144 00:16:50,680 --> 00: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. 145 00:17:05,080 --> 00:17:08,600 Again, assume role with web identity is a general design pattern. 146 00:17:08,600 --> 00:17:14,460 The specific condition you'll need will differ depending on the service and what specific scenario you're in. 147 00:17:14,460 --> 00: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. 148 00:17:25,000 --> 00: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. 149 00:17:40,700 --> 00: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. 150 00:17:46,800 --> 00: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. 151 00:17:53,800 --> 00: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. 152 00:18:01,300 --> 00:18:05,640 Uh, now to AWS' credit, they actually did something about this. 153 00:18:05,640 --> 00:18:11,200 In particular, they made what was once an optional condition, now mandatory. 154 00:18:11,320 --> 00:18:17,940 You can no longer create a role trust policy for the GitHub identity provider that doesn't include a condition. 155 00:18:17,980 --> 00:18:19,500 And so, that's good. 156 00:18:19,500 --> 00:18:21,820 Kudos to AWS, that's a great change. 157 00:18:22,280 --> 00: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. 158 00:18:32,420 --> 00:18:39,960 Any of the other technologies or services that have this very same potential misconfiguration were slash are still vulnerable. 159 00:18:39,960 --> 00:18:42,820 So again, definitely encourage you to audit your roles. 160 00:18:42,920 --> 00: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. 161 00:18:48,700 --> 00:18:53,340 Uh, Cognito is a sign in as a service offering from AWS. 162 00:18:53,340 --> 00: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. 163 00:19:04,420 --> 00:19:08,880 One of the core features of Cognito is something called an identity pool. 164 00:19:08,880 --> 00: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. 165 00:19:20,840 --> 00: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, 166 00:19:35,100 --> 00: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. 167 00:19:44,040 --> 00:19:50,400 The good news about Cognito is that they seemingly foresaw the very same attack that occurred with GitHub actions. 168 00:19:50,400 --> 00:19:55,380 They do, by default, include a condition to defend against it. 169 00:19:55,540 --> 00:20:02,740 Specifically, the condition will restrict which identity pool is allowed to assume a role. 170 00:20:02,740 --> 00: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. 171 00:20:09,440 --> 00:20:13,940 And we're gonna talk about some reasons why that trust policy might look like this in just a little bit. 172 00:20:14,920 --> 00:20:20,800 Uh, the way that we can take advantage of it is slightly different than what we described with GitHub actions. 173 00:20:20,800 --> 00:20:25,420 This is mostly an implementation detail specific to Cognito identity pools. 174 00:20:25,420 --> 00:20:30,300 Specifically, what we're gonna do is use a uh, Cognito offload. 175 00:20:30,300 --> 00:20:41,160 Offloads are essentially like the, essentially the step by step operations uh, that a user would use to generate those credentials. 176 00:20:41,160 --> 00:20:48,320 There are two offloads currently supported, an enhanced offload and a basic offload, sometimes referred to as classic. 177 00:20:48,540 --> 00: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. 178 00:20:58,380 --> 00:21:03,820 Um, the specific step by steps are as an attacker, we're gonna create our own Cognito identity pool. 179 00:21:03,820 --> 00:21:09,500 We're gonna, going to then perform get ID and get open ID tokens to generate that JWT. 180 00:21:09,500 --> 00: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. 181 00:21:17,120 --> 00: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. 182 00:21:23,680 --> 00: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. 183 00:21:32,460 --> 00:21:35,860 The reason we call this Variant 1 is because there's a Variant 2 as well. 184 00:21:35,860 --> 00:21:41,900 You might have noticed there's actually two conditions on the default trust policy associated with roles using Cognito. 185 00:21:41,900 --> 00:21:48,300 And this condition is the AMR condition, or the authentication methods references. 186 00:21:48,300 --> 00:21:51,300 And this value can be either authenticated or unauthenticated. 187 00:21:51,300 --> 00:21:54,680 You might wonder, could we assume a role if this condition was set? 188 00:21:54,680 --> 00:21:57,120 And turns out, yeah, absolutely, we totally could. 189 00:21:57,120 --> 00:22:03,780 If the value is set to unauthenticated, then literally everything I just said works completely the same, no changes required. 190 00:22:04,000 --> 00:22:08,200 If the value is authenticated, then we do have to jump through some extra hoops. 191 00:22:08,200 --> 00: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. 192 00:22:19,780 --> 00: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. 193 00:22:29,240 --> 00: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. 194 00:22:35,640 --> 00:22:41,060 Now, earlier you might have noticed that I called this a misconfiguration, and that's because it is. 195 00:22:41,060 --> 00: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. 196 00:22:51,400 --> 00: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. 197 00:23:01,160 --> 00: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? 198 00:23:07,340 --> 00: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. 199 00:23:17,940 --> 00: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. 200 00:23:27,420 --> 00: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. 201 00:23:40,480 --> 00:23:43,340 To do this, we used a tool called Sourcegraph. 202 00:23:43,340 --> 00:23:48,700 One of the free features of which is essentially like a Google search, but for public GitHub repos. 203 00:23:48,700 --> 00:23:53,500 Uh, we we wrote a regular expression to find IEM role ARNs. 204 00:23:53,500 --> 00: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. 205 00:24:03,280 --> 00:24:06,980 Uh, and that left us with a little over 8,000 results. 206 00:24:07,020 --> 00:24:09,560 We then tried to assume each role twice. 207 00:24:09,560 --> 00:24:12,020 Once authenticated and once unauthenticated. 208 00:24:12,020 --> 00:24:18,320 And we let our automation run and pretty much immediately it was clear, something was terribly wrong. 209 00:24:18,460 --> 00:24:21,280 Remember, this was across all of public GitHub. 210 00:24:21,280 --> 00:24:25,040 Across teams, organi- organizations, individuals and companies. 211 00:24:25,040 --> 00: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? 212 00:24:34,600 --> 00: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. 213 00:24:45,760 --> 00:24:51,660 Now, what made these roles so weird was that they all ended in either auth role or unauth role. 214 00:24:51,660 --> 00: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. 215 00:24:59,800 --> 00:25:02,040 Presumably, these were the newer ones. 216 00:25:02,420 --> 00: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. 217 00:25:10,240 --> 00: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. 218 00:25:23,480 --> 00:25:30,520 Uh, using source graph, we were able to see the name of the file where these roles were being found. 219 00:25:30,520 --> 00:25:37,080 And again, the overwhelming majority were found in files called team provider info dot Jason. 220 00:25:37,160 --> 00:25:41,040 And through this, this led us ultimately to the culprit. 221 00:25:41,040 --> 00:25:45,200 The thing that was causing all these roles to let anybody assume them. 222 00:25:45,200 --> 00:25:48,700 Turns out, it was AWS Amplify. 223 00:25:49,020 --> 00: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. 224 00:26:01,740 --> 00:26:09,580 This was a rare circumstance in which an AWS service itself was exposing IEM roles, such that anyone could assume them. 225 00:26:09,880 --> 00:26:14,700 The vulnerability was not that you could misconfigure roles, it's that AWS was doing it to you. 226 00:26:14,700 --> 00:26:17,620 And fortunately, not just once, they actually did it twice. 227 00:26:17,780 --> 00: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. 228 00:26:25,120 --> 00: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. 229 00:26:34,520 --> 00: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. 230 00:26:44,980 --> 00: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. 231 00:26:53,800 --> 00:26:57,940 Key emphasis, Amplify configures those Cognito resources. 232 00:26:58,320 --> 00:27:02,320 Now, there's two ways you can build an Amplify app or configure them. 233 00:27:02,320 --> 00:27:04,880 Uh, they're not mutually exclusive, you can use either or. 234 00:27:04,880 --> 00: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. 235 00:27:14,760 --> 00: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. 236 00:27:23,540 --> 00: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. 237 00:27:29,800 --> 00: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. 238 00:27:38,880 --> 00:27:41,820 So we run into these types of scenarios fairly frequently. 239 00:27:42,260 --> 00: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. 240 00:27:53,000 --> 00:27:58,960 That's because the Amplify CLI written by AWS is actually open source. 241 00:27:59,000 --> 00:28:05,020 And by digging through the commit history, we can see how and when these vulnerabilities were introduced. 242 00:28:05,060 --> 00: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. 243 00:28:17,900 --> 00: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. 244 00:28:32,680 --> 00:28:39,340 What happened here is that any time you create an Amplify project, two roles are created for your account. 245 00:28:39,340 --> 00:28:42,760 An auth role and an unauth role, like we saw previously. 246 00:28:43,200 --> 00: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. 247 00:28:53,480 --> 00: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. 248 00:29:05,160 --> 00:29:09,620 Anybody could just assume those roles and access whatever was associated with them. 249 00:29:10,000 --> 00:29:13,240 Like I said, that was introduced on July 3rd, 2018. 250 00:29:13,340 --> 00:29:19,960 A little over a year later, on August 8th, 2019, AWS sort of fixed this issue. 251 00:29:19,960 --> 00:29:21,780 Uh, seemingly unintentionally. 252 00:29:21,780 --> 00:29:27,500 What they did was they set the default effect to a deny and they removed the condition entirely. 253 00:29:27,500 --> 00:29:33,400 This is actually the exact same behavior we see today when creating a new Amplify project. 254 00:29:33,540 --> 00: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. 255 00:29:41,880 --> 00:29:48,520 Any that had already been created were still vulnerable and that's how we were able to assume them in 2024. 256 00:29:49,120 --> 00:29:55,620 Later on in July of 2020, variant one was introduced to the Amplify CLI in studio. 257 00:29:55,620 --> 00:29:58,680 And this one was a bit more complicated than the previous one. 258 00:29:58,860 --> 00:30:04,960 What happened here was that, uh, like I said previously, you can add authentication to an Amplify project. 259 00:30:04,960 --> 00:30:11,760 If at any time you chose to remove authentication for any reason, that would introduce the variant one policy. 260 00:30:11,760 --> 00: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. 261 00:30:30,300 --> 00: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. 262 00:30:40,760 --> 00:30:43,240 This is the secure trust policy. 263 00:30:43,360 --> 00: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. 264 00:30:54,180 --> 00:30:56,500 The variant one vulnerable policy. 265 00:30:56,900 --> 00:31:03,920 Whatever identity permissions were associated with this rule, when this exposure occurred, it still had access to. 266 00:31:03,920 --> 00: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. 267 00:31:11,680 --> 00:31:15,400 Additionally, at the end of the day, these are just plain IEM rules. 268 00:31:15,400 --> 00:31:19,940 And unfortunately, developers love to over-privilege their identities. 269 00:31:20,040 --> 00: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. 270 00:31:32,640 --> 00: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. 271 00:31:42,000 --> 00: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. 272 00:31:50,960 --> 00: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. 273 00:32:00,080 --> 00: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. 274 00:32:09,860 --> 00: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. 275 00:32:17,320 --> 00: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. 276 00:32:25,620 --> 00: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. 277 00:32:34,380 --> 00:32:40,220 By comparison, the whole point of Cognito is that these roles are supposed to be available to your users. 278 00:32:40,240 --> 00:32:41,800 They're basically public. 279 00:32:41,900 --> 00: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. 280 00:32:48,540 --> 00: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. 281 00:32:59,980 --> 00: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. 282 00:33:13,720 --> 00: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. 283 00:33:21,740 --> 00: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. 284 00:33:27,360 --> 00:33:30,040 But in addition, they sort of went above and beyond. 285 00:33:30,100 --> 00: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. 286 00:33:39,160 --> 00: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. 287 00:33:46,640 --> 00: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. 288 00:34:02,120 --> 00: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. 289 00:34:12,880 --> 00:34:15,240 The reason for doing this is simplicity. 290 00:34:15,240 --> 00: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. 291 00:34:26,560 --> 00:34:33,120 Specific to the Amplify vulnerability, they fixed cross-account role assumption using identity pools. 292 00:34:33,120 --> 00:34:38,180 It's no longer possible for me to use one of my identity pools to assume a role in your account. 293 00:34:38,680 --> 00:34:41,440 But they didn't do anything about the same account scenario. 294 00:34:41,440 --> 00:34:45,220 And to be clear, I don't really think there's much they could do. 295 00:34:45,220 --> 00: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. 296 00:34:51,720 --> 00:34:57,700 It's very likely zero if any real organizations were doing this in the wild. 297 00:34:57,700 --> 00: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. 298 00:35:03,100 --> 00: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. 299 00:35:10,440 --> 00: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. 300 00:35:22,480 --> 00: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, 301 00:35:40,020 --> 00: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. 302 00:35:51,460 --> 00: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. 303 00:36:03,960 --> 00: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. 304 00:36:10,720 --> 00: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, 305 00:36:25,020 --> 00:36:30,360 it might be helpful to know that we do have some controls that can potentially prevent some of these attacks. 306 00:36:30,380 --> 00: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. 307 00:36:39,420 --> 00:36:43,360 Sort of similar to what we saw with a Sumo with WebIdentity previously. 308 00:36:43,420 --> 00:36:51,120 These conditions allow us to restrict either the ARN, the account, or the organization that is permitted to assume a role. 309 00:36:51,220 --> 00: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, 310 00:37:03,000 --> 00:37:09,080 or want to protect, and more importantly, make sure that those services are compatible with these condition keys. 311 00:37:09,080 --> 00: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. 312 00:37:18,100 --> 00: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. 313 00:37:33,320 --> 00: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. 314 00:37:43,940 --> 00: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. 315 00:37:53,280 --> 00: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. 316 00:38:02,660 --> 00:38:06,260 The other reason I like this is from a defense in depth perspective. 317 00:38:06,260 --> 00:38:13,480 If pass rule says, under absolutely no circumstance should someone be able to assume a role cross-tenant, well great. 318 00:38:13,480 --> 00:38:15,080 We broke that with Spongebob memes. 319 00:38:15,080 --> 00: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. 320 00:38:23,980 --> 00:38:26,820 You're also unlikely to run into many issues. 321 00:38:26,820 --> 00:38:30,460 If it works, it's very unlikely to cause, uh, problems. 322 00:38:30,460 --> 00:38:33,840 It's, this is more of a static thing that stays the same over time. 323 00:38:34,260 --> 00:38:40,360 So in conclusion, we took a look today at how confused epi attacks can weaponize cloud services against us. 324 00:38:40,360 --> 00:38:45,680 We took a look at a very dangerous misconfiguration when using assume role with web identity. 325 00:38:45,680 --> 00: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. 326 00:38:53,360 --> 00:38:54,820 It's an easy mistake to make. 327 00:38:54,820 --> 00:38:56,560 AWS actually made it twice. 328 00:38:56,780 --> 00: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. 329 00:39:03,900 --> 00:39:08,740 If you enjoyed this talk, you can find more of our research at securitylabs.daydoghq.com. 330 00:39:08,740 --> 00:39:12,700 If you have any questions, feel free to find me after or reach out to me on social media. 331 00:39:12,700 --> 00:39:14,140 Again, my name's Nick Furchette. 332 00:39:14,140 --> 00:39:15,220 Thank you all so much.