WEBVTT

00:00:00.000 --> 00:00:03.493 align:middle line:90%


00:00:03.493 --> 00:00:06.986 align:middle line:90%
[MUSIC PLAYING]

00:00:06.986 --> 00:00:09.990 align:middle line:90%


00:00:09.990 --> 00:00:12.000 align:middle line:90%
Obfuscating PowerShell code.

00:00:12.000 --> 00:00:15.030 align:middle line:84%
In this video, we are going to
be exploring the process of how

00:00:15.030 --> 00:00:19.170 align:middle line:84%
to obfuscate PowerShell code
in order to essentially evade

00:00:19.170 --> 00:00:21.280 align:middle line:90%
or avoid antivirus detection.

00:00:21.280 --> 00:00:24.810 align:middle line:84%
So let's get an idea of
what obfuscation is firstly.

00:00:24.810 --> 00:00:27.090 align:middle line:84%
So obfuscation
refers to the process

00:00:27.090 --> 00:00:29.370 align:middle line:84%
of concealing something
important, valuable,

00:00:29.370 --> 00:00:30.270 align:middle line:90%
or critical.

00:00:30.270 --> 00:00:32.460 align:middle line:84%
And in the context
of exploitation,

00:00:32.460 --> 00:00:35.160 align:middle line:84%
obfuscation can be
used to reorganize code

00:00:35.160 --> 00:00:37.320 align:middle line:84%
or in this case
PowerShell code in order

00:00:37.320 --> 00:00:40.470 align:middle line:84%
to make it harder to
analyze or reverse engineer.

00:00:40.470 --> 00:00:42.960 align:middle line:84%
And in the context of
an antivirus solution,

00:00:42.960 --> 00:00:45.630 align:middle line:84%
obfuscation will make
it harder to flag

00:00:45.630 --> 00:00:49.710 align:middle line:84%
or rather harder to analyze
as and obviously categorize

00:00:49.710 --> 00:00:51.610 align:middle line:90%
as either malicious or not.

00:00:51.610 --> 00:00:53.430 align:middle line:84%
So as a penetration
tester, you'll

00:00:53.430 --> 00:00:56.430 align:middle line:84%
find yourself working with
PowerShell code frequently.

00:00:56.430 --> 00:00:58.770 align:middle line:84%
Most antivirus solutions
will immediately

00:00:58.770 --> 00:01:02.220 align:middle line:84%
flag PowerShell code that hasn't
been encoded or obfuscated

00:01:02.220 --> 00:01:03.510 align:middle line:90%
for obvious reasons.

00:01:03.510 --> 00:01:07.170 align:middle line:84%
And as a result, you must be
able to obfuscate or encode

00:01:07.170 --> 00:01:10.390 align:middle line:84%
your PowerShell code and scripts
in order to avoid detection.

00:01:10.390 --> 00:01:13.920 align:middle line:84%
So in regards to
obfuscating PowerShell code,

00:01:13.920 --> 00:01:15.480 align:middle line:84%
we are going to be
taking advantage

00:01:15.480 --> 00:01:20.610 align:middle line:84%
of a fantastic tool or utility
called Invoke-Obfuscation.

00:01:20.610 --> 00:01:23.850 align:middle line:84%
Invoke-Obfuscation is an open
source PowerShell version

00:01:23.850 --> 00:01:26.610 align:middle line:84%
2 and higher, compatible
PowerShell command

00:01:26.610 --> 00:01:28.050 align:middle line:90%
and script obfuscator.

00:01:28.050 --> 00:01:30.270 align:middle line:84%
So the way it works
is that it essentially

00:01:30.270 --> 00:01:34.830 align:middle line:84%
allows us to load up or to
load in our PowerShell script

00:01:34.830 --> 00:01:36.810 align:middle line:84%
that we want to
execute on the target.

00:01:36.810 --> 00:01:39.360 align:middle line:84%
It then provides us
with various options

00:01:39.360 --> 00:01:42.460 align:middle line:84%
that we can use to obfuscate
or encode the code.

00:01:42.460 --> 00:01:44.460 align:middle line:84%
And then generates the
output, which we can then

00:01:44.460 --> 00:01:46.440 align:middle line:84%
save into a new
PowerShell script,

00:01:46.440 --> 00:01:49.860 align:middle line:84%
and that PowerShell script is
fully obfuscated or encoded,

00:01:49.860 --> 00:01:51.930 align:middle line:84%
and we can then transfer
that to the target

00:01:51.930 --> 00:01:53.520 align:middle line:90%
system for execution.

00:01:53.520 --> 00:01:56.220 align:middle line:84%
Or alternatively, that
code can be included

00:01:56.220 --> 00:01:58.080 align:middle line:90%
as part of a larger exploit.

00:01:58.080 --> 00:02:00.990 align:middle line:84%
So the GitHub repository
for Invoke-Obfuscation

00:02:00.990 --> 00:02:04.150 align:middle line:84%
is listed or linked to
this particular slide.

00:02:04.150 --> 00:02:07.590 align:middle line:84%
Now, this video doesn't
have a lab environment

