WEBVTT

00:00.000 --> 00:01.200
All right, thanks Jeff.

00:01.700 --> 00:05.040
We're here to talk about temporary credentials, right?

00:05.280 --> 00:14.240
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.

00:14.240 --> 00:14.900
Thanks a lot.

00:14.900 --> 00:16.460
So I'm gonna talk at one and a half speed, right?

00:16.460 --> 00:18.780
So listen quickly, you know, wake up.

00:18.780 --> 00:20.820
If you leave in the middle, I'm gonna be pissed, right?

00:21.140 --> 00:23.260
All right, so let's get to it.

00:23.260 --> 00:27.260
Basically, to understand temporary credentials, let's just jump into a simple attack scenario.

00:27.340 --> 00:29.280
So I've got a recorded video.

00:29.280 --> 00:30.600
Let's just go through that.

00:30.620 --> 00:34.360
Then let's switch to defender viewpoint and see what the heck difference it makes, right?

00:34.360 --> 00:36.180
And the whole premise is it makes some difference.

00:36.180 --> 00:38.100
Both sides need to consider it.

00:38.100 --> 00:40.460
And then we'll wrap up with do's and don'ts, all right?

00:40.660 --> 00:42.360
So here's the basic scenario.

00:42.360 --> 00:43.380
Nothing super fancy.

00:43.380 --> 00:49.240
All you guys, I'm sure, have encountered worse or done worse, but we're basically gonna start with a compromise key.

00:49.240 --> 00:54.060
We're gonna generate a temporary credential, more for backdoor access, though I could use it right off the bat.

00:54.360 --> 00:58.740
Then I'll use that to escalate privileges and get access to a bucket, right?

00:58.740 --> 01:01.060
Okay, so let's move on.

01:01.060 --> 01:04.100
So here we'll start the demo and I'll talk you through it.

01:04.100 --> 01:06.000
Promise it's not huge.

01:06.000 --> 01:07.480
We'll start with credentials.

01:07.480 --> 01:11.220
And as we all know, it's not hard to find credentials these days.

01:11.520 --> 01:19.100
Whether you're on Pastebin, you got GitHub check-ins, you've got Gist, and of course you're harvesting or taking them, right?

01:19.100 --> 01:21.080
Plenty of malware still doing that.

01:21.080 --> 01:23.240
So that's not a problem.

01:23.240 --> 01:24.580
We've got a temporary credential.

01:24.580 --> 01:29.360
And for those of you who've worked with access keys, API keys, it's pretty much the same.

01:29.360 --> 01:36.240
I said environment variables, cause I'm gonna show CLI, but this is my compromised credential and starting point.

01:36.240 --> 01:37.800
All right, so let's continue on.

01:37.940 --> 01:41.900
So first thing I'm gonna do, I'm gonna immediately generate some temporary credentials.

01:41.900 --> 01:46.480
This'll make more sense as we get into the fact on the defensive side.

01:46.840 --> 01:48.600
I'm showing command line.

01:49.320 --> 01:54.800
Normally I'd run some Python code, but command line's good, nice and concise and fairly descriptive, right?

01:54.800 --> 01:57.420
So get session token off the STS service.

01:57.820 --> 02:01.900
If you can read the JSON, just two fields are what you expect.

02:01.900 --> 02:07.640
You get an access key ID and you get the secret, which is what a normal access key looks like.

02:07.640 --> 02:09.600
Then you've got the session token and expiration.

02:09.780 --> 02:12.700
When I called it into the API, I set the expiration time.

02:12.700 --> 02:17.740
We'll get into what those are, but it can be up to 36 hours, minimum 15 minutes.

02:17.980 --> 02:18.320
All right?

02:18.320 --> 02:25.520
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?

02:25.520 --> 02:26.600
But I've got another credential.

02:26.600 --> 02:30.640
I've got two, the compromised one, and then right off the bat, I generated another one.

02:30.640 --> 02:32.600
And functionally, it's pretty much the same.

02:32.600 --> 02:35.900
99% privileges access, right?

02:36.460 --> 02:39.220
All right, so let's continue on.

02:41.480 --> 02:44.980
And well, I don't know anything about the environment, so let's do a little bit of discovery.

02:44.980 --> 02:48.180
So again, we're going to do a very simplified version.

02:48.180 --> 02:49.320
Let me pause this here.

