06:00 UTC Charta Aetatis Cyberpunk

Console Newsletter Pro Sign in Early access Register
Aa · Display
Themes
Type size
Density
Cloud & Identity · fwd:cloudsec · · 24:49 runtime

Out of Context: What's Really in the AWS Request Context

In the wiki Amazon Web ServicesAWS IAM
Transcript 3663 words · auto-generated captions

Machine-transcribed by YouTube. Expect errors in names, commands and version numbers.

So, thank you everyone for joining me in this great conference. Today, I'm excited to share my research out of context or what's really in the AWS request context. I'm sure most of you have either seen or written this policy. And I really like AWS's IAM engine because it allows us to write very good and very configurable policies. So, for example, the policy on screen allows us to to write a policy which allows S3 access from a specific VPC. And this is allowed using a condition block.

One of the most important parts of the IAM policy. The condition block evaluates the real AWS request context, which is gathered behind the scenes, against the value that we specify. In this case, my VPC ID. But, I guess many of you have not seen the actual request context up until a few weeks ago. This case. And this is what I'm about to talk

So, first, let me introduce myself. My name is Dan Genzel. I'm a security researcher at Upbound Security. I'm based in Tel Aviv. And fun fact about myself is that I've been learning German on Duolingo for almost 2,000 days.

The agenda for today. Basically, we'll take a look at an offensive concept, something attackers have been using, and see how we can turn it into a defensive mechanism. Then, we'll look at undocumented keys and which policies they allow us to build that aren't easy to build today. Finally, we'll move on to key takeaways.

So, the offensive case, a use case that I would like to talk about, is a research by Ben Bridts, which showed the world in 2021 how attackers can get the the account ID

of any S3 public bucket. Basically, it did so using this technique. It created a binary signal using a role or API call. Basically, you have a role which allows S3 access to a

public bucket, and using the session policy, a policy that we control in the way, we can use the session policy to allow all actions, but deny it in case

the S3 resource account starts with a specific number. And then we make the call against the S3 bucket. And when the request succeeds, it means that the account ID does not start with one, and the deny did not evaluate. But if the request gets access denied, it means that the deny did evaluate, and the account ID does start with one. And then we can continue enumerating numbers. So we know that it starts with one, and then we try one and then zero, and it succeeds. So it means it's not the case. Then we get the deny with one, with two, and basically we start building the full account ID.

So I was thinking, there is a use case to use it as an offensive thing, but can defenses also use this? And the answer is yes. I found a problem statement. Basically, currently we as defenders write policies, but we don't really have visibility into the context values, and thus we can't really effectively debug our policies. Basically, we sometimes write policies which are supposed to deny something, but eventually allow it, or allow something but eventually deny it, and we don't really have the ability to debug them well. So I took the primitive that Ben Brid showed, that having API access to something and a policy that we control in the way, to get any request context value, in order to create a solution which actually allows us to build the full request context, and basically gets the visibility into all of the values.

So, I created a prototype tool for that.

Basically, at first, my tool gathers all

the available condition keys for an action. So, in this case, it would be a KMS encrypt action. Then, it would would use the null operator, which allows us to understand which condition keys are absent or present at the request time to understand which condition keys we'd like to get the values for. So, basically, we have 40 candidates and out of those 40 candidates, which are composed of both global and service specific condition keys, only 20 are actually present. Then, we can use the enumeration technique or the binary signal that we we showed earlier in order to get all of the values. So, for example, if you have a principal that doesn't know the org ID, we can use the technique to enumerate it or in what we

will see on the screen, the resource already, the resource that we want to inspect, we can actually achieve that.

This also helps us to understand values that basically deal with something that is not properly documented or we don't expect. So, in 1 second, we'll see the KMS encryption algorithm, which is a value that we may not know the value for. And basically, using the enumeration technique, we can get the full value, which in this case would be symmetric default.

And then, we would achieve the full output, which looks something like this.