00:02:07.590 --> 00:02:09.360 align:middle line:90%
for obvious reasons.

00:02:09.360 --> 00:02:12.150 align:middle line:84%
And again, I'm just
going to be performing

00:02:12.150 --> 00:02:13.560 align:middle line:90%
this within my lab environment.

00:02:13.560 --> 00:02:15.210 align:middle line:84%
In this case, the
target system is

00:02:15.210 --> 00:02:18.570 align:middle line:84%
going to be a specific
build of Windows 10,

00:02:18.570 --> 00:02:21.100 align:middle line:84%
where I do know that
this technique does work.

00:02:21.100 --> 00:02:23.880 align:middle line:84%
The purpose of this video
is to just demonstrate

00:02:23.880 --> 00:02:26.670 align:middle line:84%
the process of obfuscating
PowerShell code,

00:02:26.670 --> 00:02:28.170 align:middle line:84%
and how it can be
done, and the fact

00:02:28.170 --> 00:02:30.900 align:middle line:84%
that it does actually
work in regards

00:02:30.900 --> 00:02:32.700 align:middle line:90%
to obtaining a reverse shell.

00:02:32.700 --> 00:02:35.340 align:middle line:84%
So I'll just switch
over to my Kali Linux VM

00:02:35.340 --> 00:02:36.615 align:middle line:90%
and we can get started.

00:02:36.615 --> 00:02:40.360 align:middle line:90%


00:02:40.360 --> 00:02:42.780 align:middle line:84%
All right, so I'm back
within my Kali Linux VM,

00:02:42.780 --> 00:02:46.650 align:middle line:84%
and I'm currently on the
Invoke-Obfuscation GitHub

00:02:46.650 --> 00:02:48.070 align:middle line:90%
repository.

00:02:48.070 --> 00:02:52.170 align:middle line:84%
And you can see that it has
a list of PowerShell scripts

00:02:52.170 --> 00:02:57.180 align:middle line:84%
here, as well as a specific
Invoke-Obfuscation PowerShell

00:02:57.180 --> 00:02:59.820 align:middle line:90%
module that we can import.

00:02:59.820 --> 00:03:02.490 align:middle line:84%
And you can go through
the GitHub repository

00:03:02.490 --> 00:03:04.500 align:middle line:90%
to learn more about it.

00:03:04.500 --> 00:03:06.120 align:middle line:84%
And you can take a
look at the purpose

00:03:06.120 --> 00:03:10.110 align:middle line:84%
here, which is very
really is fantastic

00:03:10.110 --> 00:03:12.220 align:middle line:90%
as to why this tool was created.

00:03:12.220 --> 00:03:14.800 align:middle line:84%
So it really is a very,
very powerful tool.

00:03:14.800 --> 00:03:18.510 align:middle line:84%
And again, it automates that
entire process of obfuscation.

00:03:18.510 --> 00:03:20.460 align:middle line:84%
All right, so in
regards to using it,

00:03:20.460 --> 00:03:22.950 align:middle line:84%
there are a few dependencies
that we need to install.

00:03:22.950 --> 00:03:27.210 align:middle line:84%
Now you might have noticed
that it has PowerShell scripts

00:03:27.210 --> 00:03:28.240 align:middle line:90%
and modules.

00:03:28.240 --> 00:03:32.850 align:middle line:84%
So how do we execute or load
or import a PowerShell module

00:03:32.850 --> 00:03:33.630 align:middle line:90%
on Linux?

00:03:33.630 --> 00:03:36.510 align:middle line:84%
Because we currently
don't have access

00:03:36.510 --> 00:03:38.280 align:middle line:90%
to PowerShell on a Linux system.

00:03:38.280 --> 00:03:39.750 align:middle line:90%
Well, here's the great thing.

00:03:39.750 --> 00:03:42.660 align:middle line:84%
We actually can run
PowerShell on Linux,

00:03:42.660 --> 00:03:44.790 align:middle line:84%
and that can be
done by installing

00:03:44.790 --> 00:03:47.790 align:middle line:84%
the PowerShell package, which
is part of the Kali Linux

00:03:47.790 --> 00:03:48.810 align:middle line:90%
repositories.

00:03:48.810 --> 00:03:52.680 align:middle line:84%
So that will allow us to
import the Invoke-Obfuscation

00:03:52.680 --> 00:03:54.000 align:middle line:90%
PowerShell module here.

00:03:54.000 --> 00:03:56.490 align:middle line:84%
And consequently,
allow us to load up

00:03:56.490 --> 00:04:00.540 align:middle line:84%
Invoke-Obfuscation, which we
can then use to essentially pass

00:04:00.540 --> 00:04:03.850 align:middle line:84%
in our reverse shell
code, which is,

00:04:03.850 --> 00:04:05.580 align:middle line:84%
of course, going to
be in PowerShell.

00:04:05.580 --> 00:04:08.910 align:middle line:84%
So just clone the
repository into any folder

00:04:08.910 --> 00:04:12.210 align:middle line:84%
you want on your desktop
wherever you feel