02:49.740 --> 02:52.980
Bunch of CLI commands are very oriented to IAM.

02:52.980 --> 03:00.220
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?

03:00.220 --> 03:01.060
Pretty basic.

03:01.120 --> 03:02.740
I would normally enumerate a lot more.

03:02.740 --> 03:04.100
Do I know EC2 instances?

03:04.100 --> 03:05.400
Do I know what buckets are there?

03:05.400 --> 03:06.440
Blah, blah, blah.

03:06.520 --> 03:13.100
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?

03:14.540 --> 03:16.400
So nothing big and fancy.

03:16.900 --> 03:20.380
I'm going to take a look at the output and pull just some of the salient pieces.

03:20.840 --> 03:26.280
And so I can barely read my screen, but at the top, right, I had an access key.

03:26.280 --> 03:27.880
Oh, it's JenkoTempUser.

03:27.880 --> 03:29.160
That's the actual username.

03:29.160 --> 03:31.220
I've got the account ID, super useful.

03:31.220 --> 03:32.900
I'm going to be exploring the environment.

03:32.900 --> 03:35.140
I'm going to need this in other API calls.

03:35.420 --> 03:40.080
Basically, I start to look through this, and I mean, no one reads JSON in their sleep.

03:40.080 --> 03:41.840
This is a pain in the ass, basically, right?

03:41.840 --> 03:46.220
But the point is I'm looking for what policies are attached right off.

03:46.220 --> 03:50.780
And boom, I start to see stuff that hints at bucket roles, right?

03:50.780 --> 03:53.900
And assuming bucket roles, which is an elevation, right?

03:53.900 --> 03:58.020
It's our cloud version of sudo wrapped in some other stuff.

03:58.020 --> 04:07.060
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?

04:07.060 --> 04:13.860
The user that I've compromised credentials can assume this bucket role, which has a policy and there's a JenkoBucket6.

04:13.860 --> 04:15.540
And so I'm happy.

04:15.540 --> 04:17.120
Man, this looks interesting.

04:17.120 --> 04:18.180
Now it's only one bucket.

04:18.180 --> 04:22.840
You can see the policy, but it's a little bit wide open because it's S3 colon star.

04:22.980 --> 04:29.280
So you could argue Blue Team's done maybe a little bit bad of a job here, but it's not horrible.

04:29.280 --> 04:31.400
It's one bucket and all the objects there, all right?

04:31.400 --> 04:35.960
Maybe it's a support guy that I got keys off of or something like that, a dev engineer.

04:36.460 --> 04:45.900
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?

04:46.460 --> 04:49.740
You think our discovery tools could visualize a little bit better.

04:49.740 --> 04:52.080
Basically we're saying, look, I've got a compromise key.

04:52.080 --> 04:54.980
I'm going to call it A instead of the 50 characters.

04:54.980 --> 04:56.520
So we all know what we're talking about.

04:56.520 --> 05:00.180
That key that was compromised, I found on, let's say, Pastebin.

05:00.180 --> 05:04.980
I used, and I know it relates to JenkoTempUser.

05:04.980 --> 05:07.660
It was created underneath that user.

05:07.800 --> 05:11.400
It happens to be able to assume role, right?

05:11.440 --> 05:12.920
To a bucket role.

05:12.920 --> 05:13.920
Man, these guys are next door.

05:13.920 --> 05:15.420
We got to tell them to be quiet.

05:16.000 --> 05:20.360
And that has access to this bucket, JenkoBucket6, right?

05:20.460 --> 05:24.760
That's basically the path that we're going to exploit, right?

05:25.100 --> 05:29.240
With what looks like to be a hole in escalation of privileges here.

05:29.240 --> 05:36.680
So just to test though, I did try to access the bucket directly with my compromised credentials, right?

05:36.680 --> 05:41.560
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?

05:41.560 --> 05:43.040
I mean, so why bother?

05:43.040 --> 05:43.680
Let's go after it.

05:43.680 --> 05:48.220
But I can't, I got an error just doing an LS on the bucket.

05:48.220 --> 05:50.920
So great, let's then think about the exploits.

05:50.920 --> 05:56.940
So taking that relationship, the actual exploits more in terms of API and flow more looks like this, right?

05:56.940 --> 06:04.620
You're basically going to make a call to the STS service doing an assume role.

06:04.620 --> 06:15.140
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?

06:15.540 --> 06:18.740
Then you're going to use that with your regular API calls.

