1 00:00:00,000 --> 00:00:01,200 All right, thanks Jeff. 2 00:00:01,700 --> 00:00:05,040 We're here to talk about temporary credentials, right? 3 00:00:05,280 --> 00: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. 4 00:00:14,240 --> 00:00:14,900 Thanks a lot. 5 00:00:14,900 --> 00:00:16,460 So I'm gonna talk at one and a half speed, right? 6 00:00:16,460 --> 00:00:18,780 So listen quickly, you know, wake up. 7 00:00:18,780 --> 00:00:20,820 If you leave in the middle, I'm gonna be pissed, right? 8 00:00:21,140 --> 00:00:23,260 All right, so let's get to it. 9 00:00:23,260 --> 00:00:27,260 Basically, to understand temporary credentials, let's just jump into a simple attack scenario. 10 00:00:27,340 --> 00:00:29,280 So I've got a recorded video. 11 00:00:29,280 --> 00:00:30,600 Let's just go through that. 12 00:00:30,620 --> 00:00:34,360 Then let's switch to defender viewpoint and see what the heck difference it makes, right? 13 00:00:34,360 --> 00:00:36,180 And the whole premise is it makes some difference. 14 00:00:36,180 --> 00:00:38,100 Both sides need to consider it. 15 00:00:38,100 --> 00:00:40,460 And then we'll wrap up with do's and don'ts, all right? 16 00:00:40,660 --> 00:00:42,360 So here's the basic scenario. 17 00:00:42,360 --> 00:00:43,380 Nothing super fancy. 18 00:00:43,380 --> 00: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. 19 00:00:49,240 --> 00:00:54,060 We're gonna generate a temporary credential, more for backdoor access, though I could use it right off the bat. 20 00:00:54,360 --> 00:00:58,740 Then I'll use that to escalate privileges and get access to a bucket, right? 21 00:00:58,740 --> 00:01:01,060 Okay, so let's move on. 22 00:01:01,060 --> 00:01:04,100 So here we'll start the demo and I'll talk you through it. 23 00:01:04,100 --> 00:01:06,000 Promise it's not huge. 24 00:01:06,000 --> 00:01:07,480 We'll start with credentials. 25 00:01:07,480 --> 00:01:11,220 And as we all know, it's not hard to find credentials these days. 26 00:01:11,520 --> 00: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? 27 00:01:19,100 --> 00:01:21,080 Plenty of malware still doing that. 28 00:01:21,080 --> 00:01:23,240 So that's not a problem. 29 00:01:23,240 --> 00:01:24,580 We've got a temporary credential. 30 00:01:24,580 --> 00:01:29,360 And for those of you who've worked with access keys, API keys, it's pretty much the same. 31 00:01:29,360 --> 00:01:36,240 I said environment variables, cause I'm gonna show CLI, but this is my compromised credential and starting point. 32 00:01:36,240 --> 00:01:37,800 All right, so let's continue on. 33 00:01:37,940 --> 00:01:41,900 So first thing I'm gonna do, I'm gonna immediately generate some temporary credentials. 34 00:01:41,900 --> 00:01:46,480 This'll make more sense as we get into the fact on the defensive side. 35 00:01:46,840 --> 00:01:48,600 I'm showing command line. 36 00:01:49,320 --> 00:01:54,800 Normally I'd run some Python code, but command line's good, nice and concise and fairly descriptive, right? 37 00:01:54,800 --> 00:01:57,420 So get session token off the STS service. 38 00:01:57,820 --> 00:02:01,900 If you can read the JSON, just two fields are what you expect. 39 00:02:01,900 --> 00:02:07,640 You get an access key ID and you get the secret, which is what a normal access key looks like. 40 00:02:07,640 --> 00:02:09,600 Then you've got the session token and expiration. 41 00:02:09,780 --> 00:02:12,700 When I called it into the API, I set the expiration time. 42 00:02:12,700 --> 00:02:17,740 We'll get into what those are, but it can be up to 36 hours, minimum 15 minutes. 43 00:02:17,980 --> 00:02:18,320 All right? 44 00:02:18,320 --> 00: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? 45 00:02:25,520 --> 00:02:26,600 But I've got another credential. 46 00:02:26,600 --> 00:02:30,640 I've got two, the compromised one, and then right off the bat, I generated another one. 47 00:02:30,640 --> 00:02:32,600 And functionally, it's pretty much the same. 48 00:02:32,600 --> 00:02:35,900 99% privileges access, right? 49 00:02:36,460 --> 00:02:39,220 All right, so let's continue on. 50 00:02:41,480 --> 00:02:44,980 And well, I don't know anything about the environment, so let's do a little bit of discovery. 51 00:02:44,980 --> 00:02:48,180 So again, we're going to do a very simplified version. 52 00:02:48,180 --> 00:02:49,320 Let me pause this here. 53 00:02:49,740 --> 00:02:52,980 Bunch of CLI commands are very oriented to IAM. 54 00:02:52,980 --> 00: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? 55 00:03:00,220 --> 00:03:01,060 Pretty basic. 56 00:03:01,120 --> 00:03:02,740 I would normally enumerate a lot more. 57 00:03:02,740 --> 00:03:04,100 Do I know EC2 instances? 58 00:03:04,100 --> 00:03:05,400 Do I know what buckets are there? 59 00:03:05,400 --> 00:03:06,440 Blah, blah, blah. 60 00:03:06,520 --> 00: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? 61 00:03:14,540 --> 00:03:16,400 So nothing big and fancy. 62 00:03:16,900 --> 00:03:20,380 I'm going to take a look at the output and pull just some of the salient pieces. 63 00:03:20,840 --> 00:03:26,280 And so I can barely read my screen, but at the top, right, I had an access key. 64 00:03:26,280 --> 00:03:27,880 Oh, it's JenkoTempUser. 65 00:03:27,880 --> 00:03:29,160 That's the actual username. 66 00:03:29,160 --> 00:03:31,220 I've got the account ID, super useful. 67 00:03:31,220 --> 00:03:32,900 I'm going to be exploring the environment. 68 00:03:32,900 --> 00:03:35,140 I'm going to need this in other API calls. 69 00:03:35,420 --> 00:03:40,080 Basically, I start to look through this, and I mean, no one reads JSON in their sleep. 70 00:03:40,080 --> 00:03:41,840 This is a pain in the ass, basically, right? 71 00:03:41,840 --> 00:03:46,220 But the point is I'm looking for what policies are attached right off. 72 00:03:46,220 --> 00:03:50,780 And boom, I start to see stuff that hints at bucket roles, right? 73 00:03:50,780 --> 00:03:53,900 And assuming bucket roles, which is an elevation, right? 74 00:03:53,900 --> 00:03:58,020 It's our cloud version of sudo wrapped in some other stuff. 75 00:03:58,020 --> 00: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? 76 00:04:07,060 --> 00:04:13,860 The user that I've compromised credentials can assume this bucket role, which has a policy and there's a JenkoBucket6. 77 00:04:13,860 --> 00:04:15,540 And so I'm happy. 78 00:04:15,540 --> 00:04:17,120 Man, this looks interesting. 79 00:04:17,120 --> 00:04:18,180 Now it's only one bucket. 80 00:04:18,180 --> 00:04:22,840 You can see the policy, but it's a little bit wide open because it's S3 colon star. 81 00:04:22,980 --> 00: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. 82 00:04:29,280 --> 00:04:31,400 It's one bucket and all the objects there, all right? 83 00:04:31,400 --> 00:04:35,960 Maybe it's a support guy that I got keys off of or something like that, a dev engineer. 84 00:04:36,460 --> 00: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? 85 00:04:46,460 --> 00:04:49,740 You think our discovery tools could visualize a little bit better. 86 00:04:49,740 --> 00:04:52,080 Basically we're saying, look, I've got a compromise key. 87 00:04:52,080 --> 00:04:54,980 I'm going to call it A instead of the 50 characters. 88 00:04:54,980 --> 00:04:56,520 So we all know what we're talking about. 89 00:04:56,520 --> 00:05:00,180 That key that was compromised, I found on, let's say, Pastebin. 90 00:05:00,180 --> 00:05:04,980 I used, and I know it relates to JenkoTempUser. 91 00:05:04,980 --> 00:05:07,660 It was created underneath that user. 92 00:05:07,800 --> 00:05:11,400 It happens to be able to assume role, right? 93 00:05:11,440 --> 00:05:12,920 To a bucket role. 94 00:05:12,920 --> 00:05:13,920 Man, these guys are next door. 95 00:05:13,920 --> 00:05:15,420 We got to tell them to be quiet. 96 00:05:16,000 --> 00:05:20,360 And that has access to this bucket, JenkoBucket6, right? 97 00:05:20,460 --> 00:05:24,760 That's basically the path that we're going to exploit, right? 98 00:05:25,100 --> 00:05:29,240 With what looks like to be a hole in escalation of privileges here. 99 00:05:29,240 --> 00:05:36,680 So just to test though, I did try to access the bucket directly with my compromised credentials, right? 100 00:05:36,680 --> 00: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? 101 00:05:41,560 --> 00:05:43,040 I mean, so why bother? 102 00:05:43,040 --> 00:05:43,680 Let's go after it. 103 00:05:43,680 --> 00:05:48,220 But I can't, I got an error just doing an LS on the bucket. 104 00:05:48,220 --> 00:05:50,920 So great, let's then think about the exploits. 105 00:05:50,920 --> 00:05:56,940 So taking that relationship, the actual exploits more in terms of API and flow more looks like this, right? 106 00:05:56,940 --> 00:06:04,620 You're basically going to make a call to the STS service doing an assume role. 107 00:06:04,620 --> 00: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? 108 00:06:15,540 --> 00:06:18,740 Then you're going to use that with your regular API calls. 109 00:06:19,040 --> 00:06:20,740 Great, pretty easy. 110 00:06:20,740 --> 00:06:22,420 Sounds pretty straightforward to me. 111 00:06:22,660 --> 00:06:25,700 Real scenarios, there's a million of things, right? 112 00:06:25,700 --> 00:06:27,580 We might be going after EC2 instances. 113 00:06:27,580 --> 00:06:28,940 We might go after logs. 114 00:06:28,940 --> 00:06:30,980 We might be putting in lambdas. 115 00:06:31,000 --> 00:06:32,220 We'd be doing a bunch of things. 116 00:06:32,220 --> 00:06:36,280 Right now it's super simple, but everything we talk about today should apply, right? 117 00:06:36,560 --> 00:06:38,280 In terms of temporary tokens. 118 00:06:38,280 --> 00:06:39,320 So let's keep going. 119 00:06:41,740 --> 00:06:47,740 So next thing I'm going to do is actually assume role, right? 120 00:06:47,740 --> 00:06:53,480 So if you can make out the command line, basically another call to STS and assume role. 121 00:06:53,480 --> 00:06:58,780 And what I get back, again, just looks like another temporary credential, right? 122 00:06:58,780 --> 00:07:00,560 Same thing as my first attempt. 123 00:07:00,560 --> 00:07:02,700 My first attempt gave me a little backdoor count. 124 00:07:02,700 --> 00:07:05,380 Now I have assumed role and I get another temporary credential. 125 00:07:05,380 --> 00: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. 126 00:07:11,960 --> 00:07:14,680 And this gives me an A prime with elevated privileges. 127 00:07:14,800 --> 00:07:15,460 Great. 128 00:07:15,460 --> 00:07:21,720 Set some environment variables if I want to use it, but for the actual next step, copy, paste. 129 00:07:21,720 --> 00:07:23,140 I'm going to use a CLI. 130 00:07:23,140 --> 00:07:29,320 And now when I do the actual bucket command, boom, comes back, right? 131 00:07:29,320 --> 00:07:30,260 Makes sense? 132 00:07:30,260 --> 00:07:34,020 Basically on the left, I've just fulfilled that whole path. 133 00:07:34,040 --> 00:07:36,080 So no big deal. 134 00:07:36,080 --> 00:07:40,580 And unfortunately, it's like, if you want to do CLI, it's not that bad to do it. 135 00:07:40,580 --> 00:07:43,740 If you're doing Python, you'd wrap in a few Python commands. 136 00:07:43,740 --> 00:07:47,780 And all we've shown is that we started with compromised credentials and we escalated. 137 00:07:47,780 --> 00:07:51,700 So, so far, nothing big, strange and new, right? 138 00:07:51,700 --> 00:07:53,660 I did generate temporary tokens. 139 00:07:53,920 --> 00:07:59,600 So we're going to now flip to the defender side to see what difference this all makes, okay? 140 00:08:02,740 --> 00:08:03,180 So... 141 00:08:03,800 --> 00:08:04,600 Ahem. 142 00:08:08,800 --> 00:08:10,220 Sorry, reset here. 143 00:08:10,220 --> 00:08:12,520 So let's go to the defender viewpoint. 144 00:08:13,200 --> 00:08:15,940 So basically, put on your blue hat for a minute. 145 00:08:15,940 --> 00:08:19,220 We've had an incident like we just went through, right? 146 00:08:19,220 --> 00:08:20,340 You're catching up with it. 147 00:08:20,340 --> 00:08:24,800 You're at least 20 minutes late because we all know CloudTrail has a lag that they document, right? 148 00:08:24,800 --> 00:08:28,440 15 minutes to get the API logged and five minutes at least to get to the bucket. 149 00:08:28,440 --> 00:08:31,360 You're already late by the time you pick it up out of CloudTrail. 150 00:08:31,620 --> 00:08:32,240 Okay. 151 00:08:33,080 --> 00:08:36,100 But your team is not terrible. 152 00:08:36,100 --> 00:08:37,720 You've got AWS experience. 153 00:08:38,160 --> 00:08:43,300 You've got logging in place, some kind of alarms, CloudWatch, your SIM, whatnot. 154 00:08:43,520 --> 00:08:44,640 You got a little bit of a gap though. 155 00:08:44,640 --> 00:08:46,460 You haven't really studied up on temporary credentials. 156 00:08:46,460 --> 00: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. 157 00:08:53,480 --> 00:08:54,700 So what's our starting point? 158 00:08:54,700 --> 00:08:56,540 Well, you know, two obvious ones. 159 00:08:56,540 --> 00:09:02,260 Someone tells you from outside that your data's up on GIST or whatever financial information or something, right? 160 00:09:02,260 --> 00:09:03,140 That happens. 161 00:09:03,140 --> 00:09:06,420 Or maybe our venting is good enough that you get alarms. 162 00:09:06,420 --> 00:09:10,720 So let's just say we're competent enough that we actually picked this up in a reasonable point of time. 163 00:09:10,860 --> 00: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. 164 00:09:20,380 --> 00:09:21,480 Did we detect it? 165 00:09:21,480 --> 00:09:23,180 Well, yeah, we probably did. 166 00:09:23,180 --> 00:09:26,580 Maybe the data exfil stage was a reasonable point, right? 167 00:09:26,580 --> 00:09:33,260 I think maybe the action of copying however it was done was suspicious and you had filters on that. 168 00:09:33,260 --> 00:09:39,340 Maybe the destination was definitely suspicious, either another bucket that you weren't expecting or an IP address that was strained. 169 00:09:39,340 --> 00:09:40,760 So I think that's reasonable. 170 00:09:40,900 --> 00: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? 171 00:09:54,540 --> 00:09:56,300 The problem really is compromised credentials. 172 00:09:56,300 --> 00:09:59,140 It wasn't that this role shouldn't be there, right? 173 00:09:59,140 --> 00:10:02,860 So I'm gonna say two is questionable whether you picked up the privilege escalation. 174 00:10:02,860 --> 00:10:03,840 That might be hard. 175 00:10:03,840 --> 00:10:06,180 Of course, you might not be just looking at events. 176 00:10:06,180 --> 00:10:09,280 You might have correlation anomaly detection in place. 177 00:10:09,280 --> 00:10:10,020 I think that's fair. 178 00:10:10,020 --> 00:10:12,100 That might've picked up some strange behavior. 179 00:10:12,280 --> 00:10:18,120 But either way, we're off to a decent start in that we were reacting reasonably fast. 180 00:10:18,820 --> 00:10:21,380 All right, where does it start getting interesting? 181 00:10:21,380 --> 00:10:24,060 So one, we're starting with the logs. 182 00:10:24,060 --> 00:10:26,860 That's pretty much our main starting point with anything. 183 00:10:27,040 --> 00: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. 184 00:10:34,860 --> 00:10:36,980 I added some highlighting so we could all talk about it. 185 00:10:36,980 --> 00:10:39,580 Up top is what I call access key A. 186 00:10:39,580 --> 00:10:42,780 That's the one I started with, the compromised credential, right? 187 00:10:43,140 --> 00:10:49,600 This is when I use it to assume role and get back another temporary key with an elevated privilege. 188 00:10:49,600 --> 00:10:50,980 So you see assume role. 189 00:10:51,060 --> 00:10:57,640 And then in the response, you see that temporary token, which I'm calling A prime, right? 190 00:10:58,360 --> 00:11:02,600 Okay, this is where you're starting to look at what the heck's going on, right? 191 00:11:02,600 --> 00:11:07,520 And you're trying to go back and trace to the source and shut off every little gateway. 192 00:11:08,020 --> 00:11:15,540 So really, your analysis might, I think, reasonably lead to, look, the roles and the bucket access was okay. 193 00:11:15,780 --> 00: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? 194 00:11:23,480 --> 00:11:26,760 And let's just say it was carelessness through the interview. 195 00:11:26,760 --> 00:11:28,660 And we say, look, it's a compromised key issue. 196 00:11:28,660 --> 00:11:30,240 Let's handle it that way, right? 197 00:11:30,240 --> 00:11:31,680 So we move on to mitigation. 198 00:11:31,840 --> 00:11:36,320 We delete that access key, which was the one that I got, or make it inactive. 199 00:11:37,220 --> 00: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. 200 00:11:43,940 --> 00:11:48,160 Definitely change the console password and send that guy to training, right? 201 00:11:48,160 --> 00:11:49,960 Or whatever is appropriate, right? 202 00:11:49,960 --> 00:11:52,960 Maybe these are parts of a reasonable step. 203 00:11:53,640 --> 00:11:56,860 So, you know, GUI has it, CLI, no big deal. 204 00:11:56,860 --> 00:11:58,500 This is probably in your playbook. 205 00:11:58,540 --> 00: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. 206 00:12:06,020 --> 00:12:09,400 So we pick up another event and here it gets interesting. 207 00:12:09,400 --> 00:12:13,340 Here's where sort of blue thinks this might be different than what they've seen before. 208 00:12:13,340 --> 00:12:14,820 Maybe, but they don't really know. 209 00:12:14,820 --> 00:12:15,820 They see get session token. 210 00:12:15,820 --> 00:12:16,880 What the heck is that? 211 00:12:16,920 --> 00:12:17,980 Not too familiar with it. 212 00:12:17,980 --> 00:12:19,940 It's a STS, gotta go read up on it. 213 00:12:20,120 --> 00: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? 214 00:12:27,020 --> 00:12:28,560 I'd probably do it for 36 hours. 215 00:12:28,560 --> 00: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? 216 00:12:33,100 --> 00:12:34,740 To try to see if it's active, right? 217 00:12:34,740 --> 00:12:37,520 But really I would have given myself 36 hours, right? 218 00:12:38,080 --> 00:12:42,680 Here, defender might not be an expert, but this is raising their hackles. 219 00:12:42,680 --> 00:12:45,240 They read up quickly in five minutes, STS doc. 220 00:12:45,240 --> 00:12:47,720 This is another access key, A prime. 221 00:12:47,860 --> 00:12:49,260 The heck, I shot one off. 222 00:12:49,260 --> 00:12:50,540 Now I gotta go worry about another one. 223 00:12:50,540 --> 00:12:53,040 Hey boss, not quite over yet, right? 224 00:12:53,040 --> 00:12:54,440 We're still working it. 225 00:12:54,720 --> 00:12:59,820 So let's just pause for a minute and explain any differences with temporary tokens. 226 00:12:59,820 --> 00: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. 227 00:13:06,980 --> 00:13:10,560 It's 15 minutes to 36 hours, which is an eternity. 228 00:13:11,020 --> 00:13:16,580 On top of that, you're late because CloudTrail is not anywhere near real time. 229 00:13:16,580 --> 00:13:20,440 You're 20 minutes, I think, if you're lucky on top of that. 230 00:13:20,440 --> 00:13:21,540 So they've got a headstart. 231 00:13:21,540 --> 00:13:26,440 If they're smashing and grabbing, they're maybe done by the time you see the event, right? 232 00:13:26,440 --> 00:13:29,160 If they know what they needed, they don't care if you pick it up. 233 00:13:30,220 --> 00:13:31,640 There are some nuances. 234 00:13:31,640 --> 00: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. 235 00:13:40,040 --> 00:13:41,620 So those tend to be an hour. 236 00:13:41,620 --> 00: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. 237 00:13:48,320 --> 00:13:50,320 So if they haven't detected you, you just keep grabbing it. 238 00:13:50,320 --> 00:13:52,860 So there's all these nuances. 239 00:13:52,860 --> 00:13:56,340 API access, 99% the same as a permanent access key. 240 00:13:56,420 --> 00:13:57,320 A little bit of a difference. 241 00:13:57,320 --> 00:14:01,620 You can't regenerate a new temporary token off of a temporary token, right? 242 00:14:01,620 --> 00:14:07,360 They're not quite that loose on the AWS side, but you can, and you have to assume roles. 243 00:14:07,360 --> 00:14:13,080 So escalation of privilege is key to sort of long-term use of temporary tokens for that. 244 00:14:13,080 --> 00:14:18,400 As we said, assuming roles and escalation of privilege is not a big barrier. 245 00:14:18,760 --> 00:14:20,960 The infrastructure is way too complicated. 246 00:14:21,180 --> 00:14:26,160 And if you need some thinking on that, love Rhino, they share a lot. 247 00:14:26,160 --> 00:14:31,500 There's plenty of things on their blog about the next dozen escalation of privileges. 248 00:14:31,780 --> 00: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. 249 00:14:38,400 --> 00:14:38,760 What do you mean? 250 00:14:38,760 --> 00:14:40,960 You can go through that and maybe escalate privileges. 251 00:14:40,960 --> 00: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. 252 00:14:48,960 --> 00:14:51,440 Because I still have an active key out there, right? 253 00:14:51,440 --> 00:14:55,060 Maybe it hasn't been used, or maybe it is being used. 254 00:14:55,060 --> 00:14:56,560 Either way, I gotta do something about it. 255 00:14:56,560 --> 00:15:00,040 I mean, I'm aware of it because of one event in CloudTrail. 256 00:15:00,420 --> 00:15:01,600 Here's the problem. 257 00:15:01,820 --> 00:15:03,700 Number one, it's untracked. 258 00:15:03,740 --> 00: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. 259 00:15:13,800 --> 00:15:16,480 Your best bet is you could parse it out of CloudTrail. 260 00:15:16,960 --> 00: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. 261 00:15:26,380 --> 00:15:27,840 When do they expire? 262 00:15:27,840 --> 00:15:29,480 Click, cancel. 263 00:15:29,480 --> 00:15:31,280 You don't have that, all right? 264 00:15:31,280 --> 00:15:32,920 So bad news. 265 00:15:32,920 --> 00:15:35,880 We're not getting a good feeling as we think about this. 266 00:15:35,880 --> 00:15:38,960 Let's think about detection because we are in CloudTrail land. 267 00:15:39,440 --> 00: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. 268 00:15:45,820 --> 00:15:50,580 Focus on creation of tokens because you just don't want tokens out there that you never knew about. 269 00:15:50,580 --> 00: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. 270 00:16:00,500 --> 00:16:03,320 The problem is assume role happens all over the place. 271 00:16:03,460 --> 00:16:07,840 So when you have federated identity, single sign-on, you got temporary tokens. 272 00:16:07,840 --> 00:16:09,420 So the problem is it's noisy. 273 00:16:09,420 --> 00:16:12,040 So false positives are gonna kill you, right? 274 00:16:12,040 --> 00:16:13,760 Get session token is gonna be rare. 275 00:16:13,760 --> 00:16:14,980 Focus on that. 276 00:16:14,980 --> 00:16:22,120 Assume role, boy, if you can escalate privileges, on the red side, you're hiding, right? 277 00:16:22,220 --> 00:16:30,720 But basically get your tracking with CloudTrail, CloudWatch, your SIEM, and make sure you got your filters on. 278 00:16:30,720 --> 00:16:33,220 Focus on the usage, of course, as well. 279 00:16:33,220 --> 00:16:34,860 This is not clear at all. 280 00:16:36,160 --> 00:16:42,760 When you look at the JSON minus my red highlight, there's no obvious attributes saying this is a temporary token. 281 00:16:43,080 --> 00:16:46,140 But there is a naming convention if you've been good enough to find it. 282 00:16:46,140 --> 00:16:53,120 It took me a long time, but AWS says if it begins with Asia, A-S-I-A, it's temporary. 283 00:16:53,120 --> 00:16:54,860 A-K-I-A is permanent. 284 00:16:54,860 --> 00:16:57,640 So you can do a regex or glob in your filter. 285 00:16:57,640 --> 00:16:58,400 Do it. 286 00:16:59,460 --> 00:17:04,320 And they publicize it, so hopefully it's at least stable and they won't break that, right? 287 00:17:04,320 --> 00:17:05,740 You gotta know when they're used. 288 00:17:05,740 --> 00:17:08,240 You can figure out what to do with it, but you gotta have some eyesight. 289 00:17:08,440 --> 00:17:10,660 So let's keep going here. 290 00:17:11,220 --> 00:17:17,320 Really, being aware of it's one issue, you've got some ability through logs, you gotta do something about it. 291 00:17:17,320 --> 00:17:20,000 Here is where it gets worse and worse, okay? 292 00:17:20,000 --> 00:17:24,480 So let's think about our normal reaction when we did the permanent compromise key. 293 00:17:25,000 --> 00:17:26,660 Let's delete it, make it inactive. 294 00:17:26,660 --> 00:17:27,620 You cannot. 295 00:17:27,800 --> 00:17:32,700 You can't even see it in the console, so you're not gonna do it there. 296 00:17:32,700 --> 00:17:38,100 And there is no CLI API command to revoke or delete a temporary credential. 297 00:17:38,100 --> 00:17:39,340 There is not. 298 00:17:39,340 --> 00:17:42,600 And I think AWS is even public about that. 299 00:17:42,940 --> 00:17:44,220 What do they recommend? 300 00:17:44,220 --> 00: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. 301 00:17:56,060 --> 00:17:58,700 If it's one user, sure. 302 00:17:58,960 --> 00: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? 303 00:18:17,360 --> 00:18:18,760 It doesn't make it easy. 304 00:18:18,760 --> 00:18:20,820 You have things, but you have to think about it. 305 00:18:20,820 --> 00: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. 306 00:18:29,380 --> 00:18:35,600 You got probably a playbook for compromised accounts, both console login and permanent access keys. 307 00:18:35,600 --> 00:18:38,120 You gotta see if you've got one for temporary tokens. 308 00:18:38,140 --> 00:18:40,580 And you gotta go through that and see what the implications are. 309 00:18:40,580 --> 00: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? 310 00:18:45,820 --> 00:18:48,580 Hey, let's see what this does. 311 00:18:48,760 --> 00:18:51,640 You know, stop the bleeding, but the patient's gone anyway. 312 00:18:51,640 --> 00:18:53,100 So what the heck, right? 313 00:18:53,540 --> 00:18:55,740 There is some hope. 314 00:18:55,780 --> 00:18:58,720 You're not completely without means. 315 00:18:59,000 --> 00: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. 316 00:19:09,620 --> 00:19:14,720 So it's in the GUI, it's a fifth tab, it's right here, okay? 317 00:19:14,780 --> 00:19:21,800 It's sort of faking it, I gotta admit, in the sense that it doesn't really revoke the token. 318 00:19:21,900 --> 00: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. 319 00:19:32,100 --> 00: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. 320 00:19:40,640 --> 00:19:47,120 And basically, the thing that was created in the past by the attacker will be denied by this policy. 321 00:19:47,600 --> 00:19:51,180 So hey, it's good for mitigation, but it doesn't solve it, right? 322 00:19:51,180 --> 00:19:51,980 Because guess what? 323 00:19:51,980 --> 00:19:54,400 The temporary token still works. 324 00:19:54,540 --> 00: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? 325 00:20:02,820 --> 00:20:05,680 But hey, we'll take what we can get, right? 326 00:20:05,820 --> 00:20:07,280 Let's not deny that. 327 00:20:07,280 --> 00:20:10,480 So let's try to step away from the fire drill. 328 00:20:10,480 --> 00: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. 329 00:20:18,080 --> 00:20:20,140 So we got a minute to pause, but we're not feeling good. 330 00:20:20,140 --> 00:20:22,780 How do we actually prevent this from happening in the first place, right? 331 00:20:23,240 --> 00: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? 332 00:20:30,980 --> 00:20:32,400 You can't with GetSessionToken. 333 00:20:32,600 --> 00:20:37,320 You can do stuff with assume role, but you cannot do it with GetSessionToken. 334 00:20:37,420 --> 00: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. 335 00:20:45,220 --> 00:20:53,580 Some engineers thought hard about this, and they said, look, GetSessionToken is a part of our authentication, and nothing restricts that. 336 00:20:53,580 --> 00:20:56,180 You gotta let people attempt to log in. 337 00:20:56,180 --> 00:21:00,040 Doesn't make any sense to me, but that's what you find in the doc, all right? 338 00:21:00,040 --> 00:21:04,620 So if your boss needs an explanation on BlueSide, you can go point him, yeah, that's what our CSPs know. 339 00:21:04,620 --> 00:21:06,400 They took their shared responsibility. 340 00:21:06,780 --> 00:21:11,280 Okay, sorry, was that a bad burn there? 341 00:21:11,280 --> 00:21:14,080 Okay, so we can't prevent GetSessionToken. 342 00:21:14,080 --> 00:21:15,020 How about MFA? 343 00:21:15,020 --> 00:21:16,380 Same reason, can't do it. 344 00:21:16,380 --> 00:21:17,760 Can't restrict with MFA. 345 00:21:18,180 --> 00:21:20,680 They consider this like the first step of the auth. 346 00:21:21,180 --> 00: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. 347 00:21:31,560 --> 00:21:33,040 Try it, doesn't work. 348 00:21:33,040 --> 00:21:35,720 I mean, they'll allow you to enter it, won't do anything. 349 00:21:36,720 --> 00:21:39,960 If it's assume role, you can restrict that. 350 00:21:39,960 --> 00:21:43,640 It's post-authentication in their minds, and you should. 351 00:21:43,640 --> 00:21:45,180 And we did in that scenario. 352 00:21:45,180 --> 00:21:49,020 We restricted it to some support guy, Django temp user, and he blew it. 353 00:21:49,040 --> 00:21:54,440 So you should still do it, minimal privileges, but again, this is not a silver bullet. 354 00:21:55,060 --> 00:21:59,700 And you do have the revoke active sessions for any role. 355 00:21:59,700 --> 00:22:05,360 Again, assume role path, but that's really mitigation, my, my, not really prevention. 356 00:22:05,360 --> 00: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. 357 00:22:11,940 --> 00:22:15,420 And while it's being used, you don't have a direct way to cancel it. 358 00:22:15,540 --> 00:22:19,120 But in your mitigation procedures, you have some in some cases. 359 00:22:19,160 --> 00:22:25,060 And then in terms of lockdown and prevention for the user, you also don't quite have stuff. 360 00:22:26,000 --> 00:22:27,780 So this is what you're dealing with, right? 361 00:22:27,780 --> 00:22:32,300 This, this is sort of the story with temp tokens. 362 00:22:32,600 --> 00:22:35,460 And I guess I've been talking at 1.5x speed. 363 00:22:35,460 --> 00:22:38,140 So we got about seven minutes, Jeff, by my time. 364 00:22:38,140 --> 00:22:39,580 So I've got two more slides. 365 00:22:39,580 --> 00:22:41,340 So we might even be able to squeeze in a question. 366 00:22:41,340 --> 00:22:46,960 Otherwise, out, out front, I'd be happy to pursue more, more discussion. 367 00:22:46,960 --> 00:22:50,800 So let's, let's talk about sort of the wrap of do's and don'ts. 368 00:22:51,480 --> 00: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. 369 00:23:05,620 --> 00:23:10,500 It's true, if they're savvy, they might pick that up, your get session token call. 370 00:23:11,120 --> 00:23:12,540 That's okay. 371 00:23:14,780 --> 00: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. 372 00:23:24,040 --> 00:23:26,200 So pre-signed URLs are nothing super fancy. 373 00:23:26,200 --> 00: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. 374 00:23:32,080 --> 00:23:33,440 It's just the convenience. 375 00:23:33,520 --> 00:23:37,540 Instead of having, you know, two or three lines of code, you can have a URL. 376 00:23:37,600 --> 00: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. 377 00:23:46,040 --> 00:23:51,160 That might be sort of an interesting thing and more a distraction to obfuscate a bunch of other activity. 378 00:23:51,340 --> 00: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. 379 00:24:06,700 --> 00:24:10,460 So why not add an extra layer of friction to the whole thing, confusion. 380 00:24:10,740 --> 00: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? 381 00:24:19,320 --> 00:24:22,060 It expires in 36 hours, the max. 382 00:24:22,060 --> 00: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. 383 00:24:30,420 --> 00: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? 384 00:24:36,860 --> 00:24:38,140 Just why not? 385 00:24:38,140 --> 00:24:43,460 And it just, just makes everything more obscure, harder to track, harder to figure out. 386 00:24:44,500 --> 00: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. 387 00:24:54,300 --> 00:24:59,980 If they're that knowledgeable and ready, I mean, nothing lost, but you at least know. 388 00:24:59,980 --> 00: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? 389 00:25:07,040 --> 00:25:12,520 So that's the sort of, you know, attack mindset with temporary tokens. 390 00:25:12,520 --> 00:25:16,760 Now let's try to end up on the blue side and see where we're at. 391 00:25:16,760 --> 00: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. 392 00:25:24,100 --> 00:25:28,760 If you haven't spent time on it, do it, get your plan in place, just revise it. 393 00:25:28,760 --> 00:25:36,500 If you have, good for you, but I would still suggest reviewing it because the APIs change all the time. 394 00:25:36,500 --> 00:25:40,500 And, you know, you're not sure what tools are available for you. 395 00:25:40,500 --> 00:25:41,100 Who knows? 396 00:25:41,100 --> 00:25:46,560 We'll probably get a revoke token API call at some point, right, if there's enough abuse. 397 00:25:46,560 --> 00:25:47,720 Talk about prevention. 398 00:25:47,720 --> 00:25:49,240 A lot of things I already covered. 399 00:25:49,340 --> 00:25:51,200 Yeah, you're going to lock down access keys. 400 00:25:51,200 --> 00: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. 401 00:25:57,020 --> 00:25:58,820 So minimal privileges everywhere. 402 00:25:59,300 --> 00: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? 403 00:26:11,100 --> 00:26:16,460 So that's a way to sort of, because it comes through an assume role path, right? 404 00:26:16,460 --> 00: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. 405 00:26:25,680 --> 00:26:27,380 Minimal privileges, so on. 406 00:26:27,380 --> 00:26:28,440 Detection. 407 00:26:28,440 --> 00:26:29,460 We went through that. 408 00:26:29,460 --> 00:26:31,080 Focus on get session token. 409 00:26:31,080 --> 00:26:33,920 Think about assume role, if that's noisy or not. 410 00:26:33,980 --> 00: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. 411 00:26:46,440 --> 00:26:48,380 You have a lot worse problems. 412 00:26:48,380 --> 00:26:49,560 Mitigation remediation. 413 00:26:49,560 --> 00:26:51,080 The hardest part last. 414 00:26:51,080 --> 00:26:54,280 You don't have great things, but review your playbook. 415 00:26:54,500 --> 00: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. 416 00:27:01,600 --> 00:27:06,220 Any use of get session token is immediately worth investigating, right? 417 00:27:07,720 --> 00:27:11,620 Use assume role because you can control it, but it's really noisy, right? 418 00:27:11,900 --> 00:27:14,320 But it allows you to revoke those active sessions, right? 419 00:27:14,320 --> 00:27:16,320 Gives you some mitigation means. 420 00:27:17,320 --> 00:27:23,040 Recovery, I can't stress enough because I think we may be focused on mitigation. 421 00:27:23,260 --> 00: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? 422 00:27:32,580 --> 00:27:34,680 Because you might have blown away user accounts. 423 00:27:35,320 --> 00: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? 424 00:27:45,780 --> 00: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. 425 00:28:07,860 --> 00: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. 426 00:28:24,200 --> 00: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. 427 00:28:34,720 --> 00:28:39,240 But again, that would be valid activity in a lot of cases, so imperfect, right? 428 00:28:39,380 --> 00: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. 429 00:28:56,900 --> 00:28:57,780 Thanks. 430 00:28:57,780 --> 00:28:58,800 Thank you. 431 00:28:58,800 --> 00:28:59,620 Thank you.