WEBVTT

00:00:00.000 --> 00:00:02.882
So you've showed me quite a bit about enabling logging and

00:00:02.882 --> 00:00:06.733
the stuff that's not done by default, and so those logs are now there,

00:00:06.733 --> 00:00:08.580
but with all logging,

00:00:08.580 --> 00:00:12.369
someone actually has to look at them or they're only so useful.

00:00:12.369 --> 00:00:14.769
And no one really like scanning through logs visually.

00:00:14.769 --> 00:00:18.008
The scroll wheel is not the best tool of detection.

00:00:18.008 --> 00:00:20.765
And unfortunately, the Windows Event Viewer,

00:00:20.765 --> 00:00:24.279
it's kind of hard to use to search through logs,

00:00:24.279 --> 00:00:27.028
especially if you're looking at a local system,

00:00:27.028 --> 00:00:29.410
and there are some better tools to do that.

00:00:29.411 --> 00:00:33.241
So what we can do is look at the system with the malicious

00:00:33.241 --> 00:00:35.890
document that launches the PowerShell that I've already

00:00:35.890 --> 00:00:39.517
compromised the system here, and so we can look at what logs I get set off.

00:00:39.518 --> 00:00:42.227
So the tool that I'm going to use here is called Event Log Explorer.

00:00:42.228 --> 00:00:44.515
Event Log Explorer, it is a commercial tool,

00:00:44.515 --> 00:00:48.838
but you can download it for free as well for limited use.

00:00:48.838 --> 00:00:51.922
Event Log Explorer is essentially the Event Viewer on steroids.

00:00:51.922 --> 00:00:55.184
It gives you a lot more searching and filtering capabilities,

00:00:55.184 --> 00:00:58.260
which for an investigator is extremely powerful.

00:00:58.261 --> 00:01:01.461
So this is another enhancement on the Windows Event Viewer.

00:01:01.461 --> 00:01:01.698
Exactly.

00:01:01.698 --> 00:01:06.656
So what I'm going to do here is I've opened up the local security logs on my PC,

00:01:06.656 --> 00:01:08.385
which we've already compromised, again,

00:01:08.385 --> 00:01:12.047
and you can see that there a lot of different logs that I've turned on

00:01:12.047 --> 00:01:16.906
because I went in and I modified the logs based off of what Log-MD was

00:01:16.906 --> 00:01:18.946
telling me what I needed to turn on,

00:01:18.946 --> 00:01:22.618
so there's a lot more logs here that are being logged.

00:01:22.619 --> 00:01:24.723
So based on the report that we got that we saw previously,

00:01:24.723 --> 00:01:26.673
you've went ahead and enabled all those things,

00:01:26.673 --> 00:01:27.598
and this is the result.

00:01:27.598 --> 00:01:28.270
Yes, exactly.

00:01:28.270 --> 00:01:31.044
And so we're going to cheat a little bit.

00:01:31.044 --> 00:01:35.241
So we know that PowerShell was ran from our Word doc,

00:01:35.241 --> 00:01:38.553
and so we're going to search for any event log that

00:01:38.553 --> 00:01:40.747
has the word PowerShell in it.

00:01:40.747 --> 00:01:44.493
If I was doing threat hunting, I would pretty much do the same thing.

00:01:44.493 --> 00:01:47.916
I know that PowerShell is used in attacks,

00:01:47.916 --> 00:01:52.021
so I'm going to search for any instances of PowerShell in my logs.

00:01:52.021 --> 00:01:53.578
I love how simple that is.

00:01:53.578 --> 00:01:54.054
It is.

00:01:54.054 --> 00:01:54.530
It is.

00:01:54.530 --> 00:01:55.244
It's very simple.

00:01:55.244 --> 00:01:58.644
And we can see down here, we have a Process Creation event,

00:01:58.644 --> 00:02:03.972
so let me open that up.

00:02:03.972 --> 00:02:09.111
And here, we see our 4688 event, and just by looking at this,

00:02:09.111 --> 00:02:11.596
you should see something jump out to you right away.

00:02:11.597 --> 00:02:12.584
We see powershell.

00:02:12.584 --> 00:02:17.502
exe, and then that EncodedCommand, and then that huge Base64 encoded string.

00:02:17.502 --> 00:02:21.389
This definitely tells you something happened here.