06:19.040 --> 06:20.740
Great, pretty easy.

06:20.740 --> 06:22.420
Sounds pretty straightforward to me.

06:22.660 --> 06:25.700
Real scenarios, there's a million of things, right?

06:25.700 --> 06:27.580
We might be going after EC2 instances.

06:27.580 --> 06:28.940
We might go after logs.

06:28.940 --> 06:30.980
We might be putting in lambdas.

06:31.000 --> 06:32.220
We'd be doing a bunch of things.

06:32.220 --> 06:36.280
Right now it's super simple, but everything we talk about today should apply, right?

06:36.560 --> 06:38.280
In terms of temporary tokens.

06:38.280 --> 06:39.320
So let's keep going.

06:41.740 --> 06:47.740
So next thing I'm going to do is actually assume role, right?

06:47.740 --> 06:53.480
So if you can make out the command line, basically another call to STS and assume role.

06:53.480 --> 06:58.780
And what I get back, again, just looks like another temporary credential, right?

06:58.780 --> 07:00.560
Same thing as my first attempt.

07:00.560 --> 07:02.700
My first attempt gave me a little backdoor count.

07:02.700 --> 07:05.380
Now I have assumed role and I get another temporary credential.

07:05.380 --> 07:11.960
Let me call it A prime because I used, you know, the original compromised credential A and that I'm calling A.

07:11.960 --> 07:14.680
And this gives me an A prime with elevated privileges.

07:14.800 --> 07:15.460
Great.

07:15.460 --> 07:21.720
Set some environment variables if I want to use it, but for the actual next step, copy, paste.

07:21.720 --> 07:23.140
I'm going to use a CLI.

07:23.140 --> 07:29.320
And now when I do the actual bucket command, boom, comes back, right?

07:29.320 --> 07:30.260
Makes sense?

07:30.260 --> 07:34.020
Basically on the left, I've just fulfilled that whole path.

07:34.040 --> 07:36.080
So no big deal.

07:36.080 --> 07:40.580
And unfortunately, it's like, if you want to do CLI, it's not that bad to do it.

07:40.580 --> 07:43.740
If you're doing Python, you'd wrap in a few Python commands.

07:43.740 --> 07:47.780
And all we've shown is that we started with compromised credentials and we escalated.

07:47.780 --> 07:51.700
So, so far, nothing big, strange and new, right?

07:51.700 --> 07:53.660
I did generate temporary tokens.

07:53.920 --> 07:59.600
So we're going to now flip to the defender side to see what difference this all makes, okay?

08:02.740 --> 08:03.180
So...

08:03.800 --> 08:04.600
Ahem.

08:08.800 --> 08:10.220
Sorry, reset here.

08:10.220 --> 08:12.520
So let's go to the defender viewpoint.

08:13.200 --> 08:15.940
So basically, put on your blue hat for a minute.

08:15.940 --> 08:19.220
We've had an incident like we just went through, right?

08:19.220 --> 08:20.340
You're catching up with it.

08:20.340 --> 08:24.800
You're at least 20 minutes late because we all know CloudTrail has a lag that they document, right?

08:24.800 --> 08:28.440
15 minutes to get the API logged and five minutes at least to get to the bucket.

08:28.440 --> 08:31.360
You're already late by the time you pick it up out of CloudTrail.

08:31.620 --> 08:32.240
Okay.

08:33.080 --> 08:36.100
But your team is not terrible.

08:36.100 --> 08:37.720
You've got AWS experience.

08:38.160 --> 08:43.300
You've got logging in place, some kind of alarms, CloudWatch, your SIM, whatnot.

08:43.520 --> 08:44.640
You got a little bit of a gap though.

08:44.640 --> 08:46.460
You haven't really studied up on temporary credentials.

08:46.460 --> 08:53.280
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.

08:53.480 --> 08:54.700
So what's our starting point?

08:54.700 --> 08:56.540
Well, you know, two obvious ones.

08:56.540 --> 09:02.260
Someone tells you from outside that your data's up on GIST or whatever financial information or something, right?

09:02.260 --> 09:03.140
That happens.

09:03.140 --> 09:06.420
Or maybe our venting is good enough that you get alarms.

09:06.420 --> 09:10.720
So let's just say we're competent enough that we actually picked this up in a reasonable point of time.

09:10.860 --> 09:20.380
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.