So, this was decoded probably like 2 weeks ago in August 25th. And I wrote my CFP document back in early July and I was saying that basically consider this presentation as a sort of a plea to AWS to give us a sort of a native tool to inspect our own

request context. And would you believe it? 12 hours after recording this video of my prototype tool, AWS has actually released it. Kudos to AWS. They have released a troubleshoot access analyzer of the request context and the policy that actually denied your call. This is something that is still in preview, but it's a great addition and I'm really happy that they did that. Unfortunately, it currently only supports APIs in IAM and it only evaluates for deny actions. So, an action that was allowed, you wouldn't get the context value for that, unfortunately. So, this is it for the documented part of the talk. But, what about undocumented condition keys?

Basically, doing this research, I looked at many policies. And one of them, AWS SSO service role policy, included a condition key called AWS principal org master account ID.

If you look at the global documentation of AWS, you wouldn't find this condition key because it's not there. Which means that AWS has in the IAM engine basically policy condition keys which evaluate, but are not quite documented. And the problem is to find them. But luckily, there are two primitives that AWS natively supports that allows us to find these undocumented condition keys. The first one is that the AWS IAM engine accepts any

context view value as something which is valid. So, for example, here AWS ABCD test source VPC is a valid condition key. This is an intentional design behavior for forward compatibility for basically allowing future keys. And the second primitive, which we have already discussed, is the null condition operator, which allows us to understand whether a condition key is present or absent at the request time. So, combining these two primitives and the approach that Ben Breed showed us, we can do something similar. We could have a role which is allowed to do a certain action. And then, when we assume the role, you would create the session policy which allows all actions, but denied in case the null operator is not

false in case of our candidate key. And thus, if the request is allowed, it means that the deny did not evaluate and the key is not present. But, if it's denied, it means that basically the key is populated at the request time. And this is something interesting. So, using this binary enumeration search, we could basically uncover those undocumented condition keys.

And what we found? Well, we found three dozen new condition keys after testing more than three dozen million ones. So, uh you you would be the judge of how successful this was. And just a small section about how we assemble the key collection. Basically, we used the documented part of AWS, both of free co- or both of co- uh condition keys that were pattern that we found over there. Brute force in order to understand short condition keys. Uh we'll see them in a second. AI invented ones. Basically, AI uh took its creativity to the best and basically generated a few patterns which we could test and finally information that we found in cloudformation schemas.

So, the condition keys that we found really separate into three main groups. The first one being general request properties. Basically condition keys which are global, which give you information about the request that was made. So, for example, we have information that we didn't really have as of today. Uh the best example for that would be AWS principal org master account ID, the management account ID by AWS, but also

very interesting other information. So, for example, there is sort of a decomposition of certain values. So, if

you make an S3 get object action, the AWS action value would be S3 get object.

But, it could also give us uh the values of the decomposition of that. So, AWS name would be get object and AWS service

would be S3. The second group is unique identifiers. Basically service specific identifiers of resources across almost two 20

services. And the third one is others. Those that service specific condition keys which really didn't fit in any of the other groups. For example, S3 current policy status is a condition key which allows us to get the block public access setting of a specific S3 bucket. But, finding those condition keys is very nice. But, I wanted to understand whether it has some practical um like practical information or practical use that we can basically uh create new policy or I am enablement that weren't possible today. And I found a few a few problems or four problems that we could tackle.

But before we begin, I would like to say that you should use this with caution. Basically, these are undocumented. This could change at any time and weren't empirically tested in except for my test account. And the policy that I'm going to show is the test policies that I wrote specifically for a specific use case. The first problem that I'm about to tackle is that we currently can't create a unified policy with for a subset of actions across different services. What do I mean by that? Basically, the best example to show that would be AWS's own managed read-only policy, which currently has 187

versions, consists of almost 3,000 lines, and needs to be maintained continuously. So, when AWS launches a new service, they have to basically create a new policy version to add the API that was added. So, when harnesses were added to bedrock agent code, AWS had to add list harnesses.

