WEBVTT

00:00:01.640 --> 00:00:02.880
In this demonstration,

00:00:02.880 --> 00:00:06.260
we're going to take a look at making changes to Suricata's configuration.

00:00:06.740 --> 00:00:08.950
First up, let's disable the fast.log.

00:00:09.340 --> 00:00:11.160
We'll assume that nothing is consuming it,

00:00:11.160 --> 00:00:12.760
and therefore, it doesn't need to be generated.

00:00:13.640 --> 00:00:15.920
You can cap the content of fast.log.

00:00:15.930 --> 00:00:20.560
We'll be looking at service mode logs, and you'll find those in var/log/suricata.

00:00:21.340 --> 00:00:24.740
You'll likely see alert messages from our previous pcap replace.

00:00:24.930 --> 00:00:26.470
If for some reason you don't,

00:00:26.470 --> 00:00:29.930
feel free to use the replay script to replay a pcap, almost

00:00:29.940 --> 00:00:31.960
all of them should generate alert data.

00:00:32.640 --> 00:00:33.180
Next,

00:00:33.190 --> 00:00:36.450
let's simply empty this file by echoing an empty string

00:00:36.450 --> 00:00:38.850
and redirecting to the fast.log file.

00:00:39.340 --> 00:00:42.520
Since these are service mode logs, you'll need to be root to do this.

00:00:43.840 --> 00:00:47.260
Cat again and you should see that the alert messages are now gone.

00:00:47.740 --> 00:00:50.340
Before we make any changes to the configuration file,

00:00:50.350 --> 00:00:52.300
it's a good idea to save a copy of it.

00:00:52.520 --> 00:00:55.180
This way, you have something to not only compare against,

00:00:55.180 --> 00:00:58.110
but also restore to in case you make a mistake.

00:00:58.160 --> 00:00:59.730
How you do this is up to you.

00:00:59.890 --> 00:01:01.210
To keep things simple though,

00:01:01.210 --> 00:01:04.860
I'll just copy the file and append a .bak extension to it.

00:01:06.040 --> 00:01:06.450
Next,

00:01:06.460 --> 00:01:09.420
open surakarta.yaml with a text editor and with root

00:01:09.420 --> 00:01:10.960
privileges using the sudo command.

00:01:11.740 --> 00:01:16.050
Search for the fast.log section under outputs and then

00:01:16.050 --> 00:01:18.760
modify the enabled value from yes to no.

00:01:19.840 --> 00:01:22.960
We can now save our file and exit out of our text editor.

00:01:23.740 --> 00:01:25.270
When making config changes,

00:01:25.280 --> 00:01:28.860
it's a good idea to test those changes to ensure that nothing will break.

00:01:29.330 --> 00:01:30.210
If you've noticed,

00:01:30.210 --> 00:01:34.060
Suricata update does this as one of the last items during the update process.

00:01:34.740 --> 00:01:38.760
To test the config, you can use the ‑T argument, uppercase T.

00:01:39.340 --> 00:01:41.810
This will use the default configuration file and let you

00:01:41.810 --> 00:01:43.300
know if any errors were encountered.

00:01:43.940 --> 00:01:46.460
Also notice how long it takes Suricata to initialize.

00:01:47.140 --> 00:01:51.060
Before it is done, it's not ready to process traffic and generate data.

00:01:51.640 --> 00:01:54.920
When you restart Suricata as a service, which we'll do shortly,

00:01:55.020 --> 00:01:57.420
you need to give it a couple of minutes to initialize before

00:01:57.420 --> 00:01:59.260
you can expect it to process your traffic.

00:01:59.640 --> 00:02:03.080
Keep this in mind as you make changes and go to replay pcaps.

00:02:03.360 --> 00:02:04.830
If you aren't seeing any data,

00:02:04.830 --> 00:02:07.260
it may be that Suricata just isn't quite ready for you.

00:02:08.130 --> 00:02:09.180
Looks like we're all set.

00:02:09.190 --> 00:02:12.440
No errors were printed and we received a message indicating that

00:02:12.440 --> 00:02:14.730
the configuration file was successfully loaded.

00:02:15.940 --> 00:02:18.330
After we've made changes to the configuration file,

00:02:18.340 --> 00:02:21.840
in order to apply those changes, we'll need to restart the Suricata service.

00:02:22.170 --> 00:02:23.860
Let's use systemd to do that.

00:02:24.340 --> 00:02:25.330
And as I mentioned,

00:02:25.340 --> 00:02:27.150
let's give Suricata a couple of minutes to

00:02:27.150 --> 00:02:29.560
reinitialize before we replay our next pcap.

00:02:31.940 --> 00:02:34.510
Now we're ready to replay a pcap that generates alerts.

00:02:34.650 --> 00:02:36.860
We'll use the replay script along with the demo pcap.

00:02:38.040 --> 00:02:41.110
And there are the alert events from the eve.json file.