00:04:12.210 --> 00:04:13.620 align:middle line:90%
is comfortable for you.

00:04:13.620 --> 00:04:17.070 align:middle line:84%
In my case, I have cloned
it into my AVBypass folder

00:04:17.070 --> 00:04:18.959 align:middle line:84%
that I created in
the previous video.

00:04:18.959 --> 00:04:22.650 align:middle line:84%
And you can see I have it right
over here, Invoke-Obfuscation.

00:04:22.650 --> 00:04:26.370 align:middle line:84%
Now, we also need to take
a look at the reversal code

00:04:26.370 --> 00:04:27.310 align:middle line:90%
that we'll be using.

00:04:27.310 --> 00:04:31.410 align:middle line:84%
So during the bind and reversal
section of this course,

00:04:31.410 --> 00:04:33.690 align:middle line:84%
I went over the
reversal cheat sheet,

00:04:33.690 --> 00:04:38.070 align:middle line:84%
and I referenced the actual
payload all the things

00:04:38.070 --> 00:04:39.300 align:middle line:90%
GitHub repository.

00:04:39.300 --> 00:04:44.710 align:middle line:84%
And I'm currently within the
PowerShell reversal section.

00:04:44.710 --> 00:04:48.880 align:middle line:84%
So we will be utilizing
the following code here.

00:04:48.880 --> 00:04:51.900 align:middle line:84%
So this is just a basic
reversal written in PowerShell.

00:04:51.900 --> 00:04:55.860 align:middle line:84%
And the only variables
that we need to modify

00:04:55.860 --> 00:04:58.620 align:middle line:84%
is the attacker's
IP here, as well as

00:04:58.620 --> 00:05:01.800 align:middle line:84%
the port that we will be
listening on with Netcat.

00:05:01.800 --> 00:05:03.340 align:middle line:90%
So just keep that in mind.

00:05:03.340 --> 00:05:05.850 align:middle line:84%
Now, the first dependency
that we need to install

00:05:05.850 --> 00:05:07.260 align:middle line:90%
is going to be PowerShell.

00:05:07.260 --> 00:05:09.120 align:middle line:84%
So this can be
installed on Linux

00:05:09.120 --> 00:05:12.840 align:middle line:90%
by saying sudo apt-get install.

00:05:12.840 --> 00:05:15.150 align:middle line:90%
And I'll say apt-get install.

00:05:15.150 --> 00:05:17.938 align:middle line:90%
And we can say powershell.

00:05:17.938 --> 00:05:18.480 align:middle line:90%
There we are.

00:05:18.480 --> 00:05:20.530 align:middle line:90%
And I'll say yes.

00:05:20.530 --> 00:05:23.260 align:middle line:84%
And I'll just provide
my password here.

00:05:23.260 --> 00:05:24.860 align:middle line:90%
We also have the latest version.

00:05:24.860 --> 00:05:26.680 align:middle line:84%
So how do you launch
PowerShell on Linux?

00:05:26.680 --> 00:05:31.030 align:middle line:84%
Well, we just type in pwsh,
so powershell, hit Enter.

00:05:31.030 --> 00:05:35.980 align:middle line:84%
And voila, we have access to
a PowerShell session on Linux.

00:05:35.980 --> 00:05:38.500 align:middle line:84%
All right, so that
means we can essentially

00:05:38.500 --> 00:05:41.080 align:middle line:84%
execute PowerShell
scripts and import

00:05:41.080 --> 00:05:43.190 align:middle line:90%
modules that we can then use.

00:05:43.190 --> 00:05:45.940 align:middle line:84%
So I'm currently within
the AVBypass folder.

00:05:45.940 --> 00:05:49.330 align:middle line:84%
I want to navigate into the
cloned Invoke-Obfuscation

00:05:49.330 --> 00:05:50.200 align:middle line:90%
directory.

00:05:50.200 --> 00:05:52.090 align:middle line:84%
Within this
directory, you can see

00:05:52.090 --> 00:05:54.580 align:middle line:84%
that I have all the
various PowerShell scripts.

00:05:54.580 --> 00:05:57.580 align:middle line:84%
What I'm interested in is the
Invoke-Obfuscation PowerShell

00:05:57.580 --> 00:05:58.280 align:middle line:90%
module.

00:05:58.280 --> 00:06:00.640 align:middle line:84%
So we can import it
by saying import,

00:06:00.640 --> 00:06:02.150 align:middle line:84%
and this is a
PowerShell command.

00:06:02.150 --> 00:06:04.630 align:middle line:90%
So we can say import module.

00:06:04.630 --> 00:06:06.790 align:middle line:84%
And then we specify
the name of the module.

00:06:06.790 --> 00:06:11.230 align:middle line:84%
In this case, it's
Invoke-Obfuscation.psd1.

00:06:11.230 --> 00:06:12.640 align:middle line:90%
So I'll hit Enter.

00:06:12.640 --> 00:06:13.730 align:middle line:90%
That is imported.

00:06:13.730 --> 00:06:15.580 align:middle line:84%
I can then take a
step back or get out

