WEBVTT

00:00.000 --> 00:05.040
Alright, so the next speaker that we have is Gunner Andrews.

00:05.040 --> 00:10.480
And Gunner is working in the application security space for almost five years now.

00:10.520 --> 00:14.700
He is a hacker who is passionate about software and sharing knowledge.

00:14.700 --> 00:20.980
And is currently working as a senior application and a cloud security engineer at Interwell Health.

00:21.340 --> 00:24.380
And also, he's also a SynecRed team member.

00:24.380 --> 00:26.220
So please welcome Gunner Andrews.

00:26.220 --> 00:27.100
Alright

00:33.940 --> 00:35.100
, hello?

00:35.840 --> 00:37.740
Thanks for coming, first of all.

00:37.740 --> 00:42.480
So this is my talk, called How I Built Recon to Scale with Serverless Architecture.

00:42.680 --> 00:51.460
So we're going to go over a couple different kinds of serverless, some logistics, and then there's a bunch of screenshots, workflows, code, all that kind of stuff.

00:51.640 --> 00:57.900
The slides get shared and everything else, so if I'm going too fast, it's all available after.

00:57.900 --> 01:00.840
I just wanted to leave it at that, just so people are interested.

01:01.980 --> 01:08.000
Okay , so again, this is kind of what we're going to go over in order.

01:08.380 --> 01:13.380
So obviously I have to start with the Who Am I slide, kind of like what you just heard.

01:13.720 --> 01:16.000
I do AppSec and CloudSec full-time.

01:16.200 --> 01:24.240
In my off-time, I like to develop stuff, I like to build stuff, like to play video games, like to bug bounty hunt, and I'm into fitness as well.

01:26.980 --> 01:29.640
So we're going to talk about two different kinds of serverless.

01:29.780 --> 01:32.180
So there's a lot of the word serverless flying around.

01:32.260 --> 01:35.020
One is kind of an idea, one is a framework.

01:35.360 --> 01:38.060
So the first one we're going to talk about is the idea of serverless.

01:38.300 --> 01:44.980
So there's a couple quotes up here from both Red Hat and CloudFlare, a little bit about what serverless actually is.

01:45.020 --> 01:58.440
So basically, if you read a little bit of those snippets, I'm sorry about the small text, it basically allows you to build applications, manage applications, deploy, etc., without actually having to manage the infrastructure under it.

01:59.040 --> 02:04.900
There are tools, especially in the bug bounty space, that are developed to help with this.

02:04.900 --> 02:14.580
One is called Axiom, that allows you to basically take a workload and spread it over a bunch of servers, and then it will basically ingest the data, bring it back, and give it all to you as one thing.

02:14.580 --> 02:23.080
There's also a tool called ShadowClone that actually does get into the serverless space, that basically allows you to do the same thing, but break up a workload over a bunch of Lambda functions.

02:23.080 --> 02:26.200
Or, I think it uses Azure and GCP, too.

02:26.540 --> 02:31.340
But basically, what serverless computing is, is if you take the...

02:31.340 --> 02:36.620
there's a line that what you're responsible for, and then what, let's say, a cloud provider is responsible for.

02:36.620 --> 02:47.500
If you spin up an EC2 instance in AWS, you are responsible for updating that server, you're responsible for managing what ports are open on that server, and there's a whole laundry list of things that you're responsible for.

02:47.500 --> 02:49.940
AWS is responsible for the data center.

02:49.940 --> 02:52.940
If someone breaks into the data center, you are not responsible.

02:53.000 --> 02:55.940
If someone breaks into the server, you are very responsible.

02:57.160 --> 03:00.760
Serverless takes that line and moves it basically one more step up.

03:00.820 --> 03:04.960
You are now only responsible for what you are deploying on the servers.

03:04.960 --> 03:12.060
That's actually the code you're writing, the software you may be deploying, whatever it may be, that's now the only thing you are responsible for.

03:12.320 --> 03:18.840
AWS is actually managing the runtime environments for you, the servers in the backend for you, scaling, everything.

03:19.600 --> 03:25.000
Caveat that we'll talk about later, obviously you have to pay for that, but we will talk about that a little bit more in a bit.

03:27.950 --> 03:32.930
So there is a lot of these out there, there's a lot of different flavors, and they do a lot of different functions.

03:33.430 --> 03:38.230
A lot of what we're going to be seeing today is AWS, and that's some of the stuff you see there on the top.

03:38.270 --> 03:45.130
So we're going to talk about AWS Lambda, AWS DynamoDB, Step Functions, but GCP has this kind of thing too.

03:45.130 --> 03:51.910
One example is Cloud Run, and Azure also has Azure functions, I'm pretty sure DigitalOcean also has DigitalOcean functions.

03:51.990 --> 04:02.110
There's a lot of it out there, serverless is kind of spreading to everybody, but the ones that we're going to focus on today in some of the demos and the screenshots is all AWS, but it is not cloud agnostic.

04:03.010 --> 04:15.890
But this basically allows a user to either package up code in a zip file, or use Docker files and Docker containers, and basically take it to your image, or your zip file of code, and just deploy it.

04:15.890 --> 04:20.130
You're basically telling the cloud this is Python, Go, whatever it may be, and it handles the rest.

04:20.130 --> 04:24.750
All you're worried about is updating and managing the actual code base, or the software you're deploying, and nothing else.

04:26.830 --> 04:29.410
So this is the other serverless.

04:29.490 --> 04:31.410
This is the serverless framework.

04:32.350 --> 04:34.690
This is basically a CLI tool.

04:34.790 --> 04:42.290
If anyone here has heard of Terraform, it's pretty much a spinoff of Terraform for only serverless products.

04:42.570 --> 04:48.470
It works with all the different clouds, all the main cloud providers, and it works with their serverless offerings.

04:48.470 --> 04:51.070
It comes with a whole bunch of plugins to do a whole bunch of things.

04:51.070 --> 05:01.310
One of the plugins we'll see is it allows you to deploy a Python Lambda function with a requirements.txt file, which has been annoying in the past, if anyone has done Lambda development.

