WEBVTT

00:00:01.440 --> 00:00:06.360
Ingesting and analyzing audit logs are not the only things we can do with Kafka.

00:00:07.040 --> 00:00:07.730
In fact,

00:00:07.740 --> 00:00:10.990
we're going to have some extra fun by detecting network

00:00:10.990 --> 00:00:14.130
port scan attacks and triggering alerts in a similar

00:00:14.130 --> 00:00:16.550
fashion as the audit.log scenario.

00:00:17.440 --> 00:00:19.780
I'm going to get started by creating a file that will

00:00:19.780 --> 00:00:22.820
store our network logs using touch.

00:00:22.820 --> 00:00:26.660
The file must be placed in the same logs directory

00:00:26.760 --> 00:00:28.960
so Kafka Connect can access it.

00:00:29.740 --> 00:00:32.460
The network logs will have the following format.

00:00:33.340 --> 00:00:37.040
I'm actually going to insert one in the network.log file so

00:00:37.050 --> 00:00:39.760
Kafka Connect can publish one event right away.

00:00:41.040 --> 00:00:45.440
The network logs will be created using a traffic sniffer like tcpdump,

00:00:45.440 --> 00:00:48.660
but other network analyzers such as Wireshark,

00:00:48.660 --> 00:00:50.160
may work just fine.

00:00:50.940 --> 00:00:55.620
The format is rather standard and includes the time when the event occurred,

00:00:55.620 --> 00:01:00.620
the source IP of the network package, its target or destination,

00:01:00.620 --> 00:01:03.750
and some other details we can cover a bit later.

00:01:04.840 --> 00:01:09.160
Back to the README file, we can deploy a new connector on Kafka Streams.

00:01:09.940 --> 00:01:12.590
The pattern is rather similar as in the previous demo.

00:01:13.740 --> 00:01:18.060
We're using a FileStreamSource connector that we're calling network‑logs.

00:01:18.840 --> 00:01:22.600
This connector will check the network.log file for new appended rows,

00:01:22.850 --> 00:01:24.770
and for each and every one of them,

00:01:24.770 --> 00:01:29.550
it will create a new event that will be published in the network‑logs topic.

00:01:30.740 --> 00:01:34.660
Now, this time, we're going to use another component called Kafka Streams.

00:01:35.240 --> 00:01:39.590
Kafka Streams offers a similar set of functionalities as ksqlDB,

00:01:39.590 --> 00:01:42.260
but it's using Java code instead.

00:01:42.260 --> 00:01:45.340
You're more than free to check the source code inside

00:01:45.340 --> 00:01:49.650
the network‑logs‑analyzer folder, but the logic sounds something like this.

00:01:50.640 --> 00:01:54.230
A port scan attack is defined by a rapid succession of

00:01:54.230 --> 00:01:57.560
connections on different ports from a single source.

00:01:58.340 --> 00:02:01.770
So what the network‑logs‑analyzer does is checks if

00:02:01.770 --> 00:02:04.250
in a time interval of 10 seconds,

00:02:04.250 --> 00:02:08.560
a single source has tried to connect to multiple ports on the target.

00:02:09.240 --> 00:02:14.360
If such a scenario occurs, the network‑logs‑analyzer will trigger an alert.

00:02:15.740 --> 00:02:17.760
Now, looking at this Docker command,

00:02:17.900 --> 00:02:20.570
you should take two factors into consideration.

00:02:20.570 --> 00:02:21.170
First,

00:02:21.170 --> 00:02:25.420
if the directory where you placed the docker‑compose file is called differently,

00:02:25.420 --> 00:02:27.960
then the network name should be adjusted.

00:02:28.940 --> 00:02:31.780
The same thing applies to the volume model.

00:02:31.820 --> 00:02:35.510
We need to mount the secrets folder so that the absolute path

00:02:35.520 --> 00:02:37.860
might also match what's relevant for you.

00:02:39.040 --> 00:02:42.480
Just like ksqlDB, this application will run in the background,

00:02:42.480 --> 00:02:45.250
so we won't be bothered by its logs.

00:02:45.250 --> 00:02:47.990
With everything related to Kafka in place,

00:02:47.990 --> 00:02:52.680
we can start analyzing the traffic and performing the port scan attack.

00:02:52.680 --> 00:02:56.670
To analyze the network traffic, we're going to use tcpdump,

00:02:56.670 --> 00:02:58.650
but we need a target first.

00:02:59.540 --> 00:03:02.950
I'm actually going to attack the audit‑logger application.