00:06:15.580 --> 00:06:17.770 align:middle line:84%
of the Invoke-Obfuscation
directory,

00:06:17.770 --> 00:06:22.250 align:middle line:84%
and I can say
Invoke-Obfuscation.

00:06:22.250 --> 00:06:23.750 align:middle line:84%
Let me just type
that incorrectly.

00:06:23.750 --> 00:06:25.190 align:middle line:90%
So Invoke-Obfuscation.

00:06:25.190 --> 00:06:28.340 align:middle line:84%
And I just want to run the
command, not the actual--

00:06:28.340 --> 00:06:29.970 align:middle line:90%
I don't get into the directory.

00:06:29.970 --> 00:06:31.850 align:middle line:84%
So I'll just say
Invoke-Obfuscation.

00:06:31.850 --> 00:06:35.190 align:middle line:84%
And if successful, it should
bring up Invoke-Obfuscation

00:06:35.190 --> 00:06:35.690 align:middle line:90%
now.

00:06:35.690 --> 00:06:37.430 align:middle line:84%
So give that a
couple of seconds.

00:06:37.430 --> 00:06:39.890 align:middle line:90%
As you can see, it's loading up.

00:06:39.890 --> 00:06:40.805 align:middle line:90%
And there we are.

00:06:40.805 --> 00:06:42.200 align:middle line:90%
So Invoke-Obfuscation.

00:06:42.200 --> 00:06:42.800 align:middle line:90%
Welcome.

00:06:42.800 --> 00:06:47.480 align:middle line:84%
So this is a fantastic tool
for essentially obfuscating

00:06:47.480 --> 00:06:49.670 align:middle line:90%
and encoding PowerShell code.

00:06:49.670 --> 00:06:52.730 align:middle line:84%
So it gives you a
great list of commands

00:06:52.730 --> 00:06:54.480 align:middle line:90%
in regards to documentation.

00:06:54.480 --> 00:06:56.750 align:middle line:84%
So you can take a
look at the tutorial

00:06:56.750 --> 00:06:58.260 align:middle line:90%
of how to use this tool.

00:06:58.260 --> 00:07:01.010 align:middle line:84%
You can also show this Help menu
with the following commands.

00:07:01.010 --> 00:07:03.440 align:middle line:84%
You can show the options for
the payload to obfuscate,

00:07:03.440 --> 00:07:05.610 align:middle line:90%
so on, and so forth.

00:07:05.610 --> 00:07:07.760 align:middle line:84%
But what's the
most important here

00:07:07.760 --> 00:07:12.030 align:middle line:84%
is the actual obfuscation
or encoding techniques.

00:07:12.030 --> 00:07:14.210 align:middle line:90%
So the first one is token.

00:07:14.210 --> 00:07:17.360 align:middle line:84%
This allows you to obfuscate
PowerShell command tokens.

00:07:17.360 --> 00:07:20.030 align:middle line:84%
You then have AST, which is
what we are going to be using.

00:07:20.030 --> 00:07:23.150 align:middle line:84%
And this is for PowerShell
version 3 and higher.

00:07:23.150 --> 00:07:25.340 align:middle line:84%
That's because the target
is running Windows 10,

00:07:25.340 --> 00:07:29.960 align:middle line:84%
and this specific technique
works probably the best

00:07:29.960 --> 00:07:31.040 align:middle line:90%
out of all of them.

00:07:31.040 --> 00:07:33.600 align:middle line:90%
You then have your string.

00:07:33.600 --> 00:07:35.570 align:middle line:84%
You also have encoding,
compress, launcher.

00:07:35.570 --> 00:07:37.800 align:middle line:90%
So what do we do now?

00:07:37.800 --> 00:07:39.590 align:middle line:84%
Well firstly, we
actually need to create

00:07:39.590 --> 00:07:41.270 align:middle line:84%
our reverse shell
PowerShell script.

00:07:41.270 --> 00:07:44.360 align:middle line:84%
So we'll copy the code
from the GitHub repository.

00:07:44.360 --> 00:07:46.230 align:middle line:84%
This is the reverse
shell cheat sheet.

00:07:46.230 --> 00:07:48.290 align:middle line:84%
So this is the code
I'll copy there.

00:07:48.290 --> 00:07:50.570 align:middle line:84%
And I'll then open
up a text editor.

00:07:50.570 --> 00:07:53.250 align:middle line:84%
So I'll just open up
a text editor here,

00:07:53.250 --> 00:07:56.340 align:middle line:84%
and I'll paste that code in
there, and I'll just zoom in.

00:07:56.340 --> 00:08:00.310 align:middle line:84%
And what we want to do is get
rid of this particular command

00:08:00.310 --> 00:08:00.810 align:middle line:90%
here.

00:08:00.810 --> 00:08:02.720 align:middle line:90%
So powershell, nop, and c.

00:08:02.720 --> 00:08:05.030 align:middle line:90%
And also the quotation marks.

00:08:05.030 --> 00:08:07.230 align:middle line:84%
And I'll get rid of the
quotation marks at the end

00:08:07.230 --> 00:08:07.730 align:middle line:90%
here.