09:20.380 --> 09:21.480
Did we detect it?

09:21.480 --> 09:23.180
Well, yeah, we probably did.

09:23.180 --> 09:26.580
Maybe the data exfil stage was a reasonable point, right?

09:26.580 --> 09:33.260
I think maybe the action of copying however it was done was suspicious and you had filters on that.

09:33.260 --> 09:39.340
Maybe the destination was definitely suspicious, either another bucket that you weren't expecting or an IP address that was strained.

09:39.340 --> 09:40.760
So I think that's reasonable.

09:40.900 --> 09:54.540
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?

09:54.540 --> 09:56.300
The problem really is compromised credentials.

09:56.300 --> 09:59.140
It wasn't that this role shouldn't be there, right?

09:59.140 --> 10:02.860
So I'm gonna say two is questionable whether you picked up the privilege escalation.

10:02.860 --> 10:03.840
That might be hard.

10:03.840 --> 10:06.180
Of course, you might not be just looking at events.

10:06.180 --> 10:09.280
You might have correlation anomaly detection in place.

10:09.280 --> 10:10.020
I think that's fair.

10:10.020 --> 10:12.100
That might've picked up some strange behavior.

10:12.280 --> 10:18.120
But either way, we're off to a decent start in that we were reacting reasonably fast.

10:18.820 --> 10:21.380
All right, where does it start getting interesting?

10:21.380 --> 10:24.060
So one, we're starting with the logs.

10:24.060 --> 10:26.860
That's pretty much our main starting point with anything.

10:27.040 --> 10:34.840
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.

10:34.860 --> 10:36.980
I added some highlighting so we could all talk about it.

10:36.980 --> 10:39.580
Up top is what I call access key A.

10:39.580 --> 10:42.780
That's the one I started with, the compromised credential, right?

10:43.140 --> 10:49.600
This is when I use it to assume role and get back another temporary key with an elevated privilege.

10:49.600 --> 10:50.980
So you see assume role.

10:51.060 --> 10:57.640
And then in the response, you see that temporary token, which I'm calling A prime, right?

10:58.360 --> 11:02.600
Okay, this is where you're starting to look at what the heck's going on, right?

11:02.600 --> 11:07.520
And you're trying to go back and trace to the source and shut off every little gateway.

11:08.020 --> 11:15.540
So really, your analysis might, I think, reasonably lead to, look, the roles and the bucket access was okay.

11:15.780 --> 11:23.480
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?

11:23.480 --> 11:26.760
And let's just say it was carelessness through the interview.

11:26.760 --> 11:28.660
And we say, look, it's a compromised key issue.

11:28.660 --> 11:30.240
Let's handle it that way, right?

11:30.240 --> 11:31.680
So we move on to mitigation.

11:31.840 --> 11:36.320
We delete that access key, which was the one that I got, or make it inactive.

11:37.220 --> 11:43.880
Maybe set him, if he deserves it, set him up with a new key, but really focus on key rotation and other practices.

11:43.940 --> 11:48.160
Definitely change the console password and send that guy to training, right?

11:48.160 --> 11:49.960
Or whatever is appropriate, right?

11:49.960 --> 11:52.960
Maybe these are parts of a reasonable step.

11:53.640 --> 11:56.860
So, you know, GUI has it, CLI, no big deal.

11:56.860 --> 11:58.500
This is probably in your playbook.

11:58.540 --> 12:06.020
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.

12:06.020 --> 12:09.400
So we pick up another event and here it gets interesting.

12:09.400 --> 12:13.340
Here's where sort of blue thinks this might be different than what they've seen before.

12:13.340 --> 12:14.820
Maybe, but they don't really know.

12:14.820 --> 12:15.820
They see get session token.

12:15.820 --> 12:16.880
What the heck is that?

12:16.920 --> 12:17.980
Not too familiar with it.

12:17.980 --> 12:19.940
It's a STS, gotta go read up on it.

12:20.120 --> 12:27.020
This is the part in the text scenario where second step or first step, I just generated backdoor set of credentials, right?

12:27.020 --> 12:28.560
I'd probably do it for 36 hours.

12:28.560 --> 12:33.100
And the demo is 900 seconds because I don't trust any of you guys just in case you're logged in, right?

12:33.100 --> 12:34.740
To try to see if it's active, right?

12:34.740 --> 12:37.520
But really I would have given myself 36 hours, right?