00:02:21.389 --> 00:02:23.949
As a threat hunter, or an investigator, or an analyst,

00:02:23.949 --> 00:02:25.575
if I see this, big red flag.

00:02:25.575 --> 00:02:28.165
We're going to start looking and seeing what's going on here.

00:02:28.166 --> 00:02:32.216
So like you said before, you see EncodedCommand, it's probably nefarious.

00:02:32.216 --> 00:02:32.890
It is.

00:02:32.890 --> 00:02:33.563
It is.

00:02:33.563 --> 00:02:33.900
Absolutely.

00:02:33.901 --> 00:02:37.018
Now not only with this, this is a Process Creation event,

00:02:37.018 --> 00:02:39.486
but we saw a lot more events.

00:02:39.486 --> 00:02:42.129
So let me start scrolling through the events a little bit.

00:02:42.129 --> 00:02:45.226
Yeah, so this doesn't even, that wasn't even the PowerShell logging.

00:02:45.226 --> 00:02:47.185
That was a--- No, that was the security log.

00:02:47.186 --> 00:02:48.592
We haven't even gotten to the PowerShell logging yet.

00:02:48.592 --> 00:02:52.191
So here we're getting to another event, a Filtered Platform Connection.

00:02:52.191 --> 00:02:55.066
This basically logs all network connections that are

00:02:55.066 --> 00:02:56.738
occurring within your computer.

00:02:56.738 --> 00:03:00.975
And I'm going to go up one more, and here we see that our Process ID,

00:03:00.976 --> 00:03:03.367
and if we were to compare this Process ID to the previous

00:03:03.367 --> 00:03:06.588
one from the Process Creation event, they're the same.

00:03:06.589 --> 00:03:08.892
The application name, powershell.

00:03:08.892 --> 00:03:13.364
exe, we can see that it connected to this IP address on port 443.

00:03:13.365 --> 00:03:16.250
So now our logging not only has told us that this

00:03:16.250 --> 00:03:18.707
PowerShell launched some encoded command,

00:03:18.707 --> 00:03:21.352
but it also connected out to this IP address.

00:03:21.352 --> 00:03:23.207
And then HTTPS.

00:03:23.207 --> 00:03:27.165
And if we would look, this would be the IP address of Pastebin,

00:03:27.165 --> 00:03:31.091
and if we were to see that, that should definitely set off red flags.

00:03:31.091 --> 00:03:33.984
PowerShell does not connect out to Pastebin by default,

00:03:33.984 --> 00:03:35.766
so something is going on here.

00:03:35.767 --> 00:03:37.662
And Pastebin in particular may be something that

00:03:37.662 --> 00:03:39.327
you're alerting on on the network side,

00:03:39.327 --> 00:03:43.029
but actual malware is not going to go to something known like Pastebin.

00:03:43.029 --> 00:03:45.741
It's going to go through a recently spun up community control,

00:03:45.741 --> 00:03:48.258
or like a fast flux DNS, or something like that.

00:03:48.259 --> 00:03:48.547
Exactly.

00:03:48.547 --> 00:03:50.859
So let's go up a little bit more.

00:03:50.859 --> 00:03:52.893
So we're going up one more event,

00:03:52.893 --> 00:03:55.544
and we see that we have another Process Creation event,

00:03:55.544 --> 00:03:58.619
and we know that this is not the same Process Creation

00:03:58.619 --> 00:04:00.693
event as before for two reasons.

00:04:00.694 --> 00:04:02.960
One, we look at the new Process ID here.

00:04:02.961 --> 00:04:06.172
This is the Process ID of the process that's getting executed.

00:04:06.173 --> 00:04:08.518
It's unique to every process on the system.

00:04:08.518 --> 00:04:11.853
And so this is different than our previous one.

00:04:11.853 --> 00:04:13.142
If we scroll down,

00:04:13.142 --> 00:04:18.136
we can see that the command line is showing us something new here.

00:04:18.136 --> 00:04:20.666
So what happened here is our original PowerShell,

00:04:20.666 --> 00:04:23.826
remember, it went out to Pastebin, it downloaded more PowerShell to execute,

00:04:23.826 --> 00:04:26.254
this is the more PowerShell that it executed.

00:04:26.254 --> 00:04:30.040
So now not only do, within the logs, do we see the original stuff that happened,