00:08:07.730 --> 00:08:10.100 align:middle line:90%
And I'm going to save this as--

00:08:10.100 --> 00:08:11.510 align:middle line:84%
before I actually
save it, I need

00:08:11.510 --> 00:08:15.570 align:middle line:84%
to change the attacker's
IP here to my IP.

00:08:15.570 --> 00:08:17.870 align:middle line:84%
So I'll change that
to my Kali Linux IP.

00:08:17.870 --> 00:08:21.020 align:middle line:90%
So that's 10.10.10.10.

00:08:21.020 --> 00:08:25.850 align:middle line:84%
And the port that the target
should connect to is port 1234.

00:08:25.850 --> 00:08:27.480 align:middle line:90%
And we can now save it.

00:08:27.480 --> 00:08:30.710 align:middle line:84%
So I'll save it under my
desktop under AVBypass,

00:08:30.710 --> 00:08:36.320 align:middle line:84%
and I'll give it the
name of shell.ps1, right?

00:08:36.320 --> 00:08:39.890 align:middle line:84%
Yeah, we can just call it
shell.ps1 and hit Save.

00:08:39.890 --> 00:08:41.900 align:middle line:90%
So that saved now.

00:08:41.900 --> 00:08:43.850 align:middle line:84%
So what do we do with
Invoke-Obfuscation?

00:08:43.850 --> 00:08:45.330 align:middle line:90%
How do we load that file?

00:08:45.330 --> 00:08:51.140 align:middle line:84%
Well, in order to do this,
we can say SET SCRIPTPATH.

00:08:51.140 --> 00:08:52.580 align:middle line:90%
And this has to be in uppercase.

00:08:52.580 --> 00:08:53.750 align:middle line:90%
So SCRIPTPATH.

00:08:53.750 --> 00:08:56.620 align:middle line:84%
And then we specify the path
to that PowerShell script.

00:08:56.620 --> 00:09:05.140 align:middle line:84%
So in my case, it's on the home,
Kali, Desktop, under AVBypass,

00:09:05.140 --> 00:09:08.350 align:middle line:90%
and that is shell.ps1.

00:09:08.350 --> 00:09:09.700 align:middle line:90%
So I'll hit Enter.

00:09:09.700 --> 00:09:12.460 align:middle line:84%
As you can see successfully
set the SCRIPTPATH.

00:09:12.460 --> 00:09:15.250 align:middle line:84%
It'll then tell it to choose
one of the following options.

00:09:15.250 --> 00:09:18.700 align:middle line:84%
In my case, I'm going to
be using the AST option.

00:09:18.700 --> 00:09:21.040 align:middle line:84%
You can take a look at the
various options available.

00:09:21.040 --> 00:09:24.220 align:middle line:84%
As I said, this is
quite a complex tool.

00:09:24.220 --> 00:09:27.160 align:middle line:84%
I think I can actually take
you through one example

00:09:27.160 --> 00:09:28.330 align:middle line:90%
and show you how that works.

00:09:28.330 --> 00:09:32.650 align:middle line:84%
So, for example, if I wanted
to encode my PowerShell code,

00:09:32.650 --> 00:09:34.870 align:middle line:90%
I can say encoding.

00:09:34.870 --> 00:09:37.450 align:middle line:84%
That will bring up another
menu that provides me

00:09:37.450 --> 00:09:38.860 align:middle line:90%
with various encoding options.

00:09:38.860 --> 00:09:43.420 align:middle line:84%
So I can encode my code in
ASCII, hex, octal, binary,

00:09:43.420 --> 00:09:47.440 align:middle line:84%
special characters,
whitespace, et cetera.

00:09:47.440 --> 00:09:49.960 align:middle line:84%
All right, so for
example, I can say ASCII

00:09:49.960 --> 00:09:52.590 align:middle line:84%
if I wanted to encode that
PowerShell code in ASCII.

00:09:52.590 --> 00:09:57.270 align:middle line:90%
I hit Enter, or rather option 1.

00:09:57.270 --> 00:09:57.770 align:middle line:90%
Sorry.

00:09:57.770 --> 00:09:59.360 align:middle line:84%
That is option 1
instead of ASCII.

00:09:59.360 --> 00:10:00.860 align:middle line:90%
So option 1 there.

00:10:00.860 --> 00:10:06.050 align:middle line:84%
And you can see it'll output
the actual PowerShell code that

00:10:06.050 --> 00:10:09.110 align:middle line:90%
has now been encoded in ASCII.

00:10:09.110 --> 00:10:12.110 align:middle line:84%
So I can then copy that and save
it in a new PowerShell script,

00:10:12.110 --> 00:10:15.020 align:middle line:84%
and then transfer that
over to the target.

00:10:15.020 --> 00:10:18.380 align:middle line:84%
But that's really not what
I'm interested in doing now.

00:10:18.380 --> 00:10:20.090 align:middle line:84%
So what I'm going
to do is I'm just

00:10:20.090 --> 00:10:23.070 align:middle line:84%
going to set the
script path again here.