00:02:41.310 --> 00:02:44.250
However, if you cat fast.log, it should remain empty,

00:02:44.640 --> 00:02:47.280
and that's it, our first configuration change.

00:02:47.510 --> 00:02:49.760
Let's move onto something a bit more complex now.

00:02:51.940 --> 00:02:54.960
Let's now take a look at the difference between logging and parsers.

00:02:55.340 --> 00:02:58.740
From the previous pcap, there are several DNS event records,

00:02:58.750 --> 00:03:02.140
and we can grab grep the log file and pipe the results through

00:03:02.140 --> 00:03:04.760
jq to get a sense of what data is there,

00:03:05.840 --> 00:03:08.260
but how does Suricata decide what data to log?

00:03:08.840 --> 00:03:11.260
Open the configuration file in a text editor and

00:03:11.260 --> 00:03:13.320
navigate to the eve‑log section.

00:03:14.340 --> 00:03:18.140
This will be located right under where we just disabled the fast.log.

00:03:19.040 --> 00:03:22.960
Under this section defines what data will be logged in the eve.json file.

00:03:23.440 --> 00:03:25.860
Let's say that we want to disable logging of DNS.

00:03:26.740 --> 00:03:29.450
You can disable logger output by commenting out the

00:03:29.450 --> 00:03:33.240
line‑space and then the protocol, in this case,

00:03:33.240 --> 00:03:33.890
DNS.

00:03:34.440 --> 00:03:36.820
By commenting it out, we just add a hashtag.

00:03:37.740 --> 00:03:40.740
After making the change, just as we did with the fast.log,

00:03:40.740 --> 00:03:44.500
you can save the file and then go ahead and restart Suricata using systemd.

00:03:46.640 --> 00:03:50.120
If we replay the previous pcap, we'll still see alerts,

00:03:50.130 --> 00:03:53.590
but won't find any DNS records in the eve.json file.

00:03:54.340 --> 00:03:57.730
Using the same grep command, we no longer get any results.

00:03:58.540 --> 00:04:00.460
So why was an alert still generated?

00:04:00.840 --> 00:04:04.260
Well, this is due to the fact that the DNS parser is still enabled.

00:04:04.840 --> 00:04:08.810
Let's look at this rule and do so by modifying our jq to

00:04:08.810 --> 00:04:11.100
show the signature and signature ID.

00:04:12.240 --> 00:04:17.160
Now let's grep the rule file based on this sid 2022918.

00:04:17.540 --> 00:04:18.500
As a reminder,

00:04:18.510 --> 00:04:20.920
Suricata update will write the rules file to

00:04:20.920 --> 00:04:24.560
var/lib/suricata/rules/suricata.rules.

00:04:25.740 --> 00:04:31.000
This rule uses the dns.query content modifier to match on a .duckdns.

00:04:31.000 --> 00:04:32.250
string.

00:04:32.840 --> 00:04:35.770
So if the string shows up in the DNS query,

00:04:35.780 --> 00:04:40.260
then it will generate the alert, but what happens if we disabled the DNS parser?

00:04:40.740 --> 00:04:41.750
We can always try.

00:04:42.130 --> 00:04:46.260
In the Suricata YAML, you'll find all the parsers under the app layer section.

00:04:46.840 --> 00:04:51.660
DNS parsing can be done over both TCP and UDP and each can be enabled/disabled

00:04:51.660 --> 00:04:55.660
by changing the enabled value from yes to no and vice versa.

00:04:56.740 --> 00:05:00.470
Let's open up the Suricata configuration file and make some modifications.

00:05:02.040 --> 00:05:02.880
As you can see,

00:05:02.880 --> 00:05:07.000
we are at the app‑layer section of the Suricata configuration file.

00:05:07.540 --> 00:05:09.690
We can scroll down until we find the protocol that

00:05:09.690 --> 00:05:12.280
we're interested in modifying, in this case,

00:05:12.280 --> 00:05:14.130
DNS.

00:05:14.130 --> 00:05:18.950
You'll notice that some protocols simply have an enabled option,

00:05:19.220 --> 00:05:20.860
enabled yes or enabled no.

00:05:21.210 --> 00:05:24.960
Others like DNS provide additional configuration such as

00:05:24.960 --> 00:05:29.680
what protocol to enable DNS parsers on, TCP or UDP.

00:05:29.830 --> 00:05:32.960
While we could disable the DNS parser under both protocols,

00:05:33.220 --> 00:05:36.140
this actually will impact the use of Suricata update,

00:05:36.140 --> 00:05:37.460
which you'll see in just a moment.

00:05:37.840 --> 00:05:42.250
So instead, we'll add an enabled no under the main protocol.

00:05:43.340 --> 00:05:46.870
This will override the other enabled values under

00:05:46.870 --> 00:05:48.510
the protocol specific sections.

00:05:48.940 --> 00:05:50.260
Let's save the file and exit.

