WEBVTT

00:00:01.640 --> 00:00:04.830
Let's begin by making changes to Suricata's configuration.

00:00:04.830 --> 00:00:05.350
First,

00:00:05.350 --> 00:00:08.680
we'll enable file‑store by changing the value from no

00:00:08.690 --> 00:00:10.650
to yes under the file‑store section.

00:00:12.540 --> 00:00:16.210
We're also going to remove the comment in front of the stream‑depth property,

00:00:16.430 --> 00:00:17.850
ensuring it has a value of 0.

00:00:17.850 --> 00:00:20.550
As the notes in the configuration mention,

00:00:20.560 --> 00:00:23.510
setting this value to 0 will ensure that Suricata performs

00:00:23.510 --> 00:00:25.760
an unlimited read during file extraction.

00:00:27.640 --> 00:00:28.070
Next,

00:00:28.070 --> 00:00:30.630
we'll set a value of 0 for the response‑body‑limit

00:00:30.630 --> 00:00:32.860
setting under the libhtp section.

00:00:33.640 --> 00:00:35.390
We're now ready to save our configuration.

00:00:35.390 --> 00:00:37.480
With any changes to the configuration,

00:00:37.480 --> 00:00:40.760
we need to restart Suricata and can do that with systemd.

00:00:41.140 --> 00:00:43.890
Keep in mind that you need to give Suricata a few minutes after

00:00:43.890 --> 00:00:46.930
restarting before it's ready to process traffic; however,

00:00:46.930 --> 00:00:47.960
for this demonstration,

00:00:47.960 --> 00:00:52.080
we don't need to restart Suricata as we'll be utilizing the ingest script,

00:00:52.250 --> 00:00:56.840
which relies on Suricata's ability to process pcaps and not the replace script,

00:00:56.910 --> 00:00:59.220
which is utilizing Suricata as a service.

00:01:00.940 --> 00:01:04.349
Before we're ready to extract files, we need to create custom rules.

00:01:04.349 --> 00:01:07.750
Open the file custom.rules in the training directory.

00:01:07.750 --> 00:01:12.550
Here, we'll add our custom rule to extract PE files from the HTTP protocol.

00:01:13.440 --> 00:01:16.210
I've chosen PE files because of their prevalent use for

00:01:16.210 --> 00:01:19.640
distributing malware and that a lot of organizations rely on

00:01:19.640 --> 00:01:24.260
Windows as their main end‑user PC, as well as server infrastructure.

00:01:25.540 --> 00:01:27.090
We'll keep this rule simple.

00:01:27.090 --> 00:01:29.560
First, it will alert when a file matches.

00:01:29.940 --> 00:01:32.830
We'll use the HTTP protocol and tell it to match on any

00:01:32.830 --> 00:01:35.200
source port to any destination port.

00:01:35.520 --> 00:01:39.350
We'll then add the filestore keyword and use the filemagic

00:01:39.360 --> 00:01:41.360
keyword to match the lib magic value.

00:01:41.840 --> 00:01:46.060
For this, I use the string PE32 executable.

00:01:46.540 --> 00:01:49.150
We'll discuss where I came up with this value in just a moment.

00:01:49.740 --> 00:01:53.550
All that is now left is to add the revision and the SID and save the file.

00:01:55.340 --> 00:01:57.910
With our demo pcap, we'll use the ingest script.

00:01:58.260 --> 00:02:00.610
This is due to the fact that in the ingest script,

00:02:00.620 --> 00:02:04.760
it will tell Suricata to load not only the rules configured by suricata‑update,

00:02:05.140 --> 00:02:10.560
but also a custom rule file we defined with a ‑s argument at the command line.

00:02:10.940 --> 00:02:14.760
You can see this inside of the script if you'd like to take a look.

00:02:14.760 --> 00:02:16.980
After processing the pcap,

00:02:16.990 --> 00:02:20.790
you should see alerts that indicate that a PE file was not only downloaded,

00:02:20.800 --> 00:02:22.160
but also extracted.

00:02:23.540 --> 00:02:26.560
Let's go ahead down and investigate this data using EveBox.

00:02:26.940 --> 00:02:29.390
We can use oneshot mode with EveBox.

00:02:29.400 --> 00:02:33.290
All you need to do is to tell EveBox to run in oneshot mode and point it

00:02:33.290 --> 00:02:37.780
to the location of an eve.json file you want to analyze. Since our ingest