00:04:30.040 --> 00:04:31.428
we see what else it did.

00:04:31.428 --> 00:04:32.858
It executed PowerShell again,

00:04:32.858 --> 00:04:36.072
and now here's some new stuff that it downloaded and ran.

00:04:36.072 --> 00:04:39.973
So and that binary text that came down that it downloaded wasn't detected

00:04:39.973 --> 00:04:42.574
as executable or anything malicious is now running,

00:04:42.574 --> 00:04:44.275
and this is the result.

00:04:44.276 --> 00:04:48.391
And it looks like this is some more encoded string that we could go

00:04:48.391 --> 00:04:51.609
in and try to figure out what it is and decode it.

00:04:51.609 --> 00:04:54.437
If I remember right, this is just another Base64 code of string.

00:04:54.438 --> 00:04:56.927
Would could use CyberChef to decode it and see what it is.

00:04:56.928 --> 00:05:00.781
Yeah, and I also see gzip in there and MemoryStream.

00:05:00.781 --> 00:05:03.520
So that's the part we're talking about fileless.

00:05:03.521 --> 00:05:06.978
Is that what's streaming it directly into memory using that function call?

00:05:06.978 --> 00:05:10.799
We would never find this code on disk anywhere.

00:05:10.799 --> 00:05:12.276
There's no file that contains this.

00:05:12.277 --> 00:05:13.235
It's all in-memory.

00:05:13.235 --> 00:05:14.833
This is the fileless attack.

00:05:14.834 --> 00:05:17.230
So if we didn't log it, there is no way to catch this.

00:05:17.230 --> 00:05:20.253
If we didn't log it, we would not have seen this.

00:05:20.253 --> 00:05:23.631
So this is just the Security event logs.

00:05:23.632 --> 00:05:27.593
Let's go over and let's look at the PowerShell logs.

00:05:27.593 --> 00:05:31.149
Scroll down here.

00:05:31.149 --> 00:05:32.737
Here, we have the PowerShell Operational logs,

00:05:32.737 --> 00:05:36.591
and you can see that it logged a lot.

00:05:36.592 --> 00:05:39.942
Looking through this, the PowerShell 4103 logs,

00:05:39.942 --> 00:05:45.027
these are the module logging, the modules that are being executed.

00:05:45.028 --> 00:05:48.307
The 4104 logs are the script block logs.

00:05:48.307 --> 00:05:49.774
And we can go in here,

00:05:49.774 --> 00:05:53.225
and we can just start looking through and seeing what we're finding.

00:05:53.226 --> 00:05:56.239
We're seeing bits and pieces of code.

00:05:56.239 --> 00:05:58.607
Let's see if I can go and find something interesting.

00:05:58.608 --> 00:05:59.751
Yeah, it lets you know when it pipes something,

00:05:59.751 --> 00:06:01.800
so when we're changing from one function call to another.

00:06:01.800 --> 00:06:02.396
It does.

00:06:02.396 --> 00:06:04.780
Here we have, here is the host application.

00:06:04.781 --> 00:06:07.681
We can see that this is the secondary PowerShell that was logged,

00:06:07.681 --> 00:06:11.114
and we can start scrolling through here and trying to

00:06:11.114 --> 00:06:13.127
figure out what had happened here.

00:06:13.127 --> 00:06:16.081
Deconstructing the intention there.

00:06:16.082 --> 00:06:18.654
And you can see it's not giving you a lot of information,

00:06:18.654 --> 00:06:22.784
but it's definitely more information than if you would look normally.

00:06:22.784 --> 00:06:25.690
Now this is great, but also remember, we turned on transcripts.

00:06:25.691 --> 00:06:27.936
We turned on the PowerShell transcripts,

00:06:27.937 --> 00:06:32.966
and the PowerShell transcripts, they're in the file,

00:06:32.966 --> 00:06:35.539
and they show us exactly what happened.

00:06:35.539 --> 00:06:36.572
Is that a time/date thing?

00:06:36.573 --> 00:06:37.350
Is that automatic?

00:06:37.350 --> 00:06:40.456
It's stored by time and date automatically.

00:06:40.456 --> 00:06:46.067
So what I'm going to do here is I'm going to open up this first one.

00:06:46.067 --> 00:06:50.468
Let me turn on Word wrap just so we can see everything.