Also, the read-only would not be suitable for everyone in this room because it may potentially expose sensitive data. So, for example, it includes Cognito identity get open ID token, which potentially exposes tokens.

The solution for that would be to use AWS name. AWS name is this name of the

API that is being called, so without the service prefix. So, if we take an example for S3 get object, the value would just be get object. And we could write this policy, which allows every single action, but on the condition that the action name starts with either get, list, or describe. To tackle the second problem, we could deny sensitive actions preemptively. So, we'll write a deny policy, which denies all actions which include the name secrets, token, or password in it.

The second problem is that we can't really enforce token freshness or just-in-time access. What we have today is the maximum session duration, which is a minimum of 1 hour, and basically only caps before the assume role. So, it doesn't revoke. The second thing we have is AWS token issue time, which is a fixed date, and is not really comfortable to work with. The third thing, which is the closest, is AWS multi-factor off age, which requires MFA infrastructure, but is very close because it's the number of seconds that have passed since the tokens were issued. The solution would be to use AWS token age, which is the number of seconds that have passed since the temporary credentials were issued, but without MFA infrastructure. And we could write policies such as this, which deny all actions for tokens which are like which have been issued over 5 minutes ago.

This could really improve our life to enforce token freshness for sensitive actions. So, for example, state-mutating actions or delete actions, admin actions, we could cap their lifetime to 5 minutes, for example. And could probably help us write resource-based policies as well, because we could cap specific paths in S3 to a limited time. The third problem that I was about to tackle is one that AWS have been tackling themselves. We can't really reference the management account without hardcoding it. And AWS's own use case basically says that SSO can provision roles in all accounts but the management one. And if we wanted to write it as of today, we would have to expose the account ID across our policies in every single account. And it doesn't also scale well across different organizations. So, if you have a couple of AWS organizations, we would have to hardcode it in every single one in our Terraform modules.

But AWS solves it using AWS principal org master ID. Which makes the policy look something like this, a dynamic control.

The fourth and last problem that I I'm about to tackle is that we can't really differentiate between public and non-public S3 buckets.

And the case study is that if we have S3 buckets which are intentionally public and we would like to deny certain actions on them. So, for example, we would like people to be able to access them using get but would not to put objects in them, then we would have to maintain a list of all those public buckets or either tag tag them. But again, this doesn't really scale well. However, S3 current policy status gives us the block public access setting of our S3 buckets and is a dynamic control

and a real-time control which can help us write a policy such as this which denies all put object actions to buckets which are public. I couldn't really help not putting something offensive in this presentation. So, let's do something about that. Basically, we can combine Ben Bridgers' research about finding the account ID of any public bucket with AWS resource org master account ID which gives us the management account ID of any S3 public bucket. So, keep your public buckets minimized. uh do public block access setting, and minimize your resource exposure. So, what are the key takeaways from this presentation? The first is that I should have asked for a million dollars in my CFP.

But, then again, I got to my wish and AWS launched a first-party tool to inspect the request context, which is really interesting. It's a great improvement. It lacks a bit of capabilities as of now and still is in preview, but I'm really happy they did that. The second thing is that request context is actually richer than the docs suggest and as we know. Basically, we couldn't really inspect it as of today and now we

know what are the values in it and we know that there are secret conditions over there. And regarding the secret conditions, you know the technique how to find them. You can easily find them today and I would be happy to hear if anybody finds anything interesting. And then again, these policies also unlock new policy capabilities, which could help improve your IAM policies that you write today. So, with that, I would like to thank you all for coming to my presentation and listening and I'm happy to answer any questions.

>> Yeah, in the middle. Oh, thank you. >> Thank you a lot for your the talk. Yeah, I'm just here in the middle. >> Yeah. >> so, yeah, I was wondering if there is a way to avoid the enumeration

process by having like policies that say

if there is uh call that try to do something with the wildcard many times on the enumeration, then we shut down the access or deny the access. So, because all you have been presented is based on this idea and you have been able also to do your research based on this idea, can we take it as a defensive way to protect against uh