00:02:37.780 --> 00:02:43.030
script is placing log files at a temporary location, /tmp/suricata, we

00:02:43.030 --> 00:02:47.570
can provide that path. EveBox should now open up in your browser. Ensure

00:02:47.570 --> 00:02:53.780
that the time span is all and then navigate to Events, FileInfo. This

00:02:53.780 --> 00:02:57.520
provides file info events for every file that was encountered in that

00:02:57.520 --> 00:02:58.060
pcap.

00:02:59.240 --> 00:03:03.350
Well there are several files here, let's focus on the file os2.exe.

00:03:04.940 --> 00:03:08.050
The details of this file include a magic that should have matched in our file

00:03:08.050 --> 00:03:11.460
extraction rule, at least in part. The State is Closed,

00:03:11.460 --> 00:03:15.060
which means it was not only fully read, but also fully extracted.

00:03:15.440 --> 00:03:19.550
And we have several hashes, MD5, SHA‑1, SHA‑256.

00:03:20.340 --> 00:03:24.840
Let's take note of the first two bytes, or characters, of the SHA‑256.

00:03:25.240 --> 00:03:28.750
These values are used to determine where to store this file during extraction.

00:03:30.240 --> 00:03:34.520
Next, let's go ahead and click on the Flow ID. You'll see all of the events

00:03:34.520 --> 00:03:39.480
surrounding this file to include our file extraction alerts. Remember, the flow

00:03:39.480 --> 00:03:43.930
ID helps us to take a step backwards and oftentimes get a better, broader

00:03:43.930 --> 00:03:46.350
context around events that occur on our network.

00:03:48.140 --> 00:03:50.050
Let's now head to our log location at

00:03:50.050 --> 00:03:53.790
tmp/suricata/filestore. Listing the contents of this

00:03:53.790 --> 00:03:56.760
directory reveals several folders with two character names.

00:03:57.140 --> 00:03:59.660
These are the first two values from the SHA‑256.

00:04:00.340 --> 00:04:03.660
The file that we're investigating started with the characters 57.

00:04:04.040 --> 00:04:05.560
Let's navigate into that folder.

00:04:06.740 --> 00:04:08.260
Doing so reveals a file.

00:04:08.940 --> 00:04:12.860
If you use the file utility, you'll see that it is a PE32 file.

00:04:13.240 --> 00:04:15.810
So, the file utility is another way to get the

00:04:15.810 --> 00:04:17.860
results of a file type using libmagic.

00:04:18.339 --> 00:04:20.620
As long as the file was completely extracted,

00:04:20.630 --> 00:04:23.860
you can now use it with other analysis tools, such as a sandbox.

00:04:24.440 --> 00:04:26.660
When investigating files to extract,

00:04:26.670 --> 00:04:30.010
you can now use the file utility on those file types in

00:04:30.010 --> 00:04:33.130
order to see what the libmagic is and devise the patterns

00:04:33.130 --> 00:04:34.580
that you want to use in your rules.

00:04:34.870 --> 00:04:35.670
As you can see,

00:04:35.670 --> 00:04:38.690
the results for a PE file are quite a bit longer than the

00:04:38.690 --> 00:04:43.650
string or value that I used; however, running file across a large dataset,

00:04:43.650 --> 00:04:48.550
a large number of PE files, I found that PE32 executable

00:04:48.580 --> 00:04:50.550
was one of the most common patterns.

00:04:51.240 --> 00:04:52.770
If we wanted to get more precise,

00:04:52.780 --> 00:04:56.400
say we only wanted to extract .NET assemblies, .NET files as

00:04:56.400 --> 00:05:00.140
you see here, then we would need to include parts of this

00:05:00.150 --> 00:05:03.520
libmagic result that were more unique to these files, such as

00:05:03.520 --> 00:05:05.760
the string Mono/.Net assembly.

00:05:06.340 --> 00:05:06.920
In any case,

00:05:06.920 --> 00:05:10.460
this gives you a really good idea as to how to configure Suricata to

00:05:10.460 --> 00:05:13.970
perform file extraction, the rules that you need to write in order to

00:05:13.970 --> 00:05:18.070
extract the files, where those files are stored, and how to determine

00:05:18.080 --> 00:05:22.920
what value to use for the filemagic result. That wraps up this section

00:05:22.930 --> 00:05:26.050
on deployment considerations. We're now ready to move on to the next

00:05:26.050 --> 00:05:27.020
section in this course
