WEBVTT

00:00:02.640 --> 00:00:06.400
I'm currently within the agent interaction section within the Merlin server

00:00:06.400 --> 00:00:10.860
container. As this tutorial is focused on Wazuh, I'm not going to cover how

00:00:10.860 --> 00:00:13.360
I got to this area or how to configure Merlin.

00:00:14.040 --> 00:00:15.440
If you're curious about Merlin,

00:00:15.600 --> 00:00:18.960
please check out my Pluralsight course, Command and Control with Merlin.

00:00:19.440 --> 00:00:21.960
Also, please check out course notes number 6 for the link.

00:00:22.940 --> 00:00:26.800
Additionally, the Merlin environment in both courses is nearly identical,

00:00:26.970 --> 00:00:30.770
so you can use the commands covered in the Merlin course to fill in any gaps.

00:00:31.740 --> 00:00:34.670
As a blue teamer, you need to guard against C2 threats,

00:00:34.780 --> 00:00:35.760
and in particular,

00:00:35.770 --> 00:00:38.960
you need to look for signs of initial compromise. In this

00:00:38.960 --> 00:00:42.050
simulation environment, the attacker has an initial foothold on

00:00:42.050 --> 00:00:44.560
the victim's machine through the Merlin agent.

00:00:45.840 --> 00:00:48.400
If you want to review the architecture diagram again,

00:00:48.570 --> 00:00:49.940
please see course notes number 7.

00:00:50.940 --> 00:00:54.960
Anyhow, the Merlin agent's foothold doesn't maintain after a system restart,

00:00:55.440 --> 00:00:59.070
so the attacker is going to use a script to escalate their initial foothold.

00:01:00.240 --> 00:01:03.570
Let's put on our attacker hat and accomplish this objective.

00:01:03.940 --> 00:01:04.410
First,

00:01:04.420 --> 00:01:07.450
we're going to upload libprocesshider onto the victim's machine.

00:01:08.040 --> 00:01:11.290
Libprocesshider will attempt to make the Merlin agent invisible to

00:01:11.290 --> 00:01:18.200
Wazuh. More on this later. I'm going to pause the video while this

00:01:18.200 --> 00:01:22.650
upload finishes. Nice, the upload was successful.

00:01:22.960 --> 00:01:24.670
Next up is foothold.py.

00:01:24.960 --> 00:01:28.050
This script can be seen as the main orchestrator of the foothold,

00:01:28.060 --> 00:01:30.870
and I actually created this script myself for this course.

00:01:31.540 --> 00:01:33.700
So, a little bit of an aside here,

00:01:33.710 --> 00:01:37.360
a real attacker wouldn't make the names this obvious, foothold.py.

00:01:37.890 --> 00:01:38.910
However,

00:01:38.920 --> 00:01:40.860
I just wanted to make it clear what these scripts

00:01:40.860 --> 00:01:42.670
were doing for learning purposes.

00:01:43.240 --> 00:01:44.560
Let's go ahead and upload it.

00:01:47.540 --> 00:01:50.450
Perfect, foothold.py was successfully uploaded.

00:01:50.840 --> 00:01:51.360
Okay,

00:01:51.480 --> 00:01:56.150
let's use the Merlin server to run the foothold script on the victim's machine.

00:01:56.640 --> 00:01:58.650
As an aside, before running this command,

00:01:59.040 --> 00:02:03.450
I waited about 5 minutes to allow the simulation environment to fully bootstrap.

00:02:10.240 --> 00:02:10.750
Okay,

00:02:10.759 --> 00:02:15.370
let's scroll up here a little bit and see what's going on here with foothold.py.

00:02:16.840 --> 00:02:20.000
Okay, we're doing some checks to see if a previous foothold exists.

00:02:20.010 --> 00:02:25.030
The main portion here that's important is the Running observability commands.

00:02:25.040 --> 00:02:26.560
First we run ps.

00:02:27.340 --> 00:02:30.960
Notice how the merlinAgent is clearly visible within

00:02:30.960 --> 00:02:36.850
the output. And we scroll down, but we also see netstat output.

00:02:37.740 --> 00:02:39.870
Alright, let me zoom out a little bit here.

00:02:42.740 --> 00:02:44.270
Okay, we're recentered now.

00:02:44.740 --> 00:02:49.500
Notice the PID/Program. So, clearly the Merlin agent is

00:02:49.500 --> 00:02:51.850
visible within the netstat output as well.

00:02:53.540 --> 00:02:54.770
Zoom back in.

00:02:59.940 --> 00:03:03.450
Let's start here, Starting compilation of libprocesshider.

00:03:03.940 --> 00:03:07.460
An artifact from this compilation will be injected into

00:03:07.470 --> 00:03:12.100
/etc/ld.so.preload. Code injected into this location will run

00:03:12.100 --> 00:03:13.960
before any program on the system.

00:03:14.540 --> 00:03:16.070
This is a Linux convention.

00:03:16.440 --> 00:03:17.840
Once this code is injected,

00:03:17.850 --> 00:03:21.570
Merlin should be invisible to commands that are used to monitor processes.

00:03:22.340 --> 00:03:24.950
An example is netstat, ps, etc.

00:03:25.640 --> 00:03:28.420
By default, Wazuh uses netstat to monitor network

00:03:28.420 --> 00:03:30.560
connections, just as a little bit of a heads‑up.

00:03:31.640 --> 00:03:35.040
Okay, we see Successfully compiled libprocesshider.

00:03:35.050 --> 00:03:36.420
It was injected.

00:03:36.430 --> 00:03:40.000
And we also see that the script, foothold.py, is being

00:03:40.000 --> 00:03:43.530
injected into bash.bashrc for persistence.

00:03:43.630 --> 00:03:47.270
Whenever a user logs into the system, this command will be executed.

00:03:48.440 --> 00:03:49.850
Okay, let's scroll down here a little bit.

00:03:53.440 --> 00:03:55.450
The observability commands are run again.

00:03:56.040 --> 00:04:00.360
Notice in the ps output how the Merlin agent is not visible any longer.

00:04:01.140 --> 00:04:08.770
Scroll down here and check out the netstat output. By zooming out, we also see

00:04:08.770 --> 00:04:12.160
the Merlin agent isn't visible within the netstat output.

00:04:13.640 --> 00:04:18.470
One item to note here is that the listening port still shows; however,

00:04:18.940 --> 00:04:20.860
the actual process name is cloaked.

00:04:21.640 --> 00:04:24.160
Let's go into Wazuh and see if any alerts were triggered.