12:38.080 --> 12:42.680
Here, defender might not be an expert, but this is raising their hackles.

12:42.680 --> 12:45.240
They read up quickly in five minutes, STS doc.

12:45.240 --> 12:47.720
This is another access key, A prime.

12:47.860 --> 12:49.260
The heck, I shot one off.

12:49.260 --> 12:50.540
Now I gotta go worry about another one.

12:50.540 --> 12:53.040
Hey boss, not quite over yet, right?

12:53.040 --> 12:54.440
We're still working it.

12:54.720 --> 12:59.820
So let's just pause for a minute and explain any differences with temporary tokens.

12:59.820 --> 13:06.180
You read up another hour on this if it's first time or two or three, because the doc is pretty messy.

13:06.980 --> 13:10.560
It's 15 minutes to 36 hours, which is an eternity.

13:11.020 --> 13:16.580
On top of that, you're late because CloudTrail is not anywhere near real time.

13:16.580 --> 13:20.440
You're 20 minutes, I think, if you're lucky on top of that.

13:20.440 --> 13:21.540
So they've got a headstart.

13:21.540 --> 13:26.440
If they're smashing and grabbing, they're maybe done by the time you see the event, right?

13:26.440 --> 13:29.160
If they know what they needed, they don't care if you pick it up.

13:30.220 --> 13:31.640
There are some nuances.

13:31.640 --> 13:40.040
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.

13:40.040 --> 13:41.620
So those tend to be an hour.

13:41.620 --> 13:48.320
But if you compromise an EC2 instance and grab that temporary token, you more have an hour timeframe, but it gets refreshed automatically.

13:48.320 --> 13:50.320
So if they haven't detected you, you just keep grabbing it.

13:50.320 --> 13:52.860
So there's all these nuances.

13:52.860 --> 13:56.340
API access, 99% the same as a permanent access key.

13:56.420 --> 13:57.320
A little bit of a difference.

13:57.320 --> 14:01.620
You can't regenerate a new temporary token off of a temporary token, right?

14:01.620 --> 14:07.360
They're not quite that loose on the AWS side, but you can, and you have to assume roles.

14:07.360 --> 14:13.080
So escalation of privilege is key to sort of long-term use of temporary tokens for that.

14:13.080 --> 14:18.400
As we said, assuming roles and escalation of privilege is not a big barrier.

14:18.760 --> 14:20.960
The infrastructure is way too complicated.

14:21.180 --> 14:26.160
And if you need some thinking on that, love Rhino, they share a lot.

14:26.160 --> 14:31.500
There's plenty of things on their blog about the next dozen escalation of privileges.

14:31.780 --> 14:38.400
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.

14:38.400 --> 14:38.760
What do you mean?

14:38.760 --> 14:40.960
You can go through that and maybe escalate privileges.

14:40.960 --> 14:48.960
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.

14:48.960 --> 14:51.440
Because I still have an active key out there, right?

14:51.440 --> 14:55.060
Maybe it hasn't been used, or maybe it is being used.

14:55.060 --> 14:56.560
Either way, I gotta do something about it.

14:56.560 --> 15:00.040
I mean, I'm aware of it because of one event in CloudTrail.

15:00.420 --> 15:01.600
Here's the problem.

15:01.820 --> 15:03.700
Number one, it's untracked.

15:03.740 --> 15:13.800
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.

15:13.800 --> 15:16.480
Your best bet is you could parse it out of CloudTrail.

15:16.960 --> 15:26.300
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.

15:26.380 --> 15:27.840
When do they expire?

15:27.840 --> 15:29.480
Click, cancel.

15:29.480 --> 15:31.280
You don't have that, all right?

15:31.280 --> 15:32.920
So bad news.

15:32.920 --> 15:35.880
We're not getting a good feeling as we think about this.

15:35.880 --> 15:38.960
Let's think about detection because we are in CloudTrail land.

15:39.440 --> 15:45.820
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.

15:45.820 --> 15:50.580
Focus on creation of tokens because you just don't want tokens out there that you never knew about.

15:50.580 --> 16:00.500
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.

16:00.500 --> 16:03.320
The problem is assume role happens all over the place.

16:03.460 --> 16:07.840
So when you have federated identity, single sign-on, you got temporary tokens.

16:07.840 --> 16:09.420
So the problem is it's noisy.