05:01.310 --> 05:07.130
And it handles these laundry lists of languages that I have up there, plus a lot more.

05:07.530 --> 05:13.290
And the reason why we're going to talk about it is because there's a lot of different ways to remotely deploy serverless.

05:13.490 --> 05:17.290
AWS has something called SAM that you can use to deploy serverless.

05:18.190 --> 05:21.630
It's not user-friendly 100% of the time.

05:22.310 --> 05:24.830
This, in my argument, is.

05:24.830 --> 05:30.450
And we're going to show a little video walkthrough of it, but basically it breaks down to these four things.

05:30.450 --> 05:32.450
It's an npm package that you install.

05:33.030 --> 05:43.190
When you type just serverless, it pulls up a whole list of templates that you can choose, and it will basically do what a lot of other tools do, and it will make you a new directory and populate that directory with what you need.

05:43.630 --> 05:49.570
For example, with Lambda, a Lambda handler, the YAML file, you'll need to deploy it and configure it and everything else.

05:49.870 --> 05:56.450
Whenever you're ready to deploy, you just type serverless deploy, and obviously there's a bunch of flags if you want to configure it, but serverless deploy will deploy it.

05:56.450 --> 06:00.390
And then you can invoke it right from the command line, and we'll show that.

06:00.530 --> 06:04.150
There's also ways that I'll show you when you invoke the function.

06:04.150 --> 06:08.590
If you want to test your Lambda locally, you do not have to pay for AWS Cloud9.

06:08.610 --> 06:10.530
You do not have to mess around with SAM.

06:10.530 --> 06:16.330
All you do is, instead of serverless invoke, and you're calling your function, you just add in local, and we'll show that.

06:16.330 --> 06:22.510
But then you're testing your Lambda function locally, and you're not actually paying to run a bunch of tests.

06:22.730 --> 06:29.210
And you can hand it data, fake data, dummy data, and everything else, and you can test all your serverless stuff locally before you actually deploy it.

06:29.550 --> 06:36.350
And if you turn out you want to remove something, serverless remove removes all the backend, as well as the actual Lambda.

06:36.350 --> 06:42.230
So this runs on the CloudFormation stack, and then uses, obviously, S3 as a backend for CloudFormation.

06:42.270 --> 06:44.150
And that's actually how it will be deployed.

06:44.150 --> 06:52.670
Very similar to SAM, but it puts it all in a nice little YAML format for you that we're going to go over, and basically puts a CLI wrapper on it.

06:52.670 --> 06:58.370
So I have a video here, and I'm going to probably speed it up, and skip through some stuff.

06:59.090 --> 07:04.110
But basically, like I said, when you type serverless in the beginning, it will let you pick from a bunch of templates.

07:04.110 --> 07:06.190
And there's a whole bunch there if you click Other.

07:06.410 --> 07:12.210
But all I did here was pick an Amazon starter one, which is obviously, of course, your cliche Hello World.

07:12.730 --> 07:19.970
You're naming it, and it will then build you that new directory, and deploy it out there, right?

07:21.170 --> 07:22.670
You can use the dashboard.

07:22.670 --> 07:23.810
The dashboard is a paid thing.

07:23.810 --> 07:26.050
You definitely don't have to use, right?

07:26.390 --> 07:28.570
And we don't want to deploy it.

07:28.570 --> 07:32.770
After we CD into the directory, I'll show you when you LS in here.

07:32.770 --> 07:38.210
This right here is in your directory.

07:38.210 --> 07:40.070
There's two things in the beginning one.

07:40.070 --> 07:45.890
The handler is the basic handler that you would use, whether using SAM or something else, to deploy something.

07:45.910 --> 07:50.410
And then the serverless.yaml is the actual YAML file you're using to configure the Lambda function.

07:50.410 --> 07:54.950
So this is how much memory you want to have, the timeout you want to have, and stuff like that.

07:54.990 --> 07:57.430
But as you'll see here in a second...

07:57.430 --> 07:58.650
Oh, geez.

08:00.070 --> 08:02.530
I even tried to avoid live demos, too.

08:08.040 --> 08:09.080
So let's go.

08:09.820 --> 08:12.040
Okay, so back where we were.

08:13.420 --> 08:15.360
The handler looks a little bit like this.

08:15.360 --> 08:17.740
This is like a super basic handler, right?

08:18.720 --> 08:22.040
You're defining a function called Hello, since the Hello World.

08:22.040 --> 08:24.060
You'll see that show up in the YAML file.

08:24.160 --> 08:28.300
That function is how you'll tell the YAML file, like, this function is my handler function.

08:28.300 --> 08:31.440
So it's in a file called handler.py, and the function's called Hello.

08:31.440 --> 08:35.740
So that's key here, because the next thing that's going to come up is the YAML file.

08:35.900 --> 08:40.240
The YAML file is very small, because it's just the basic version.

08:40.500 --> 08:43.460
And I'll show you some of mine later, as we go into the thing.

08:46.180 --> 08:47.400
There we go.

08:47.500 --> 08:49.140
So this is the YAML file.

08:49.140 --> 08:52.060
So you see in the bottom, you're calling functions, you're naming a function.

08:52.380 --> 08:53.780
The name is called Hello.

08:53.780 --> 08:55.340
And then you're pointing it to the handler.

08:55.340 --> 08:59.240
So you're pointing it to the file that it should go to, and then dot whatever function.

08:59.400 --> 09:03.800
You can have a bunch of functions in one directory.

09:03.800 --> 09:05.740
You can make one directory per.

09:05.800 --> 09:06.540
All that kind of stuff.

09:06.540 --> 09:08.900
You don't have to put any secrets in here.

09:08.900 --> 09:18.380
This makes it so you can actually package up Lambda functions in directories, and use Git or any other type of version control to actually co-develop serverless architecture.

09:18.380 --> 09:19.020
Right?

09:22.160 --> 09:22.620
So...

09:22.620 --> 09:23.260
In

09:27.900 --> 09:29.620
the hallway, and they stopped everybody.

09:30.140 --> 09:30.840
Oh.

09:32.500 --> 09:33.660
Don't fight.