00:03:02.950 --> 00:03:07.460
To determine the target IP, we can use docker inspect command.

00:03:08.040 --> 00:03:12.200
Typically, port scan attacks are performed against other machines,

00:03:12.200 --> 00:03:16.360
but today I'm going to keep things simple and attack a Docker container.

00:03:17.040 --> 00:03:22.800
The IP is 172.28.0.4, so I need to note it somewhere,

00:03:22.800 --> 00:03:25.000
because we're going to use it right away.

00:03:25.000 --> 00:03:29.130
To analyze the traffic, we're going to use the tcpdump tool.

00:03:29.130 --> 00:03:29.710
Here,

00:03:29.710 --> 00:03:35.230
we are telling you to only analyze the traffic that occurs on the en0 interface,

00:03:35.230 --> 00:03:43.040
which is my network interface, and with the target host IP address 172.28.0.4,

00:03:43.050 --> 00:03:44.850
which is the Docker container.

00:03:45.840 --> 00:03:49.260
Since we want all these network logs to end up in Kafka,

00:03:49.640 --> 00:03:52.680
we're piping them on the network.log file.

00:03:52.680 --> 00:03:57.580
In parallel, we also need to perform the port scan attack.

00:03:57.580 --> 00:04:01.660
This attack can be performed using a tool called Nmap.

00:04:02.440 --> 00:04:05.810
If you're not familiar with Nmap or port scan attacks,

00:04:05.810 --> 00:04:10.560
I definitely recommend checking the Nmap.org website for more information.

00:04:11.740 --> 00:04:14.720
Again, the target can be any machine on your network,

00:04:14.720 --> 00:04:17.860
but for now I'm going to stick with the Docker container.

00:04:18.940 --> 00:04:19.519
However,

00:04:19.529 --> 00:04:22.510
I don't recommend using Nmap for launching port scan

00:04:22.510 --> 00:04:24.940
attacks against systems you do not own,

00:04:24.940 --> 00:04:28.060
as it may attract severe negative consequences.

00:04:28.740 --> 00:04:32.700
Civil lawsuits may be brought by the owner of the scan system,

00:04:32.700 --> 00:04:35.850
so it's best to only target systems that you own.

00:04:37.040 --> 00:04:38.670
It seems the scan was pretty quick,

00:04:38.670 --> 00:04:42.230
so let's head back over to tcpdump and stop the sniffing

00:04:42.230 --> 00:04:45.160
process as well by pressing Ctrl+C keys.

00:04:45.840 --> 00:04:46.500
Excellent!

00:04:46.560 --> 00:04:49.680
We can see that 2008 packets have been captured.

00:04:49.860 --> 00:04:54.490
So this means our network‑logs analyzers should have triggered another.

00:04:54.490 --> 00:04:58.510
To check if this happened, we're going to use ksqlDB again,

00:04:58.550 --> 00:05:01.650
since it's the easiest way to inspect the content of a topic.

00:05:02.440 --> 00:05:05.860
The topic name is alerts.port‑scan‑attack.

00:05:07.440 --> 00:05:10.410
It seems something has indeed been published in this topic,

00:05:10.420 --> 00:05:15.560
but ksqlDB is having some troubles to figure out which type of data it is.

00:05:16.140 --> 00:05:17.460
To solve this issue,

00:05:17.520 --> 00:05:21.530
we need to define a data structure just like in the previous demo.

00:05:21.530 --> 00:05:25.160
Only then, we can see the result using a select statement.

00:05:25.840 --> 00:05:30.020
The downside to this approach is that we can only see events that have

00:05:30.020 --> 00:05:32.950
been published after the select statement started.

00:05:33.340 --> 00:05:36.670
So we need to perform another port scan attack.

00:05:36.670 --> 00:05:40.790
First, I'm going to initialize traffic sniffing using tcpdump,

00:05:40.790 --> 00:05:45.150
and then launch another port scan attack using Nmap.

00:05:46.040 --> 00:05:50.060
The best part is that a port scan attack only takes a couple of seconds,

00:05:50.060 --> 00:05:53.750
so we don't have to wait a long time until we get the results.

00:05:54.840 --> 00:05:58.160
Again, 2006 packets have been captured.

00:05:58.290 --> 00:06:00.120
So we should definitely have an alert produced.

00:06:00.120 --> 00:06:04.600
Switching back to ksqlDB terminal, and indeed,

00:06:04.600 --> 00:06:09.050
we can see that Nmap has launched the attacks from two different ports.