16:09.420 --> 16:12.040
So false positives are gonna kill you, right?

16:12.040 --> 16:13.760
Get session token is gonna be rare.

16:13.760 --> 16:14.980
Focus on that.

16:14.980 --> 16:22.120
Assume role, boy, if you can escalate privileges, on the red side, you're hiding, right?

16:22.220 --> 16:30.720
But basically get your tracking with CloudTrail, CloudWatch, your SIEM, and make sure you got your filters on.

16:30.720 --> 16:33.220
Focus on the usage, of course, as well.

16:33.220 --> 16:34.860
This is not clear at all.

16:36.160 --> 16:42.760
When you look at the JSON minus my red highlight, there's no obvious attributes saying this is a temporary token.

16:43.080 --> 16:46.140
But there is a naming convention if you've been good enough to find it.

16:46.140 --> 16:53.120
It took me a long time, but AWS says if it begins with Asia, A-S-I-A, it's temporary.

16:53.120 --> 16:54.860
A-K-I-A is permanent.

16:54.860 --> 16:57.640
So you can do a regex or glob in your filter.

16:57.640 --> 16:58.400
Do it.

16:59.460 --> 17:04.320
And they publicize it, so hopefully it's at least stable and they won't break that, right?

17:04.320 --> 17:05.740
You gotta know when they're used.

17:05.740 --> 17:08.240
You can figure out what to do with it, but you gotta have some eyesight.

17:08.440 --> 17:10.660
So let's keep going here.

17:11.220 --> 17:17.320
Really, being aware of it's one issue, you've got some ability through logs, you gotta do something about it.

17:17.320 --> 17:20.000
Here is where it gets worse and worse, okay?

17:20.000 --> 17:24.480
So let's think about our normal reaction when we did the permanent compromise key.

17:25.000 --> 17:26.660
Let's delete it, make it inactive.

17:26.660 --> 17:27.620
You cannot.

17:27.800 --> 17:32.700
You can't even see it in the console, so you're not gonna do it there.

17:32.700 --> 17:38.100
And there is no CLI API command to revoke or delete a temporary credential.

17:38.100 --> 17:39.340
There is not.

17:39.340 --> 17:42.600
And I think AWS is even public about that.

17:42.940 --> 17:44.220
What do they recommend?

17:44.220 --> 17:54.380
Number two, restrict the role that governs that temporary credential, which is the Django temp user, like reduce their permissions or blow them away.

17:56.060 --> 17:58.700
If it's one user, sure.

17:58.960 --> 18:16.900
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?

18:17.360 --> 18:18.760
It doesn't make it easy.

18:18.760 --> 18:20.820
You have things, but you have to think about it.

18:20.820 --> 18:29.380
So really, number three is, there's some things imperfect, but they're not nice and clean, but you gotta rethink your playbook.

18:29.380 --> 18:35.600
You got probably a playbook for compromised accounts, both console login and permanent access keys.

18:35.600 --> 18:38.120
You gotta see if you've got one for temporary tokens.

18:38.140 --> 18:40.580
And you gotta go through that and see what the implications are.

18:40.580 --> 18:45.820
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?

18:45.820 --> 18:48.580
Hey, let's see what this does.

18:48.760 --> 18:51.640
You know, stop the bleeding, but the patient's gone anyway.

18:51.640 --> 18:53.100
So what the heck, right?

18:53.540 --> 18:55.740
There is some hope.

18:55.780 --> 18:58.720
You're not completely without means.

18:59.000 --> 19:09.120
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.

19:09.620 --> 19:14.720
So it's in the GUI, it's a fifth tab, it's right here, okay?

19:14.780 --> 19:21.800
It's sort of faking it, I gotta admit, in the sense that it doesn't really revoke the token.

19:21.900 --> 19:31.680
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.

19:32.100 --> 19:40.640
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.

19:40.640 --> 19:47.120
And basically, the thing that was created in the past by the attacker will be denied by this policy.

19:47.600 --> 19:51.180
So hey, it's good for mitigation, but it doesn't solve it, right?

19:51.180 --> 19:51.980
Because guess what?

19:51.980 --> 19:54.400
The temporary token still works.

19:54.540 --> 20:02.660
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?

20:02.820 --> 20:05.680
But hey, we'll take what we can get, right?

20:05.820 --> 20:07.280
Let's not deny that.

20:07.280 --> 20:10.480
So let's try to step away from the fire drill.