09:37.300 --> 09:44.300
So, this is the part I'm probably going to skip through, because this is basically just like, it runs for about 75 seconds.

09:44.740 --> 09:51.400
But when you type serverless deploy, like I said, it's using CloudFormation and S3, just like SAM does, in the back.

09:51.400 --> 09:55.700
And that will basically, this is now just deploying it to my AWS account.

09:55.700 --> 10:02.000
So the only requirement to get this to work is you download the npm package, and you have your AWS credentials configured.

10:02.000 --> 10:04.760
Just like, you know, if you're using the AWS CLI.

10:04.760 --> 10:05.640
It's the same thing.

10:06.440 --> 10:14.760
So really, at the end of the day, what it is, is it's a CLI wrapper and YAML wrapper around the AWS CLI, and basically doing what SAM does.

10:14.760 --> 10:20.660
It just makes it a lot easier to locally develop, deploy, and update what you're doing.

10:20.660 --> 10:26.180
So, once it finishes here, right here, we're going to invoke it.

10:26.180 --> 10:29.500
You invoke it by the function, which we called hello.

10:29.540 --> 10:33.280
And when you invoke it, this is actually running on my AWS account.

10:33.280 --> 10:34.540
After it was deployed.

10:34.880 --> 10:39.660
Like I said before, though, you can do the same exact thing, and just tell it to invoke locally.

10:41.620 --> 10:45.580
And this is now using whatever I have on my machine.

10:45.600 --> 10:46.100
Right?

10:46.820 --> 10:58.960
So if you want to test before you deploy, you can invoke locally, and then whenever you're ready to remove it, the last step, since I don't necessarily need to keep a hello thing on my account, you serverless remove, and it removes everything.

11:00.380 --> 11:08.160
It's very simple, it's very easy to use, especially compared to some of the other stuff, like SAM, or just using the AWS console.

11:08.800 --> 11:11.220
So now, of course, we have to talk logistics.

11:11.780 --> 11:14.600
What I mean by that is we're going to talk about cost and scalability.

11:16.360 --> 11:30.240
So, I'm going to pre-wreck this by saying if you want to use serverless to build your own automation framework for either red teaming, bug bounty hunting, or blue teaming, or whatever it may be, and you want to scan 100 million domains every five minutes,

11:30.240 --> 11:33.720
forever, it's going to cost you money.

11:34.120 --> 11:37.660
There's no way around it not costing you money.

11:37.740 --> 11:47.080
There is a free tier for a lot of this stuff, and I will talk about some of the ways to save money if you want to maybe make it a little bit less user-friendly, but a little more cost-saving.

11:47.080 --> 11:51.660
We're going to go over that during the example, but a little caveat is it does save you money.

11:51.960 --> 11:56.140
But, a decent example, and I'm sorry, again, I'm sorry for the small text.

11:56.140 --> 11:57.780
I tried to make it as big as I could.

11:57.900 --> 12:05.000
At the top is doing 10 million DNS resolutions in Lambda, in estimate.

12:05.200 --> 12:10.520
So if you Google it, or chat GPT, the average DNS resolution is about 33 milliseconds.

12:10.980 --> 12:21.680
So if you run a little Lambda function that resolves one domain, which will happen in hopefully 33 milliseconds, and you run it 10 million times, you pay $1.80.

12:23.080 --> 12:28.080
So if you resolve 10 million domains per month, you paid $1, almost $2.

12:28.280 --> 12:28.940
Right?

12:28.940 --> 12:35.920
If you buy the smallest EC2 box you can buy, at least on my account, you pay $3.65 a month.

12:36.660 --> 12:44.940
So, if you're resolving 10 million domains, you're still cheaper doing it with Lambda than doing it in EC2.

12:45.260 --> 12:50.740
Now, as data storage comes into play, or continuous scanning, right?

12:50.740 --> 12:56.680
If you're going to try and resolve domains every minute of every month, that gets a little bit different.

12:56.760 --> 13:02.880
So some of the advantages of serverless are as follows.

13:02.880 --> 13:04.640
I tried to fit it all in.

13:04.720 --> 13:08.940
The one thing to look at is whatever you're trying to build will have a traffic pattern.

13:08.940 --> 13:15.840
If you're doing continuous scanning and it's always running and it's always on all the time, don't use serverless.

13:15.960 --> 13:17.940
This is probably not for you.

13:18.360 --> 13:24.340
Because you will spend more money using serverless than you would using server-based.

13:24.340 --> 13:28.700
The only advantage is you would be paying more money to not have to worry about your infrastructure.

13:28.700 --> 13:32.620
That may be worth it to you, it may not, but this won't save you money.

13:32.680 --> 13:40.540
If you have spiky workloads, let's say you want to resolve 10 million domains once a month, serverless is for you.

13:40.680 --> 13:45.700
Because you don't have to worry about spinning up and spinning down servers and forgetting it's there and then paying for the whole month.

13:45.700 --> 13:51.500
You don't have to worry about where your servers are and how big or how small they are and if they can handle the load or if you're going to overload the server.

13:52.000 --> 13:56.220
All of serverless has scalability basically to unlimited.

13:56.520 --> 14:02.560
Obviously there's benchmarks, but just quote-unquote unlimited for whatever workload you want to give it.

14:02.760 --> 14:07.200
It will scale for you and you only pay for what you use in serverless.

14:07.320 --> 14:11.840
So Lambda for instance, you pay for the computing resources times the amount of time you're using them.

14:11.840 --> 14:12.600
That's it.

14:12.600 --> 14:24.620
It doesn't matter if you do it one Lambda at a time, it doesn't matter if you do it 100,000 Lambdas at a time, you're using the same amount of computing resources, the math works out the same whether you run it one at a time or 100,000 at once.

14:25.720 --> 14:33.920
So for very spiky workloads, serverless normally will perform better than servers and it's way easier to manage and it's way easier to scale.

14:34.420 --> 14:37.520
The other thing like I talked about is the development maintenance.

14:37.720 --> 14:40.160
I do this for fun and I'm one person.

14:40.220 --> 14:44.120
I do not have a dev team, I do not have an infrastructure team, I don't have anybody.