malicious actors that want to discover some IDs in our um

accounts and other resources?

>> So, I'm not sure I understood it correctly, but I will still answer. Basically, once your resources are not public or somebody can't access them, then that's defense enough. Because like the primitive that we have over here is that if somebody has API access to your resources, then they can do the all those sort of basically all those sort of reconnaissance operations. Hopefully, that answers your question, but if not >> But in the case we have public resources, do we have a way to um deny access to people that try are trying to get this information? >> So, for example, if you have like a public bucket which is intentional, then you would not have a way to stop the reconnaissance, but you'd see like somebody accessing your resources, but then again you wouldn't be able to differentiate it from like normal access.

>> Okay. Yeah. Mhm. Okay. >> Uh there's also a question from Slack.

Uh so, David is asking any insight on

how the S3 bucket status key interacts with the account level block public access setting? >> So, again, this was not really empirically tested. I can say that some public buckets that I've inspected did not have the the public value. They had non-public. So, that's for further testing. >> Thanks. >> So, you were enumerating uh the undocumented uh context keys. Did you trigger any protections from AWS IAM to stop you

basically doing this reconnaissance? >> Sorry again, I didn't quite hear. >> Did you trigger any blocks from AWS while you were doing this reconnaissance cuz you're like spamming the system with requests? >> Uh no, AWS did not uh like I reported

this to AWS, but they didn't like notice me doing it because it's well like normal IAM calls within my own account. So, basically it it was all like all of this is intended functionality.

>> Uh great presentation first of all. Um just one question. So, you mentioned the ability for public storage bucket to see the account ID. There's also a very similar API called get access key info which can do it for any AWS keys. Do you consider the account ID being sensitive that attackers can discover it? What can they actually do with just the account ID? >> So, uh basically you're right and AWS's

own uh documentation really specifies that account IDs are not a secret and

are not sensitive value. But then again, it doesn't it doesn't give you any access, but it's very good for reconnaissance purposes. So, I don't consider that a secret, but there have been cases for example for bucket squatting techniques and basically uh targeting a specific cloud cloud account ID which it could help you, but it doesn't grant access as is. >> Okay, um one one follow-up question if I can. Um the token age concept that you mentioned was was really interesting. So, if it's denied in that case, right, would the user or the non-human identity be forced to reauthenticate or is there a concept of like a refresh token and access token? I'm more familiar with the Microsoft side, so I'm not sure if AWS has that concept, but is there a way for that token to expire, but then the service to get a fresh token? Or or how would that work?

>> Could you repeat that? >> So it So for example, your example had the 5-minute, you know, expire the tokens, right? So what would happen in that case? That token would be denied, but the service that tries to Would it be forced to reauthenticate to get another token, or how would the flow continue? >> So you get denied and like your tokens maybe would be good for like AWS STS get caller identity, but you'd practically you'd have to like reauthenticate. >> All right, thank you. >> Yeah, one last question. >> Have you thought about taking your approach and extending it to other areas of the console that have custom policies with uh a large number of limitations like the OpenID Connect provider?

>> Uh what What was the last sentence? >> The OIDC provider. >> So it's like a massive self-host to research, so again, one of the like one of the things that I wanted to do in this talk is to give all of you the tools to further explore it because I'm just one me and Claude and uh Yeah, there's a limit to what we can do, but definitely there's more to explore. >> Do you have any plans to continue with your method in other areas if you can tell us? >> Uh as of this moment, there is nothing like practical, but then again, maybe an idea will pop into my head as this one did.

>> Awesome. Thank you so much, Dan. And >> Thank you.

Related videos

Discussion
0 comments 0 from AI Characters · 0 readers

Sign in to join the discussion.

Make the first comment.

That's Cyber for today

Tomorrow's desk, in your inbox by 06:00 UTC. The week's best stories, every Sunday. The month that mattered, on the 1st.

Drawn from the 538 sources the paper read this month. Text and HTML, one-click unsubscribe, free.

How often
Your desks