WEBVTT

00:00.000 --> 00:05.900
He's giving the presentation on serverless log analysis on AWS.

00:06.700 --> 00:13.280
Georges is an incident responder at Verizon Media where they have the chance to work on complex problems at scale.

00:13.560 --> 00:16.040
He's originally from Greece and has been living in the U.S.

00:16.040 --> 00:17.980
for the past four years.

00:18.480 --> 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.

00:31.380 --> 00:36.420
Please give a Blue Team Village warm welcome to Georges.

00:40.560 --> 00:42.560
Thank you.

00:42.560 --> 00:46.260
Wait, because I have a loud voice, let me fix this.

00:46.420 --> 00:48.740
Hey everybody, how are you all doing?

00:48.740 --> 00:53.860
Alright, we're going to talk today about serverless log analysis on AWS.

00:53.860 --> 00:57.680
Hopefully I'm not going to keep you long so you can go to the parties afterwards.

00:57.720 --> 00:59.500
Hope you guys are having fun.

01:01.680 --> 01:07.760
I'm Georges, as it was said, I'm an incident security engineer at Verizon Media.

01:07.760 --> 01:15.260
I work for the Paranoids Fire Team, which we are the forensics incident response engineering team.

01:15.260 --> 01:17.500
This is my handle if you want to follow me on Twitter.

01:17.960 --> 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.

01:24.240 --> 01:26.700
So, first of all, why are we having this talk?

01:26.700 --> 01:31.920
We're having this talk because of all the security challenges that we have on the cloud.

01:32.060 --> 01:35.400
And as a result, the different challenges that we have on the cloud, right?

01:35.400 --> 01:38.640
So, everybody wants to move on the cloud.

01:38.640 --> 01:45.480
Either because it might be because of auto scaling or because they want more space or they need more power.

01:45.480 --> 01:48.420
They have all the infrastructure they want to move to the cloud.

01:48.440 --> 01:50.440
Everyone wants to move to the cloud.

01:50.480 --> 01:56.200
And then where the problem comes in because engineers are still learning the tech stack of the cloud.

01:56.200 --> 02:01.280
And all the new services that companies like Amazon or Google are spinning up all the time.

02:01.280 --> 02:03.960
So, they're not able to keep up.

02:03.960 --> 02:06.200
Sorry for that.

02:06.780 --> 02:11.400
And also, my last point in this slide is what about cloud security?

02:11.400 --> 02:20.140
Because everything in IT, as far as I know, is built up without security in mind in the beginning.

02:20.140 --> 02:22.140
So, we have to build up on it.

02:22.180 --> 02:23.780
So, yeah, everyone wants in.

02:24.980 --> 02:27.880
And then we have fails all the time.

02:27.880 --> 02:37.100
Because people do git repos that have AWS keys and they copy the AWS key on the git repos.

02:37.100 --> 02:44.900
And actually, there have been a lot of critical incidents out there that have been because of that.

02:45.000 --> 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.

02:55.180 --> 02:57.100
I'm not going to say more about that.

02:57.100 --> 03:05.240
Then we also have security groups because of misconfigurations, other AWS resources misconfigurations that always bring up problems.

03:05.420 --> 03:09.540
But what happens even if we have amazing cloud security teams?

03:09.540 --> 03:12.500
What happens if our engineers are amazing at what they're doing?

03:12.500 --> 03:13.880
We still have fails.

03:13.880 --> 03:17.480
Even if we have the pros defending us, we still have fails.

03:17.480 --> 03:18.540
Why is that?

03:18.540 --> 03:23.420
Because we always have the server-side vulnerabilities that are never going to go away.

03:23.420 --> 03:28.440
We have SSRFs, RCs out there, anything in the OWASP top 10.

03:28.440 --> 03:35.740
Anything out there that can lead to exposures on our prem environment, but also on our AWS environment.

03:36.160 --> 03:39.720
Does anyone recognize this IP over here that I have on the bottom?

03:41.120 --> 03:45.620
If you don't, this is the metadata service that AWS has.

03:45.620 --> 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.

03:55.200 --> 03:59.640
Potentially, AWS keys are going to give you access to the rest of your environment.