14:45.740 --> 14:52.320
This makes it very easy because all I do is write code and do what you just saw, I just deploy it.

14:52.460 --> 14:53.760
And then I don't worry about it.

14:54.380 --> 14:57.820
And we're going to talk about how to schedule it and it'll even run on its own and all that kind of stuff.

14:57.820 --> 15:02.020
You basically code, it's basically like you're pushing to get you code, push and you forget.

15:02.160 --> 15:03.600
Unless it breaks.

15:03.780 --> 15:05.060
But we'll talk about that too.

15:08.520 --> 15:10.700
So now... okay good, I'm doing good on time.

15:10.820 --> 15:13.080
So I'm going to go through my stuff.

15:14.680 --> 15:19.240
A little birdie told me opening AWS console, a hacker conference, was probably not a good idea.

15:19.620 --> 15:21.380
So it's all screenshots.

15:22.260 --> 15:23.760
I am not hiding anything.

15:23.760 --> 15:27.720
If you have a question about something or you want to see something, get in touch with me.

15:27.720 --> 15:28.400
Ask me.

15:28.400 --> 15:30.160
I am more than willing to share it with you.

15:30.160 --> 15:31.620
These slides will be available.

15:31.820 --> 15:34.760
All the code is in the slides.

15:34.760 --> 15:43.420
It's just kind of the best way of both worlds where I'm not showing my AWS console at a hacker conference and I can show you guys how I do things.

15:44.020 --> 15:47.740
So this is one of the workflows.

15:47.800 --> 15:49.060
This is the one we're going to focus on.

15:49.060 --> 15:53.180
This is a passive enumeration that I use for bug bounty.

15:53.200 --> 15:55.020
There's passive and active enumeration.

15:55.020 --> 15:56.940
This is the passive side of things.

15:57.220 --> 16:03.360
So any bug bounty people in here, any all the recon folks in here have heard of subfinder and amass.

16:03.940 --> 16:09.440
This is basically bundling those tools up and running them for me against whatever I want it to run on.

16:10.240 --> 16:12.080
This is called step functions.

16:12.080 --> 16:17.260
In AWS, this basically allows you to orchestrate both serverless and non-serverless.

16:18.040 --> 16:20.040
And this basically is a workflow.

16:20.300 --> 16:24.440
So it comes in on the top to a lambda function that's called passive enumeration.

16:24.680 --> 16:33.220
And then in parallel it will both delete what I just processed from the queue, assuming it's successful, and it will loop through all my results.

16:33.220 --> 16:35.720
And if the domain is a new domain, it stores it in my database.

16:35.720 --> 16:38.420
Which is going to be DynamoDB, which we'll show in a second.

16:38.600 --> 16:45.020
After that, there's temporary recon data, because step functions can only handle so much data being passed from step to step.

16:45.020 --> 16:51.560
And you use S3 just like basically every other AWS tool to handle the large temporary data you're handling in between.

16:51.560 --> 16:53.420
And then it all just gets deleted at the end.

16:53.420 --> 16:55.400
Because it ends up in the database.

16:57.620 --> 16:59.640
So this is just a really quick...

16:59.640 --> 17:04.440
Again, this is my configuration I use, but this is just the configuration for a very basic SQS queue.

17:04.440 --> 17:06.860
This is basically how everything talks.

17:06.860 --> 17:09.940
So I use a PubSub type model for my stuff.

17:09.940 --> 17:13.260
And I use SQS queue as that basically broker in the middle.

17:13.300 --> 17:22.060
So anything that either will go from workflow to workflow, or that goes from a workflow getting kicked off into a workflow, all happens through SQS queues.

17:22.060 --> 17:25.100
SQS queues have a massive free tier.

17:25.100 --> 17:27.000
I have never paid for it yet.

17:27.300 --> 17:30.080
This is not one of the services where you will pay.

17:30.260 --> 17:33.840
If you break the free tier, congratulations.

17:34.740 --> 17:38.680
I think it's like 50 million messages or something.

17:38.940 --> 17:40.260
So this is how everything starts.

17:40.260 --> 17:42.400
Again, I use this for bug bounties, mostly.

17:43.280 --> 17:44.900
As well as a little bit of work.

17:45.060 --> 17:47.240
So PlayStation is pretty cool.

17:47.240 --> 17:49.460
They're giving one away, I think, in the CTF.

17:49.460 --> 17:51.260
But PlayStation has a bug bounty program.

17:51.400 --> 17:59.700
So I have a separate table in DynamoDB, which is a NoSQL serverless database that scales with you, just like everything else in serverless, on AWS.

18:00.040 --> 18:03.020
And this is what every target I have looks like.

18:03.020 --> 18:11.080
So I put in the URL of where I would turn in bugs, hopefully, the name of the program, and then a list of domains, whatever their root domains may be.

18:11.080 --> 18:17.860
I put any wildcard domains in here that I'm going to do wide scope recon on, and these will automatically get ingested, as we'll see in a moment.

18:18.760 --> 18:25.320
Then this program, and this kind of thing, will be cross-searchable across the other tables, which I'll show in a second.

18:27.280 --> 18:30.100
This is an example of what it would look like after.

18:30.300 --> 18:34.760
So, again, there are other steps to this that I only have 45 minutes to go over.

18:34.760 --> 18:37.440
Again, if you're interested, we can chat.

18:38.640 --> 18:48.020
But it starts out as it finds domains, it'll put them in there with the subdomain, the program, and then an empty list for CNAMEs and IPs that it finds, and then there's more, obviously.

18:48.020 --> 18:51.740
This is kind of truncated, but then whether or not it resolves, there's timestamps, everything else.

18:51.740 --> 18:53.260
You can add whatever you want here.

18:53.980 --> 18:58.540
And this can be updated, and this is one of the tables as a source of truth for results.

18:58.960 --> 19:02.760
Now, with this, you can do something in DynamoDB called scanning.

19:02.840 --> 19:09.620
It's sort of an intensive process, but it works very well cross-table, and you can do a lot of very cool queries with it.

19:09.620 --> 19:12.380
So, in my opinion, I think it's worth it to look into.