00:06:50.468 --> 00:06:51.049
And here,

00:06:51.049 --> 00:06:55.528
this is almost like we were sitting behind the shoulder of the attacker.

00:06:55.528 --> 00:06:59.790
Remember that in the initial command, we had this Base64 encoded string.

00:06:59.791 --> 00:07:02.194
And then it downloads from the Pastebin.

00:07:02.195 --> 00:07:06.351
But if you look below, the transcripts decoded the Base64 string for us.

00:07:06.351 --> 00:07:09.880
So we don't even have to, if we didn't know how to do it, we wouldn't have to.

00:07:09.880 --> 00:07:12.455
The transcript shows this to us.

00:07:12.456 --> 00:07:16.446
And transcript, that's an automatic Windows feature as long as you enable it.

00:07:16.446 --> 00:07:18.668
You have to enable it, but yeah, it's built in there.

00:07:18.668 --> 00:07:20.982
So it'll automatically decode the Base64.

00:07:20.982 --> 00:07:22.216
And this is just the first command.

00:07:22.216 --> 00:07:24.592
We can jump over to the second command.

00:07:24.592 --> 00:07:30.086
Actually, Windows just got some points for that.

00:07:30.086 --> 00:07:31.694
instance of PowerShell.

00:07:31.694 --> 00:07:34.336
So if we look at this one, here we've got this huge,

00:07:34.336 --> 00:07:37.903
the new thing that was launched, and unfortunately,

00:07:37.903 --> 00:07:41.639
in this case, it didn't decode it for us.

00:07:41.639 --> 00:07:45.703
But if this has run more commands, we would see everything that had happened.

00:07:45.703 --> 00:07:50.080
And think about how powerful this would be is if you had an attacker

00:07:50.080 --> 00:07:54.166
that had launched a PowerShell command through one of the attack

00:07:54.166 --> 00:07:57.109
toolkits and was interactively using it,

00:07:57.109 --> 00:07:59.503
it would log everything here.

00:07:59.504 --> 00:08:02.550
We would see everything that the attacker did--- As they did it.

00:08:02.551 --> 00:08:03.594
---as they did it.

00:08:03.594 --> 00:08:03.854
Again,

00:08:03.854 --> 00:08:06.002
that's just like sitting over their shoulder and

00:08:06.002 --> 00:08:07.590
watching what the attacker was doing.

00:08:07.591 --> 00:08:07.963
Absolutely.

00:08:07.963 --> 00:08:11.601
And that's not only great, so I'm certain that we can alert on this,

00:08:11.601 --> 00:08:15.970
and I'm sure we'll get to that, but from a responding after the fact perspective,

00:08:15.970 --> 00:08:18.042
it's really good to be able to put that timeline back

00:08:18.042 --> 00:08:20.008
together and find out exactly what happened.

00:08:20.008 --> 00:08:24.126
This is just immensely invaluable to anybody.

00:08:24.127 --> 00:08:25.392
And this is just the PowerShell logs.

00:08:25.393 --> 00:08:28.819
Remember, we also turned on Sysmon.

00:08:28.819 --> 00:08:32.366
So let me go in here, I'm back in Event Log Explorer,

00:08:32.366 --> 00:08:42.553
I open up Sysmon, and here we can see pretty much everything that we saw before.

00:08:42.554 --> 00:08:46.251
And even better, you may have noticed that when we were looking at the 4688 logs,

00:08:46.251 --> 00:08:49.403
it doesn't tell us the parent process.

00:08:49.403 --> 00:08:51.240
I believe it gives us the parent process ID,

00:08:51.240 --> 00:08:52.966
but it doesn't tell us what that process is.

00:08:52.966 --> 00:08:55.078
So we kind of have to do some manual correlation there.

00:08:55.078 --> 00:08:58.264
Sysmon shows that for us, which is great.

00:08:58.264 --> 00:09:01.147
Here, we've got this Process Creation event.

00:09:01.148 --> 00:09:04.057
We say that when Word was logged, Word was ran.

00:09:04.058 --> 00:09:07.612
So otherwise, we would know this came from Microsoft.

00:09:07.613 --> 00:09:08.601
We wouldn't have know that it came from Word.

00:09:08.601 --> 00:09:10.113
And in fact, by looking at the command line,