00:10:23.070 --> 00:10:24.575 align:middle line:90%
So SET SCRIPTPATH.

00:10:24.575 --> 00:10:27.240 align:middle line:90%


00:10:27.240 --> 00:10:31.770 align:middle line:84%
And again, that is going to
be under my home directory

00:10:31.770 --> 00:10:36.937 align:middle line:84%
under Kali, Desktop,
AVBypass, and shell.ps1.

00:10:36.937 --> 00:10:40.720 align:middle line:90%


00:10:40.720 --> 00:10:44.950 align:middle line:84%
And if you ever want to open
up the documentation, just

00:10:44.950 --> 00:10:46.480 align:middle line:90%
type in help.

00:10:46.480 --> 00:10:48.490 align:middle line:84%
And so, for example,
if we wanted

00:10:48.490 --> 00:10:51.520 align:middle line:84%
to clear or reset
all obfuscation,

00:10:51.520 --> 00:10:52.780 align:middle line:90%
that's very, very important.

00:10:52.780 --> 00:10:55.750 align:middle line:84%
I can just say reset if I
wanted to take a step back.

00:10:55.750 --> 00:10:56.980 align:middle line:90%
There we are.

00:10:56.980 --> 00:11:00.880 align:middle line:84%
And again, it's going to tell us
no obfuscation has been applied

00:11:00.880 --> 00:11:02.270 align:middle line:90%
to the obfuscated command.

00:11:02.270 --> 00:11:08.090 align:middle line:84%
So we can also go back using
this particular command here.

00:11:08.090 --> 00:11:10.930 align:middle line:90%
So I'll just say back.

00:11:10.930 --> 00:11:15.010 align:middle line:84%
And we can now obfuscate or
set the actual script path,

00:11:15.010 --> 00:11:16.000 align:middle line:90%
but that's already set.

00:11:16.000 --> 00:11:19.360 align:middle line:84%
So I want to obfuscate
PowerShell AST nodes.

00:11:19.360 --> 00:11:21.460 align:middle line:90%
So I'll AST.

00:11:21.460 --> 00:11:24.320 align:middle line:84%
And I want to use
the all options.

00:11:24.320 --> 00:11:26.380 align:middle line:84%
So this will select all
the choices from above.

00:11:26.380 --> 00:11:30.010 align:middle line:84%
So it's going to obfuscate all
of the various PowerShell AST

00:11:30.010 --> 00:11:30.640 align:middle line:90%
nodes.

00:11:30.640 --> 00:11:32.530 align:middle line:84%
So you can see,
for example, it's

00:11:32.530 --> 00:11:35.410 align:middle line:84%
going to obfuscate the
parameter block AST nodes,

00:11:35.410 --> 00:11:39.250 align:middle line:84%
the script block AST nodes,
attribute AST nodes, et cetera.

00:11:39.250 --> 00:11:41.310 align:middle line:90%
So I'll say all.

00:11:41.310 --> 00:11:44.340 align:middle line:84%
And then I'm going to say one
to execute all obfuscation

00:11:44.340 --> 00:11:46.230 align:middle line:90%
techniques, hit Enter.

00:11:46.230 --> 00:11:48.520 align:middle line:84%
And this is my new
obfuscated code.

00:11:48.520 --> 00:11:50.790 align:middle line:84%
So you'll actually
see the difference

00:11:50.790 --> 00:11:52.770 align:middle line:84%
once I compare
them side by side.

00:11:52.770 --> 00:11:54.060 align:middle line:90%
So I'll copy that there.

00:11:54.060 --> 00:11:55.920 align:middle line:84%
And I'll go back
into my text editor

00:11:55.920 --> 00:11:57.690 align:middle line:90%
and I'll create a new file.

00:11:57.690 --> 00:11:58.260 align:middle line:90%
There we are.

00:11:58.260 --> 00:11:59.980 align:middle line:84%
And I'll just paste
that in there.

00:11:59.980 --> 00:12:02.880 align:middle line:90%
And I'll save this as--

00:12:02.880 --> 00:12:05.190 align:middle line:84%
we can just call
this obfuscated.ps1.

00:12:05.190 --> 00:12:08.460 align:middle line:90%


00:12:08.460 --> 00:12:09.863 align:middle line:84%
So this is the
obfuscated script.

00:12:09.863 --> 00:12:11.530 align:middle line:84%
And you can actually
see the difference.

00:12:11.530 --> 00:12:13.470 align:middle line:84%
So this is the
original code here,

00:12:13.470 --> 00:12:15.810 align:middle line:90%
and this is the new code here.

00:12:15.810 --> 00:12:18.600 align:middle line:84%
And what it's done is it's
obfuscated all the PowerShell

00:12:18.600 --> 00:12:19.780 align:middle line:90%
AST nodes.

00:12:19.780 --> 00:12:22.170 align:middle line:84%
So now that we've
been able to create

00:12:22.170 --> 00:12:24.660 align:middle line:84%
a new obfuscated
PowerShell script,

00:12:24.660 --> 00:12:30.180 align:middle line:84%
we can actually transfer this
over to the target system,