19:12.900 --> 19:27.860
So, for example, here, if I wanted to go into my domains table of all my recon of any amount of domains, and I just want to find the PlayStation one, it's very easy to just scan my table called domains, and the attribute name is program, and I want it to be equal to PlayStation.

19:27.860 --> 19:32.500
And I'll get every domain from all three of those seed domains that PlayStation is a part of.

19:32.500 --> 19:38.440
If I just wanted one of those domains, I can set the attribute name to seed name equal to whatever the one domain that I wanted to find was.

19:38.540 --> 19:39.740
And you can scan...

19:39.740 --> 19:43.120
those filters are, like I said, very intense.

19:43.180 --> 19:45.460
You can basically filter against anything you want.

19:48.400 --> 19:49.800
So, this is the other thing.

19:49.800 --> 19:55.260
So, a lot of bug bounty hunters, especially when you're running automated recon, you want to know when new stuff shows up, right?

19:55.260 --> 19:57.840
You want to be the first one to it, all that kind of stuff.

19:58.500 --> 20:03.760
DynamoDB makes that very easy, because there's something called a DynamoDB stream that streams...

20:03.760 --> 20:07.620
it's basically an event, API, of everything that's happening to your DynamoDB.

20:07.720 --> 20:14.120
It's very easy to make a trigger and hook on, just like you see in the thing, to hook on a Lambda function to that trigger.

20:14.120 --> 20:22.000
So, anytime a new thing happens to your DynamoDB, there's a Lambda function to ingest it, and you can tell it, only ingest inserts, only ingest updates, whatever it is.

20:22.000 --> 20:25.200
So, obviously, for a new domain, it's pretty straightforward.

20:25.240 --> 20:31.240
Anytime a new insert goes into my domains table, that means there's a new domain.

20:31.760 --> 20:41.780
There's a Lambda function called NewDomainNotification that we're going to show on the screen that will basically ingest that stream's API, grab the new domain that just got added to the database, and shoot it to Slack.

20:42.540 --> 20:43.980
So, I don't use...

20:43.980 --> 20:45.420
there's not necessarily a tool for that.

20:45.420 --> 20:49.300
It's just a POST request to a Slack webhook that we're going to go over.

20:50.580 --> 20:53.160
So, this is actually some of the code.

20:53.240 --> 20:58.200
Again, I tried to make it as big as I possibly could, so it's split up into chunks.

20:58.860 --> 21:08.100
So, this is a Lambda function that actually kicks off running my recon against every domain I have in that domains table I showed you.

21:08.100 --> 21:12.300
So, all it is, is I go through the table name that I call targets.

21:12.340 --> 21:14.920
I just have one item in the database.

21:14.920 --> 21:16.340
It's just one big item.

21:17.460 --> 21:20.460
And for that item, there's a bunch of programs.

21:20.500 --> 21:25.160
So, I loop through the programs, and for every program, as we saw, we'll have that list of domains.

21:25.680 --> 21:31.440
And all I'm doing is queuing those domains up in my SQS queue to the beginning of the workflow.

21:32.900 --> 21:34.340
We'll look at this later.

21:34.340 --> 21:36.040
This one gets scheduled.

21:36.040 --> 21:37.500
So, I don't kick it off.

21:37.500 --> 21:40.760
I have it scheduled for, I think, every 10 days, I think, in the picture.

21:40.840 --> 21:43.340
So, every 10 days, this gets kicked off.

21:43.340 --> 21:55.480
It takes everything out of the programs that I'm hacking on, takes those domains, puts them into the SQS queue, and there's another event that we're going to go over that whenever something gets added to the SQS queue, it automatically kicks off workflow.

21:55.480 --> 21:56.880
So, I'm not touching it.

21:56.880 --> 21:59.160
I'm not starting and stopping it.

21:59.160 --> 22:00.280
You can if you want.

22:00.800 --> 22:02.160
But it is...

22:02.160 --> 22:04.160
it can go, basically, fully automated.

22:04.160 --> 22:07.500
This is the big lambda function that sat at the top of the workflow.

22:07.760 --> 22:10.040
This is the passive enumeration runner.

22:10.180 --> 22:13.500
So, as you can see, there's a little bit more than when we did the serverless demo.

22:13.540 --> 22:14.480
There's the handler.

22:14.480 --> 22:15.300
It's the same thing.

22:15.300 --> 22:16.900
And there's the serverless YAML.

22:17.360 --> 22:18.280
Requirements.txt.

22:18.280 --> 22:19.320
Any Python people in here?

22:19.320 --> 22:21.500
That's your requirements, right?

22:21.840 --> 22:24.320
Now, subfinder and amass are actually just binaries.

22:24.580 --> 22:27.420
Those still get packaged up in the zip file and go with it.

22:27.580 --> 22:34.780
So, all this is, it's nothing special, as much as I'd like to pretend it is, is it's just Python wrapping around tools that I want to use.

22:34.900 --> 22:37.660
That I don't want to run myself over and over.

22:38.680 --> 22:40.480
And this is the passive part.

22:40.680 --> 22:42.740
The active part looks very similar to this.

22:42.740 --> 22:47.720
Again, I don't have enough slides and enough time to go over everything, but the active part would be very similar to this.

22:47.720 --> 22:49.840
And you can break up the workload however you want.

22:53.360 --> 22:55.940
So this, again, I split it up into chunks.

22:56.000 --> 23:02.180
So this is all, this is the whole YAML file to deploy the passive enumeration runner.

23:02.180 --> 23:03.220
It's only this long.

23:03.220 --> 23:08.480
It's not, if you do this in Terraform, anybody who's done Terraform, it's a lot of lines.

23:08.480 --> 23:10.340
It's a lot of lines.

23:10.580 --> 23:13.480
And it's very readable in my opinion.

23:13.660 --> 23:19.600
So we're telling how much memory size we want, what we want the timeout to be for the lambda function, and then the same thing as before.

23:19.600 --> 23:25.620
I'm declaring a function, it's called passive enum runner, I'm pointing it to the handler, and then I guess in this one I add a name and a description.

