WEBVTT

00:00:00.140 --> 00:00:01.060
In this demo,

00:00:01.190 --> 00:00:05.700
I will verify the Winlogbeat configuration as the event IDs necessary to

00:00:05.700 --> 00:00:09.180
facilitate the detection of PowerShell execution anomalies.

00:00:09.180 --> 00:00:11.850
Then, as I mentioned in the previous clip,

00:00:12.240 --> 00:00:14.750
we need to enable PowerShell login explicitly.

00:00:14.750 --> 00:00:16.770
When all of that is complete,

00:00:16.800 --> 00:00:20.340
I will simulate malicious PowerShell activity and then pivot to the

00:00:20.340 --> 00:00:23.660
Kibana web UI and look at what artifacts were generated.

00:00:24.540 --> 00:00:27.240
This is the Winlogbeat configuration file from one

00:00:27.240 --> 00:00:28.950
of the Windows 10 workstations.

00:00:29.440 --> 00:00:35.260
The event IDs we need are 4688, 4103, and 4104.

00:00:35.260 --> 00:00:38.410
We have verified the event IDs are configured,

00:00:38.410 --> 00:00:41.620
now let's head over to the domain controller and check that we

00:00:41.620 --> 00:00:44.150
have the PowerShell login GPOs configured.

00:00:45.040 --> 00:00:47.310
We will start with the PowerShell module login,

00:00:47.560 --> 00:00:50.810
which can be found under Policies, Admin Templates,

00:00:50.960 --> 00:00:54.490
Windows Components, and if I scroll down a bit further,

00:00:54.680 --> 00:00:56.930
we can see the Windows PowerShell.

00:00:56.930 --> 00:01:01.160
This gives us the five settings we see in the window pane on the right.

00:01:01.840 --> 00:01:03.680
I've already enabled Module Logging.

00:01:04.140 --> 00:01:07.070
If you want to also enable Script Block Logging here,

00:01:07.340 --> 00:01:11.460
you can, but I prefer to use a separate Group Policy Object for the flexibility.

00:01:12.240 --> 00:01:13.950
I'm going to bring up the second window,

00:01:14.280 --> 00:01:17.760
and here we can see we have Script Block Logging enabled.

00:01:18.740 --> 00:01:22.460
The only thing left is to simulate adversarial PowerShell execution.

00:01:22.940 --> 00:01:25.250
So let's go back to the Windows 10 machine,

00:01:25.740 --> 00:01:28.460
and I'm going to execute an encoded PowerShell command.

00:01:28.840 --> 00:01:31.460
Now, instead of telling you what it does,

00:01:31.840 --> 00:01:33.710
when we visit the Kibana web UI,

00:01:33.760 --> 00:01:36.850
you'll get to experience the value of having Winlogbeat

00:01:36.860 --> 00:01:40.500
collect PowerShell logs. Remember, even if you can decode

00:01:40.500 --> 00:01:41.980
what you see on the screen,

00:01:42.000 --> 00:01:46.180
real‑world malware will not be as trivial. You may have to rely on the

00:01:46.180 --> 00:01:48.760
PowerShell logs that contain the decoded contents.

00:01:49.440 --> 00:01:52.250
Okay, so the command has executed,

00:01:52.740 --> 00:01:55.860
let's head over to the Kibana UI and talk about detection.

00:01:56.540 --> 00:02:00.640
One way we can approach finding anomalous PowerShell execution is to

00:02:00.650 --> 00:02:03.950
understand if our environment uses encoded PowerShell commands.

00:02:04.840 --> 00:02:08.870
This isn't common in the Globomantics environment, so we can start our hunt

00:02:09.030 --> 00:02:14.440
using the event ID 4103 and check in if the command line field contains the

00:02:14.440 --> 00:02:17.760
eNc string, which is shorthand for encoded command.

00:02:18.640 --> 00:02:21.840
If I select and run the saved query I created earlier,

00:02:22.070 --> 00:02:26.050
it appears we have 29 documents that have the eNc string.

00:02:26.840 --> 00:02:31.000
I made the letter N uppercase to show that the text field was designed to allow

00:02:31.000 --> 00:02:35.910
case insensitive searching. To get a better view of the details, I'm going to

00:02:35.910 --> 00:02:43.060
select the fields process.command_line, agent.hostname, related.user, and the

00:02:43.060 --> 00:02:48.530
activity.id, which we will use for correlation with the event ID 4104 in a

00:02:48.530 --> 00:02:53.460
moment. Notice that the command line is still encoded and we can't tell if this

00:02:53.460 --> 00:02:54.960
is benign or malicious.

00:02:55.440 --> 00:02:58.820
Additionally, I only executed the PowerShell command once,

00:02:59.040 --> 00:03:01.160
but it generated multiple log events.

00:03:02.140 --> 00:03:06.110
I want to reduce some of the noise and scope the result to just the activity

00:03:06.110 --> 00:03:09.360
ID, which groups events that are part of the same activity.

00:03:10.540 --> 00:03:14.360
Then, I'm going to change the event code to 4104,

00:03:14.500 --> 00:03:17.150
which is Script Block Logging, and this should give us the

00:03:17.150 --> 00:03:18.960
decoded commands that were executed.

00:03:19.540 --> 00:03:22.260
Let's get the filters from the earlier query out of the way.

00:03:23.340 --> 00:03:29.490
Now, I need to add the powershell.file.script_block_text field, and voila,

00:03:29.560 --> 00:03:31.060
we have the decoded commands.

00:03:32.040 --> 00:03:35.810
It appears that the adversary attempted to create a scheduled task that

00:03:35.810 --> 00:03:40.730
ran an executable daily at 7pm. Thanks to Winlogbeat, we were able to

00:03:40.730 --> 00:03:43.560
collect this data and can perform remediation.

00:03:44.240 --> 00:03:47.470
If we had other instances of legitimate encoded commands,

00:03:47.630 --> 00:03:50.910
you would simply filter the known good out and that should

00:03:50.910 --> 00:03:53.260
reveal the anomalous PowerShell executions.

00:03:53.740 --> 00:03:58.360
We didn't look at event ID 4688 here because we were able to see the

00:03:58.360 --> 00:04:02.560
command line execution from the 4103 event code.

00:04:03.040 --> 00:04:06.910
If you do not enable Script Block Logging or Module Logging,

00:04:07.000 --> 00:04:10.660
then event ID 4688 would at least be a starting point