00:12:30.180 --> 00:12:32.760 align:middle line:84%
and let's see whether
we're able to execute it

00:12:32.760 --> 00:12:33.850 align:middle line:90%
without any issues.

00:12:33.850 --> 00:12:37.990 align:middle line:84%
So I'm just going to
split my terminal here.

00:12:37.990 --> 00:12:40.350 align:middle line:84%
So I'm going to
split it vertically.

00:12:40.350 --> 00:12:43.140 align:middle line:84%
We are actually done
with Invoke-Obfuscation.

00:12:43.140 --> 00:12:46.600 align:middle line:84%
So I'll just exit from
PowerShell as well.

00:12:46.600 --> 00:12:48.970 align:middle line:84%
Let me just reduce
the font size there.

00:12:48.970 --> 00:12:51.390 align:middle line:84%
So what we need to
do now is we actually

00:12:51.390 --> 00:12:54.570 align:middle line:84%
need to host a web
server, so that we

00:12:54.570 --> 00:12:56.730 align:middle line:84%
can download the
obfuscated PowerShell

00:12:56.730 --> 00:12:58.950 align:middle line:90%
script onto the Windows target.

00:12:58.950 --> 00:13:02.445 align:middle line:84%
We then need to set
up a Netcat list now

00:13:02.445 --> 00:13:05.770 align:middle line:84%
that will essentially listen for
any connection from the target.

00:13:05.770 --> 00:13:07.920 align:middle line:84%
And that will tell us
whether this was successful.

00:13:07.920 --> 00:13:12.420 align:middle line:90%
So netcat -nvlp 1234.

00:13:12.420 --> 00:13:14.780 align:middle line:90%
And I'll hit Enter.

00:13:14.780 --> 00:13:15.740 align:middle line:90%
I'm then going to--

00:13:15.740 --> 00:13:17.450 align:middle line:84%
I'm currently
within-- there we are.

00:13:17.450 --> 00:13:19.450 align:middle line:84%
So if I list all the
contents of this directory,

00:13:19.450 --> 00:13:20.810 align:middle line:90%
we have obfuscated.ps1.

00:13:20.810 --> 00:13:26.450 align:middle line:84%
So I'll say sudo python
3 and http.server.

00:13:26.450 --> 00:13:29.490 align:middle line:90%
And I'll host this on port 80.

00:13:29.490 --> 00:13:31.540 align:middle line:90%
I'll provide my password.

00:13:31.540 --> 00:13:35.040 align:middle line:90%
And that is Python 3 module.

00:13:35.040 --> 00:13:36.730 align:middle line:90%
So there we are.

00:13:36.730 --> 00:13:38.680 align:middle line:84%
That's going to start
up the web server.

00:13:38.680 --> 00:13:41.100 align:middle line:84%
So I'll just switch over
to my Windows 10 VM,

00:13:41.100 --> 00:13:44.820 align:middle line:84%
and we can take a look at
whether or not this works.

00:13:44.820 --> 00:13:47.640 align:middle line:84%
All right, so I'm back
on the Windows 10 VM.

00:13:47.640 --> 00:13:50.040 align:middle line:84%
And as you can see,
real-time protection

00:13:50.040 --> 00:13:53.130 align:middle line:90%
is enabled for Windows Defender.

00:13:53.130 --> 00:13:55.230 align:middle line:84%
The only options
I've disabled are

00:13:55.230 --> 00:13:59.580 align:middle line:84%
cloud delivered protection and
automatic sample submission.

00:13:59.580 --> 00:14:02.070 align:middle line:84%
The reason I've disabled
automatic sample submission

00:14:02.070 --> 00:14:04.110 align:middle line:84%
is in the event
that I'm actually

00:14:04.110 --> 00:14:06.120 align:middle line:84%
testing some
obfuscation techniques,

00:14:06.120 --> 00:14:10.740 align:middle line:84%
I don't want Microsoft
to send the actual virus

00:14:10.740 --> 00:14:13.320 align:middle line:84%
samples or the
actual code sample,

00:14:13.320 --> 00:14:15.870 align:middle line:84%
as they will create a
signature for it immediately

00:14:15.870 --> 00:14:17.920 align:middle line:84%
or whenever they
get time to do that.

00:14:17.920 --> 00:14:21.400 align:middle line:84%
So again, I've left
real-time protection on.

00:14:21.400 --> 00:14:23.200 align:middle line:84%
So I just wanted
to highlight that.

00:14:23.200 --> 00:14:27.020 align:middle line:84%
So again, this doesn't mean that
it's essentially been disabled.

00:14:27.020 --> 00:14:30.360 align:middle line:84%
So if I'm going to-- you can
see virus and threat protection

00:14:30.360 --> 00:14:31.830 align:middle line:90%
settings, it's saying turn on.

00:14:31.830 --> 00:14:33.210 align:middle line:90%
That's just how Windows is.

00:14:33.210 --> 00:14:36.760 align:middle line:84%
It wants me to essentially
enable these two options here.

00:14:36.760 --> 00:14:39.040 align:middle line:84%
But real time
protection is still on.