23:25.940 --> 23:28.680
When you want to use a plugin, it's right there at the bottom.

23:29.220 --> 23:30.900
So serverless Python requirements.

23:30.900 --> 23:34.840
That's the plugin to bring Python requirements with me into the lambda.

23:38.190 --> 23:40.590
So this code is broken into chunks.

23:40.590 --> 23:42.890
So this is basically my function.

23:42.890 --> 23:47.110
From the serverless YAML that we just saw, this is the handler that it's calling.

23:47.510 --> 23:50.110
The data that it's going to ingest is from event.

23:50.110 --> 23:53.230
That stuff you see at the top is configuring the lambda.

23:53.230 --> 23:58.050
I'm adding some config, as people know who run the tools, there's some config files, API keys, you know all the secrets off.

23:58.890 --> 24:02.970
And basically I'm using Python threading to run both SubFinder and Amass at the same time.

24:02.970 --> 24:07.570
Because being that they're passive, they're pretty low memory, pretty easy to use.

24:07.990 --> 24:11.730
So it's just running Amass and SubFinder against whatever domain I give it.

24:11.750 --> 24:15.230
It's pulling the results together, and it's saving them to S3.

24:15.230 --> 24:33.030
Again, it's saving them to S3 because if I run it on Yahoo, and I pull tens of thousands or hundreds of thousands or whatever of domains, that step function that's orchestrating my workflow, as data passes in between it, you can't pass over I think it's like 5 megabytes worth of data in between steps.

24:33.490 --> 24:38.730
S3 is what you use because all of the steps will ingest directly from S3.

24:38.730 --> 24:43.970
So you can output directly to S3 and at the next step just say, yeah, grab this S3 file from the step before.

24:44.150 --> 24:48.550
And that's how you handle... and again, that definitely won't put you over the free tier.

24:48.550 --> 24:51.510
I mean, unless you are doing something very crazy, in which case, talk to me.

24:53.970 --> 24:54.690
This is...

24:54.690 --> 25:01.530
I put this on here just in case anyone's curious how I actually wrap up SubFinder in a mass in Python.

25:01.530 --> 25:02.770
It just looks like that.

25:02.810 --> 25:06.290
This is the new version of a mass too, so it changed a little bit.

25:07.450 --> 25:08.830
But it's basically like that.

25:08.830 --> 25:10.250
I'm using my config files.

25:10.250 --> 25:11.290
I'm putting in the domains.

25:11.290 --> 25:12.810
It's all very simple.

25:12.810 --> 25:14.170
It's just a wrapper.

25:14.350 --> 25:15.830
Again, there's more than this.

25:15.830 --> 25:17.130
I just don't have time.

25:17.130 --> 25:20.210
If this interests you, we can talk.

25:21.430 --> 25:23.390
So this is the notification lambda.

25:23.390 --> 25:28.030
This is the handler for the notification... sorry, the serverless.yaml for the notification lambda.

25:28.030 --> 25:29.910
Notice how it looks very similar.

25:29.990 --> 25:33.250
Once you do this like twice, it gets pretty quick.

25:35.270 --> 25:37.490
And this is the code, right?

25:37.490 --> 25:42.230
So all it is, down at the bottom is my handler function.

25:42.430 --> 25:47.230
I'm starting a message with new domains found from my records in the event.

25:47.230 --> 25:51.030
The event is basically the API data that came from the API.

25:51.450 --> 25:52.090
I'm grabbing...

25:52.650 --> 25:54.050
it's called keys.

25:54.770 --> 26:00.410
And basically all that long string there is doing that appends to the message is just appending all the new domains that were inserted.

26:00.570 --> 26:07.070
Once those are done, as long as it counts greater than zero, which means assuming there was an insert, I'm sending a message to Slack.

26:07.070 --> 26:07.850
It's a POST request.

26:07.850 --> 26:09.550
It's just a POST request to a webhook.

26:09.830 --> 26:15.800
So this is what it looks like when it works.

26:16.960 --> 26:31.260
The reason why I use step functions is because as you build it, and as you use it, it will track every run for you and it will tell you what worked, what didn't work, the input, the output, how long things ran, all that kind of stuff.

26:31.260 --> 26:32.880
So this is an example of one that worked.

26:32.880 --> 26:34.760
This was ran against Costco.

26:34.780 --> 26:43.220
So you can see the body there was the program, and then I do like three lines just to separate and then the domain that I was trying to call.

26:44.420 --> 26:45.860
As you can see, everything is green.

26:45.860 --> 26:46.820
That means it works.

26:46.820 --> 26:47.380
That's great.

26:47.380 --> 26:49.120
It doesn't always work.

26:49.120 --> 26:50.280
Right?

26:51.140 --> 26:52.700
This is what it looks like.

26:52.740 --> 26:55.540
So this was from a while ago when I was first making it.

26:55.540 --> 26:59.160
As you saw, my serverless.yaml set the timeout to 900 seconds.

26:59.220 --> 27:02.660
That's because I had it at 600 and it wasn't enough, if you can read.

27:02.860 --> 27:05.960
Right at the bottom there, it says the task timed out after 600 seconds.

27:05.960 --> 27:06.960
It tells me the error.

27:06.960 --> 27:10.240
Sometimes the error that it gives you right there isn't the best.

27:10.300 --> 27:16.840
That's okay because right under the passive enumeration title, that little text that I apologize for again, says log.

27:17.440 --> 27:23.740
That link takes you directly to the CloudWatch logs, directly for that invocation of the Lambda.

27:23.740 --> 27:26.580
Tells you exactly what happened, exactly each step.

27:26.580 --> 27:34.820
If that error doesn't give you exactly what you're looking for, there's a link directly to the CloudWatch log of directly that invocation.

27:34.820 --> 27:38.580
Which is why step functions really come in handy as you grow.

27:38.920 --> 27:42.380
Again, before I move on, this is where you will spend the money.

27:42.560 --> 27:44.220
Probably even more than Lambda.

27:44.260 --> 27:47.500
Step functions are either standard or express.

27:47.680 --> 27:51.460
Standard, you are charged by state transition.