04:01.760 --> 04:05.460
With that, we know that our environment is going to get compromised.

04:06.100 --> 04:09.020
Whatever we're going to do, it's going to get compromised at some point.

04:10.360 --> 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.

04:15.780 --> 04:17.300
We need to know the artifacts.

04:18.040 --> 04:20.140
We need to know where all our logs are.

04:20.640 --> 04:23.000
We need, first of all, to enable logging, right?

04:23.000 --> 04:24.940
Because some people do not even enable logging.

04:25.120 --> 04:27.520
We need API logs, access logs, and even more.

04:28.620 --> 04:30.980
So, here I come to the CloudTrail.

04:31.140 --> 04:33.360
Who out here knows what CloudTrail is?

04:33.520 --> 04:34.520
Let me see hands.

04:34.900 --> 04:35.620
Awesome.

04:35.620 --> 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.

04:43.080 --> 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.

04:52.620 --> 04:55.700
Or all the other services that you see here that I list.

04:56.040 --> 04:59.960
So, by default, it's enabled for up to 90 days.

04:59.960 --> 05:03.640
And you can actually really easily access it if you have a single account.

05:03.640 --> 05:07.460
You can go to the CloudTrail service and access these logs.

05:07.460 --> 05:13.980
They're going to have everything that happens in your environment, apart from host-based logs or network logs, etc.

05:13.980 --> 05:16.520
It's just for your AWS resources.

05:17.600 --> 05:24.420
So, apart from that, you can store these logs on an S3 bucket and keep them longer in time.

05:24.420 --> 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.

05:31.820 --> 05:36.580
And then you can even move them on cloud storage on AWS.

05:37.240 --> 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.

05:46.940 --> 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,

06:02.720 --> 06:02.960
right?

06:02.960 --> 06:04.620
And it's something you need to investigate.

06:04.720 --> 06:13.640
Then you have, in every CloudTrail log, you have a source IP address, which, of course, you can keep in inventory.

06:14.140 --> 06:18.860
It's a good practice to keep an inventory of the IPs that normally access your AWS environment.

06:19.200 --> 06:23.660
And then if you see something odd, a new IP or something like that, you should investigate.

06:23.660 --> 06:28.040
It might be like a developer working from home or something like that, but you definitely need to investigate.

06:28.200 --> 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.

06:41.820 --> 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.

06:47.860 --> 06:53.820
The response elements are going to be in your CloudTrail logs only when there is a change in your environment.

06:53.820 --> 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.

07:05.760 --> 07:06.880
It didn't make any change.

07:06.880 --> 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.

07:13.000 --> 07:15.220
And also, last but not least, their code.

07:15.220 --> 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.

07:29.720 --> 07:31.820
It's a good indicator of something's wrong.

07:32.720 --> 07:38.140
So now let's talk about the traditional methods of doing log analysis on CloudTrail logs.

07:38.140 --> 07:40.320
And I want to ask a quiz over here to the crowd.

07:40.600 --> 07:45.780
So who from over here has actually done investigations on CloudTrail?

07:45.780 --> 07:48.040
All right.

07:48.040 --> 07:49.020
Not too many.

07:49.020 --> 07:54.060
But who of you use grep or jq or any other command line tool?

07:54.940 --> 07:56.100
All right.

07:56.480 --> 07:59.480
Who of you have a NELT stack that just sends a log there?

07:59.820 --> 08:01.700
Okay, so we have half and half.

08:01.780 --> 08:10.380
So for the ones who use grep or jq or any other command line tool, it's amazing.

08:10.380 --> 08:14.300
It's really cool to have that knowledge and do that on the command line.

08:14.300 --> 08:18.840
But it's also like all these CloudTrail logs are already stored on an S3 bucket.

08:18.840 --> 08:23.040
And you just go and download them locally or on a server to do analysis.

08:23.100 --> 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.

08:28.000 --> 08:30.020
And then also it's more time consuming.

08:30.220 --> 08:38.040
Then for you people who have a NELT stack set up or use, for example, AWS Elasticsearch service, which is amazing.