00:14:39.040 --> 00:14:42.450 align:middle line:84%
So I just wanted to verify
that first to actually confirm

00:14:42.450 --> 00:14:44.440 align:middle line:90%
that is the case.

00:14:44.440 --> 00:14:45.990 align:middle line:84%
So I'll open up
the browser here,

00:14:45.990 --> 00:14:49.020 align:middle line:84%
and I'll navigate to the IP
address of my Kali Linux VM.

00:14:49.020 --> 00:14:50.650 align:middle line:90%
So 10.10.10.10.

00:14:50.650 --> 00:14:51.750 align:middle line:90%
Hit Enter.

00:14:51.750 --> 00:14:55.110 align:middle line:84%
And I can click
on obfuscated.ps1.

00:14:55.110 --> 00:14:57.070 align:middle line:84%
That's the obfuscated
PowerShell script.

00:14:57.070 --> 00:15:01.260 align:middle line:84%
So I'll click on it
here and I'll say Save.

00:15:01.260 --> 00:15:03.270 align:middle line:84%
As you can see, it
ran a security scan,

00:15:03.270 --> 00:15:06.130 align:middle line:84%
and it actually finished
downloading without any issues.

00:15:06.130 --> 00:15:07.960 align:middle line:84%
So it's within my
Downloads directory.

00:15:07.960 --> 00:15:09.540 align:middle line:84%
So again, if I
wanted to run this,

00:15:09.540 --> 00:15:11.490 align:middle line:84%
I can just say run
with PowerShell.

00:15:11.490 --> 00:15:16.170 align:middle line:84%
And if it works successfully,
the actual PowerShell code

00:15:16.170 --> 00:15:19.830 align:middle line:84%
that we used should actually
leave the PowerShell window

00:15:19.830 --> 00:15:23.670 align:middle line:84%
or terminal open or running
as long as the execution was

00:15:23.670 --> 00:15:24.610 align:middle line:90%
successful.

00:15:24.610 --> 00:15:29.765 align:middle line:90%
So I'll say run and open.

00:15:29.765 --> 00:15:32.390 align:middle line:84%
All right, so it looks like it's
working because the PowerShell

00:15:32.390 --> 00:15:33.510 align:middle line:90%
window is not closed.

00:15:33.510 --> 00:15:36.320 align:middle line:84%
If it was detected, I
would get a notification

00:15:36.320 --> 00:15:38.990 align:middle line:84%
from Windows Defender,
and the PowerShell session

00:15:38.990 --> 00:15:40.320 align:middle line:90%
would be terminated.

00:15:40.320 --> 00:15:42.380 align:middle line:84%
So let's see if I've
obtained a reverse shell.

00:15:42.380 --> 00:15:45.988 align:middle line:84%
I'll just switch over
to my Kali Linux VM.

00:15:45.988 --> 00:15:47.280 align:middle line:90%
All right, so I'm back on Kali.

00:15:47.280 --> 00:15:50.500 align:middle line:84%
And as you can see with Netcat,
I've received the connection.

00:15:50.500 --> 00:15:53.580 align:middle line:84%
And if I hit Enter, I should
get a PowerShell session.

00:15:53.580 --> 00:15:56.580 align:middle line:84%
So this is a remote or a
PowerShell reverse shell.

00:15:56.580 --> 00:15:59.310 align:middle line:84%
So again, I can pretty much
run whatever commands I want.

00:15:59.310 --> 00:16:02.040 align:middle line:84%
And I've essentially gained
access to the target system

00:16:02.040 --> 00:16:02.910 align:middle line:90%
really simply.

00:16:02.910 --> 00:16:07.650 align:middle line:84%
So who am I. You can see
msedgewin10, i.e. user.

00:16:07.650 --> 00:16:10.620 align:middle line:84%
And I can enumerate
this system info here.

00:16:10.620 --> 00:16:12.270 align:middle line:90%
So system info.

00:16:12.270 --> 00:16:15.720 align:middle line:84%
And that will just display or
tell me what version of Windows

00:16:15.720 --> 00:16:16.980 align:middle line:90%
exactly is running.

00:16:16.980 --> 00:16:21.720 align:middle line:84%
So Windows 10 Enterprise
Valuation Build 17763.

00:16:21.720 --> 00:16:24.540 align:middle line:84%
So this technique works on
this version, as well as

00:16:24.540 --> 00:16:26.580 align:middle line:90%
a couple of newer versions.

00:16:26.580 --> 00:16:29.310 align:middle line:84%
However, you may want to
use Invoke-Obfuscation

00:16:29.310 --> 00:16:31.470 align:middle line:84%
to take a look at
the other techniques

00:16:31.470 --> 00:16:34.620 align:middle line:84%
that you can use in regards
to encoding and obfuscation

00:16:34.620 --> 00:16:37.060 align:middle line:90%
of your PowerShell code.

00:16:37.060 --> 00:16:40.080 align:middle line:84%
So that is going to conclude
the practical demonstration

00:16:40.080 --> 00:16:42.260 align:middle line:90%
side of this video.