27:51.500 --> 27:55.200
So when you saw that flow chart, every time you go to a new square, you're charged.

27:55.200 --> 28:01.440
There is a free tier, it's kind of small, and then it's like .000025 cents per state transition.

28:01.440 --> 28:09.820
But, if let's say you have a state to store a domain, for instance, and you're storing 100,000 domains, that could be 100,000 states.

28:10.360 --> 28:17.540
But, the other form of a state function is called express.

28:17.540 --> 28:20.920
That, you are not charged by state transition.

28:20.920 --> 28:26.580
You're charged similar to Lambda based on how much compute resources you use and for how long.

28:26.580 --> 28:29.860
You're not charged by state transition.

28:30.320 --> 28:37.920
The kicker to that is express will only run up to five minutes for the whole, whatever you have in an express state function.

28:38.420 --> 28:40.260
Standard will run for a year.

28:40.260 --> 28:45.180
So, if you have a very large workflow, you kind of have to go standard if it's long running.

28:45.180 --> 28:51.080
But, if I'm using a workflow to store domains 100,000 times, it should be express.

28:51.080 --> 28:55.700
I haven't broken the express free tier yet, I have broken the standard one.

28:56.320 --> 28:57.140
Right?

28:57.380 --> 29:10.900
The good thing about that is, is when you looked at my workflow, you can take the map element, which is a loop element, and inside of a looping element, people assume you're going to loop a lot.

29:11.000 --> 29:17.860
So, you're allowed to take a map element in a standard step function and make just that map element express.

29:17.900 --> 29:23.240
So, you're charged by an express state function for that loop.

29:23.240 --> 29:30.440
So, when I loop through all those domains, even though the whole workflow is a standard state function, that loop where I'm storing all my domains is charged as express.

29:30.440 --> 29:32.320
And that saves a lot of money.

29:32.360 --> 29:35.320
You can plug and play state functions into each other.

29:35.320 --> 29:42.100
One state function can call another state function, so you can embed them, and you can basically plug and play with that as you will.

29:42.100 --> 29:51.760
I like using it for this reason, but if you're trying to save money, you can ditch the state function and just have one lambda trigger another lambda, trigger another, and do its own thing.

29:51.760 --> 29:53.940
You don't have to use state functions.

29:53.940 --> 29:57.240
You just get much less visibility as you scale.

29:57.300 --> 29:59.240
But, you don't have to use it.

30:01.700 --> 30:04.960
This is now getting into how I trigger it.

30:04.960 --> 30:07.680
All of this happens in event bridge.

30:07.680 --> 30:13.040
There's an event bridge pipe that I use in this demo, and there's an event bridge schedule.

30:13.040 --> 30:18.920
Schedule is cron, pipe is basically event happens, what you see at the bottom.

30:18.920 --> 30:20.360
There's a source and a target.

30:20.360 --> 30:23.620
The source in this pipe is my SQS queue.

30:23.680 --> 30:29.280
Anytime a message gets added to the SQS queue, it triggers the pipe and the target is the step function.

30:30.000 --> 30:31.500
It's very easy.

30:31.500 --> 30:41.840
Anytime a message gets sent to the SQS queue, it will either sit in the queue if I have the max amount of concurrent step functions I have set running, and then it will trigger it when it's ready.

30:41.840 --> 30:49.460
Or, if there's none running, it will automatically kick off a step function, which will ingest the message from the SQS queue and kick off.

30:50.000 --> 30:55.820
The other one that I have in event bridge, again, is called a schedule, which is basically cron in AWS.

30:56.280 --> 31:01.240
So, I have a schedule at a rate of 10 days, and you target it at a lambda function.

31:01.240 --> 31:05.500
Like I said, that target one right next to the schedule is where you'll pick your lambda.

31:06.000 --> 31:18.600
And I pick... so every 10 days, I have a target of that full run lambda that we talked about that just goes through my targets table and posts them all to the queue, which will then trigger the pipe on the last slide and ingest it all into step functions.

31:18.600 --> 31:21.740
And that happens every 10 days automatically without touching it.

31:21.740 --> 31:23.980
You can change that, you can delete it, you can do whatever you want.

31:23.980 --> 31:29.220
You can obviously manually kick off and invoke lambdas if you want to and you don't feel comfortable doing it automatic.

31:29.220 --> 31:32.200
That is basically what it is.

31:32.620 --> 31:35.220
I will say since I'm pretty sure...

31:35.220 --> 31:45.700
So I will say before the thank you and the questions, I will say I have personally monitored a couple hundred thousand domains, because I don't do mass recon.

31:45.700 --> 31:48.760
I like to do recon on the targets that I'm hacking on at that time.

31:49.120 --> 31:58.740
I have monitored fairly continuously a couple hundred thousand domains and kept my price pretty firmly under $50 a month.

31:58.740 --> 32:10.540
So it's not crazy expensive, it does cost money, and again, it's not... if you scale it, it will scale with you and it will work very good, but you still pay for it.

32:11.360 --> 32:13.240
So yeah, that's all I have.

32:13.240 --> 32:22.680
It looks like I do have 10 or 15 minutes here for questions, because I do have to jet after, but if there's any questions, I would love to answer them.

32:22.720 --> 32:23.360
Yeah.

32:24.860 --> 32:26.420
Thank you.

32:44.540 --> 32:45.580
Yes and no.

32:45.580 --> 32:49.600
No, because the Lambda has ephemeral memory that will grow with you.

32:49.600 --> 32:55.700
Yes, because there is a limit to that, and you pay for that also, and there is a limit.

32:55.700 --> 32:58.280
It's rather large , but there is a limit.

32:58.280 --> 32:58.860
Yeah.

32:59.680 --> 33:00.720
Sure .

33:07.990 --> 33:19.810
Yes , so serverless will set up the IAM roles that go with the Lambdas automatically, and you can configure those either in the YAML or in AWS, but they do get spun up automatically.

33:19.810 --> 33:32.870
So if your handler imports the Bottles3 library and uses DynamoDB, it will spin up an IAM role for you that gives you access to DynamoDB to that Lambda.