08:38.220 --> 08:41.200
This is amazing, but it's so costly.

08:41.280 --> 08:42.700
It's so costly.

08:43.260 --> 08:47.580
Then you can also use CloudWatch, which has some limitations.

08:47.620 --> 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.

08:57.540 --> 09:01.120
But wait, why did we come over here this late on Friday?

09:01.120 --> 09:06.600
To discuss about something that is most efficient, that it scales, and it's fast.

09:07.960 --> 09:15.600
So how we do actually AWS logs at scale at Verizon Media is that we have somewhere about...

09:16.300 --> 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.

09:22.560 --> 09:23.960
I'm not going to say the exact number.

09:24.280 --> 09:27.460
So we have to find a way to manage all this, right?

09:27.460 --> 09:30.760
And if we want to do an investigation, how are we going to find all these logs?

09:30.760 --> 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.

09:41.300 --> 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?

09:48.460 --> 09:51.420
It's going to sit on AWS on an S3 bucket.

09:51.480 --> 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.

09:57.860 --> 10:02.760
You're going to have them encrypted with a key that they send with you, et cetera, et cetera.

10:03.220 --> 10:06.280
Okay, um, first of all, please encrypt.

10:06.280 --> 10:07.920
Don't have the logs just sitting there.

10:07.920 --> 10:10.220
Because they're really valuable for an attacker as well.

10:10.220 --> 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.

10:21.120 --> 10:24.400
So yeah, so we have them, let's say that we did that, and we have them all centralized.

10:24.400 --> 10:25.420
What do we do now?

10:26.600 --> 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.

10:37.960 --> 10:40.360
So Athena is amazing, actually.

10:40.400 --> 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.

10:50.500 --> 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.

10:56.060 --> 10:57.400
So how it works.

10:57.480 --> 11:02.320
So you first need to have your logs stored in an S3 bucket, and wait.

11:02.320 --> 11:06.120
We already have these logs, the CloudStory logs, in an S3 bucket already stored.

11:06.120 --> 11:07.240
We don't need to do anything.

11:07.300 --> 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.

11:17.960 --> 11:20.980
You don't need to know Hive or create table queries.

11:20.980 --> 11:22.440
It's already in AWS.

11:22.600 --> 11:27.480
If you search create table CloudTrail, you're going to find the query ready for you.

11:27.480 --> 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.

11:34.580 --> 11:40.580
And what Athena does, essentially, is look at the logs, query them, and create a table for you.

11:40.580 --> 11:42.860
So what do you need to do afterwards to do your investigation?

11:43.060 --> 11:44.000
Just SQL.

11:44.220 --> 11:45.180
You don't need anything else.

11:45.180 --> 11:49.080
You just go to Athena, use SQL, and do your investigation.

11:49.080 --> 11:52.740
No downloading, no Elk Stack, no big money.

11:54.240 --> 11:57.340
And as we said, so Athena is a serverless service.

11:57.340 --> 11:59.820
You don't need to spin up anything, no instances.

11:59.860 --> 12:02.460
It's fast, it's cost efficient, and scalable.

12:02.580 --> 12:05.440
It's actually really, really, really cheap.

12:05.480 --> 12:07.480
It's $5 per terabyte.

12:07.520 --> 12:11.560
And if that doesn't make a lot of sense to you, what is $5 per terabyte?

12:11.560 --> 12:16.020
Essentially, what AWS does, they charge you per query.

12:16.340 --> 12:17.920
And I'll give you an example.

12:18.400 --> 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.

12:26.520 --> 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.

12:34.340 --> 12:38.000
Every hour, for 24 hours, for 30 days.

12:38.000 --> 12:42.220
So again, one gigabyte of logs, 24 hours, for 30 days.

12:42.220 --> 12:46.120
It's only going to cost you $3.56.

12:46.860 --> 12:51.640
You know how much it would cost you to just have an ELK stack, just sitting there, not doing anything.

12:51.640 --> 12:53.500
Just have an ELK stack on the Cloud.

12:54.860 --> 12:56.420
$150 for a month.

12:56.420 --> 12:58.420
Just sitting there, not doing any analysis.