20:10.480 --> 20:18.080
Let's just say, for better or worse, we're able to nail or restrict this temporary credential that's been hanging around.

20:18.080 --> 20:20.140
So we got a minute to pause, but we're not feeling good.

20:20.140 --> 20:22.780
How do we actually prevent this from happening in the first place, right?

20:23.240 --> 20:30.980
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?

20:30.980 --> 20:32.400
You can't with GetSessionToken.

20:32.600 --> 20:37.320
You can do stuff with assume role, but you cannot do it with GetSessionToken.

20:37.420 --> 20:44.680
And clearly, it's not just me saying that and testing it, which is true, it's an AWS by design thing.

20:45.220 --> 20:53.580
Some engineers thought hard about this, and they said, look, GetSessionToken is a part of our authentication, and nothing restricts that.

20:53.580 --> 20:56.180
You gotta let people attempt to log in.

20:56.180 --> 21:00.040
Doesn't make any sense to me, but that's what you find in the doc, all right?

21:00.040 --> 21:04.620
So if your boss needs an explanation on BlueSide, you can go point him, yeah, that's what our CSPs know.

21:04.620 --> 21:06.400
They took their shared responsibility.

21:06.780 --> 21:11.280
Okay, sorry, was that a bad burn there?

21:11.280 --> 21:14.080
Okay, so we can't prevent GetSessionToken.

21:14.080 --> 21:15.020
How about MFA?

21:15.020 --> 21:16.380
Same reason, can't do it.

21:16.380 --> 21:17.760
Can't restrict with MFA.

21:18.180 --> 21:20.680
They consider this like the first step of the auth.

21:21.180 --> 21:31.560
You can't do permission boundaries, which specify max permissions for, right, the sort of maximum permissions could be assigned to an IAM user.

21:31.560 --> 21:33.040
Try it, doesn't work.

21:33.040 --> 21:35.720
I mean, they'll allow you to enter it, won't do anything.

21:36.720 --> 21:39.960
If it's assume role, you can restrict that.

21:39.960 --> 21:43.640
It's post-authentication in their minds, and you should.

21:43.640 --> 21:45.180
And we did in that scenario.

21:45.180 --> 21:49.020
We restricted it to some support guy, Django temp user, and he blew it.

21:49.040 --> 21:54.440
So you should still do it, minimal privileges, but again, this is not a silver bullet.

21:55.060 --> 21:59.700
And you do have the revoke active sessions for any role.

21:59.700 --> 22:05.360
Again, assume role path, but that's really mitigation, my, my, not really prevention.

22:05.360 --> 22:11.940
So the problem is, we've got a temporary token feature, which is sort of obscure to detect in the first place.

22:11.940 --> 22:15.420
And while it's being used, you don't have a direct way to cancel it.

22:15.540 --> 22:19.120
But in your mitigation procedures, you have some in some cases.

22:19.160 --> 22:25.060
And then in terms of lockdown and prevention for the user, you also don't quite have stuff.

22:26.000 --> 22:27.780
So this is what you're dealing with, right?

22:27.780 --> 22:32.300
This, this is sort of the story with temp tokens.

22:32.600 --> 22:35.460
And I guess I've been talking at 1.5x speed.

22:35.460 --> 22:38.140
So we got about seven minutes, Jeff, by my time.

22:38.140 --> 22:39.580
So I've got two more slides.

22:39.580 --> 22:41.340
So we might even be able to squeeze in a question.

22:41.340 --> 22:46.960
Otherwise, out, out front, I'd be happy to pursue more, more discussion.

22:46.960 --> 22:50.800
So let's, let's talk about sort of the wrap of do's and don'ts.

22:51.480 --> 23:05.620
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.

23:05.620 --> 23:10.500
It's true, if they're savvy, they might pick that up, your get session token call.

23:11.120 --> 23:12.540
That's okay.

23:14.780 --> 23:24.040
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.

23:24.040 --> 23:26.200
So pre-signed URLs are nothing super fancy.

23:26.200 --> 23:32.080
If you use them, you wrap in a URL, it's pre-signed and you can download, but also upload data to a bucket.

23:32.080 --> 23:33.440
It's just the convenience.

23:33.520 --> 23:37.540
Instead of having, you know, two or three lines of code, you can have a URL.

23:37.600 --> 23:46.040
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.