00:09:10.113 --> 00:09:13.455
we see the exact document that was what was run.

00:09:13.455 --> 00:09:16.582
So as an investigator, if I didn't know where that document was,

00:09:16.582 --> 00:09:19.561
now I do, and I can try to recover it if it's still on disk.

00:09:19.562 --> 00:09:23.158
So that's really an incredible benefit of Sysmon.

00:09:23.159 --> 00:09:24.308
Because I can see where the argument would be made like oh,

00:09:24.308 --> 00:09:26.278
I already turned on all this logging for commands

00:09:26.278 --> 00:09:27.773
and security events in PowerShell.

00:09:27.773 --> 00:09:30.094
Why do I really need Sysmon?

00:09:30.095 --> 00:09:31.943
And here is a great reason why.

00:09:31.944 --> 00:09:32.451
So here,

00:09:32.451 --> 00:09:34.900
I've kind of scrolled up until we found the process

00:09:34.900 --> 00:09:38.222
creation event from Sysmon from PowerShell.

00:09:38.223 --> 00:09:41.814
Here we see the EncodedCommand.

00:09:41.815 --> 00:09:43.514
And even better, we see the parent process,

00:09:43.515 --> 00:09:46.468
and it actually shows us the parent process command line as well.

00:09:46.468 --> 00:09:50.132
So just in this, if we only had this one event,

00:09:50.132 --> 00:09:53.964
we can tell a pretty good story as to what happened.

00:09:53.964 --> 00:09:58.177
Somebody opened up a document, and that document ran PowerShell,

00:09:58.177 --> 00:10:00.127
and here is what the PowerShell was.

00:10:00.128 --> 00:10:02.020
And taking that back to our behavioral analysis we

00:10:02.020 --> 00:10:04.976
were talking about is now in one log, we can say hey,

00:10:04.977 --> 00:10:06.969
when PowerShell runs on Word, it's weird,

00:10:06.969 --> 00:10:08.036
and now alert on that.

00:10:08.036 --> 00:10:11.297
And in that one logged document, we have that event happening.

00:10:11.298 --> 00:10:12.682
That's kind of a unique thing.

00:10:12.682 --> 00:10:15.886
So if you see a PowerShell log, or a Sysmon log,

00:10:15.886 --> 00:10:19.286
that has PowerShell executing, as well as Microsoft Word executing,

00:10:19.286 --> 00:10:21.677
then that's something that you can alert on.

00:10:21.678 --> 00:10:24.385
Attackers have lots of different techniques that they can do.

00:10:24.385 --> 00:10:26.629
They can inject code into other processes.

00:10:26.630 --> 00:10:30.148
So imagine if you're looking through your logs and you see calc,

00:10:30.149 --> 00:10:33.414
the Windows Calculator, has launched PowerShell.

00:10:33.415 --> 00:10:35.251
When will calc ever launch PowerShell?

00:10:35.252 --> 00:10:36.848
But something like that.

00:10:36.848 --> 00:10:38.901
These anomalies should stand out.

00:10:38.901 --> 00:10:39.195
Yeah,

00:10:39.195 --> 00:10:41.579
that's almost anything other than Task Scheduler running

00:10:41.579 --> 00:10:43.151
PowerShell is probably pretty weird.

00:10:43.152 --> 00:10:46.014
Or even PowerShell running PowerShell.

00:10:46.014 --> 00:10:47.649
You should see PowerShell running PowerShell.

00:10:47.650 --> 00:10:48.658
That makes sense.

00:10:48.658 --> 00:10:52.141
Or if somebody is launching from the command line,

00:10:52.142 --> 00:10:54.106
you should see the parent process being cmd.

00:10:54.106 --> 00:10:56.270
exe or maybe even explorer.

00:10:56.270 --> 00:10:56.702
exe.

00:10:56.703 --> 00:10:59.097
Very rarely should you see it be Word, or Adobe,

00:10:59.097 --> 00:11:00.871
or any other program for that matter.

00:11:00.872 --> 00:11:04.637
So you could likely whitelist the things that you should see,

00:11:04.637 --> 00:11:07.071
and then just say anything other than this so then

00:11:07.071 --> 00:11:08.691
you've narrowed the case down a bit.

00:11:08.691 --> 00:11:10.191
Absolutely.

00:11:10.191 --> 00:11:11.691
Absolutely.