12:58.480 --> 13:00.160
Imagine doing the analysis as well.

13:00.200 --> 13:01.960
It's really cheap, it's really efficient.

13:02.020 --> 13:04.020
It's essentially a Cloud Presto.

13:04.020 --> 13:09.480
And it's available through the AWS console, which you're going to see right after in my quick demo.

13:09.480 --> 13:12.560
Through an API, and also through AWS CLI.

13:13.260 --> 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.

13:21.360 --> 13:23.980
And you're going to see how I implement it on the demo.

13:23.980 --> 13:29.280
It's a cooperatively framework for teams to work together.

13:29.280 --> 13:36.380
You essentially have a space that you can save queries in AWS Athena, and other analysts can reuse, make them better.

13:36.420 --> 13:38.800
They don't need to have essentially any SQL skills.

13:38.800 --> 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.

13:45.780 --> 13:54.560
Then management actually has great oversight on your investigations, because Athena stores your queries for 90 days.

13:54.560 --> 13:59.600
So let's say that you work on an investigation, and your management wants to check out your results.

13:59.600 --> 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.

14:05.920 --> 14:07.660
For back to 90 days.

14:07.660 --> 14:11.620
And essentially, AWS doesn't even make you run the query again.

14:11.620 --> 14:16.880
It stores the query, and you can just click on the query, and access the results.

14:17.220 --> 14:18.260
That simple.

14:21.500 --> 14:22.760
I said all that?

14:22.760 --> 14:23.680
Let's go to the next one.

14:23.680 --> 14:27.940
So over here I have some sample queries for different type of investigations for you.

14:27.940 --> 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.

14:34.820 --> 14:40.280
So we can look for unauthorized operations in AWS resources, or access denied.

14:40.380 --> 14:46.840
Then the second one, that's really important, that actually we could use on the breach that happened two weeks ago.

14:46.840 --> 14:53.760
We look for a specific key that potentially has been compromised, or that we know that was exposed.

14:53.760 --> 14:56.600
And we can see all the activity that happened through that key.

14:56.600 --> 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.

15:04.440 --> 15:07.580
So I save all the queries for other people to use in my team.

15:07.640 --> 15:09.620
And then this is just a placeholder.

15:09.620 --> 15:14.600
Every time you can change the database, the table, and just put your key that you want to look for.

15:14.600 --> 15:20.140
Then the last one just looks for changes in security groups.

15:20.940 --> 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.

15:29.800 --> 15:35.300
But over here, as you can see, the first one just checks for console logging on your AWS resources.

15:35.520 --> 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.

15:40.700 --> 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.

15:47.200 --> 15:50.200
So the first one looks at Apache Access logs.

15:50.200 --> 15:56.020
And you can see at a path traversal tag to find a password essentially on a web server.

15:56.020 --> 16:00.260
And the second one, you look for your string that you want to look.

16:00.640 --> 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.

16:10.520 --> 16:13.020
So here I just talk about this.

16:13.180 --> 16:16.040
Athena can work with any type of logs that you want.

16:16.040 --> 16:17.960
As many logs as you want.

16:17.960 --> 16:20.540
They just have to be in a structured way.

16:20.540 --> 16:22.420
You just need to define the schema.

16:23.000 --> 16:26.440
Some of them, maybe most of them, are already out there.

16:26.440 --> 16:27.880
People have the schema.

16:27.940 --> 16:30.080
AWS has the schema for a lot of them.

16:30.080 --> 16:36.200
Or if you have a custom log or something that you couldn't find, you can just define the schema.

16:36.200 --> 16:42.160
By schema, I mean you just need to define the different columns and the different fields that your logs have.

16:43.720 --> 16:45.140
Let's go to the demo.

16:45.300 --> 16:47.500
Let's see if this video is going to play or not.

16:53.440 --> 16:54.180
All right.

16:54.180 --> 16:57.160
So here I'm just on the AWS console.

16:57.680 --> 17:00.280
And we can easily access Athena.

17:00.360 --> 17:05.660
You just find it on your history if you used it before or just click Athena on the services tab.

17:06.840 --> 17:10.020
So now we are inside Athena from the console, right?

