start	end	text
500	5280	Good afternoon DEF CON. Thank you so much for being here. Welcome to my talk on exploiting
5280	11000	AWS service vulnerabilities for initial access. My name is Nick Furchette. I'm a security
11000	16540	researcher over at Datadog where I specialize in AWS offensive security. So finding ways
16540	20960	to more effectively attack AWS environments and then hopefully how do we detect that behavior
20960	26700	or potentially prevent it entirely. As a result of that research sometimes I find vulnerabilities
26700	32040	in the underlying AWS services. Some of which we're going to be talking about today. Uh in
32040	36520	my free time I'm the creator and maintainer of Hacking the Cloud which is an open source
36520	41760	encyclopedia of offensive security techniques that you can use in cloud hacking adventures. Uh
41760	45520	if you'd like a Hacking the Cloud sticker come find me after I have quite a few to give away.
47420	52600	Now breaking into AWS accounts is a topic that's near and dear to my heart. And I'm sure it
52600	58220	is for many of you as well. But I think if we're being honest with ourselves the traditional
58220	65340	methods for gaining access to AWS environments are boring. If we were to poll the audience
65340	72260	for real world AWS breaches, compromises and other security incidents I guarantee 95% of
72260	77900	scenarios would fall into one of three categories. They were either caused by a leaked access
77900	85700	key, an exposed S3 bucket or an exploited EC2 instance. These are the stereotypical ways that
85700	92400	adversaries gain access to AWS accounts. And to be clear these are very real risks that we do
92400	97620	have to contend with but it's nothing you haven't seen before and again these methods are
97620	102680	boring. What we're going to be doing instead is kicking it in the door to the cloud and
102680	108560	exploiting vulnerabilities in AWS services to get initial access. Particularly by abusing
108560	117000	pre-existing trust. What I mean by that is a common design pattern in AWS is to have IAM roles
117000	124160	in your account that have a trust relationship back to some AWS service. This enables that
124160	130440	service to perform actions and uh do functionality in your account. Today we're going to look
130440	135120	at some vulnerabilities that would allow us to hijack that trust relationship and gain access
135120	140160	to victim accounts so that from there we can escalate privileges, move laterally, access
140160	144640	resources and more. In this session we're going to talk a little bit about how trust is
144640	150480	established between IAM roles and AWS services. Then we're going to dive deep on two
150480	154960	vulnerabilities as well as a more general misconfiguration that would allow us to take
154960	160300	advantage of this. And finally we're going to discuss prevention options. In the absolute
160300	166120	worst case scenario of an adversary having a cross tenant zero day in AWS, what options do we
166120	172420	have to try and mitigate some of these attacks? Now it's worth noting that the majority of
172420	177320	vulnerabilities we're going to be talking about today have been remediated by AWS. So think of
177320	180980	this more from the perspective of what can we learn from these vulnerabilities that we can
180980	186700	apply to better attack or defend cloud environments. To get us started on the topic of
186700	192700	abusing pre-existing trust, we should probably talk about how that trust is established. In
192700	201280	AWS, every IAM role is going to have a role trust policy. And this policy determines who or
201280	208480	what is permitted to assume a role. Trust policies can trust a variety of identities. Users,
208480	214500	roles, AWS organizations, uh identity providers and many others. But where I think it's most
214500	221260	interesting is when they trust an AWS service itself. What you see here on the slide is the
221940	226660	default trust policy that is associated with roles for the Lambda service. If you were to
226660	230940	create a Lambda function today, the role that would be created for you would have this very
230940	237180	same trust policy. And what it says is that we're going to allow the Lambda service to assume
237180	244080	role with web, or sorry, to assume role. Now, the way this works in practice is every time your
244080	250160	Lambda function runs, the Lambda service assumes that role in your account and does whatever it
250160	256420	is that you want it to do. This behavior introduces some really interesting questions. Since I
256420	262360	already said that this is the default policy, theoretically the majority of roles using Lambda
262360	268340	wouldn't have it. And since the trust policy just says that it trusts Lambda, could I do
268340	273820	something a little bit sneaky? Could I create a Lambda function in my account but point to or
273820	279020	reference a role in a different AWS account? Preferably one that I don't have legitimate
279020	285600	access to. Uh could we cause that Lambda service to assume that role in the victim account and
285600	291780	carry out whatever operations would be beneficial to us as adversaries? Well, the good news or
291780	295500	bad news depending on your perspective is there is something that stops this. And that's
295500	302400	called pass role. Any time you are providing a role to an AWS service for it to assume it,
302400	307720	you're interacting with pass role. One of the core rules of which is that you can only pass a
307720	313820	role within your same AWS account. If you try to pass a role outside of it, you get the error
313820	319300	message, access denied, cross account pass role is not allowed. Now, this is a very important
319300	325040	security boundary in AWS because without it, theoretically we could just arbitrarily assume
325040	330160	role into pretty much any account and access any of the resources associated with it. So this
330160	334300	is going to be the goal for the first part of our session today. Finding a vulnerability in
334300	339400	the pass role implementation to allow us to weaponize a service against roles that trust it
339400	345120	and access resources in victim accounts. So the first vulnerability is a confused deputy
345120	350900	vuln in AWS AppSync. If you're not familiar with AppSync, AppSync is a managed GraphQL
350900	358720	service offered by AWS. And it allows you to quickly and easily build GraphQL APIs. The way
358720	362900	that it works is pretty similar to what I described with Lambda, where you first create an
362900	368540	AppSync API in your account, configure it, set your schema, and so on. And then as a part of
368540	373900	setting your data source, a role will be created for you that by default has a trust policy back
373900	380260	to the AppSync service. Then, when your AppSync API is run, the AppSync service assumes that
380260	385960	role and does whatever that API is supposed to do. And again, if you try to pass a role outside
385960	391500	of your account, cross account pass role is not allowed. Now, I recognize this is DEF CON
391500	395300	and I'm sure many of you are already trying to come up with ways that we can bypass this
395300	401100	control. Things like unique encoding schemes, maybe something like HTTP request smuggling or
401100	406000	maybe even something more exotic. These are all great ideas and I strongly encourage you to
406000	411660	pursue them, but we actually found a much simpler approach to get around this. Through the
411660	419260	power of Spongebob memes. See, under normal circumstances, the AWS API is typically case
419260	425800	sensitive. And what I mean by that is, if you pass a parameter to the AWS API, it expects it in
425940	431300	a very particular casing format. If you don't meet that expectation, you'll get an error. So
431300	437520	to demonstrate this with a completely unrelated API, here we're performing secrets manager
437520	443800	create secret. And that API expects a name parameter with a capital N. So long as you pass
443800	450900	it in that format, 200 OK, everything works, you created a secret. However, if we were to
450900	456520	deviate from that format in any way, in this case we've put it to all uppercase, we try to pass
456520	462640	that to the API, it complains. 400 bad requests, member must not be null. The reason for this
462640	468620	is, well we didn't pass the parameter it was looking for. It might be the right alphabetical
468620	474420	characters, but it's not the specific one and so it rightfully so throws an error. While this
474420	479160	may sound like a fairly obvious thing to point out, the reason it matters is that by
479160	485260	comparison, the AppSync API was a bit of an oddity. It was not case sensitive. We could pass
485260	491000	arbitrary parameters of mixed casing and the API would take it totally fine. Presumably
491000	497380	somewhere on the back end it was normalizing these values in some way. Now, the parameter you
497380	504720	would use to pass a role ARN to the AppSync service was called service role ARN, capital R,
504720	509900	capital A. If you try to pass a role outside of your account, once again, cross account pass
509900	517300	role is not allowed. But, if we change the casing on that parameter in any way, even on just a
517300	522180	single character, in this case we made it all lowercase, and we try to pass a role outside of
522180	527340	our account, for some unknown reason, whatever filtering or allow listing or checking that was
527340	532320	supposed to occur, either didn't happen at all or completely failed. And so by changing the
532320	538320	casing on a parameter, we were able to now arbitrarily specify roles for the AppSync
538320	543280	service to try and assume. And so, we were able to break a major security boundary in AWS
544090	551560	with Spongebob memes. To put this in another, in another context, what this allowed us to do,
551560	558560	was to target any role that legitimately used the AppSync service in any AWS account. We
558560	563600	could now provide that role to the service and arbitrarily assume it and access whatever
563600	569900	resources were associated with it. This is an example of a cross service confused depi attack,
569900	575200	where a lower privileged entity, in this case us, was able to trick or coerce a higher
575200	580540	privileged entity, in this case the AppSync service, to do something on our behalf. And this
580540	586180	scenario, that was assuming a role in a victim account. It's really important to stress, the
586180	590940	thing that makes this possible, the thing that enables this attack, is that pre-existing
590940	597400	trust relationship between those IAM roles and the AppSync service. Because the roles trust
597400	602100	AppSync and because we found a way to weaponize that service against them, this is the path
602100	607740	that allows us to assume those roles in victim accounts. Now, if you've ever done cross
607740	613400	tenant attacks in AWS, you know that assuming a role is only half the battle. From here, we
613400	618540	have to actually do something useful. If we were in a scenario where, say, we had a
618540	623620	vulnerability similar to this, but we were limited to something like S3 list buckets as the
623620	628780	only API call we could make, well yeah, it's not great. Um, I wouldn't be very happy of it if
628780	632960	I was a defender, but at the end of the day, there's very little risk that could be
632960	637900	demonstrated there. The good news for us is that in this scenario, the AppSync service is
637900	643380	more than happy to provide. In particular, AppSync allows you to run arbitrary AWS
643380	650700	API calls. So you now have the full spectrum of API calls that you can invoke at your
650700	657420	choosing. Now for a step by step practical example of how we'd exploit this, as an attacker,
657420	662860	we'd create our own AppSync API. Configure it, set the schema, create our data sources and
662860	667620	so on. Then we would perform that pass role bypass to specify what role in the victim
667620	672960	account we want to assume. And then, under normal circumstances, the AppSync service would
672960	677600	assume the role in our account. But because of this vulnerability, it now assumes the role
677600	683400	in the victim account and carries out whatever API operation we asked it to perform. The
683400	688020	neat thing about this, from a attacker's perspective, is if you've ever done pentesting or
688020	692180	red teaming in AWS, you know that one of the challenges you have is that you're trying to
692180	696160	find credentials with access to things that you care about. And if you can't find them
696160	700880	immediately, how can you move laterally, escalate privileges, find other credentials and
700880	705780	things like that? It becomes a bit of a hassle. By comparison, with confused deputy
705780	711660	attacks, you can just land as the identity of a production application. If there's a
711660	716500	production AppSync API, it has privileges to do whatever that service needs to do. Whether
716500	723720	that is upload S3, write to DynamoDB, read from RDS or anything else. Because we land as
723720	727820	that role, we have access to whatever privileges are associated with it, and these tend to
727820	733700	be fairly beneficial. So no need for weird bloodhound-esque lateral movement paths, you
733700	738420	just pass that role and yow you're in. That's how we can do things like this in this
738420	744220	screenshot, where we dump the contents of a DynamoDB table, cross tenant in AWS, by asking it
744220	749980	to perform the DynamoDB scan operation. If you're interested in this vulnerability and you'd
749980	755600	like to learn more, AWS did release a security bulletin for it, and in addition we have a
755600	760740	blog post with a ton of additional information on conducting confused deputy attacks in AWS and
760740	765980	some things to look out for. Um, the respective QR codes with the arrows will take you to each
765980	771960	of those. Now, before we get to our next vulnerability, it's important that we learn a few
771960	778060	things about assume role with web identity. Up until this point, we've been talking about
778060	785580	plain assume role, which is typically used for AWS to AWS role assumption. As an example, if
785580	789600	you have an AWS account and you would like me to assume a role in that account to do
789600	795840	something, we'd probably end up using assume role. Now, while this is great, it does have sort
795840	802200	of a limitation, in that it requires the entity doing the role assumption to originate from
802200	806940	AWS. And unfortunately, there are a variety of use cases in which you might want to have an
806940	812380	identity from outside Amazon have the ability to assume role in your account. What do you
812380	817900	do? Well, that's where assume role with web identity comes in. The core idea here is that
817900	823140	you essentially offload the responsibility of authorizing that role assumption onto an
823140	828440	identity provider of your choosing. This can be a private identity provider, one that you
828440	833400	or your company own and maintain, or it can be a public identity provider. Think things
833400	840220	like Facebook, Amazon, Google, GitHub, and many others. The sort of core idea here is that
840220	844640	your external users, whether they be human or machine, interact with the identity provider
844640	849860	to generate a JWT, they pass that into the assume role with web identity call, and this
849860	855020	enables them to assume a role in your account. Now, before we go any further, I really want
855020	860340	to stress that assume role with web identity is a general design pattern. A variety of
860340	866020	technologies and services, both native to AWS and outside of it, will use this general
866020	871540	design pattern. In the next couple slides, we're going to use GitHub actions as an example,
871540	875300	just to sort of explain how this works and talk a little bit more about the underpinnings, but
875300	883540	really want to stress, this is not limited to just GitHub actions. To one common problem with
883540	887520	CIC pipelines, particularly if they're outside of your cloud provider, if you're using
887520	892880	something like GitHub actions, well, how do you authenticate to an S3 bucket if you wanted
892880	897720	to upload, say, some sort of build artifact or logs or anything else? Well, we could use
897720	902360	assume role with web identity. To set this up, we initially create a trust relationship
902360	907680	between our AWS account and an identity provider. Since we're already using GitHub
907680	912980	actions, we might as well use GitHub's provided identity provider. Once that trust is
912980	920120	established, we then create an IEM role. And, like I said before, all roles have a role trust
920120	925320	policy, and in that policy, we specify the identity provider as the entity that's allowed to
925320	933440	assume the role. Then, every time our GitHub action job runs, it will retrieve a JWT that has
933440	937980	been signed by that identity provider, that JWT is passed to an assume role with web
937980	942760	identity call, and thus, that job at that pipeline is able to assume the role in our account
943180	948840	and do whatever it wants to do, whether that is upload something to S3 or call any other API
948840	953460	calls. Now, throughout that explanation, you might have noticed something a little bit scary
953460	958120	and thought, perhaps I misspoke, or maybe I said something wrong. And I assure you, it's just
958120	964640	as scary as it sounds. What you see here is the most basic, bare bones, simple trust policy
964640	970280	you could possibly write when using assume role with web identity. And what it says is that
970280	975080	we're going to allow the GitHub identity provider the ability to assume role with web
975080	980040	identity. And that's a really scary thought, because if we think about it, GitHub's identity
980040	986800	provider is public. It's global. Anybody has access to it. There's nothing stopping someone
986800	991800	from creating their own GitHub account, creating their own GitHub action to generate a JWT
991800	997860	signed by that very same provider, and passing that in to the assume role with web identity
997860	1004080	call, allowing them to access those roles in your account. If you had this trust policy on a
1004080	1008780	role, anybody with access to a GitHub account could have just hijacked it and accessed
1008780	1014920	anything associated with it. That's why any time you use assume role with web identity, with
1015100	1021200	a identity provider that is public or global, you need to also have a condition which
1021200	1026600	restricts specifically who is allowed to assume that role. Again, assume role with web
1026600	1031540	identity is a general design pattern. The specific condition you'll need will differ depending
1031540	1036880	on the service and what specific scenario you're in. To continue using GitHub actions as an
1036880	1043240	example, you need to specify what GitHub repo or what GitHub organization is allowed to
1043240	1049440	assume that role. If you're a heavy AWS user, strongly encourage you to audit your roles that
1049440	1054080	use assume role with web identity for this misconfiguration, because again, if you make
1054080	1058380	this mistake, theoretically anybody could just assume that role in your account, which is
1058380	1065100	not optimal. Um, now the good news to all this is this attack that I just described was very
1065100	1068940	much in vogue last year. A number of security researchers, including my own colleague
1068940	1074160	Christoph, identified that this was a potential issue and raised awareness about it. If you'd
1074160	1077900	like to le- learn a little bit more about the GitHub specific situation, uh, we have a blog
1077900	1083900	post with a ton of details and that QR code will take you there. Uh, now to AWS' credit, they
1083900	1088640	actually did something about this. In particular, they made what was once an optional
1088640	1095340	condition, now mandatory. You can no longer create a role trust policy for the GitHub identity
1095340	1100860	provider that doesn't include a condition. And so, that's good. Kudos to AWS, that's a great
1100860	1106720	change. But, if we were to nitpick it, remember, I said assume role with web identity is used
1106720	1111300	all over the place in a variety of contexts, and they only fixed it specifically to GitHub
1111300	1116320	actions. Any of the other technologies or services that have this very same potential
1116320	1121780	misconfiguration were slash are still vulnerable. So again, definitely encourage you to audit
1121780	1127120	your roles. There is one such service that I'd like to dive a little bit more deeply on, uh,
1127120	1134400	and that is Cognito. Uh, Cognito is a sign in as a service offering from AWS. If you want to
1134400	1139160	store user credentials but you don't want to deal with the hassle of uh, hashing, salting,
1139160	1144680	and things like that, you can pay Amazon a fee and they'll take care of that for you. One of
1144680	1150520	the core features of Cognito is something called an identity pool. And an identity pool is a
1150520	1155660	resource you can create in your account that allows you to distribute short-lived IEM
1155660	1162680	credentials to your users so that they can assume roles in your account. As an example, say
1162680	1167260	you're building a web application and you want your users to be able to upload content to S3
1167260	1172580	or invoke an API gateway using IEM off, the way you could achieve this is creating a Cognito
1172580	1177520	identity pool, allowing your users to interact with it, to generate tokens, they would then uh,
1177520	1182060	through a library in the client pass that to the assume role with web identity call and assume
1182060	1188060	the role in your account. The good news about Cognito is that they seemingly foresaw the very
1188060	1193980	same attack that occurred with GitHub actions. They do, by default, include a condition to
1193980	1201420	defend against it. Specifically, the condition will restrict which identity pool is allowed to
1201420	1207020	assume a role. And this is very important because if the trust policy looked like this, anyone
1207020	1211100	in the world would be able to assume that role. And we're gonna talk about some reasons why that
1211100	1217020	trust policy might look like this in just a little bit. Uh, the way that we can take advantage
1217020	1221620	of it is slightly different than what we described with GitHub actions. This is mostly an
1221620	1226860	implementation detail specific to Cognito identity pools. Specifically, what we're gonna do
1226860	1235460	is use a uh, Cognito offload. Offloads are essentially like the, essentially the step by step
1235460	1242140	operations uh, that a user would use to generate those credentials. There are two offloads
1242140	1247400	currently supported, an enhanced offload and a basic offload, sometimes referred to as
1247400	1253120	classic. We're gonna focus on classic because that allows us to actually specify the role we
1253120	1259160	wanna assume because the final operation in this chain is assume a role with web identity. Um,
1259160	1263120	the specific step by steps are as an attacker, we're gonna create our own Cognito identity
1263120	1269500	pool. We're gonna, going to then perform get ID and get open ID tokens to generate that JWT.
1269500	1274160	And once we have that JWT, we pass it in an assume role with web identity call and this allows
1274160	1278780	us to assume the role in the victim account. So for our purposes, for the remainder of this
1278780	1285240	talk, we'll refer to this as the Variant 1 Vulnerable Trust Policy. A trust policy tied back
1285240	1290580	to uh, the Cognito service but not including a condition to restrict which identity pool is
1290580	1295300	allowed to assume it. The reason we call this Variant 1 is because there's a Variant 2 as
1295300	1299580	well. You might have noticed there's actually two conditions on the default trust policy
1299580	1305720	associated with roles using Cognito. And this condition is the AMR condition, or the
1305720	1310340	authentication methods references. And this value can be either authenticated or
1310340	1314860	unauthenticated. You might wonder, could we assume a role if this condition was set? And
1314860	1319700	turns out, yeah, absolutely, we totally could. If the value is set to unauthenticated, then
1319700	1324640	literally everything I just said works completely the same, no changes required. If the value
1324640	1329400	is authenticated, then we do have to jump through some extra hoops. In particular, in our
1329400	1333800	attacker controlled account, we have to create a Cognito user pool, configure it alongside
1333800	1338580	the identity pool, and then from there, basically all the same steps apply with some minor
1338580	1344780	changes. All this condition is doing is checking that you are authenticated to an identity
1344780	1350040	pool, not that you are authenticated to a specific identity pool. And since we can just
1350040	1353480	create our own identity pool, we can configure it however we like, so we can add
1353480	1358720	authentication if we need to. Now, earlier you might have noticed that I called this a
1358720	1363840	misconfiguration, and that's because it is. The GitHub action stuff, this Cognito stuff, any
1363840	1368560	of the other myriad of services which have this very same issue, all of these are
1369040	1373940	misconfigurations, not a vulnerability. Had you suffered a breach, compromise, or other
1373940	1378760	security incident as a result of it, well, unfortunately that would be your responsibility as a
1378760	1383240	part of the AWS shared responsibility model. And so you're probably wondering, well Nick, I
1383240	1387340	was promised a second vulnerability, you're calling this a misconfiguration, what gives?
1387340	1393140	Well, uh, this is where things get weird, and we dive into our second vulnerability of the day,
1393140	1399700	the AWS Amplify service exposing IEM roles to take over. Uh, see earlier this year when we
1399700	1404860	noticed this capability in Cognito, one of the first questions we had was, okay cool, I wonder
1404860	1410100	how common this misconfiguration is. And because it could be used for initial access,
1410100	1414700	literally just assume rolling into victim accounts, we wanted to know if we could use publicly
1414700	1420740	available data to find vulnerable roles and notify their owners so they could be fixed. To do
1420740	1426260	this, we used a tool called Sourcegraph. One of the free features of which is essentially like a
1426260	1432780	Google search, but for public GitHub repos. Uh, we we wrote a regular expression to find IEM
1432780	1438520	role ARNs. Threw that into Sourcegraph, got back results, deduplicated them, removed like
1438520	1442380	clearly placeholder ARNs, like account IDs with all one digit or incrementing digits, things
1442380	1448500	like that. Uh, and that left us with a little over 8,000 results. We then tried to assume each
1448500	1453540	role twice. Once authenticated and once unauthenticated. And we let our automation run
1453540	1459440	and pretty much immediately it was clear, something was terribly wrong. Remember, this was
1459440	1465040	across all of public GitHub. Across teams, organi- organizations, individuals and companies.
1465040	1470880	So, why was it then that the overwhelming majority of roles that we found to be vulnerable all
1470880	1477320	had this weirdly specific naming convention? What you see here on the slide are real, re-
1477320	1482460	real roles that we found in the wild that were vulnerable that we have slightly modified the
1482460	1487920	names of so as to respect the anonymity of their owners. Now, what made these roles so weird
1487920	1492940	was that they all ended in either auth role or unauth role. And additionally, they had what
1492940	1498780	appeared to be either a time stamp dating back to 2018 or 2019 or they had a six digit
1498780	1504100	integer. Presumably, these were the newer ones. To make things even more weird, as we were
1504100	1510360	going through the results, we actually found three roles that belonged to AWS themselves. And
1510360	1515040	so at this point, it wasn't clear if this was some sort of, uh, tutorial gone wrong where
1515040	1520040	somebody was demoing how to set this up with OIDC, not realizing that it was vulnerable and
1520040	1525800	letting anybody just assume these roles in anybody's account. Uh, using source graph, we
1525800	1531220	were able to see the name of the file where these roles were being found. And again, the
1531220	1537560	overwhelming majority were found in files called team provider info dot Jason. And through
1537560	1543300	this, this led us ultimately to the culprit. The thing that was causing all these roles to let
1543300	1551200	anybody assume them. Turns out, it was AWS Amplify. Normally, when we're talking about a
1551700	1556020	misconfiguration, we're talking about a mistake, misunderstanding, developers moving a little
1556020	1560280	bit too quickly and breaking things, or not realizing that something is as vulnerable as it
1560280	1567000	actually was. This was a rare circumstance in which an AWS service itself was exposing IEM
1567000	1571480	roles, such that anyone could assume them. The vulnerability was not that you could
1571480	1576340	misconfigure roles, it's that AWS was doing it to you. And fortunately, not just once, they
1576340	1581980	actually did it twice. If you're not familiar with Amplify, Amplify is a uh, web and mobile
1581980	1586620	application framework that lets you build these technologies. Uh, one of the core selling
1586620	1592700	points to Amplify is essentially that uh, by using Amplify, it will abstract away a lot of the
1592700	1597660	underlying infrastructure. So, if you build a web application and you want your users to be
1597660	1603160	able to create accounts, sign up, change their password and so on, your developers don't even
1603160	1608800	need to know what Cognito is. They can simply add authentication through Amplify, and Amplify
1608800	1614940	goes in, creates Cognito resources, configures them, sets them up, and so on. Key emphasis,
1614940	1621000	Amplify configures those Cognito resources. Now, there's two ways you can build an Amplify
1621000	1625360	app or configure them. Uh, they're not mutually exclusive, you can use either or. Uh, there
1625360	1630700	is the studio, which is the web console portal equivalent, and then there is the CLI, which
1630700	1635940	you can run from your local machine, or as a part of your CICD pipeline. Now, typically when
1635940	1639960	we do cloud security research, one of the challenges we often have is, it's not really
1639960	1645180	clear why this vulnerable behavior is occurring. We might be able to see that something has
1645180	1650380	security impacts, but it's not clear what exactly happened or why it's doing this. For example,
1650380	1654820	with the first vulnerability, for some remarkably strange reason, changing the casing on a
1654820	1660240	JSON parameter let us break a major security boundary in AWS. So we run into these types of
1660240	1664680	scenarios fairly frequently. What's neat about this Amplify vulnerability, and why it's
1664680	1669580	personally one of my favorites, is that this is actually a rare instance where we are able to
1669580	1675440	know not only how did this become vulnerable, but when. That's because the Amplify CLI
1675440	1681420	written by AWS is actually open source. And by digging through the commit history, we can
1681420	1687040	see how and when these vulnerabilities were introduced. And we didn't know at the time, but
1687040	1692740	later on in speaking to AWS employees, we came to find out that the Amplify Studio, the web
1692740	1698680	console equivalent, actually uses parts of the CLI as libraries. And that's how I can tell
1698680	1704180	you with confidence that both the Amplify Studio and CLI became vulnerable on or around
1704180	1710640	July 3rd, 2018 to the Variant 2 Vulnerable Trust Policy, allowing anyone in the world the
1710640	1716260	ability to assume these roles. What happened here is that any time you create an Amplify
1716260	1721760	project, two roles are created for your account. An auth role and an unauth role, like we saw
1721760	1728800	previously. Unfortunately, as a part of this commit, the default trust policy associated with
1728800	1733880	those roles was set to this, which would allow anybody in the world to assume them. So if you
1733880	1738240	thought you were building a private, internal only application that required authentication
1738240	1742440	and you were gatekeeping who could create accounts so that you could protect your stuff,
1742440	1748300	well, um, sorry, no you weren't. Anybody could just assume those roles and access whatever was
1748300	1754380	associated with them. Like I said, that was introduced on July 3rd, 2018. A little over a year
1754380	1762220	later, on August 8th, 2019, AWS sort of fixed this issue. Uh, seemingly unintentionally. What
1762220	1767500	they did was they set the default effect to a deny and they removed the condition entirely.
1767500	1773720	This is actually the exact same behavior we see today when creating a new Amplify project. It's
1773720	1778720	really important to stress, though, that what this change did in August of 2019 was make it so
1778720	1785120	that no future roles would become misconfigured. Any that had already been created were still
1785120	1792020	vulnerable and that's how we were able to assume them in 2024. Later on in July of 2020,
1792020	1797120	variant one was introduced to the Amplify CLI in studio. And this one was a bit more complicated
1797120	1802440	than the previous one. What happened here was that, uh, like I said previously, you can add
1802440	1808380	authentication to an Amplify project. If at any time you chose to remove authentication for any
1808380	1813700	reason, that would introduce the variant one policy. Uh, in speaking to developers who were
1813700	1818520	affected by this, it seems the most common reason that this occurred was situations in which,
1818520	1825640	uh, uh, projects started with the built-in Amplify controlled Cognito resources and then at a
1825640	1829300	point, uh, went to Cognito outside of Amplify or to just a different identity provider
1829300	1834280	entirely. Regardless of the reason why, what occurred was that a cloud formation template
1834280	1839540	would run that would start setting the default trust policy to what you see on the slide,
1839540	1845780	which is totally fine. This is the secure trust policy. However, under the line, uh, under the
1845780	1850460	condition for the deletion of the authentication configuration, there was a line to delete the
1850460	1855560	condition off of the trust policy, which left you with this. The variant one vulnerable
1855560	1861620	policy. Whatever identity permissions were associated with this rule, when this exposure
1861620	1867260	occurred, it still had access to. So, if your rule could do something like, uh, read from an
1867260	1872700	S3 bucket, write to a demo deep table, it still had that access. Additionally, at the end of
1872700	1878540	the day, these are just plain IEM rules. And unfortunately, developers love to over-privilege
1878540	1884180	their identities. When we were reacting to this vulnerability and notifying customers so
1884180	1888380	they could mitigate it, we found a number of customers who had highly privileged roles,
1888380	1893840	including some with S3 full access, Kinesis full access, and more. Unfortunately, as a part
1893840	1897740	of this vulnerability, now anyone could have just accessed them and then accessed whatever
1897740	1904120	resources were associated with those accounts. Uh, like I said, that was introduced in
1904120	1908800	July of 2020, and then between then and when we eventually disclosed in 24, more and more
1908800	1914000	rules were becoming misconfigured. One thing I'd really like to stress, uh, that makes this
1914000	1920420	Cognito issue even more extreme, is that Cognito role ARNs are easily discoverable. If we
1920420	1924400	compare this to the first vulnerability we talked about today, a confused deputy vol in some
1924400	1930160	AWS service, an adversary still has to contend with the challenge of finding role ARNs. To be
1930160	1935040	clear, an ARN is not a secret, not in the same way a password or API key is, but it does
1935040	1939820	represent some level of challenge. They would have to brute force them, enumerate them,
1939820	1943940	derive them from IAC, pull them out of build logs, rip them out of GitHub like we did, or a
1943940	1949380	myriad of other ways. Suffice to say, it's something you could do across, say, a small
1949380	1953820	number of organizations, but not something that you could easily scale to the size of the
1954380	1958980	internet. By comparison, the whole point of Cognito is that these roles are supposed to be
1958980	1963410	available to your users. They're basically public. And in addition, they're also
1963920	1967560	deterministic, in the sense that if you know the unauth role, you now also know the auth role
1967560	1972100	by default. And so what an adversary could have done is simply taken advantage of the
1972840	1977700	default domain associated with Amplify apps to suddenly crawl tens of thousands of apps
1977700	1982980	looking for vulnerable roles. And to be clear, the majority should be fine, but undoubtedly
1982980	1988320	some number of them were created between July, or sorry, uh, 2018 and 2019, or who have
1988320	1995180	since changed their authentication configuration since July of 2020. Like I said before, we
1995180	2000360	did disclose this to AWS in January of this year, and AWS released comprehensive fixes in
2000360	2004540	February and April. Uh, they did the same thing they did with GitHub Actions, where you can no
2004540	2008760	longer create these vulnerable trust policies anymore. But in addition, they sort of went
2008760	2015080	above and beyond. Specific to this Amplify issue, they actually made changes to STS so that
2015080	2021220	you can no longer assume a role cross-account in AWS. So even if you had a variant 1 or
2021220	2026180	variant 2 role in your account, somebody from a different account can no longer assume it.
2026640	2030520	If you'd like to learn more about this vulnerability, AWS did release a security bulletin
2030520	2034700	for it, and we have a blog post here with a ton of additional content and information on
2034700	2039100	carrying out these types of attacks, how we found this vulnerability, and more advice on
2039100	2045640	dealing with assume role with web identity. Really quickly though, I did want to mention, um,
2045640	2050020	throughout this talk, we have been focused on creating resources in an attacker account so
2050020	2055420	that we could then victimize a victim account. The reason for doing this is simplicity. If
2055420	2059560	you own the resource, you can configure it, you can set it up however you like, you know it
2059560	2064020	will always be available, you can troubleshoot it, but I wanted to mention it's not strictly
2064020	2070940	required, it's just easier. Specific to the Amplify vulnerability, they fixed cross-account
2070940	2075400	role assumption using identity pools. It's no longer possible for me to use one of my
2075400	2080400	identity pools to assume a role in your account. But they didn't do anything about the same
2080400	2085760	account scenario. And to be clear, I don't really think there's much they could do. Uh, the
2085760	2090500	reason they were able to block cross-account assume role using this is, well that's, that's a
2090500	2097180	very weird thing to do. It's very likely zero if any real organizations were doing this in
2097180	2101060	the wild. And so they said hey, we can just block this off, we can fix this attack vector
2101060	2106320	and we'll mitigate a lot of the risk. But you can still absolutely do this in the same
2106320	2111960	account and this is something that you can still take advantage of today. Um, to be clear,
2111960	2116040	this is more difficult, things are much nicer if you can just bring your own identity pool,
2116040	2120320	but it's definitely something to be aware of if you are penetration duster, red teamer, or you
2120320	2126060	simply use Amplify a lot. The way this would work is that if there is a variant one or variant
2126060	2132280	two role in that account, if there is also a identity pool that is configured with basic
2132280	2137700	authentication or the basic offload, not necessarily associated with Amplify, just any
2137700	2143420	cognitive identity pool with that enabled, you as an external adversary can still interact
2143420	2147980	with that identity pool, generate a JWT, pass it into Sumo with WebIdentity, and still
2147980	2153100	assume one of those variant one or variant two vulnerable roles. Um, in the bottom left
2153100	2157140	hand side, there's a QR code that will take you to a Hacking the Cloud article that will walk
2157140	2162160	you through step by step how you can do this in both authenticated and unauthenticated
2162160	2167800	environments. With the time we have left, I wanted to talk a little bit about what we can do
2167800	2173660	to prevent cross tenant attacks in AWS. To be clear, uh, your time is probably much better
2173660	2178680	spent doing things like deleting old access keys, uh, cleaning up old IM users, following
2178680	2183220	least privilege, and so on, but if you're already doing all those things, or you have the
2183220	2187400	technology and processes in place, it might be helpful to know that we do have some controls
2187400	2193260	that can potentially prevent some of these attacks. In particular, AWS offers us a number
2193260	2199420	of condition keys that allow us to restrict essentially where an adversary is coming from.
2199420	2204540	Sort of similar to what we saw with a Sumo with WebIdentity previously. These conditions
2204540	2210060	allow us to restrict either the ARN, the account, or the organization that is permitted to
2210060	2215040	assume a role. It's really important to stress, these are not included by default, uh, if you
2215040	2218820	were to try to create an instance profile today, it wouldn't automatically add one of these,
2218820	2223080	so you would have to manually attach these conditions to each role you want to assume, or
2223080	2227960	want to protect, and more importantly, make sure that those services are compatible with
2227960	2233240	these condition keys. From some nominal testing, EC2, Lambda, AppSync, all work totally
2233240	2238440	fine, but again, really encourage you to test before you try pushing this into production. To
2238440	2243580	demonstrate how this would work in practice, uh, using source account as an example and
2243580	2248880	tying us back to the first, uh, confused deputy attack we had in AWS, uh, by exploiting this
2248880	2253320	vulnerability, an adversary would be able to assume a role which trusted the absent service.
2253320	2259740	But if we had set a condition key on that trust policy, limiting what AWS account is permitted
2259740	2265560	to assume that role, it would successfully block that adversary. The way we know this is back
2265560	2269180	in the day when this vulnerability was present, we were able to actually test setting that
2269180	2274740	condition key, and it did successfully block an external adversary. So even in that worst
2274740	2279600	case scenario of someone having a cross-tenant zero day in AWS, by setting this condition
2279600	2285280	key, we can block that access. The other reason I like this is from a defense in depth
2285280	2290660	perspective. If pass rule says, under absolutely no circumstance should someone be able to
2290660	2295780	assume a role cross-tenant, well great. We broke that with Spongebob memes. So the next time
2295780	2300640	that happens, or if somebody finds a more inventive way around it, let's have an additional
2300640	2306100	layer of protection to block these types of attacks. You're also unlikely to run into many
2306100	2311600	issues. If it works, it's very unlikely to cause, uh, problems. It's, this is more of a static
2311600	2317000	thing that stays the same over time. So in conclusion, we took a look today at how confused
2317000	2322500	epi attacks can weaponize cloud services against us. We took a look at a very dangerous
2322500	2327300	misconfiguration when using assume role with web identity. And again, I strongly encourage you
2327300	2331800	to audit your roles that use it, because if you make this mistake, theoretically anybody can
2331800	2337020	assume roles in your account. It's an easy mistake to make. AWS actually made it twice. Um,
2337020	2342180	and then we also took a look today at how we can use, uh, condition keys to block confused
2342180	2346580	epi attacks in AWS. If you enjoyed this talk, you can find more of our research at
2346580	2351380	securitylabs.daydoghq.com. If you have any questions, feel free to find me after or reach out
2351380	2355220	to me on social media. Again, my name's Nick Furchette. Thank you all so much.