33:36.470 --> 33:37.490
Yes.

33:38.090 --> 33:38.950
Yep.

33:39.650 --> 33:40.670
Yeah.

33:53.780 --> 33:55.480
So when I...

33:55.480 --> 33:59.140
And again, the reason why I didn't touch the active one is because it gets a little more interesting.

33:59.860 --> 34:05.680
But the active stuff, the way I approach it, is I split it into super teeny chunks that run lightning fast.

34:05.720 --> 34:11.240
So that's why I talked about domain resolution because I resolve domains one at a time and they resolve in, like, milliseconds.

34:11.480 --> 34:13.440
Because at the end of the day, it doesn't matter.

34:13.440 --> 34:15.120
It's all runtime versus memory.

34:15.120 --> 34:18.960
So it doesn't matter if I resolve a chunk of 10,000 domains at the same time or one at a time.

34:18.960 --> 34:20.400
It's all the same runtime.

34:21.100 --> 34:26.760
So the only thing that would really matter, that really matters, is hitting your database a bunch.

34:26.760 --> 34:34.740
So you can resolve a bunch and have them all catch at a step in the step function, and then as batches happen, then you can batch update databases.

34:34.800 --> 34:40.420
But for the active stuff, I break it into super teeny chunks, so I never really have to worry about a time limit.

34:42.340 --> 34:42.920
Yeah.

34:54.470 --> 34:55.790
You can do either one.

34:56.850 --> 34:57.430
Yep.

34:57.430 --> 34:57.690
Yep.

34:57.690 --> 34:59.170
You can configure it to do either one.

35:00.170 --> 35:00.850
Yeah.

35:05.250 --> 35:05.430
...

35:06.290 --> 35:06.730
...

35:13.570 --> 35:14.010
...

35:15.490 --> 35:15.930
...

35:15.930 --> 35:16.050
...

35:16.670 --> 35:17.550
Absolutely.

35:18.150 --> 35:21.770
So serverless, the framework, supports Azure as well.

35:21.770 --> 35:23.310
And I think it's called Azure Functions.

35:23.310 --> 35:25.430
Again, I'm kind of hiding AWS.

35:25.690 --> 35:30.530
But Azure has Azure Functions, and it is, I'm sure it is very similar.

35:30.550 --> 35:33.150
It will handle it all for you and deploy it.

35:33.150 --> 35:33.530
...

35:33.530 --> 35:35.230
Mm-hmm.

35:39.560 --> 35:43.220
So I personally talked to AWS before I gave the talk.

35:43.220 --> 35:46.040
They said as long as I'm not doing anything naughty, it's allowed.

35:46.040 --> 35:46.860
Right?

35:47.080 --> 35:49.520
Because it's just public domain.

35:49.520 --> 35:53.760
But I did have someone else from AWS tell me to watch out.

35:53.760 --> 35:54.480
So it is.

35:54.480 --> 35:56.440
And I have heard of people getting banned off the platform.

35:56.440 --> 35:59.940
So I've got I was going to say, I've gotten pretty mixed reviews from it.

35:59.940 --> 36:01.560
I haven't gotten personally in trouble yet.

36:01.840 --> 36:05.260
As well as when Lambda spin up, they run on different IPs.

36:05.260 --> 36:07.580
So I guess there's that benefit.

36:07.580 --> 36:08.940
I don't really use it for that benefit.

36:08.940 --> 36:16.280
And again, I don't use this type of recon to continually berate sites.

36:16.280 --> 36:16.540
Right?

36:16.540 --> 36:20.540
I do pretty relaxed scanning, if at all.

36:21.060 --> 36:24.560
And I don't try and update data every minute on the minute.

36:24.560 --> 36:25.300
That kind of stuff.

36:25.300 --> 36:27.660
So I feel pretty safe about that.

36:27.660 --> 36:29.260
But I mean, if you were using it like that...

36:31.140 --> 36:31.760
Yeah.

36:31.760 --> 36:33.220
You might get in trouble.

36:33.220 --> 36:34.060
Yeah.

36:35.720 --> 36:36.140
Yeah .

36:37.160 --> 36:38.040
Absolutely.

36:40.260 --> 36:41.140
Yeah.

36:45.220 --> 36:46.100
Yep.

36:49.160 --> 36:49.960
You can.

36:49.960 --> 36:51.260
It's all the same thing.

36:51.280 --> 36:57.760
I use Lambda because again, when I do active scanning, I just break it up into super tiny chunks.

36:58.400 --> 37:00.840
Fargate, literally, you can use the same thing.

37:00.840 --> 37:03.220
You would just do the same thing with step functions, but for the longer...

37:03.220 --> 37:08.340
If you want longer running jobs, you'd have to use a standard step function, so it can run for up to a year.

37:08.360 --> 37:10.500
And then you would just plug Fargate in, and it would be the same thing.

37:11.320 --> 37:12.020
Personal preference.

37:12.020 --> 37:17.440
If you want to do the exact same thing, but with Fargate, it will work almost identically.

37:19.440 --> 37:19.980
Yeah.

37:23.920 --> 37:24.880
Good question.

37:36.480 --> 37:37.440
There you go.

37:38.660 --> 37:39.460
Yeah.

37:48.080 --> 37:49.800
Yes and no.

37:50.760 --> 37:59.840
I am, like I said, I'm willing to share, and I may, if there's a lot of ask for it, I may just make it easier to put some stuff in a GitHub repo and share it.

37:59.840 --> 38:01.100
I'm not against that.

38:02.780 --> 38:07.200
Part of it, I won't, just because it's a lot.

38:08.020 --> 38:12.080
But again, if you have a question, get in touch with me over Twitter or something like that, and I can.

38:12.080 --> 38:14.000
And if there's a lot of interest, I probably will.

38:14.320 --> 38:19.460
I guess I didn't have plans for it, but it's not necessarily because I'm secretive or anything.

38:19.460 --> 38:24.220
I guess if there was interest, I wouldn't be against it, but I didn't originally have plans to, yeah.

38:26.000 --> 38:26.460
Cool.

38:26.460 --> 38:27.160
Thanks, guys.