17:10.020 --> 17:13.960
On the right, you see the query editor, which over here you can write your queries.

17:14.040 --> 17:16.840
And you can write, I think, up to 15 queries at the same time.

17:16.840 --> 17:18.260
And we're going to see that afterwards.

17:18.460 --> 17:20.300
On the left, you have your databases.

17:20.420 --> 17:23.160
This is a personal account, so I don't have a lot of databases enabled.

17:23.320 --> 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.

17:30.060 --> 17:32.700
For example, you have a database that is called CloudTrail.

17:32.700 --> 17:35.000
A database that is called Apache Access Logs.

17:35.580 --> 17:38.300
A database that is called ELB Logs.

17:38.300 --> 17:40.900
And then you have a table for each of your investigations.

17:41.840 --> 17:45.880
And you can call the tables the name of your particular investigation.

17:45.880 --> 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.

18:00.980 --> 18:02.920
They don't need to come up with their own queries.

18:02.920 --> 18:04.200
They have them over here.

18:04.200 --> 18:05.840
It's just so easy.

18:06.440 --> 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.

18:13.880 --> 18:17.680
That is going to be the database and the table and the location.

18:17.720 --> 18:18.680
Not the location, sorry.

18:18.680 --> 18:20.620
I'm going to talk about the location right after.

18:22.180 --> 18:23.580
Let's move a little bit.

18:23.700 --> 18:25.860
And then there's the history tab.

18:25.860 --> 18:29.660
So in the history tab, you have all the queries that you ran for the past 90 days.

18:29.720 --> 18:34.800
So these queries are saved with the results in a new S3 bucket, actually.

18:34.800 --> 18:37.720
And you can access them within 90 days.

18:38.000 --> 18:42.260
And the amazing thing about it is that you won't have to run it again.

18:42.260 --> 18:43.540
The results are over there.

18:43.960 --> 18:48.900
And as you see on the encryption type field, I have them all encrypted.

18:49.020 --> 18:51.120
This is really, actually really important.

18:51.120 --> 18:53.060
It's a rookie mistake that I did in the beginning.

18:53.480 --> 18:56.680
You have to go to your settings right here on the top right.

18:56.960 --> 18:58.580
It's not going to look like that in the beginning.

18:58.640 --> 18:59.720
It's going to look like this.

18:59.720 --> 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.

19:07.860 --> 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.

19:15.440 --> 19:19.060
Otherwise, we are failing as security folks, right?

19:19.540 --> 19:24.520
Okay, so now let's go back to actually, let me stop this so I can explain.

19:24.580 --> 19:27.160
This is a personal AWS account that I had.

19:27.160 --> 19:29.400
And I used an amazing project out there.

19:29.400 --> 19:37.740
If you want to test attacks on AWS and defenses and CloudTree logs in Athena, it's called CloudGoat.

19:37.740 --> 19:38.760
It's on GitHub.

19:38.760 --> 19:41.480
It's an amazing project by some amazing folks.

19:42.200 --> 19:44.820
They have some CloudFormation scripts.

19:44.860 --> 19:46.620
And again, it's called CloudGoat.

19:46.620 --> 19:50.280
That you can create a vulnerable AWS environment.

19:50.280 --> 19:53.480
And then they have even the scenarios for you to run attacks.

19:53.480 --> 19:54.300
Different types of attacks.

19:54.300 --> 19:58.540
I think they have five or six different scenarios that you can attack them.

19:58.540 --> 20:01.820
So then I created an environment in my own personal account.

20:01.820 --> 20:03.960
I didn't want to use our corporate data, of course.

20:04.720 --> 20:10.040
And then I performed a scenario so we can have the logs to see how this works.

20:10.220 --> 20:12.740
So first of all, let's go and create the table.

20:12.740 --> 20:14.240
We already have the logs.

20:14.720 --> 20:18.840
And this is the create table query that is already in AWS.

20:18.840 --> 20:20.420
You don't need to create that, right?

20:20.680 --> 20:22.920
It's a Hive query that creates a schema.

20:22.920 --> 20:26.160
And the only thing you need to do is over here at the bottom.

