1 00:00:00,000 --> 00:00:05,900 He's giving the presentation on serverless log analysis on AWS. 2 00:00:06,700 --> 00:00:13,280 Georges is an incident responder at Verizon Media where they have the chance to work on complex problems at scale. 3 00:00:13,560 --> 00:00:16,040 He's originally from Greece and has been living in the U.S. 4 00:00:16,040 --> 00:00:17,980 for the past four years. 5 00:00:18,480 --> 00:00:30,190 They got their Master's in Cyber Security from Stevens Institute of Technology in Hoboken, New Jersey and hold the GCIH and GNFA from GIAC. 6 00:00:31,380 --> 00:00:36,420 Please give a Blue Team Village warm welcome to Georges. 7 00:00:40,560 --> 00:00:42,560 Thank you. 8 00:00:42,560 --> 00:00:46,260 Wait, because I have a loud voice, let me fix this. 9 00:00:46,420 --> 00:00:48,740 Hey everybody, how are you all doing? 10 00:00:48,740 --> 00:00:53,860 Alright, we're going to talk today about serverless log analysis on AWS. 11 00:00:53,860 --> 00:00:57,680 Hopefully I'm not going to keep you long so you can go to the parties afterwards. 12 00:00:57,720 --> 00:00:59,500 Hope you guys are having fun. 13 00:01:01,680 --> 00:01:07,760 I'm Georges, as it was said, I'm an incident security engineer at Verizon Media. 14 00:01:07,760 --> 00:01:15,260 I work for the Paranoids Fire Team, which we are the forensics incident response engineering team. 15 00:01:15,260 --> 00:01:17,500 This is my handle if you want to follow me on Twitter. 16 00:01:17,960 --> 00:01:22,960 And also I am a first time speaker, so if I am saying or anything like that, it's because of that. 17 00:01:24,240 --> 00:01:26,700 So, first of all, why are we having this talk? 18 00:01:26,700 --> 00:01:31,920 We're having this talk because of all the security challenges that we have on the cloud. 19 00:01:32,060 --> 00:01:35,400 And as a result, the different challenges that we have on the cloud, right? 20 00:01:35,400 --> 00:01:38,640 So, everybody wants to move on the cloud. 21 00:01:38,640 --> 00:01:45,480 Either because it might be because of auto scaling or because they want more space or they need more power. 22 00:01:45,480 --> 00:01:48,420 They have all the infrastructure they want to move to the cloud. 23 00:01:48,440 --> 00:01:50,440 Everyone wants to move to the cloud. 24 00:01:50,480 --> 00:01:56,200 And then where the problem comes in because engineers are still learning the tech stack of the cloud. 25 00:01:56,200 --> 00:02:01,280 And all the new services that companies like Amazon or Google are spinning up all the time. 26 00:02:01,280 --> 00:02:03,960 So, they're not able to keep up. 27 00:02:03,960 --> 00:02:06,200 Sorry for that. 28 00:02:06,780 --> 00:02:11,400 And also, my last point in this slide is what about cloud security? 29 00:02:11,400 --> 00:02:20,140 Because everything in IT, as far as I know, is built up without security in mind in the beginning. 30 00:02:20,140 --> 00:02:22,140 So, we have to build up on it. 31 00:02:22,180 --> 00:02:23,780 So, yeah, everyone wants in. 32 00:02:24,980 --> 00:02:27,880 And then we have fails all the time. 33 00:02:27,880 --> 00:02:37,100 Because people do git repos that have AWS keys and they copy the AWS key on the git repos. 34 00:02:37,100 --> 00:02:44,900 And actually, there have been a lot of critical incidents out there that have been because of that. 35 00:02:45,000 --> 00:02:55,180 Like, I don't know if you guys hear, two weeks ago, a big bank, I'm not going to call the name, had a security incident because of some AWS keys that were exposed. 36 00:02:55,180 --> 00:02:57,100 I'm not going to say more about that. 37 00:02:57,100 --> 00:03:05,240 Then we also have security groups because of misconfigurations, other AWS resources misconfigurations that always bring up problems. 38 00:03:05,420 --> 00:03:09,540 But what happens even if we have amazing cloud security teams? 39 00:03:09,540 --> 00:03:12,500 What happens if our engineers are amazing at what they're doing? 40 00:03:12,500 --> 00:03:13,880 We still have fails. 41 00:03:13,880 --> 00:03:17,480 Even if we have the pros defending us, we still have fails. 42 00:03:17,480 --> 00:03:18,540 Why is that? 43 00:03:18,540 --> 00:03:23,420 Because we always have the server-side vulnerabilities that are never going to go away. 44 00:03:23,420 --> 00:03:28,440 We have SSRFs, RCs out there, anything in the OWASP top 10. 45 00:03:28,440 --> 00:03:35,740 Anything out there that can lead to exposures on our prem environment, but also on our AWS environment. 46 00:03:36,160 --> 00:03:39,720 Does anyone recognize this IP over here that I have on the bottom? 47 00:03:41,120 --> 00:03:45,620 If you don't, this is the metadata service that AWS has. 48 00:03:45,620 --> 00:03:54,200 Essentially, if you get an SSRF on a host that is hosted on AWS, you're going to be able to get a lot of information out there. 49 00:03:55,200 --> 00:03:59,640 Potentially, AWS keys are going to give you access to the rest of your environment. 50 00:04:01,760 --> 00:04:05,460 With that, we know that our environment is going to get compromised. 51 00:04:06,100 --> 00:04:09,020 Whatever we're going to do, it's going to get compromised at some point. 52 00:04:10,360 --> 00:04:15,780 Apart from the defenses, which I'm not going to talk about anything about security defenses in this talk, we need the forensics. 53 00:04:15,780 --> 00:04:17,300 We need to know the artifacts. 54 00:04:18,040 --> 00:04:20,140 We need to know where all our logs are. 55 00:04:20,640 --> 00:04:23,000 We need, first of all, to enable logging, right? 56 00:04:23,000 --> 00:04:24,940 Because some people do not even enable logging. 57 00:04:25,120 --> 00:04:27,520 We need API logs, access logs, and even more. 58 00:04:28,620 --> 00:04:30,980 So, here I come to the CloudTrail. 59 00:04:31,140 --> 00:04:33,360 Who out here knows what CloudTrail is? 60 00:04:33,520 --> 00:04:34,520 Let me see hands. 61 00:04:34,900 --> 00:04:35,620 Awesome. 62 00:04:35,620 --> 00:04:43,080 So, CloudTrail essentially is a service that records all the API calls or any other AWS actions that happen on your AWS environment. 63 00:04:43,080 --> 00:04:52,620 It records all the activity from EC2, it can be security group changes, anything that happens on auto-scaling, like if it's EC2 instance that's been up or shut down, anything like that. 64 00:04:52,620 --> 00:04:55,700 Or all the other services that you see here that I list. 65 00:04:56,040 --> 00:04:59,960 So, by default, it's enabled for up to 90 days. 66 00:04:59,960 --> 00:05:03,640 And you can actually really easily access it if you have a single account. 67 00:05:03,640 --> 00:05:07,460 You can go to the CloudTrail service and access these logs. 68 00:05:07,460 --> 00:05:13,980 They're going to have everything that happens in your environment, apart from host-based logs or network logs, etc. 69 00:05:13,980 --> 00:05:16,520 It's just for your AWS resources. 70 00:05:17,600 --> 00:05:24,420 So, apart from that, you can store these logs on an S3 bucket and keep them longer in time. 71 00:05:24,420 --> 00:05:31,820 And then potentially, depending on your policy, you can store them there for six months, a year, I don't know, whatever your policy for retention. 72 00:05:31,820 --> 00:05:36,580 And then you can even move them on cloud storage on AWS. 73 00:05:37,240 --> 00:05:46,820 So, some of the most important artifacts, and this list is not inclusive, but this is just some of the artifacts that we need to know on AWS. 74 00:05:46,940 --> 00:06:02,720 For example, we can catch script kitties with a user agent, because if there's a script kitty attacking our environment, you're going to see potentially malicious or weird-looking user agents making changes in your environment or accessing your environment that you probably shouldn't have, 75 00:06:02,720 --> 00:06:02,960 right? 76 00:06:02,960 --> 00:06:04,620 And it's something you need to investigate. 77 00:06:04,720 --> 00:06:13,640 Then you have, in every CloudTrail log, you have a source IP address, which, of course, you can keep in inventory. 78 00:06:14,140 --> 00:06:18,860 It's a good practice to keep an inventory of the IPs that normally access your AWS environment. 79 00:06:19,200 --> 00:06:23,660 And then if you see something odd, a new IP or something like that, you should investigate. 80 00:06:23,660 --> 00:06:28,040 It might be like a developer working from home or something like that, but you definitely need to investigate. 81 00:06:28,200 --> 00:06:41,780 Then we have the event name and event source, which, of course, define what you're looking at, and the user identity logs that are going to essentially identify the identity behind the actions that are happening. 82 00:06:41,820 --> 00:06:47,780 Then I want to really point out the response elements, because it's going to make sense also while we go forward in this talk. 83 00:06:47,860 --> 00:06:53,820 The response elements are going to be in your CloudTrail logs only when there is a change in your environment. 84 00:06:53,820 --> 00:07:05,760 So if you see someone on the CloudTrail logs trying to make changes on security groups, but you don't see a response element log in there, like if the field be having some information, it means that they failed. 85 00:07:05,760 --> 00:07:06,880 It didn't make any change. 86 00:07:06,880 --> 00:07:12,680 But if you see the response elements field have information there, it's going to have all the changes that have been made there. 87 00:07:13,000 --> 00:07:15,220 And also, last but not least, their code. 88 00:07:15,220 --> 00:07:29,720 Their code field in CloudTrail log is really important, because there you're going to see any access denied activity or any user that was not supposed to access some resources, is going to have an error code and you're going to find it there. 89 00:07:29,720 --> 00:07:31,820 It's a good indicator of something's wrong. 90 00:07:32,720 --> 00:07:38,140 So now let's talk about the traditional methods of doing log analysis on CloudTrail logs. 91 00:07:38,140 --> 00:07:40,320 And I want to ask a quiz over here to the crowd. 92 00:07:40,600 --> 00:07:45,780 So who from over here has actually done investigations on CloudTrail? 93 00:07:45,780 --> 00:07:48,040 All right. 94 00:07:48,040 --> 00:07:49,020 Not too many. 95 00:07:49,020 --> 00:07:54,060 But who of you use grep or jq or any other command line tool? 96 00:07:54,940 --> 00:07:56,100 All right. 97 00:07:56,480 --> 00:07:59,480 Who of you have a NELT stack that just sends a log there? 98 00:07:59,820 --> 00:08:01,700 Okay, so we have half and half. 99 00:08:01,780 --> 00:08:10,380 So for the ones who use grep or jq or any other command line tool, it's amazing. 100 00:08:10,380 --> 00:08:14,300 It's really cool to have that knowledge and do that on the command line. 101 00:08:14,300 --> 00:08:18,840 But it's also like all these CloudTrail logs are already stored on an S3 bucket. 102 00:08:18,840 --> 00:08:23,040 And you just go and download them locally or on a server to do analysis. 103 00:08:23,100 --> 00:08:28,000 First of all, it's costly to download from the S3 bucket if you want to go download 10 or 20 gigabytes of logs. 104 00:08:28,000 --> 00:08:30,020 And then also it's more time consuming. 105 00:08:30,220 --> 00:08:38,040 Then for you people who have a NELT stack set up or use, for example, AWS Elasticsearch service, which is amazing. 106 00:08:38,220 --> 00:08:41,200 This is amazing, but it's so costly. 107 00:08:41,280 --> 00:08:42,700 It's so costly. 108 00:08:43,260 --> 00:08:47,580 Then you can also use CloudWatch, which has some limitations. 109 00:08:47,620 --> 00:08:57,380 Or if you have a lot of money, I don't know who you work for, but if you have a lot of money, you can use AWS logs to be sent to your SIEM and pay all that money. 110 00:08:57,540 --> 00:09:01,120 But wait, why did we come over here this late on Friday? 111 00:09:01,120 --> 00:09:06,600 To discuss about something that is most efficient, that it scales, and it's fast. 112 00:09:07,960 --> 00:09:15,600 So how we do actually AWS logs at scale at Verizon Media is that we have somewhere about... 113 00:09:16,300 --> 00:09:22,560 I'm going to just say that we have more than 1,000 accounts, AWS accounts, more than 1,000 AWS accounts. 114 00:09:22,560 --> 00:09:23,960 I'm not going to say the exact number. 115 00:09:24,280 --> 00:09:27,460 So we have to find a way to manage all this, right? 116 00:09:27,460 --> 00:09:30,760 And if we want to do an investigation, how are we going to find all these logs? 117 00:09:30,760 --> 00:09:41,300 So what we suggest that you also guys do, if you have more than tens or hundreds of accounts, you need to have all the different account owners send the logs your way. 118 00:09:41,300 --> 00:09:48,360 You need to have a centralized security AWS account that you're going to have all the logs centralized, like a SIEM, right? 119 00:09:48,460 --> 00:09:51,420 It's going to sit on AWS on an S3 bucket. 120 00:09:51,480 --> 00:09:57,860 So you're going to have them all pointed to your S3 bucket, and you're going to have them stored locally, where you're going to keep backups. 121 00:09:57,860 --> 00:10:02,760 You're going to have them encrypted with a key that they send with you, et cetera, et cetera. 122 00:10:03,220 --> 00:10:06,280 Okay, um, first of all, please encrypt. 123 00:10:06,280 --> 00:10:07,920 Don't have the logs just sitting there. 124 00:10:07,920 --> 00:10:10,220 Because they're really valuable for an attacker as well. 125 00:10:10,220 --> 00:10:20,360 Like, they may not, uh, exploit, like, uh, breach, do another breach, but if they find your logs, that's a really good resource for them. 126 00:10:21,120 --> 00:10:24,400 So yeah, so we have them, let's say that we did that, and we have them all centralized. 127 00:10:24,400 --> 00:10:25,420 What do we do now? 128 00:10:26,600 --> 00:10:37,620 So, for you who don't know, Athena is actually an ancient Greek goddess of wisdom, and it happens to also be a serverless query service in AWS. 129 00:10:37,960 --> 00:10:40,360 So Athena is amazing, actually. 130 00:10:40,400 --> 00:10:50,500 It lets you query structured data that are stored in an S3 bucket, and the only thing you need to do is to point it to the right direction, and still do all the magic. 131 00:10:50,500 --> 00:10:55,620 I mean, no, really, she will do all the magic, but there are some details that we're going to talk about. 132 00:10:56,060 --> 00:10:57,400 So how it works. 133 00:10:57,480 --> 00:11:02,320 So you first need to have your logs stored in an S3 bucket, and wait. 134 00:11:02,320 --> 00:11:06,120 We already have these logs, the CloudStory logs, in an S3 bucket already stored. 135 00:11:06,120 --> 00:11:07,240 We don't need to do anything. 136 00:11:07,300 --> 00:11:17,960 We just need to point Athena in the right direction, then define the schema in a create table query, which is actually already, you don't need to do anything. 137 00:11:17,960 --> 00:11:20,980 You don't need to know Hive or create table queries. 138 00:11:20,980 --> 00:11:22,440 It's already in AWS. 139 00:11:22,600 --> 00:11:27,480 If you search create table CloudTrail, you're going to find the query ready for you. 140 00:11:27,480 --> 00:11:34,580 The only thing you need to do is to change the location of the logs that you have, and also name your table the way that you want to name it. 141 00:11:34,580 --> 00:11:40,580 And what Athena does, essentially, is look at the logs, query them, and create a table for you. 142 00:11:40,580 --> 00:11:42,860 So what do you need to do afterwards to do your investigation? 143 00:11:43,060 --> 00:11:44,000 Just SQL. 144 00:11:44,220 --> 00:11:45,180 You don't need anything else. 145 00:11:45,180 --> 00:11:49,080 You just go to Athena, use SQL, and do your investigation. 146 00:11:49,080 --> 00:11:52,740 No downloading, no Elk Stack, no big money. 147 00:11:54,240 --> 00:11:57,340 And as we said, so Athena is a serverless service. 148 00:11:57,340 --> 00:11:59,820 You don't need to spin up anything, no instances. 149 00:11:59,860 --> 00:12:02,460 It's fast, it's cost efficient, and scalable. 150 00:12:02,580 --> 00:12:05,440 It's actually really, really, really cheap. 151 00:12:05,480 --> 00:12:07,480 It's $5 per terabyte. 152 00:12:07,520 --> 00:12:11,560 And if that doesn't make a lot of sense to you, what is $5 per terabyte? 153 00:12:11,560 --> 00:12:16,020 Essentially, what AWS does, they charge you per query. 154 00:12:16,340 --> 00:12:17,920 And I'll give you an example. 155 00:12:18,400 --> 00:12:26,440 If you run, let's say that you have some monitoring on your CloudTrail logs, and you have Athena looking at it. 156 00:12:26,520 --> 00:12:33,940 Like, if you want to search one gigabyte, which wouldn't be the case at all, where you have way less amount of data scanning on CloudTrail. 157 00:12:34,340 --> 00:12:38,000 Every hour, for 24 hours, for 30 days. 158 00:12:38,000 --> 00:12:42,220 So again, one gigabyte of logs, 24 hours, for 30 days. 159 00:12:42,220 --> 00:12:46,120 It's only going to cost you $3.56. 160 00:12:46,860 --> 00:12:51,640 You know how much it would cost you to just have an ELK stack, just sitting there, not doing anything. 161 00:12:51,640 --> 00:12:53,500 Just have an ELK stack on the Cloud. 162 00:12:54,860 --> 00:12:56,420 $150 for a month. 163 00:12:56,420 --> 00:12:58,420 Just sitting there, not doing any analysis. 164 00:12:58,480 --> 00:13:00,160 Imagine doing the analysis as well. 165 00:13:00,200 --> 00:13:01,960 It's really cheap, it's really efficient. 166 00:13:02,020 --> 00:13:04,020 It's essentially a Cloud Presto. 167 00:13:04,020 --> 00:13:09,480 And it's available through the AWS console, which you're going to see right after in my quick demo. 168 00:13:09,480 --> 00:13:12,560 Through an API, and also through AWS CLI. 169 00:13:13,260 --> 00:13:21,280 So essentially, the framework that I'm suggesting today to all of you, to go back home and work with your teams, and hopefully implement it. 170 00:13:21,360 --> 00:13:23,980 And you're going to see how I implement it on the demo. 171 00:13:23,980 --> 00:13:29,280 It's a cooperatively framework for teams to work together. 172 00:13:29,280 --> 00:13:36,380 You essentially have a space that you can save queries in AWS Athena, and other analysts can reuse, make them better. 173 00:13:36,420 --> 00:13:38,800 They don't need to have essentially any SQL skills. 174 00:13:38,800 --> 00:13:45,780 They just need to have someone who creates an amazing SQL query for investigations, and you just go back and reuse them. 175 00:13:45,780 --> 00:13:54,560 Then management actually has great oversight on your investigations, because Athena stores your queries for 90 days. 176 00:13:54,560 --> 00:13:59,600 So let's say that you work on an investigation, and your management wants to check out your results. 177 00:13:59,600 --> 00:14:05,680 You give them a report, but they can also go in Athena and see the results from your queries, and what queries you run. 178 00:14:05,920 --> 00:14:07,660 For back to 90 days. 179 00:14:07,660 --> 00:14:11,620 And essentially, AWS doesn't even make you run the query again. 180 00:14:11,620 --> 00:14:16,880 It stores the query, and you can just click on the query, and access the results. 181 00:14:17,220 --> 00:14:18,260 That simple. 182 00:14:21,500 --> 00:14:22,760 I said all that? 183 00:14:22,760 --> 00:14:23,680 Let's go to the next one. 184 00:14:23,680 --> 00:14:27,940 So over here I have some sample queries for different type of investigations for you. 185 00:14:27,940 --> 00:14:34,820 The first one on the top is going to be a query that we look for, as I talked about before, about error code. 186 00:14:34,820 --> 00:14:40,280 So we can look for unauthorized operations in AWS resources, or access denied. 187 00:14:40,380 --> 00:14:46,840 Then the second one, that's really important, that actually we could use on the breach that happened two weeks ago. 188 00:14:46,840 --> 00:14:53,760 We look for a specific key that potentially has been compromised, or that we know that was exposed. 189 00:14:53,760 --> 00:14:56,600 And we can see all the activity that happened through that key. 190 00:14:56,600 --> 00:15:04,340 And as you see, over here, I have the database and the table, because these queries are on my saved queries tab. 191 00:15:04,440 --> 00:15:07,580 So I save all the queries for other people to use in my team. 192 00:15:07,640 --> 00:15:09,620 And then this is just a placeholder. 193 00:15:09,620 --> 00:15:14,600 Every time you can change the database, the table, and just put your key that you want to look for. 194 00:15:14,600 --> 00:15:20,140 Then the last one just looks for changes in security groups. 195 00:15:20,940 --> 00:15:29,780 Next, actually I should have put that slide after the next one, because I haven't already said that we can use Athena for other logs. 196 00:15:29,800 --> 00:15:35,300 But over here, as you can see, the first one just checks for console logging on your AWS resources. 197 00:15:35,520 --> 00:15:40,700 And then the next two, as you're going to see on the next slide, you can use AWS Athena for more than CloudTrail logs. 198 00:15:40,700 --> 00:15:47,200 You can use AWS Athena essentially for any structured logs that you may have on AWS or you want to put on AWS. 199 00:15:47,200 --> 00:15:50,200 So the first one looks at Apache Access logs. 200 00:15:50,200 --> 00:15:56,020 And you can see at a path traversal tag to find a password essentially on a web server. 201 00:15:56,020 --> 00:16:00,260 And the second one, you look for your string that you want to look. 202 00:16:00,640 --> 00:16:09,540 Maybe it could be in a SQL injection or an XSS or anything that you want to look at your Apache Access logs that has a response code of 200. 203 00:16:10,520 --> 00:16:13,020 So here I just talk about this. 204 00:16:13,180 --> 00:16:16,040 Athena can work with any type of logs that you want. 205 00:16:16,040 --> 00:16:17,960 As many logs as you want. 206 00:16:17,960 --> 00:16:20,540 They just have to be in a structured way. 207 00:16:20,540 --> 00:16:22,420 You just need to define the schema. 208 00:16:23,000 --> 00:16:26,440 Some of them, maybe most of them, are already out there. 209 00:16:26,440 --> 00:16:27,880 People have the schema. 210 00:16:27,940 --> 00:16:30,080 AWS has the schema for a lot of them. 211 00:16:30,080 --> 00:16:36,200 Or if you have a custom log or something that you couldn't find, you can just define the schema. 212 00:16:36,200 --> 00:16:42,160 By schema, I mean you just need to define the different columns and the different fields that your logs have. 213 00:16:43,720 --> 00:16:45,140 Let's go to the demo. 214 00:16:45,300 --> 00:16:47,500 Let's see if this video is going to play or not. 215 00:16:53,440 --> 00:16:54,180 All right. 216 00:16:54,180 --> 00:16:57,160 So here I'm just on the AWS console. 217 00:16:57,680 --> 00:17:00,280 And we can easily access Athena. 218 00:17:00,360 --> 00:17:05,660 You just find it on your history if you used it before or just click Athena on the services tab. 219 00:17:06,840 --> 00:17:10,020 So now we are inside Athena from the console, right? 220 00:17:10,020 --> 00:17:13,960 On the right, you see the query editor, which over here you can write your queries. 221 00:17:14,040 --> 00:17:16,840 And you can write, I think, up to 15 queries at the same time. 222 00:17:16,840 --> 00:17:18,260 And we're going to see that afterwards. 223 00:17:18,460 --> 00:17:20,300 On the left, you have your databases. 224 00:17:20,420 --> 00:17:23,160 This is a personal account, so I don't have a lot of databases enabled. 225 00:17:23,320 --> 00:17:29,960 But essentially, what I recommend over here for you guys to do is to have a database with its different type of investigation. 226 00:17:30,060 --> 00:17:32,700 For example, you have a database that is called CloudTrail. 227 00:17:32,700 --> 00:17:35,000 A database that is called Apache Access Logs. 228 00:17:35,580 --> 00:17:38,300 A database that is called ELB Logs. 229 00:17:38,300 --> 00:17:40,900 And then you have a table for each of your investigations. 230 00:17:41,840 --> 00:17:45,880 And you can call the tables the name of your particular investigation. 231 00:17:45,880 --> 00:18:00,980 Over here, we have the safe query tabs, which I already spoke about, which we can have senior analysts or amazing SQL engineers that you may have on your team create really good queries that then your team can reuse in the future to perform investigations. 232 00:18:00,980 --> 00:18:02,920 They don't need to come up with their own queries. 233 00:18:02,920 --> 00:18:04,200 They have them over here. 234 00:18:04,200 --> 00:18:05,840 It's just so easy. 235 00:18:06,440 --> 00:18:13,880 And then the only thing that you need to do is to select the query and just change the placeholder that I have in each one. 236 00:18:13,880 --> 00:18:17,680 That is going to be the database and the table and the location. 237 00:18:17,720 --> 00:18:18,680 Not the location, sorry. 238 00:18:18,680 --> 00:18:20,620 I'm going to talk about the location right after. 239 00:18:22,180 --> 00:18:23,580 Let's move a little bit. 240 00:18:23,700 --> 00:18:25,860 And then there's the history tab. 241 00:18:25,860 --> 00:18:29,660 So in the history tab, you have all the queries that you ran for the past 90 days. 242 00:18:29,720 --> 00:18:34,800 So these queries are saved with the results in a new S3 bucket, actually. 243 00:18:34,800 --> 00:18:37,720 And you can access them within 90 days. 244 00:18:38,000 --> 00:18:42,260 And the amazing thing about it is that you won't have to run it again. 245 00:18:42,260 --> 00:18:43,540 The results are over there. 246 00:18:43,960 --> 00:18:48,900 And as you see on the encryption type field, I have them all encrypted. 247 00:18:49,020 --> 00:18:51,120 This is really, actually really important. 248 00:18:51,120 --> 00:18:53,060 It's a rookie mistake that I did in the beginning. 249 00:18:53,480 --> 00:18:56,680 You have to go to your settings right here on the top right. 250 00:18:56,960 --> 00:18:58,580 It's not going to look like that in the beginning. 251 00:18:58,640 --> 00:18:59,720 It's going to look like this. 252 00:18:59,720 --> 00:19:07,640 If it's like this, it means that when you run a query, even if your CloudTree logs are encrypted, your results are going to be in clear text. 253 00:19:07,860 --> 00:19:15,360 You need to make sure that you enable this and select the KMS key that you already have to encrypt your CloudTree logs. 254 00:19:15,440 --> 00:19:19,060 Otherwise, we are failing as security folks, right? 255 00:19:19,540 --> 00:19:24,520 Okay, so now let's go back to actually, let me stop this so I can explain. 256 00:19:24,580 --> 00:19:27,160 This is a personal AWS account that I had. 257 00:19:27,160 --> 00:19:29,400 And I used an amazing project out there. 258 00:19:29,400 --> 00:19:37,740 If you want to test attacks on AWS and defenses and CloudTree logs in Athena, it's called CloudGoat. 259 00:19:37,740 --> 00:19:38,760 It's on GitHub. 260 00:19:38,760 --> 00:19:41,480 It's an amazing project by some amazing folks. 261 00:19:42,200 --> 00:19:44,820 They have some CloudFormation scripts. 262 00:19:44,860 --> 00:19:46,620 And again, it's called CloudGoat. 263 00:19:46,620 --> 00:19:50,280 That you can create a vulnerable AWS environment. 264 00:19:50,280 --> 00:19:53,480 And then they have even the scenarios for you to run attacks. 265 00:19:53,480 --> 00:19:54,300 Different types of attacks. 266 00:19:54,300 --> 00:19:58,540 I think they have five or six different scenarios that you can attack them. 267 00:19:58,540 --> 00:20:01,820 So then I created an environment in my own personal account. 268 00:20:01,820 --> 00:20:03,960 I didn't want to use our corporate data, of course. 269 00:20:04,720 --> 00:20:10,040 And then I performed a scenario so we can have the logs to see how this works. 270 00:20:10,220 --> 00:20:12,740 So first of all, let's go and create the table. 271 00:20:12,740 --> 00:20:14,240 We already have the logs. 272 00:20:14,720 --> 00:20:18,840 And this is the create table query that is already in AWS. 273 00:20:18,840 --> 00:20:20,420 You don't need to create that, right? 274 00:20:20,680 --> 00:20:22,920 It's a Hive query that creates a schema. 275 00:20:22,920 --> 00:20:26,160 And the only thing you need to do is over here at the bottom. 276 00:20:26,320 --> 00:20:29,700 I just did it really quick because I edited the video. 277 00:20:29,780 --> 00:20:33,180 You just need to change the placeholders. 278 00:20:33,180 --> 00:20:35,260 Which is going to be like the account number that you have. 279 00:20:35,260 --> 00:20:36,200 The location. 280 00:20:36,220 --> 00:20:36,880 The region. 281 00:20:36,880 --> 00:20:42,260 And the date that you want to actually tell Athena to go and create a table from these logs. 282 00:20:43,400 --> 00:20:45,860 So over here, really quick, run query. 283 00:20:46,100 --> 00:20:47,440 My table was created. 284 00:20:47,440 --> 00:20:54,420 And then you can go and check preview table to see if actually your table was created or if there was a mistake. 285 00:20:54,680 --> 00:20:56,340 And sometimes there are some mistakes. 286 00:20:56,900 --> 00:21:01,560 Most of the time you just need to switch the schema. 287 00:21:01,560 --> 00:21:05,460 And over here at the left, you can see the schema essentially of your table. 288 00:21:05,460 --> 00:21:09,760 Which is all your different fields on CloudTrail. 289 00:21:09,760 --> 00:21:10,680 That's what it is. 290 00:21:10,680 --> 00:21:13,180 And each of these is a column on your table. 291 00:21:14,200 --> 00:21:15,040 So perfect. 292 00:21:15,040 --> 00:21:23,720 So in our scenario, we're notified that there's this user named Solo that had some suspicious activity happening on his account. 293 00:21:23,840 --> 00:21:27,080 So we have from our... this happened really quick. 294 00:21:27,080 --> 00:21:28,240 Wait, let me go back. 295 00:21:28,360 --> 00:21:29,420 Let me go back. 296 00:21:29,760 --> 00:21:35,780 So you see, I went to saved queries and I selected the user activity query that I already have there from my senior guy. 297 00:21:35,780 --> 00:21:37,300 Because I don't know SPL. 298 00:21:38,400 --> 00:21:39,620 So I select this query. 299 00:21:39,620 --> 00:21:45,620 And the only thing that I need to do as a junior analyst is just change the user name that I'm looking at. 300 00:21:45,620 --> 00:21:50,200 And also change the database and the table that I want to query. 301 00:21:51,120 --> 00:21:54,160 And as we're going to see here... 302 00:22:01,740 --> 00:22:05,400 I didn't get some results because I had principal ID and I had to change it. 303 00:22:05,480 --> 00:22:06,860 I didn't edit it on the video. 304 00:22:06,860 --> 00:22:09,700 So I'm just looking at the user identity dot user name. 305 00:22:09,700 --> 00:22:11,880 Because user identity is a struct. 306 00:22:12,020 --> 00:22:14,720 Oh, sorry about that. 307 00:22:15,280 --> 00:22:16,460 Why did that happen? 308 00:22:17,600 --> 00:22:18,460 Okay. 309 00:22:18,460 --> 00:22:20,220 And we get only two results. 310 00:22:20,220 --> 00:22:28,240 And we see that this user Solo was actually accessing some code build projects and listing the projects. 311 00:22:28,240 --> 00:22:29,420 Why would that be? 312 00:22:29,920 --> 00:22:31,880 So we don't know exactly what happened. 313 00:22:31,880 --> 00:22:34,440 But we see there's a source IP address over here. 314 00:22:34,440 --> 00:22:37,940 So we're going to check if there was any other actions based on that IP address. 315 00:22:37,940 --> 00:22:39,180 So we copy it again. 316 00:22:39,180 --> 00:22:44,220 We go to our saved queries that we have for looking for suspicious IPs. 317 00:22:44,300 --> 00:22:46,340 I already have put it in here. 318 00:22:46,360 --> 00:22:47,660 Run the query. 319 00:22:47,740 --> 00:22:50,340 And we're going to get all the results that came from that IP. 320 00:22:50,340 --> 00:22:53,020 So we pivoted from user Solo to that particular IP. 321 00:22:53,020 --> 00:22:57,240 And we see, oh, there's so many different logs over here. 322 00:22:57,420 --> 00:22:59,380 Let's first sort it by time. 323 00:22:59,380 --> 00:23:03,860 And then we see that from this IP, actually, first user Solo was accessed. 324 00:23:03,860 --> 00:23:05,400 But then something else happened. 325 00:23:05,400 --> 00:23:08,220 User Calrissian, another user, got accessed. 326 00:23:08,260 --> 00:23:12,180 And you see some actions over here in the event name create DB snapshot. 327 00:23:13,620 --> 00:23:20,140 So they are creating a snapshot of one of our RDS databases. 328 00:23:21,040 --> 00:23:22,180 This is serious. 329 00:23:22,240 --> 00:23:23,940 So let's see what's going on afterwards. 330 00:23:24,440 --> 00:23:30,520 And if you go down in the logs, I didn't have time to do, like, a really thorough demo. 331 00:23:30,520 --> 00:23:49,500 But if you see down here at the bottom, you can see actually that the user was actually able to, I was a user with Cloud Go, to create a snapshot of our database, because the user Calrissian who accessed the credentials had those permissions, and then changed the master password to that database. 332 00:23:49,500 --> 00:23:54,540 So then he had access to our secret database with all our secrets over here. 333 00:23:54,600 --> 00:24:01,040 And we can see all that in the Cloud Trail logs, all the actions, and we can query them really easily with Athena. 334 00:24:20,980 --> 00:24:23,460 Let's see how I can put it back into presentation mode. 335 00:24:25,200 --> 00:24:27,200 Anyways, you'll see my bookmarks too. 336 00:24:29,020 --> 00:24:32,840 So, apart from all this, right, what else can we do? 337 00:24:32,840 --> 00:24:35,440 We can do threat hunting, we can automate all this. 338 00:24:35,440 --> 00:24:38,860 We can have queries that are used for our threat hunting activities. 339 00:24:38,860 --> 00:24:46,960 We can have automated hunting to be in place using step functions in AWS and Lambda functions. 340 00:24:46,960 --> 00:24:57,840 So essentially what step functions is, for the people who don't know, is essentially putting together all your serverless resources, working together. 341 00:24:57,840 --> 00:25:02,300 So you can, it's like, if you think it as an orchestration tool. 342 00:25:02,300 --> 00:25:12,340 You can have Athena querying your logs, and then getting the output to a Lambda function, and then the output from the Lambda function back again to Athena to create another table, and so on. 343 00:25:13,120 --> 00:25:21,700 And something that I didn't add in this presentation, actually, that I want to mention, is that you can even have really amazing diagrams come out of this using QuickSight. 344 00:25:21,740 --> 00:25:22,160 Check it out. 345 00:25:22,160 --> 00:25:24,800 I didn't add it in the presentation, but it's something that you really should look at. 346 00:25:24,800 --> 00:25:32,000 It's called QuickSight, and you can feed the results from Athena to QuickSight and get some really cool diagrams after that. 347 00:25:32,000 --> 00:25:36,260 And I want to talk also about a suggestion to you guys. 348 00:25:36,640 --> 00:25:42,480 Even if you want to use AWS Athena or not, a really cool way to track up use the STS keys. 349 00:25:42,520 --> 00:25:54,080 So what STS keys is, the temporary credentials that actually AWS creates and assigns to your EC2 resources, which is created automatically, and it's assigned to an EC2 instance. 350 00:25:54,080 --> 00:25:57,160 It's not going to be created by you, and they're temporary. 351 00:25:57,160 --> 00:25:59,080 I think the default is six hours. 352 00:25:59,080 --> 00:26:06,080 So these credentials are actually the ones who we see mostly being abused in the wild. 353 00:26:06,080 --> 00:26:11,160 Because these are the credentials that someone is going to take advantage using an SSRF attack on your environment. 354 00:26:11,320 --> 00:26:22,960 So the way that we can track it, even if we don't know that something was exposed on a GitHub page or something like that, we can find all the Assumeral logs in our CloudTrail logs. 355 00:26:22,980 --> 00:26:29,060 And when we have an Assumeral event, that means that a key was assigned to an EC2 instance. 356 00:26:29,060 --> 00:26:36,300 Then normally what would happen is that that key would only be used by that particular EC2 instance. 357 00:26:36,540 --> 00:26:42,040 Sometimes developers do some funky stuff, so you might see some edge cases, but normally it's what happens. 358 00:26:42,140 --> 00:26:47,960 Then if you look at the AssumedRole events, you're going to see where that particular key was used. 359 00:26:48,040 --> 00:27:00,580 So if we don't have an edge case with a developer, and we see a key being used with an AssumedRole event from a different IP or a different EC2 resource, then this is something we need to investigate. 360 00:27:00,580 --> 00:27:06,660 So please, if there is one takeaway that you need to take from this, this is the one you need to take and look at your environment. 361 00:27:07,660 --> 00:27:10,680 So we can make it even faster, right? 362 00:27:10,760 --> 00:27:22,220 If we partition the data that we have on CloudTrail, in some cases you can make it even 99% better and up to 90% cheaper. 363 00:27:22,220 --> 00:27:30,380 We can compress and split the files, bucket your data, optimize file sizes, and then also just optimize your SQL queries as well. 364 00:27:31,480 --> 00:27:37,900 In conclusion, AWS Athena is fast, cost effective, and easy to use. 365 00:27:37,900 --> 00:27:43,080 And I hope that each and every of you consider it, go play with it. 366 00:27:43,080 --> 00:27:55,560 I definitely recommend setting up a personal account using Cloud Go to create the logs that you can look at afterwards and start doing some investigations on your own and then potentially bring it to your organization. 367 00:27:56,280 --> 00:28:01,280 Thanks, that was my talk, and if you have any questions, you can ask me here or later. 368 00:28:17,710 --> 00:28:20,060 So, you're talking about the history? 369 00:28:21,550 --> 00:28:27,590 So, Athena history is right now, AWS has it only for 90 days, the history. 370 00:28:27,590 --> 00:28:36,290 But then, if you would want, you could go to manually then on the S3 bucket that they are stored and move them somewhere else. 371 00:28:36,330 --> 00:28:39,650 But on the dashboard, you're only going to see it for 90 days right now. 372 00:28:39,650 --> 00:28:42,730 I looked for that, they don't have that. 373 00:28:42,830 --> 00:28:44,550 They just have for 90 days the history. 374 00:28:51,880 --> 00:28:53,600 So, it's data scanned. 375 00:28:53,600 --> 00:28:58,400 Yes , and most of the time, you won't reach one terabyte of cloud trade logs, right? 376 00:28:58,400 --> 00:29:07,900 In most of the cases, the case that I worked at has been like, I don't know, 5 gigabytes if you look for a month, maybe 10 gigabytes, which is going to be really, really cheap. 377 00:29:07,960 --> 00:29:08,660 Really cheap. 378 00:29:12,010 --> 00:29:15,470 So, it counts the data that you query. 379 00:29:15,610 --> 00:29:24,070 So, that's why I say over here, I say partition your data, because if you go and scan your whole account for the whole year, it's going to be 100 gigabytes. 380 00:29:24,070 --> 00:29:33,450 But if you partition the data and you specify that I want to look for those days, for those 10 days, it's going to be 10 times less. 381 00:29:33,470 --> 00:29:36,490 So, yeah, it's per data that you scan. 382 00:29:56,880 --> 00:29:59,780 Yes, so the best format is Parquet. 383 00:30:00,320 --> 00:30:04,660 You can scan any other data, like JSON, any other type of data. 384 00:30:04,660 --> 00:30:07,840 You can have zip files, anything, but Parquet is the best. 385 00:30:07,840 --> 00:30:10,540 So, AWS recommends to boot it on Parquet, yes. 386 00:30:13,340 --> 00:30:15,280 Ah, that's a tough question. 387 00:30:15,740 --> 00:30:16,680 It might be JSON. 388 00:30:16,680 --> 00:30:17,140 I'm not sure. 389 00:30:17,140 --> 00:30:18,520 I know that the best is Parquet. 390 00:30:18,520 --> 00:30:19,600 Maybe JSON. 391 00:30:21,800 --> 00:30:22,400 We're good? 392 00:30:22,740 --> 00:30:24,020 Thank you so much, guys. 393 00:30:26,200 --> 00:30:26,940 Thank you.