23:46.040 --> 23:51.160
That might be sort of an interesting thing and more a distraction to obfuscate a bunch of other activity.

23:51.340 --> 24:06.700
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.

24:06.700 --> 24:10.460
So why not add an extra layer of friction to the whole thing, confusion.

24:10.740 --> 24:19.320
But another way to look at it too, is you could use something like lambdas to facilitate persistence of your temporary credentials, right?

24:19.320 --> 24:22.060
It expires in 36 hours, the max.

24:22.060 --> 24:30.380
If you do escalate privileges and have access to lambdas, why not put a hook in to create user, modify user somewhere in there.

24:30.420 --> 24:36.860
And every time that happens, generate new temporary credentials and put it to a public bucket that you pick up later, right?

24:36.860 --> 24:38.140
Just why not?

24:38.140 --> 24:43.460
And it just, just makes everything more obscure, harder to track, harder to figure out.

24:44.500 --> 24:54.300
For sure, in your discovery, you're probably looking at logs and you could ascertain whether they're specifically looking for temporary credentials.

24:54.300 --> 24:59.980
If they're that knowledgeable and ready, I mean, nothing lost, but you at least know.

24:59.980 --> 25:07.040
And if they aren't, well then everything above first three bullet points is just going to be easier, more impactful, right?

25:07.040 --> 25:12.520
So that's the sort of, you know, attack mindset with temporary tokens.

25:12.520 --> 25:16.760
Now let's try to end up on the blue side and see where we're at.

25:16.760 --> 25:24.100
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.

25:24.100 --> 25:28.760
If you haven't spent time on it, do it, get your plan in place, just revise it.

25:28.760 --> 25:36.500
If you have, good for you, but I would still suggest reviewing it because the APIs change all the time.

25:36.500 --> 25:40.500
And, you know, you're not sure what tools are available for you.

25:40.500 --> 25:41.100
Who knows?

25:41.100 --> 25:46.560
We'll probably get a revoke token API call at some point, right, if there's enough abuse.

25:46.560 --> 25:47.720
Talk about prevention.

25:47.720 --> 25:49.240
A lot of things I already covered.

25:49.340 --> 25:51.200
Yeah, you're going to lock down access keys.

25:51.200 --> 25:57.020
You can't prevent the temporary credentials, but you can try to minimize the impact once they're used or in your environment.

25:57.020 --> 25:58.820
So minimal privileges everywhere.

25:59.300 --> 26:11.100
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?

26:11.100 --> 26:16.460
So that's a way to sort of, because it comes through an assume role path, right?

26:16.460 --> 26:25.680
So thinking about your org structure, your account and org structure is pretty important to dealing with messy stuff like temporary credentials.

26:25.680 --> 26:27.380
Minimal privileges, so on.

26:27.380 --> 26:28.440
Detection.

26:28.440 --> 26:29.460
We went through that.

26:29.460 --> 26:31.080
Focus on get session token.

26:31.080 --> 26:33.920
Think about assume role, if that's noisy or not.

26:33.980 --> 26:46.440
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.

26:46.440 --> 26:48.380
You have a lot worse problems.

26:48.380 --> 26:49.560
Mitigation remediation.

26:49.560 --> 26:51.080
The hardest part last.

26:51.080 --> 26:54.280
You don't have great things, but review your playbook.

26:54.500 --> 27:01.600
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.

27:01.600 --> 27:06.220
Any use of get session token is immediately worth investigating, right?

27:07.720 --> 27:11.620
Use assume role because you can control it, but it's really noisy, right?

27:11.900 --> 27:14.320
But it allows you to revoke those active sessions, right?

27:14.320 --> 27:16.320
Gives you some mitigation means.

27:17.320 --> 27:23.040
Recovery, I can't stress enough because I think we may be focused on mitigation.

27:23.260 --> 27:32.580
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?

27:32.580 --> 27:34.680
Because you might have blown away user accounts.

27:35.320 --> 27:45.440
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?

27:45.780 --> 28:07.700
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.

28:07.860 --> 28:24.200
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.

28:24.200 --> 28:34.580
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.

28:34.720 --> 28:39.240
But again, that would be valid activity in a lot of cases, so imperfect, right?

28:39.380 --> 28:55.560
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.

28:56.900 --> 28:57.780
Thanks.

28:57.780 --> 28:58.800
Thank you.

28:58.800 --> 28:59.620
Thank you.