20:26.320 --> 20:29.700
I just did it really quick because I edited the video.

20:29.780 --> 20:33.180
You just need to change the placeholders.

20:33.180 --> 20:35.260
Which is going to be like the account number that you have.

20:35.260 --> 20:36.200
The location.

20:36.220 --> 20:36.880
The region.

20:36.880 --> 20:42.260
And the date that you want to actually tell Athena to go and create a table from these logs.

20:43.400 --> 20:45.860
So over here, really quick, run query.

20:46.100 --> 20:47.440
My table was created.

20:47.440 --> 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.

20:54.680 --> 20:56.340
And sometimes there are some mistakes.

20:56.900 --> 21:01.560
Most of the time you just need to switch the schema.

21:01.560 --> 21:05.460
And over here at the left, you can see the schema essentially of your table.

21:05.460 --> 21:09.760
Which is all your different fields on CloudTrail.

21:09.760 --> 21:10.680
That's what it is.

21:10.680 --> 21:13.180
And each of these is a column on your table.

21:14.200 --> 21:15.040
So perfect.

21:15.040 --> 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.

21:23.840 --> 21:27.080
So we have from our... this happened really quick.

21:27.080 --> 21:28.240
Wait, let me go back.

21:28.360 --> 21:29.420
Let me go back.

21:29.760 --> 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.

21:35.780 --> 21:37.300
Because I don't know SPL.

21:38.400 --> 21:39.620
So I select this query.

21:39.620 --> 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.

21:45.620 --> 21:50.200
And also change the database and the table that I want to query.

21:51.120 --> 21:54.160
And as we're going to see here...

22:01.740 --> 22:05.400
I didn't get some results because I had principal ID and I had to change it.

22:05.480 --> 22:06.860
I didn't edit it on the video.

22:06.860 --> 22:09.700
So I'm just looking at the user identity dot user name.

22:09.700 --> 22:11.880
Because user identity is a struct.

22:12.020 --> 22:14.720
Oh, sorry about that.

22:15.280 --> 22:16.460
Why did that happen?

22:17.600 --> 22:18.460
Okay.

22:18.460 --> 22:20.220
And we get only two results.

22:20.220 --> 22:28.240
And we see that this user Solo was actually accessing some code build projects and listing the projects.

22:28.240 --> 22:29.420
Why would that be?

22:29.920 --> 22:31.880
So we don't know exactly what happened.

22:31.880 --> 22:34.440
But we see there's a source IP address over here.

22:34.440 --> 22:37.940
So we're going to check if there was any other actions based on that IP address.

22:37.940 --> 22:39.180
So we copy it again.

22:39.180 --> 22:44.220
We go to our saved queries that we have for looking for suspicious IPs.

22:44.300 --> 22:46.340
I already have put it in here.

22:46.360 --> 22:47.660
Run the query.

22:47.740 --> 22:50.340
And we're going to get all the results that came from that IP.

22:50.340 --> 22:53.020
So we pivoted from user Solo to that particular IP.

22:53.020 --> 22:57.240
And we see, oh, there's so many different logs over here.

22:57.420 --> 22:59.380
Let's first sort it by time.

22:59.380 --> 23:03.860
And then we see that from this IP, actually, first user Solo was accessed.

23:03.860 --> 23:05.400
But then something else happened.

23:05.400 --> 23:08.220
User Calrissian, another user, got accessed.

23:08.260 --> 23:12.180
And you see some actions over here in the event name create DB snapshot.

23:13.620 --> 23:20.140
So they are creating a snapshot of one of our RDS databases.

23:21.040 --> 23:22.180
This is serious.

23:22.240 --> 23:23.940
So let's see what's going on afterwards.

23:24.440 --> 23:30.520
And if you go down in the logs, I didn't have time to do, like, a really thorough demo.

23:30.520 --> 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.

23:49.500 --> 23:54.540
So then he had access to our secret database with all our secrets over here.

23:54.600 --> 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.

24:20.980 --> 24:23.460
Let's see how I can put it back into presentation mode.

24:25.200 --> 24:27.200
Anyways, you'll see my bookmarks too.

