He's giving the presentation on serverless log analysis on AWS. Georges is an incident responder at Verizon Media where they have the chance to work on complex problems at scale. He's originally from Greece and has been living in the U.S. for the past four years. 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. Please give a Blue Team Village warm welcome to Georges. Thank you. Wait, because I have a loud voice, let me fix this. Hey everybody, how are you all doing? Alright, we're going to talk today about serverless log analysis on AWS. Hopefully I'm not going to keep you long so you can go to the parties afterwards. Hope you guys are having fun. I'm Georges, as it was said, I'm an incident security engineer at Verizon Media. I work for the Paranoids Fire Team, which we are the forensics incident response engineering team. This is my handle if you want to follow me on Twitter. And also I am a first time speaker, so if I am saying or anything like that, it's because of that. So, first of all, why are we having this talk? We're having this talk because of all the security challenges that we have on the cloud. And as a result, the different challenges that we have on the cloud, right? So, everybody wants to move on the cloud. Either because it might be because of auto scaling or because they want more space or they need more power. They have all the infrastructure they want to move to the cloud. Everyone wants to move to the cloud. And then where the problem comes in because engineers are still learning the tech stack of the cloud. And all the new services that companies like Amazon or Google are spinning up all the time. So, they're not able to keep up. Sorry for that. And also, my last point in this slide is what about cloud security? Because everything in IT, as far as I know, is built up without security in mind in the beginning. So, we have to build up on it. So, yeah, everyone wants in. And then we have fails all the time. Because people do git repos that have AWS keys and they copy the AWS key on the git repos. And actually, there have been a lot of critical incidents out there that have been because of that. 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. I'm not going to say more about that. Then we also have security groups because of misconfigurations, other AWS resources misconfigurations that always bring up problems. But what happens even if we have amazing cloud security teams? What happens if our engineers are amazing at what they're doing? We still have fails. Even if we have the pros defending us, we still have fails. Why is that? Because we always have the server-side vulnerabilities that are never going to go away. We have SSRFs, RCs out there, anything in the OWASP top 10. Anything out there that can lead to exposures on our prem environment, but also on our AWS environment. Does anyone recognize this IP over here that I have on the bottom? If you don't, this is the metadata service that AWS has. 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. Potentially, AWS keys are going to give you access to the rest of your environment. With that, we know that our environment is going to get compromised. Whatever we're going to do, it's going to get compromised at some point. Apart from the defenses, which I'm not going to talk about anything about security defenses in this talk, we need the forensics. We need to know the artifacts. We need to know where all our logs are. We need, first of all, to enable logging, right? Because some people do not even enable logging. We need API logs, access logs, and even more. So, here I come to the CloudTrail. Who out here knows what CloudTrail is? Let me see hands. Awesome. So, CloudTrail essentially is a service that records all the API calls or any other AWS actions that happen on your AWS environment. 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. Or all the other services that you see here that I list. So, by default, it's enabled for up to 90 days. And you can actually really easily access it if you have a single account. You can go to the CloudTrail service and access these logs. They're going to have everything that happens in your environment, apart from host-based logs or network logs, etc. It's just for your AWS resources. So, apart from that, you can store these logs on an S3 bucket and keep them longer in time. 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. And then you can even move them on cloud storage on AWS. 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. 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, right? And it's something you need to investigate. Then you have, in every CloudTrail log, you have a source IP address, which, of course, you can keep in inventory. It's a good practice to keep an inventory of the IPs that normally access your AWS environment. And then if you see something odd, a new IP or something like that, you should investigate. It might be like a developer working from home or something like that, but you definitely need to investigate. 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. 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. The response elements are going to be in your CloudTrail logs only when there is a change in your environment. 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. It didn't make any change. But if you see the response elements field have information there, it's going to have all the changes that have been made there. And also, last but not least, their code. 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. It's a good indicator of something's wrong. So now let's talk about the traditional methods of doing log analysis on CloudTrail logs. And I want to ask a quiz over here to the crowd. So who from over here has actually done investigations on CloudTrail? All right. Not too many. But who of you use grep or jq or any other command line tool? All right. Who of you have a NELT stack that just sends a log there? Okay, so we have half and half. So for the ones who use grep or jq or any other command line tool, it's amazing. It's really cool to have that knowledge and do that on the command line. But it's also like all these CloudTrail logs are already stored on an S3 bucket. And you just go and download them locally or on a server to do analysis. First of all, it's costly to download from the S3 bucket if you want to go download 10 or 20 gigabytes of logs. And then also it's more time consuming. Then for you people who have a NELT stack set up or use, for example, AWS Elasticsearch service, which is amazing. This is amazing, but it's so costly. It's so costly. Then you can also use CloudWatch, which has some limitations. 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. But wait, why did we come over here this late on Friday? To discuss about something that is most efficient, that it scales, and it's fast. So how we do actually AWS logs at scale at Verizon Media is that we have somewhere about... I'm going to just say that we have more than 1,000 accounts, AWS accounts, more than 1,000 AWS accounts. I'm not going to say the exact number. So we have to find a way to manage all this, right? And if we want to do an investigation, how are we going to find all these logs? 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. You need to have a centralized security AWS account that you're going to have all the logs centralized, like a SIEM, right? It's going to sit on AWS on an S3 bucket. 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. You're going to have them encrypted with a key that they send with you, et cetera, et cetera. Okay, um, first of all, please encrypt. Don't have the logs just sitting there. Because they're really valuable for an attacker as well. 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. So yeah, so we have them, let's say that we did that, and we have them all centralized. What do we do now? 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. So Athena is amazing, actually. 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. I mean, no, really, she will do all the magic, but there are some details that we're going to talk about. So how it works. So you first need to have your logs stored in an S3 bucket, and wait. We already have these logs, the CloudStory logs, in an S3 bucket already stored. We don't need to do anything. 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. You don't need to know Hive or create table queries. It's already in AWS. If you search create table CloudTrail, you're going to find the query ready for you. 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. And what Athena does, essentially, is look at the logs, query them, and create a table for you. So what do you need to do afterwards to do your investigation? Just SQL. You don't need anything else. You just go to Athena, use SQL, and do your investigation. No downloading, no Elk Stack, no big money. And as we said, so Athena is a serverless service. You don't need to spin up anything, no instances. It's fast, it's cost efficient, and scalable. It's actually really, really, really cheap. It's $5 per terabyte. And if that doesn't make a lot of sense to you, what is $5 per terabyte? Essentially, what AWS does, they charge you per query. And I'll give you an example. If you run, let's say that you have some monitoring on your CloudTrail logs, and you have Athena looking at it. 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. Every hour, for 24 hours, for 30 days. So again, one gigabyte of logs, 24 hours, for 30 days. It's only going to cost you $3.56. You know how much it would cost you to just have an ELK stack, just sitting there, not doing anything. Just have an ELK stack on the Cloud. $150 for a month. Just sitting there, not doing any analysis. Imagine doing the analysis as well. It's really cheap, it's really efficient. It's essentially a Cloud Presto. And it's available through the AWS console, which you're going to see right after in my quick demo. Through an API, and also through AWS CLI. 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. And you're going to see how I implement it on the demo. It's a cooperatively framework for teams to work together. You essentially have a space that you can save queries in AWS Athena, and other analysts can reuse, make them better. They don't need to have essentially any SQL skills. They just need to have someone who creates an amazing SQL query for investigations, and you just go back and reuse them. Then management actually has great oversight on your investigations, because Athena stores your queries for 90 days. So let's say that you work on an investigation, and your management wants to check out your results. You give them a report, but they can also go in Athena and see the results from your queries, and what queries you run. For back to 90 days. And essentially, AWS doesn't even make you run the query again. It stores the query, and you can just click on the query, and access the results. That simple. I said all that? Let's go to the next one. So over here I have some sample queries for different type of investigations for you. The first one on the top is going to be a query that we look for, as I talked about before, about error code. So we can look for unauthorized operations in AWS resources, or access denied. Then the second one, that's really important, that actually we could use on the breach that happened two weeks ago. We look for a specific key that potentially has been compromised, or that we know that was exposed. And we can see all the activity that happened through that key. And as you see, over here, I have the database and the table, because these queries are on my saved queries tab. So I save all the queries for other people to use in my team. And then this is just a placeholder. Every time you can change the database, the table, and just put your key that you want to look for. Then the last one just looks for changes in security groups. 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. But over here, as you can see, the first one just checks for console logging on your AWS resources. 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. You can use AWS Athena essentially for any structured logs that you may have on AWS or you want to put on AWS. So the first one looks at Apache Access logs. And you can see at a path traversal tag to find a password essentially on a web server. And the second one, you look for your string that you want to look. 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. So here I just talk about this. Athena can work with any type of logs that you want. As many logs as you want. They just have to be in a structured way. You just need to define the schema. Some of them, maybe most of them, are already out there. People have the schema. AWS has the schema for a lot of them. Or if you have a custom log or something that you couldn't find, you can just define the schema. By schema, I mean you just need to define the different columns and the different fields that your logs have. Let's go to the demo. Let's see if this video is going to play or not. All right. So here I'm just on the AWS console. And we can easily access Athena. You just find it on your history if you used it before or just click Athena on the services tab. So now we are inside Athena from the console, right? On the right, you see the query editor, which over here you can write your queries. And you can write, I think, up to 15 queries at the same time. And we're going to see that afterwards. On the left, you have your databases. This is a personal account, so I don't have a lot of databases enabled. But essentially, what I recommend over here for you guys to do is to have a database with its different type of investigation. For example, you have a database that is called CloudTrail. A database that is called Apache Access Logs. A database that is called ELB Logs. And then you have a table for each of your investigations. And you can call the tables the name of your particular investigation. 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. They don't need to come up with their own queries. They have them over here. It's just so easy. 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. That is going to be the database and the table and the location. Not the location, sorry. I'm going to talk about the location right after. Let's move a little bit. And then there's the history tab. So in the history tab, you have all the queries that you ran for the past 90 days. So these queries are saved with the results in a new S3 bucket, actually. And you can access them within 90 days. And the amazing thing about it is that you won't have to run it again. The results are over there. And as you see on the encryption type field, I have them all encrypted. This is really, actually really important. It's a rookie mistake that I did in the beginning. You have to go to your settings right here on the top right. It's not going to look like that in the beginning. It's going to look like this. 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. You need to make sure that you enable this and select the KMS key that you already have to encrypt your CloudTree logs. Otherwise, we are failing as security folks, right? Okay, so now let's go back to actually, let me stop this so I can explain. This is a personal AWS account that I had. And I used an amazing project out there. If you want to test attacks on AWS and defenses and CloudTree logs in Athena, it's called CloudGoat. It's on GitHub. It's an amazing project by some amazing folks. They have some CloudFormation scripts. And again, it's called CloudGoat. That you can create a vulnerable AWS environment. And then they have even the scenarios for you to run attacks. Different types of attacks. I think they have five or six different scenarios that you can attack them. So then I created an environment in my own personal account. I didn't want to use our corporate data, of course. And then I performed a scenario so we can have the logs to see how this works. So first of all, let's go and create the table. We already have the logs. And this is the create table query that is already in AWS. You don't need to create that, right? It's a Hive query that creates a schema. And the only thing you need to do is over here at the bottom. I just did it really quick because I edited the video. You just need to change the placeholders. Which is going to be like the account number that you have. The location. The region. And the date that you want to actually tell Athena to go and create a table from these logs. So over here, really quick, run query. My table was created. And then you can go and check preview table to see if actually your table was created or if there was a mistake. And sometimes there are some mistakes. Most of the time you just need to switch the schema. And over here at the left, you can see the schema essentially of your table. Which is all your different fields on CloudTrail. That's what it is. And each of these is a column on your table. So perfect. So in our scenario, we're notified that there's this user named Solo that had some suspicious activity happening on his account. So we have from our... this happened really quick. Wait, let me go back. Let me go back. So you see, I went to saved queries and I selected the user activity query that I already have there from my senior guy. Because I don't know SPL. So I select this query. And the only thing that I need to do as a junior analyst is just change the user name that I'm looking at. And also change the database and the table that I want to query. And as we're going to see here... I didn't get some results because I had principal ID and I had to change it. I didn't edit it on the video. So I'm just looking at the user identity dot user name. Because user identity is a struct. Oh, sorry about that. Why did that happen? Okay. And we get only two results. And we see that this user Solo was actually accessing some code build projects and listing the projects. Why would that be? So we don't know exactly what happened. But we see there's a source IP address over here. So we're going to check if there was any other actions based on that IP address. So we copy it again. We go to our saved queries that we have for looking for suspicious IPs. I already have put it in here. Run the query. And we're going to get all the results that came from that IP. So we pivoted from user Solo to that particular IP. And we see, oh, there's so many different logs over here. Let's first sort it by time. And then we see that from this IP, actually, first user Solo was accessed. But then something else happened. User Calrissian, another user, got accessed. And you see some actions over here in the event name create DB snapshot. So they are creating a snapshot of one of our RDS databases. This is serious. So let's see what's going on afterwards. And if you go down in the logs, I didn't have time to do, like, a really thorough demo. 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. So then he had access to our secret database with all our secrets over here. And we can see all that in the Cloud Trail logs, all the actions, and we can query them really easily with Athena. Let's see how I can put it back into presentation mode. Anyways, you'll see my bookmarks too. So, apart from all this, right, what else can we do? We can do threat hunting, we can automate all this. We can have queries that are used for our threat hunting activities. We can have automated hunting to be in place using step functions in AWS and Lambda functions. So essentially what step functions is, for the people who don't know, is essentially putting together all your serverless resources, working together. So you can, it's like, if you think it as an orchestration tool. 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. 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. Check it out. I didn't add it in the presentation, but it's something that you really should look at. It's called QuickSight, and you can feed the results from Athena to QuickSight and get some really cool diagrams after that. And I want to talk also about a suggestion to you guys. Even if you want to use AWS Athena or not, a really cool way to track up use the STS keys. 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. It's not going to be created by you, and they're temporary. I think the default is six hours. So these credentials are actually the ones who we see mostly being abused in the wild. Because these are the credentials that someone is going to take advantage using an SSRF attack on your environment. 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. And when we have an Assumeral event, that means that a key was assigned to an EC2 instance. Then normally what would happen is that that key would only be used by that particular EC2 instance. Sometimes developers do some funky stuff, so you might see some edge cases, but normally it's what happens. Then if you look at the AssumedRole events, you're going to see where that particular key was used. 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. 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. So we can make it even faster, right? 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. We can compress and split the files, bucket your data, optimize file sizes, and then also just optimize your SQL queries as well. In conclusion, AWS Athena is fast, cost effective, and easy to use. And I hope that each and every of you consider it, go play with it. 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. Thanks, that was my talk, and if you have any questions, you can ask me here or later. So, you're talking about the history? So, Athena history is right now, AWS has it only for 90 days, the history. 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. But on the dashboard, you're only going to see it for 90 days right now. I looked for that, they don't have that. They just have for 90 days the history. So, it's data scanned. Yes, and most of the time, you won't reach one terabyte of cloud trade logs, right? 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. Really cheap. So, it counts the data that you query. 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. 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. So, yeah, it's per data that you scan. Yes, so the best format is Parquet. You can scan any other data, like JSON, any other type of data. You can have zip files, anything, but Parquet is the best. So, AWS recommends to boot it on Parquet, yes. Ah, that's a tough question. It might be JSON. I'm not sure. I know that the best is Parquet. Maybe JSON. We're good? Thank you so much, guys. Thank you.