All right, thanks Jeff. We're here to talk about temporary credentials, right? Here's a little bit about me, but problem is I've got about four hours of workshop content that I squeezed into 32 minutes of talk, and we got 29 now, because Jeff took a minute out of my time. Thanks a lot. So I'm gonna talk at one and a half speed, right? So listen quickly, you know, wake up. If you leave in the middle, I'm gonna be pissed, right? All right, so let's get to it. Basically, to understand temporary credentials, let's just jump into a simple attack scenario. So I've got a recorded video. Let's just go through that. Then let's switch to defender viewpoint and see what the heck difference it makes, right? And the whole premise is it makes some difference. Both sides need to consider it. And then we'll wrap up with do's and don'ts, all right? So here's the basic scenario. Nothing super fancy. All you guys, I'm sure, have encountered worse or done worse, but we're basically gonna start with a compromise key. We're gonna generate a temporary credential, more for backdoor access, though I could use it right off the bat. Then I'll use that to escalate privileges and get access to a bucket, right? Okay, so let's move on. So here we'll start the demo and I'll talk you through it. Promise it's not huge. We'll start with credentials. And as we all know, it's not hard to find credentials these days. Whether you're on Pastebin, you got GitHub check-ins, you've got Gist, and of course you're harvesting or taking them, right? Plenty of malware still doing that. So that's not a problem. We've got a temporary credential. And for those of you who've worked with access keys, API keys, it's pretty much the same. I said environment variables, cause I'm gonna show CLI, but this is my compromised credential and starting point. All right, so let's continue on. So first thing I'm gonna do, I'm gonna immediately generate some temporary credentials. This'll make more sense as we get into the fact on the defensive side. I'm showing command line. Normally I'd run some Python code, but command line's good, nice and concise and fairly descriptive, right? So get session token off the STS service. If you can read the JSON, just two fields are what you expect. You get an access key ID and you get the secret, which is what a normal access key looks like. Then you've got the session token and expiration. When I called it into the API, I set the expiration time. We'll get into what those are, but it can be up to 36 hours, minimum 15 minutes. All right? So right now at this stage as an attacker, I've got backdoor access and we'll see why it's hard to control and manage this from the blue side, right? But I've got another credential. I've got two, the compromised one, and then right off the bat, I generated another one. And functionally, it's pretty much the same. 99% privileges access, right? All right, so let's continue on. And well, I don't know anything about the environment, so let's do a little bit of discovery. So again, we're going to do a very simplified version. Let me pause this here. Bunch of CLI commands are very oriented to IAM. I want to find out what user IAM, what groups, what roles, what policies apply to me, because I'm looking for escalation privilege, right? Pretty basic. I would normally enumerate a lot more. Do I know EC2 instances? Do I know what buckets are there? Blah, blah, blah. And so a lot of code out there to check yourself as well as to utilize if you're on the red team side, right? So nothing big and fancy. I'm going to take a look at the output and pull just some of the salient pieces. And so I can barely read my screen, but at the top, right, I had an access key. Oh, it's JenkoTempUser. That's the actual username. I've got the account ID, super useful. I'm going to be exploring the environment. I'm going to need this in other API calls. Basically, I start to look through this, and I mean, no one reads JSON in their sleep. This is a pain in the ass, basically, right? But the point is I'm looking for what policies are attached right off. And boom, I start to see stuff that hints at bucket roles, right? And assuming bucket roles, which is an elevation, right? It's our cloud version of sudo wrapped in some other stuff. So let's just keep going and taking a look, because basically at the end, there's a lot of verbose information, but basically I can assume a role, right? The user that I've compromised credentials can assume this bucket role, which has a policy and there's a JenkoBucket6. And so I'm happy. Man, this looks interesting. Now it's only one bucket. You can see the policy, but it's a little bit wide open because it's S3 colon star. So you could argue Blue Team's done maybe a little bit bad of a job here, but it's not horrible. It's one bucket and all the objects there, all right? Maybe it's a support guy that I got keys off of or something like that, a dev engineer. All right, so now that I've got a little bit more information, basically all that JSON I've tried to distill, what are the important relationships, right? You think our discovery tools could visualize a little bit better. Basically we're saying, look, I've got a compromise key. I'm going to call it A instead of the 50 characters. So we all know what we're talking about. That key that was compromised, I found on, let's say, Pastebin. I used, and I know it relates to JenkoTempUser. It was created underneath that user. It happens to be able to assume role, right? To a bucket role. Man, these guys are next door. We got to tell them to be quiet. And that has access to this bucket, JenkoBucket6, right? That's basically the path that we're going to exploit, right? With what looks like to be a hole in escalation of privileges here. So just to test though, I did try to access the bucket directly with my compromised credentials, right? There's a hint that I have to escalate privileges, but let's just make sure that bucket's not public to begin with, right? I mean, so why bother? Let's go after it. But I can't, I got an error just doing an LS on the bucket. So great, let's then think about the exploits. So taking that relationship, the actual exploits more in terms of API and flow more looks like this, right? You're basically going to make a call to the STS service doing an assume role. And the way that works is you receive yet another new temporary credential, which when used takes that assumed role in terms of permissions, right? Then you're going to use that with your regular API calls. Great, pretty easy. Sounds pretty straightforward to me. Real scenarios, there's a million of things, right? We might be going after EC2 instances. We might go after logs. We might be putting in lambdas. We'd be doing a bunch of things. Right now it's super simple, but everything we talk about today should apply, right? In terms of temporary tokens. So let's keep going. So next thing I'm going to do is actually assume role, right? So if you can make out the command line, basically another call to STS and assume role. And what I get back, again, just looks like another temporary credential, right? Same thing as my first attempt. My first attempt gave me a little backdoor count. Now I have assumed role and I get another temporary credential. Let me call it A prime because I used, you know, the original compromised credential A and that I'm calling A. And this gives me an A prime with elevated privileges. Great. Set some environment variables if I want to use it, but for the actual next step, copy, paste. I'm going to use a CLI. And now when I do the actual bucket command, boom, comes back, right? Makes sense? Basically on the left, I've just fulfilled that whole path. So no big deal. And unfortunately, it's like, if you want to do CLI, it's not that bad to do it. If you're doing Python, you'd wrap in a few Python commands. And all we've shown is that we started with compromised credentials and we escalated. So, so far, nothing big, strange and new, right? I did generate temporary tokens. So we're going to now flip to the defender side to see what difference this all makes, okay? So... Ahem. Sorry, reset here. So let's go to the defender viewpoint. So basically, put on your blue hat for a minute. We've had an incident like we just went through, right? You're catching up with it. You're at least 20 minutes late because we all know CloudTrail has a lag that they document, right? 15 minutes to get the API logged and five minutes at least to get to the bucket. You're already late by the time you pick it up out of CloudTrail. Okay. But your team is not terrible. You've got AWS experience. You've got logging in place, some kind of alarms, CloudWatch, your SIM, whatnot. You got a little bit of a gap though. You haven't really studied up on temporary credentials. So we're going to go through and sort of, with me and you putting on your hats, try to see what effect this makes. So what's our starting point? Well, you know, two obvious ones. Someone tells you from outside that your data's up on GIST or whatever financial information or something, right? That happens. Or maybe our venting is good enough that you get alarms. So let's just say we're competent enough that we actually picked this up in a reasonable point of time. So let's go back to the same kind of flow and architecture and try to, let's go through a reasonable scenario from the blue team side while we're catching up. Did we detect it? Well, yeah, we probably did. Maybe the data exfil stage was a reasonable point, right? I think maybe the action of copying however it was done was suspicious and you had filters on that. Maybe the destination was definitely suspicious, either another bucket that you weren't expecting or an IP address that was strained. So I think that's reasonable. Maybe you did pick up the privilege escalation, but I would say in this case, it's hard because the sort of scenario I painted was there's a valid maybe support role that could be assumed to maybe support that bucket, right? The problem really is compromised credentials. It wasn't that this role shouldn't be there, right? So I'm gonna say two is questionable whether you picked up the privilege escalation. That might be hard. Of course, you might not be just looking at events. You might have correlation anomaly detection in place. I think that's fair. That might've picked up some strange behavior. But either way, we're off to a decent start in that we were reacting reasonably fast. All right, where does it start getting interesting? So one, we're starting with the logs. That's pretty much our main starting point with anything. And so as we pour through the logs to try to catch up with some notification we got that something suspicious is going on, here's CloudTrail. I added some highlighting so we could all talk about it. Up top is what I call access key A. That's the one I started with, the compromised credential, right? This is when I use it to assume role and get back another temporary key with an elevated privilege. So you see assume role. And then in the response, you see that temporary token, which I'm calling A prime, right? Okay, this is where you're starting to look at what the heck's going on, right? And you're trying to go back and trace to the source and shut off every little gateway. So really, your analysis might, I think, reasonably lead to, look, the roles and the bucket access was okay. I'm gonna drill that user, Jenko, whatever his name is, and say, look, are you doing something bad or are you just careless and losing your key? And let's just say it was carelessness through the interview. And we say, look, it's a compromised key issue. Let's handle it that way, right? So we move on to mitigation. We delete that access key, which was the one that I got, or make it inactive. Maybe set him, if he deserves it, set him up with a new key, but really focus on key rotation and other practices. Definitely change the console password and send that guy to training, right? Or whatever is appropriate, right? Maybe these are parts of a reasonable step. So, you know, GUI has it, CLI, no big deal. This is probably in your playbook. Now the problem is we close off this incident, but we're smart enough to keep looking through the logs because we're just wondering what the heck happened. So we pick up another event and here it gets interesting. Here's where sort of blue thinks this might be different than what they've seen before. Maybe, but they don't really know. They see get session token. What the heck is that? Not too familiar with it. It's a STS, gotta go read up on it. This is the part in the text scenario where second step or first step, I just generated backdoor set of credentials, right? I'd probably do it for 36 hours. And the demo is 900 seconds because I don't trust any of you guys just in case you're logged in, right? To try to see if it's active, right? But really I would have given myself 36 hours, right? Here, defender might not be an expert, but this is raising their hackles. They read up quickly in five minutes, STS doc. This is another access key, A prime. The heck, I shot one off. Now I gotta go worry about another one. Hey boss, not quite over yet, right? We're still working it. So let's just pause for a minute and explain any differences with temporary tokens. You read up another hour on this if it's first time or two or three, because the doc is pretty messy. It's 15 minutes to 36 hours, which is an eternity. On top of that, you're late because CloudTrail is not anywhere near real time. You're 20 minutes, I think, if you're lucky on top of that. So they've got a headstart. If they're smashing and grabbing, they're maybe done by the time you see the event, right? If they know what they needed, they don't care if you pick it up. There are some nuances. Temporary credentials are used when you start up services, often passing, assuming a role for an EC2 instance to get proper privileges and AWS manages that. So those tend to be an hour. But if you compromise an EC2 instance and grab that temporary token, you more have an hour timeframe, but it gets refreshed automatically. So if they haven't detected you, you just keep grabbing it. So there's all these nuances. API access, 99% the same as a permanent access key. A little bit of a difference. You can't regenerate a new temporary token off of a temporary token, right? They're not quite that loose on the AWS side, but you can, and you have to assume roles. So escalation of privilege is key to sort of long-term use of temporary tokens for that. As we said, assuming roles and escalation of privilege is not a big barrier. The infrastructure is way too complicated. And if you need some thinking on that, love Rhino, they share a lot. There's plenty of things on their blog about the next dozen escalation of privileges. And it's pretty, pretty scary when it goes through other services that you're not even thinking about, like DynamoDB, hey, we never deployed that. What do you mean? You can go through that and maybe escalate privileges. Okay, now that we're a little bit more knowledgeable on the blue side about temp tokens, let's revisit our whole process and just see where we're short. Because I still have an active key out there, right? Maybe it hasn't been used, or maybe it is being used. Either way, I gotta do something about it. I mean, I'm aware of it because of one event in CloudTrail. Here's the problem. Number one, it's untracked. What I mean by that is there is no listing of currently active or even historically generated temporary tokens, at least not easily in a form that you can do. Your best bet is you could parse it out of CloudTrail. But really what you want is a listing somewhere in the GUI or the CLI and API call to say, what the heck, temporary tokens have been generated. When do they expire? Click, cancel. You don't have that, all right? So bad news. We're not getting a good feeling as we think about this. Let's think about detection because we are in CloudTrail land. Number one thing you gotta do, you're able to deal with it because you do get logs, but it's a little obscure and confusing. Focus on creation of tokens because you just don't want tokens out there that you never knew about. So creation is looking for get session token, which is what I did in the first step, or any assume role will generate tokens underneath. The problem is assume role happens all over the place. So when you have federated identity, single sign-on, you got temporary tokens. So the problem is it's noisy. So false positives are gonna kill you, right? Get session token is gonna be rare. Focus on that. Assume role, boy, if you can escalate privileges, on the red side, you're hiding, right? But basically get your tracking with CloudTrail, CloudWatch, your SIEM, and make sure you got your filters on. Focus on the usage, of course, as well. This is not clear at all. When you look at the JSON minus my red highlight, there's no obvious attributes saying this is a temporary token. But there is a naming convention if you've been good enough to find it. It took me a long time, but AWS says if it begins with Asia, A-S-I-A, it's temporary. A-K-I-A is permanent. So you can do a regex or glob in your filter. Do it. And they publicize it, so hopefully it's at least stable and they won't break that, right? You gotta know when they're used. You can figure out what to do with it, but you gotta have some eyesight. So let's keep going here. Really, being aware of it's one issue, you've got some ability through logs, you gotta do something about it. Here is where it gets worse and worse, okay? So let's think about our normal reaction when we did the permanent compromise key. Let's delete it, make it inactive. You cannot. You can't even see it in the console, so you're not gonna do it there. And there is no CLI API command to revoke or delete a temporary credential. There is not. And I think AWS is even public about that. What do they recommend? Number two, restrict the role that governs that temporary credential, which is the Django temp user, like reduce their permissions or blow them away. If it's one user, sure. If it's a lot of tokens that you're using because IOT uses temporary tokens, what's the impact on the organization that's running an app with thousands of endpoints and clients that are suddenly invalidated because you blew away a user account or role? It doesn't make it easy. You have things, but you have to think about it. So really, number three is, there's some things imperfect, but they're not nice and clean, but you gotta rethink your playbook. You got probably a playbook for compromised accounts, both console login and permanent access keys. You gotta see if you've got one for temporary tokens. And you gotta go through that and see what the implications are. Because if you end up at number two, that's not something you wanna do in the middle of the night, in the middle of an incident, right? Hey, let's see what this does. You know, stop the bleeding, but the patient's gone anyway. So what the heck, right? There is some hope. You're not completely without means. So if it was an assume role action, which we did in this scenario, that elevated role, you have an ability to cancel or revoke active sessions. So it's in the GUI, it's a fifth tab, it's right here, okay? It's sort of faking it, I gotta admit, in the sense that it doesn't really revoke the token. It puts in place a deny policy, look, it's all wildcarded, with a condition that keys off of an attribute, and finding those attributes, of course, is impossible. But there's a creation time on the temporary token, and you basically put in today's date at the time you're looking at it. And basically, the thing that was created in the past by the attacker will be denied by this policy. So hey, it's good for mitigation, but it doesn't solve it, right? Because guess what? The temporary token still works. And if they can find another way to assume role and escalate privilege again, they're gonna be in your face, and you're gonna have to come back again and update this policy, right? But hey, we'll take what we can get, right? Let's not deny that. So let's try to step away from the fire drill. Let's just say, for better or worse, we're able to nail or restrict this temporary credential that's been hanging around. So we got a minute to pause, but we're not feeling good. How do we actually prevent this from happening in the first place, right? Well, your first thought, at least mine is, can't we just lock down in some permission schemes and use all API calls that create temporary credentials? You can't with GetSessionToken. You can do stuff with assume role, but you cannot do it with GetSessionToken. And clearly, it's not just me saying that and testing it, which is true, it's an AWS by design thing. Some engineers thought hard about this, and they said, look, GetSessionToken is a part of our authentication, and nothing restricts that. You gotta let people attempt to log in. Doesn't make any sense to me, but that's what you find in the doc, all right? So if your boss needs an explanation on BlueSide, you can go point him, yeah, that's what our CSPs know. They took their shared responsibility. Okay, sorry, was that a bad burn there? Okay, so we can't prevent GetSessionToken. How about MFA? Same reason, can't do it. Can't restrict with MFA. They consider this like the first step of the auth. You can't do permission boundaries, which specify max permissions for, right, the sort of maximum permissions could be assigned to an IAM user. Try it, doesn't work. I mean, they'll allow you to enter it, won't do anything. If it's assume role, you can restrict that. It's post-authentication in their minds, and you should. And we did in that scenario. We restricted it to some support guy, Django temp user, and he blew it. So you should still do it, minimal privileges, but again, this is not a silver bullet. And you do have the revoke active sessions for any role. Again, assume role path, but that's really mitigation, my, my, not really prevention. So the problem is, we've got a temporary token feature, which is sort of obscure to detect in the first place. And while it's being used, you don't have a direct way to cancel it. But in your mitigation procedures, you have some in some cases. And then in terms of lockdown and prevention for the user, you also don't quite have stuff. So this is what you're dealing with, right? This, this is sort of the story with temp tokens. And I guess I've been talking at 1.5x speed. So we got about seven minutes, Jeff, by my time. So I've got two more slides. So we might even be able to squeeze in a question. Otherwise, out, out front, I'd be happy to pursue more, more discussion. So let's, let's talk about sort of the wrap of do's and don'ts. And for anyone who's red teaming, pentesting, researching anything, my view is why not generate temp credentials immediately for every account you have access to, at a minimum for backdoor access. It's true, if they're savvy, they might pick that up, your get session token call. That's okay. What's more interesting is not just using those temp credentials, but combining it with all the other techniques you might use on the red team sign. So pre-signed URLs are nothing super fancy. If you use them, you wrap in a URL, it's pre-signed and you can download, but also upload data to a bucket. It's just the convenience. Instead of having, you know, two or three lines of code, you can have a URL. But I sort of wonder, well, hey, how about a phishing campaign with a bunch of URLs that mucks with buckets of, you know, some, some account. That might be sort of an interesting thing and more a distraction to obfuscate a bunch of other activity. Lambdas, certainly the point is, whether you attack logs or use lambdas, the trail will end up at a temporary credential, which if my premises holds water, it's going to be harder to deal with temporary credentials for the most part. So why not add an extra layer of friction to the whole thing, confusion. But another way to look at it too, is you could use something like lambdas to facilitate persistence of your temporary credentials, right? It expires in 36 hours, the max. If you do escalate privileges and have access to lambdas, why not put a hook in to create user, modify user somewhere in there. And every time that happens, generate new temporary credentials and put it to a public bucket that you pick up later, right? Just why not? And it just, just makes everything more obscure, harder to track, harder to figure out. For sure, in your discovery, you're probably looking at logs and you could ascertain whether they're specifically looking for temporary credentials. If they're that knowledgeable and ready, I mean, nothing lost, but you at least know. And if they aren't, well then everything above first three bullet points is just going to be easier, more impactful, right? So that's the sort of, you know, attack mindset with temporary tokens. Now let's try to end up on the blue side and see where we're at. So number one, no matter what you take away from this talk is if you never heard of temporary tokens, I don't want to say that in a bad way. If you haven't spent time on it, do it, get your plan in place, just revise it. If you have, good for you, but I would still suggest reviewing it because the APIs change all the time. And, you know, you're not sure what tools are available for you. Who knows? We'll probably get a revoke token API call at some point, right, if there's enough abuse. Talk about prevention. A lot of things I already covered. Yeah, you're going to lock down access keys. You can't prevent the temporary credentials, but you can try to minimize the impact once they're used or in your environment. So minimal privileges everywhere. You could isolate, if you have to use temporary credentials for some reason, like some business application reason, isolate in a separate account because cross-account access can be controlled no matter what, right? So that's a way to sort of, because it comes through an assume role path, right? So thinking about your org structure, your account and org structure is pretty important to dealing with messy stuff like temporary credentials. Minimal privileges, so on. Detection. We went through that. Focus on get session token. Think about assume role, if that's noisy or not. Pick up the usage with the ID scheme, the ASIA, and obviously harden like heck and test your logging, because if you're hosed on logging, then all of this doesn't matter. You have a lot worse problems. Mitigation remediation. The hardest part last. You don't have great things, but review your playbook. Don't use get session token if you don't need to, because then it's easy to pick up true positives out of the logs. Any use of get session token is immediately worth investigating, right? Use assume role because you can control it, but it's really noisy, right? But it allows you to revoke those active sessions, right? Gives you some mitigation means. Recovery, I can't stress enough because I think we may be focused on mitigation. You guys are probably better, but it's great even if you can manage and kill and restrict the temporary tokens, but how do you get the apps back and running? Because you might have blown away user accounts. And then finally, last step is really first, probably in your process, it's before you get into real-time ops, it's more did you plan and provision and manage your inventory? I think if you do have a good business case of creating temporary tokens for some application, then you're in control and you should log it, even if not log it, you should put in a database, even if AWS doesn't, because then you'll know what you've created and you'll have more context at a minimum when they're abused or compromised. But you're not in control of everything, so assume role and what AWS does, when you run an EC2 instance and pass along a role, boom, there's a temporary token created, it's in the user metadata of the EC2 instance, you didn't create it and people exploit it all the time. So there, your only choice is to go to the logs to see, look at, assume role creation as well as usage and see that key pop up, that ASIA key. But again, that would be valid activity in a lot of cases, so imperfect, right? So net-net, I don't have all the answers by any means, I have more questions than that, but I think it's to elevate the importance of this as whatever perspective, you gotta pay attention, even if you haven't been paying attention, you gotta re-look at it. Thanks. Thank you. Thank you.