24:29.020 --> 24:32.840
So, apart from all this, right, what else can we do?

24:32.840 --> 24:35.440
We can do threat hunting, we can automate all this.

24:35.440 --> 24:38.860
We can have queries that are used for our threat hunting activities.

24:38.860 --> 24:46.960
We can have automated hunting to be in place using step functions in AWS and Lambda functions.

24:46.960 --> 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.

24:57.840 --> 25:02.300
So you can, it's like, if you think it as an orchestration tool.

25:02.300 --> 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.

25:13.120 --> 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.

25:21.740 --> 25:22.160
Check it out.

25:22.160 --> 25:24.800
I didn't add it in the presentation, but it's something that you really should look at.

25:24.800 --> 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.

25:32.000 --> 25:36.260
And I want to talk also about a suggestion to you guys.

25:36.640 --> 25:42.480
Even if you want to use AWS Athena or not, a really cool way to track up use the STS keys.

25:42.520 --> 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.

25:54.080 --> 25:57.160
It's not going to be created by you, and they're temporary.

25:57.160 --> 25:59.080
I think the default is six hours.

25:59.080 --> 26:06.080
So these credentials are actually the ones who we see mostly being abused in the wild.

26:06.080 --> 26:11.160
Because these are the credentials that someone is going to take advantage using an SSRF attack on your environment.

26:11.320 --> 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.

26:22.980 --> 26:29.060
And when we have an Assumeral event, that means that a key was assigned to an EC2 instance.

26:29.060 --> 26:36.300
Then normally what would happen is that that key would only be used by that particular EC2 instance.

26:36.540 --> 26:42.040
Sometimes developers do some funky stuff, so you might see some edge cases, but normally it's what happens.

26:42.140 --> 26:47.960
Then if you look at the AssumedRole events, you're going to see where that particular key was used.

26:48.040 --> 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.

27:00.580 --> 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.

27:07.660 --> 27:10.680
So we can make it even faster, right?

27:10.760 --> 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.

27:22.220 --> 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.

27:31.480 --> 27:37.900
In conclusion, AWS Athena is fast, cost effective, and easy to use.

27:37.900 --> 27:43.080
And I hope that each and every of you consider it, go play with it.

27:43.080 --> 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.

27:56.280 --> 28:01.280
Thanks, that was my talk, and if you have any questions, you can ask me here or later.

28:17.710 --> 28:20.060
So, you're talking about the history?

28:21.550 --> 28:27.590
So, Athena history is right now, AWS has it only for 90 days, the history.

28:27.590 --> 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.

28:36.330 --> 28:39.650
But on the dashboard, you're only going to see it for 90 days right now.

28:39.650 --> 28:42.730
I looked for that, they don't have that.

28:42.830 --> 28:44.550
They just have for 90 days the history.

28:51.880 --> 28:53.600
So, it's data scanned.

28:53.600 --> 28:58.400
Yes , and most of the time, you won't reach one terabyte of cloud trade logs, right?

28:58.400 --> 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.

29:07.960 --> 29:08.660
Really cheap.

29:12.010 --> 29:15.470
So, it counts the data that you query.

29:15.610 --> 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.

29:24.070 --> 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.

29:33.470 --> 29:36.490
So, yeah, it's per data that you scan.

29:56.880 --> 29:59.780
Yes, so the best format is Parquet.

30:00.320 --> 30:04.660
You can scan any other data, like JSON, any other type of data.

30:04.660 --> 30:07.840
You can have zip files, anything, but Parquet is the best.

30:07.840 --> 30:10.540
So, AWS recommends to boot it on Parquet, yes.

30:13.340 --> 30:15.280
Ah, that's a tough question.

30:15.740 --> 30:16.680
It might be JSON.

30:16.680 --> 30:17.140
I'm not sure.

30:17.140 --> 30:18.520
I know that the best is Parquet.

30:18.520 --> 30:19.600
Maybe JSON.

30:21.800 --> 30:22.400
We're good?

30:22.740 --> 30:24.020
Thank you so much, guys.

30:26.200 --> 30:26.940
Thank you.