00:05:50.840 --> 00:05:54.220
Now, if we test the config, you'll see a bunch of errors.

00:05:54.940 --> 00:05:58.780
Testing the configuration in this way is very strict and not all error

00:05:58.780 --> 00:06:02.660
messages mean that Suricata won't run just fine. In this case,

00:06:02.670 --> 00:06:05.700
since the rules were trying to load depend on this parser,

00:06:05.700 --> 00:06:08.060
Suricata is letting you know there is a problem.

00:06:08.540 --> 00:06:11.860
The good news is that this won't actually prevents Suricata from running.

00:06:12.240 --> 00:06:15.970
All we need to do now is run Suricata update. Suricata update

00:06:15.970 --> 00:06:19.020
will recognize this change in the config file and disable any

00:06:19.020 --> 00:06:20.680
rules that it impacts for us.

00:06:22.740 --> 00:06:25.070
As you can see, a Suricata update is running,

00:06:25.290 --> 00:06:29.160
it's already notified us that it's disabled a considerable number of rules.

00:06:29.840 --> 00:06:34.520
Once it finishes, we can restart Suricata and now the DNS parser logs

00:06:34.520 --> 00:06:37.160
and any resulting data will no longer be available.

00:06:38.240 --> 00:06:41.170
So it looks like Suricata update says we're ready to go.

00:06:41.180 --> 00:06:43.880
We've gone ahead and restarted the Suricata service.

00:06:44.340 --> 00:06:49.290
We can now run the previously analyzed pcap through Suricata again, and this

00:06:49.290 --> 00:06:54.330
time, we should not see any alerts, and there are results.

00:06:54.340 --> 00:06:57.360
No alerts were generated since we had no DNS parsers.

00:06:58.440 --> 00:07:01.400
This is just to give you some ideas as to how Suricata

00:07:01.400 --> 00:07:03.660
works and how you can customize your setup.

00:07:04.340 --> 00:07:07.440
Keeping DNS records is usually very valuable data to have

00:07:07.440 --> 00:07:10.330
for not only alerting, but for incident response or

00:07:10.340 --> 00:07:11.960
investigating network activity.

00:07:12.310 --> 00:07:15.880
Ultimately, it will be up to you to get to know your network and decide what

00:07:15.880 --> 00:07:19.090
data you need and what parsers you should or could disable.

00:07:20.240 --> 00:07:22.710
The last thing we'll look at is the BPF filter.

00:07:23.140 --> 00:07:24.420
Let's start with an example.

00:07:24.660 --> 00:07:28.690
We'll play a pcap using the ingest script that has UDP traffic.

00:07:29.060 --> 00:07:30.930
Not only will this generate flow records,

00:07:30.930 --> 00:07:36.350
but also several alerts, and there are those alerts I mentioned. You can

00:07:36.350 --> 00:07:43.030
also grep the eve.json file and see the flow records. To create our

00:07:43.030 --> 00:07:46.240
filter and ignore this traffic, let's create a sample file in the

00:07:46.240 --> 00:07:48.750
training directory called bpf.example.

00:07:49.230 --> 00:07:54.850
The name is really arbitrary. In this file,

00:07:54.860 --> 00:07:59.250
I'll tell it to not monitor UDP traffic on the local /24 network.

00:07:59.840 --> 00:08:01.740
This will match the pcap we'll replay,

00:08:01.750 --> 00:08:05.150
but in a real‑world scenario, it would present a segment of your network.

00:08:05.540 --> 00:08:07.790
You can read about the BPF syntax online.

00:08:08.090 --> 00:08:10.760
This is just to show you how to use this with Suricata,

00:08:11.100 --> 00:08:15.280
Save the file and close. Next, we'll modify the suri ingest

00:08:15.280 --> 00:08:17.460
pcap script to include this BPF filter.

00:08:17.840 --> 00:08:21.300
I'm going to avoid modifying our service mode instance as that would take just

00:08:21.300 --> 00:08:24.260
a little more tweaking, but be very similar in approach.

00:08:25.040 --> 00:08:29.560
We're going to add the argument ‑F and the path to your BPF file.

00:08:30.040 --> 00:08:31.560
Now save and close this file.

00:08:33.010 --> 00:08:35.289
You can now run the ingest script again with the

00:08:35.289 --> 00:08:37.289
same pcap and you'll see no alerts.

00:08:37.580 --> 00:08:39.559
This is that BPF filter in action.

00:08:41.940 --> 00:08:45.700
You can also grep the eve.json file and there will be no flow records either.

00:08:47.040 --> 00:08:50.310
So now you have a better understanding about Suricata's loggers and

00:08:50.310 --> 00:08:53.040
parsers and how you can begin to customize those based on your

00:08:53.040 --> 00:08:56.430
environment, we're now ready to move on and continue to explore the

00:08:56.430 --> 00:08:58.290
metadata that Suricata generates.
