WEBVTT

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


00:00:10.170 --> 00:00:14.250 align:middle line:84%
"Exploiting a vulnerable
Apache Tomcat Web Server."

00:00:14.250 --> 00:00:16.890 align:middle line:84%
In this video, we are going
to be taking a look at how

00:00:16.890 --> 00:00:19.740 align:middle line:84%
to utilize the
Metasploit framework,

00:00:19.740 --> 00:00:22.080 align:middle line:84%
more specifically the
Metasploit framework

00:00:22.080 --> 00:00:26.220 align:middle line:84%
exploit modules, to exploit a
vulnerable Apache Tomcat web

00:00:26.220 --> 00:00:26.950 align:middle line:90%
server.

00:00:26.950 --> 00:00:30.480 align:middle line:84%
So first and foremost,
what is Apache Tomcat?

00:00:30.480 --> 00:00:33.480 align:middle line:84%
Apache Tomcat, also
known as Tomcat Server,

00:00:33.480 --> 00:00:37.140 align:middle line:84%
is a popular, free, and
open-source Java servlet web

00:00:37.140 --> 00:00:37.980 align:middle line:90%
server.

00:00:37.980 --> 00:00:41.730 align:middle line:84%
It's typically used to build and
host dynamic websites and web

00:00:41.730 --> 00:00:45.180 align:middle line:84%
applications based on the
Java Software Platform.

00:00:45.180 --> 00:00:47.400 align:middle line:84%
Now, the Apache
Tomcat web server

00:00:47.400 --> 00:00:50.370 align:middle line:84%
utilizes the HTTP
protocol to facilitate

00:00:50.370 --> 00:00:53.100 align:middle line:84%
the underlying communication
between the server

00:00:53.100 --> 00:00:53.830 align:middle line:90%
and the client.

00:00:53.830 --> 00:00:56.370 align:middle line:84%
So it operates like
a typical web server

00:00:56.370 --> 00:00:59.040 align:middle line:90%
and utilizes the HTTP protocol.

00:00:59.040 --> 00:01:01.710 align:middle line:84%
Now, Apache Tomcat
utilizes or runs

00:01:01.710 --> 00:01:04.500 align:middle line:84%
on TCP port 8080 by
default. So that's

00:01:04.500 --> 00:01:06.870 align:middle line:84%
one of the key
distinguishing factors

00:01:06.870 --> 00:01:11.280 align:middle line:84%
or elements between a normal
web server like Apache or Nginx,

00:01:11.280 --> 00:01:14.880 align:middle line:84%
that will typically run on port
80, and if-- or in the case

00:01:14.880 --> 00:01:17.130 align:middle line:84%
of an SSL certificate
being installed,

00:01:17.130 --> 00:01:19.230 align:middle line:90%
will run on port 443.

00:01:19.230 --> 00:01:23.910 align:middle line:84%
But with Apache Tomcat, Apache
Tomcat runs on port 8080.

00:01:23.910 --> 00:01:26.010 align:middle line:84%
So you might be a little
bit confused here,

00:01:26.010 --> 00:01:29.562 align:middle line:84%
because you're hearing about
a web server called Apache,

00:01:29.562 --> 00:01:31.770 align:middle line:84%
all right, and then you're
hearing about a web server

00:01:31.770 --> 00:01:33.180 align:middle line:90%
called Apache Tomcat.

00:01:33.180 --> 00:01:35.230 align:middle line:90%
So what's the difference here?

00:01:35.230 --> 00:01:38.340 align:middle line:84%
Well, the standard
Apache HTTP web server

00:01:38.340 --> 00:01:41.490 align:middle line:84%
is used to host static and
dynamic websites or web

00:01:41.490 --> 00:01:44.190 align:middle line:84%
applications, typically
developed in PHP.

00:01:44.190 --> 00:01:46.650 align:middle line:84%
And as I said previously,
the default port

00:01:46.650 --> 00:01:49.410 align:middle line:84%
for a standard Apache
HTTP web server

00:01:49.410 --> 00:01:52.680 align:middle line:84%
is going to be either
port 80 or port 443.

00:01:52.680 --> 00:01:54.780 align:middle line:84%
Now, in the case
of Apache Tomcat,

00:01:54.780 --> 00:01:57.300 align:middle line:84%
the Apache Tomcat web
server is primarily

00:01:57.300 --> 00:01:59.880 align:middle line:84%
used to host dynamic
websites or web

00:01:59.880 --> 00:02:01.560 align:middle line:90%
applications developed in Java.

00:02:01.560 --> 00:02:03.840 align:middle line:84%
So that's the key
difference here, all right?

00:02:03.840 --> 00:02:07.890 align:middle line:84%
So the Apache Tomcat
web server is primarily

00:02:07.890 --> 00:02:10.949 align:middle line:84%
utilized to host web
applications or applications,

00:02:10.949 --> 00:02:13.710 align:middle line:84%
for that matter, that have
been developed in the Java

00:02:13.710 --> 00:02:17.010 align:middle line:84%
programming language, whereas
the standard Apache HTTP web

00:02:17.010 --> 00:02:21.310 align:middle line:84%
server is used to host either
HTML or PHP web application.

00:02:21.310 --> 00:02:23.290 align:middle line:84%
So that's the key
difference here.

00:02:23.290 --> 00:02:26.730 align:middle line:84%
Now, given that it hosts
Java applications as well

00:02:26.730 --> 00:02:30.750 align:middle line:84%
as dynamic websites
built with Java,

00:02:30.750 --> 00:02:34.020 align:middle line:84%
that opens it up to multiple
types of vulnerabilities.

00:02:34.020 --> 00:02:38.070 align:middle line:84%
And in the case of Apache
Tomcat version 8.5.19,

00:02:38.070 --> 00:02:42.780 align:middle line:84%
or any version below version 9,
is vulnerable to a remote code

00:02:42.780 --> 00:02:45.060 align:middle line:84%
execution vulnerability
that could potentially

00:02:45.060 --> 00:02:47.610 align:middle line:84%
allow an attacker to
upload and execute

00:02:47.610 --> 00:02:51.840 align:middle line:84%
a JSP upload, which is
essentially a Java Service

00:02:51.840 --> 00:02:52.380 align:middle line:90%
Page--

00:02:52.380 --> 00:02:54.420 align:middle line:90%
that's what JSP stands for.

00:02:54.420 --> 00:02:57.180 align:middle line:84%
So an attacker could
essentially upload and execute

00:02:57.180 --> 00:03:00.780 align:middle line:84%
a JSP payload in order to gain
remote access to the target

00:03:00.780 --> 00:03:01.480 align:middle line:90%
server.

00:03:01.480 --> 00:03:05.010 align:middle line:84%
So we can utilize a pre-built
Metasploit framework exploit

00:03:05.010 --> 00:03:06.960 align:middle line:84%
module to exploit
this vulnerability

00:03:06.960 --> 00:03:10.320 align:middle line:84%
and consequently gain
access to the target server.

00:03:10.320 --> 00:03:12.725 align:middle line:84%
Now, in the case of this
particular practical

00:03:12.725 --> 00:03:14.100 align:middle line:84%
demonstration, we
are going to be

00:03:14.100 --> 00:03:15.730 align:middle line:90%
utilizing the lab environment.

00:03:15.730 --> 00:03:17.730 align:middle line:84%
So you can start
it up, and we can

00:03:17.730 --> 00:03:20.130 align:middle line:84%
begin with the
practical demonstration.

00:03:20.130 --> 00:03:24.360 align:middle line:84%
And you're going to see
how Apache Tomcat differs

00:03:24.360 --> 00:03:26.640 align:middle line:84%
from a standard
Apache web server

00:03:26.640 --> 00:03:29.680 align:middle line:84%
and how we can essentially
exploit an Apache Tomcat web

00:03:29.680 --> 00:03:30.180 align:middle line:90%
server.

00:03:30.180 --> 00:03:35.390 align:middle line:84%
So I'll see you in
the lab environment.

00:03:35.390 --> 00:03:35.890 align:middle line:90%
All right.

00:03:35.890 --> 00:03:38.230 align:middle line:84%
So I'm back within
the lab environment.

00:03:38.230 --> 00:03:40.120 align:middle line:84%
And as you can
see, it provides us

00:03:40.120 --> 00:03:42.580 align:middle line:84%
with the target IP address,
which is very handy.

00:03:42.580 --> 00:03:45.610 align:middle line:84%
And of course, in your case
it's going to be different.

00:03:45.610 --> 00:03:47.290 align:middle line:84%
But all you need to
do is just copy it,

00:03:47.290 --> 00:03:49.480 align:middle line:84%
because we'll need
it in a few seconds.

00:03:49.480 --> 00:03:52.300 align:middle line:84%
The next thing I'm going to
do is open up a terminal here.

00:03:52.300 --> 00:03:55.610 align:middle line:84%
And I'm just going to maximize
it and increase the font size

00:03:55.610 --> 00:03:57.830 align:middle line:84%
so you can actually
see what's going on.

00:03:57.830 --> 00:04:00.430 align:middle line:84%
We now need to start up
the PostgreSQL database

00:04:00.430 --> 00:04:02.290 align:middle line:84%
service, which can
be done by typing

00:04:02.290 --> 00:04:04.540 align:middle line:90%
in service postgresql start.

00:04:04.540 --> 00:04:06.160 align:middle line:84%
That's going to
ensure that we can

00:04:06.160 --> 00:04:08.380 align:middle line:84%
interact with the Metasploit
framework database

00:04:08.380 --> 00:04:11.230 align:middle line:84%
and consequently create
workspaces and store

00:04:11.230 --> 00:04:13.150 align:middle line:90%
data within those workspaces.

00:04:13.150 --> 00:04:17.339 align:middle line:84%
We can then launch the
Metasploit Framework Console.

00:04:17.339 --> 00:04:18.759 align:middle line:84%
So we'll give that
a few seconds.

00:04:18.759 --> 00:04:23.750 align:middle line:90%


00:04:23.750 --> 00:04:27.590 align:middle line:84%
We are then going to create a
workspace, as we usually do.

00:04:27.590 --> 00:04:29.120 align:middle line:90%
And we're going to call it--

00:04:29.120 --> 00:04:31.330 align:middle line:84%
we are just going to call
it Tomcat, because we're

00:04:31.330 --> 00:04:32.800 align:middle line:90%
exploiting Tomcat.

00:04:32.800 --> 00:04:34.120 align:middle line:90%
So I'm going to hit Enter.

00:04:34.120 --> 00:04:38.260 align:middle line:84%
We now can set our global
variable for the RHOSTS value.

00:04:38.260 --> 00:04:40.480 align:middle line:84%
And we're going to
specify the target IP.

00:04:40.480 --> 00:04:42.460 align:middle line:84%
This will, again,
save us time whenever

00:04:42.460 --> 00:04:45.130 align:middle line:84%
we're loading any
modules, as the RHOSTS

00:04:45.130 --> 00:04:48.530 align:middle line:84%
value will be set globally
for any modules that we load.

00:04:48.530 --> 00:04:49.900 align:middle line:90%
So I'm going to hit Enter.

00:04:49.900 --> 00:04:51.670 align:middle line:84%
If we check our
workspaces, you can

00:04:51.670 --> 00:04:55.270 align:middle line:84%
see we are currently utilizing
the Tomcat workspace.

00:04:55.270 --> 00:04:56.920 align:middle line:84%
So the first step
will essentially

00:04:56.920 --> 00:04:58.930 align:middle line:84%
involve port scanning
and enumeration,

00:04:58.930 --> 00:05:02.050 align:middle line:84%
because we need to identify
whether Apache Tomcat is,

00:05:02.050 --> 00:05:04.210 align:middle line:84%
indeed, running on
the target system.

00:05:04.210 --> 00:05:07.600 align:middle line:84%
That can be done through the use
of the db_nmap command, which

00:05:07.600 --> 00:05:10.660 align:middle line:84%
will perform an Nmap scan
within the Metasploit framework

00:05:10.660 --> 00:05:13.060 align:middle line:84%
console, and consequently
store the Nmap

00:05:13.060 --> 00:05:15.940 align:middle line:84%
results into the Metasploit
framework database

00:05:15.940 --> 00:05:17.900 align:middle line:90%
within our current workspace.

00:05:17.900 --> 00:05:19.570 align:middle line:84%
So I'm going to
perform a SYN scan.

00:05:19.570 --> 00:05:21.280 align:middle line:84%
We also perform
some-- we also want

00:05:21.280 --> 00:05:23.950 align:middle line:84%
to perform some service
detection as well as

00:05:23.950 --> 00:05:25.720 align:middle line:90%
the operating system detection.

00:05:25.720 --> 00:05:28.750 align:middle line:84%
We can then paste in the
target IP and hit Enter.

00:05:28.750 --> 00:05:31.460 align:middle line:84%
And that's going to take a
few seconds to a few minutes.

00:05:31.460 --> 00:05:34.910 align:middle line:84%
So I'm just going to wait
for this to complete.

00:05:34.910 --> 00:05:35.410 align:middle line:90%
All right.

00:05:35.410 --> 00:05:36.880 align:middle line:90%
The Nmap scan is complete.

00:05:36.880 --> 00:05:39.850 align:middle line:84%
And as we can see from
the actual results

00:05:39.850 --> 00:05:43.240 align:middle line:84%
here, that the target system
is running Windows, and more

00:05:43.240 --> 00:05:46.540 align:middle line:84%
specifically either
Windows Server 2008

00:05:46.540 --> 00:05:48.940 align:middle line:90%
R2 or Windows Server 2012.

00:05:48.940 --> 00:05:51.550 align:middle line:84%
And on port 8080,
we can also see

00:05:51.550 --> 00:05:55.750 align:middle line:84%
that we have Apache Tomcat
version 8.5.19, which,

00:05:55.750 --> 00:05:59.140 align:middle line:84%
as we know, is vulnerable
to a remote code execution

00:05:59.140 --> 00:06:00.230 align:middle line:90%
vulnerability.

00:06:00.230 --> 00:06:01.810 align:middle line:84%
So now that we've
identified that,

00:06:01.810 --> 00:06:03.490 align:middle line:90%
we can clear out terminal.

00:06:03.490 --> 00:06:06.130 align:middle line:84%
And of course, you can
always access these services

00:06:06.130 --> 00:06:08.320 align:middle line:84%
on the target
system that we just

00:06:08.320 --> 00:06:12.320 align:middle line:84%
performed an Nmap scan on by
typing in the services command.

00:06:12.320 --> 00:06:14.780 align:middle line:84%
And as you can see, we get
that information there.

00:06:14.780 --> 00:06:16.330 align:middle line:84%
So what we're going
to do is search

00:06:16.330 --> 00:06:18.310 align:middle line:84%
for the actual
exploit module that we

00:06:18.310 --> 00:06:21.730 align:middle line:84%
can use to exploit this specific
version of Apache Tomcat, which

00:06:21.730 --> 00:06:23.770 align:middle line:84%
can be done by saying
search, and we're

00:06:23.770 --> 00:06:25.910 align:middle line:90%
looking for an exploit module.

00:06:25.910 --> 00:06:28.540 align:middle line:84%
We can then specify
the actual name

00:06:28.540 --> 00:06:30.170 align:middle line:84%
of the module,
which in this case,

00:06:30.170 --> 00:06:31.420 align:middle line:90%
we know is going to be Tomcat.

00:06:31.420 --> 00:06:35.890 align:middle line:84%
And then we can specify the
actual module name here.

00:06:35.890 --> 00:06:38.600 align:middle line:84%
And this is the exploit module,
we are going to be utilizing.

00:06:38.600 --> 00:06:42.250 align:middle line:84%
So this is a Tomcat remote
code execution exploit

00:06:42.250 --> 00:06:44.950 align:middle line:90%
via the JSP upload bypass.

00:06:44.950 --> 00:06:47.950 align:middle line:84%
And we can copy this
module here, or rather,

00:06:47.950 --> 00:06:51.200 align:middle line:84%
the module name, and specify
that we want to use it.

00:06:51.200 --> 00:06:52.420 align:middle line:90%
So that's currently loaded.

00:06:52.420 --> 00:06:54.160 align:middle line:84%
We can then clear
out the terminal

00:06:54.160 --> 00:06:58.420 align:middle line:84%
and show the options for
this particular module.

00:06:58.420 --> 00:07:02.200 align:middle line:84%
And as you can see, we need
to specify the target IP

00:07:02.200 --> 00:07:03.580 align:middle line:84%
address, which is
done because we

00:07:03.580 --> 00:07:06.460 align:middle line:84%
set the global variable
for the RHOSTS option,

00:07:06.460 --> 00:07:09.020 align:middle line:90%
and we specified the target IP.

00:07:09.020 --> 00:07:11.000 align:middle line:84%
The RPORT option
is set correctly.

00:07:11.000 --> 00:07:13.000 align:middle line:84%
And if we open up
our browser, we

00:07:13.000 --> 00:07:15.560 align:middle line:84%
can actually confirm that
we have Tomcat running.

00:07:15.560 --> 00:07:18.940 align:middle line:84%
So if we paste in the actual
target IP, which in this case

00:07:18.940 --> 00:07:22.827 align:middle line:90%
is 10.2.20.126--

00:07:22.827 --> 00:07:25.160 align:middle line:84%
and of course, in your case
it's going to be different--

00:07:25.160 --> 00:07:27.760 align:middle line:84%
and we of course, try
and access port 8080,

00:07:27.760 --> 00:07:30.190 align:middle line:84%
we should see that we
have Apache Tomcat running

00:07:30.190 --> 00:07:31.360 align:middle line:90%
on that port.

00:07:31.360 --> 00:07:33.070 align:middle line:90%
And so that's confirmed.

00:07:33.070 --> 00:07:36.300 align:middle line:84%
And the target URI is at the
root of this particular web

00:07:36.300 --> 00:07:36.800 align:middle line:90%
server.

00:07:36.800 --> 00:07:41.380 align:middle line:84%
So we don't need to specify any
other directory where Tomcat

00:07:41.380 --> 00:07:45.290 align:middle line:84%
is installed, as it's installed
on the root of the web server.

00:07:45.290 --> 00:07:47.980 align:middle line:84%
Now, you can see another
piece of information

00:07:47.980 --> 00:07:49.270 align:middle line:90%
is not provided here.

00:07:49.270 --> 00:07:51.160 align:middle line:84%
And that is the
payload that we can

00:07:51.160 --> 00:07:55.880 align:middle line:84%
utilize to obtain a reverse
shell or a Meterpreter session.

00:07:55.880 --> 00:07:56.380 align:middle line:90%
All right.

00:07:56.380 --> 00:07:58.060 align:middle line:84%
So if we click on
the info command,

00:07:58.060 --> 00:08:00.760 align:middle line:84%
that'll give us an idea
of this particular exploit

00:08:00.760 --> 00:08:01.910 align:middle line:90%
and what it does.

00:08:01.910 --> 00:08:03.970 align:middle line:84%
So it says that this
exploit module uploads

00:08:03.970 --> 00:08:06.290 align:middle line:90%
a JSP payload and executes it.

00:08:06.290 --> 00:08:08.690 align:middle line:84%
So what this means
is that, again,

00:08:08.690 --> 00:08:13.100 align:middle line:84%
it will upload a JSP file,
which, again, is, as I said,

00:08:13.100 --> 00:08:17.470 align:middle line:84%
is a Java Service Page payload,
which means we cannot utilize

00:08:17.470 --> 00:08:19.540 align:middle line:84%
a Meterpreter payload
out of the box,

00:08:19.540 --> 00:08:24.100 align:middle line:84%
and we instead have to utilize
a Java JSP shell payload,

00:08:24.100 --> 00:08:25.570 align:middle line:90%
which we can specify.

00:08:25.570 --> 00:08:27.880 align:middle line:84%
As for the targets that
we can run this on,

00:08:27.880 --> 00:08:30.190 align:middle line:90%
we can run this on a Windows--

00:08:30.190 --> 00:08:32.289 align:middle line:84%
we can run this on a
Windows target, which

00:08:32.289 --> 00:08:35.919 align:middle line:84%
we know is the case, or a
Linux target in the event

00:08:35.919 --> 00:08:37.780 align:middle line:90%
that Apache is running on both--

00:08:37.780 --> 00:08:39.580 align:middle line:90%
on either Windows or Linux.

00:08:39.580 --> 00:08:42.070 align:middle line:84%
In our case, we'll
leave it as automatic.

00:08:42.070 --> 00:08:47.130 align:middle line:84%
And we can specify the
payload by saying set payload.

00:08:47.130 --> 00:08:49.860 align:middle line:84%
We can then specify
this is a Java payload.

00:08:49.860 --> 00:08:54.270 align:middle line:84%
And then the name of the
payload is jsp and shell--

00:08:54.270 --> 00:08:56.190 align:middle line:90%
so this is a nonstaged payload--

00:08:56.190 --> 00:08:58.180 align:middle line:90%
bind TCP.

00:08:58.180 --> 00:08:58.680 align:middle line:90%
All right.

00:08:58.680 --> 00:09:00.210 align:middle line:84%
And we're going to
be taking a look

00:09:00.210 --> 00:09:02.790 align:middle line:84%
at how to get a Meterpreter
session once we've

00:09:02.790 --> 00:09:03.640 align:middle line:90%
gained access.

00:09:03.640 --> 00:09:04.740 align:middle line:90%
So I'm going to hit Enter.

00:09:04.740 --> 00:09:07.470 align:middle line:84%
If we show the
options now, you can

00:09:07.470 --> 00:09:10.120 align:middle line:84%
see that we need to
specify the LPORT option.

00:09:10.120 --> 00:09:12.330 align:middle line:84%
So that's the port of
the Kali Linux system

00:09:12.330 --> 00:09:15.060 align:middle line:84%
that we want to
essentially listen on

00:09:15.060 --> 00:09:17.640 align:middle line:84%
for the remote connection
or the reverse connection.

00:09:17.640 --> 00:09:19.080 align:middle line:90%
And then the RHOST--

00:09:19.080 --> 00:09:21.840 align:middle line:84%
or rather, the
actual LHOST option.

00:09:21.840 --> 00:09:24.220 align:middle line:84%
And in this case, it's
specifying the RHOST option,

00:09:24.220 --> 00:09:27.300 align:middle line:84%
which is the target address,
and which is already

00:09:27.300 --> 00:09:29.110 align:middle line:90%
specified for us there.

00:09:29.110 --> 00:09:31.860 align:middle line:84%
And then we also need to
specify the shell command, which

00:09:31.860 --> 00:09:35.010 align:middle line:84%
will allow us to specify
the system shell to use.

00:09:35.010 --> 00:09:37.920 align:middle line:84%
And given the fact that the
target system is running

00:09:37.920 --> 00:09:39.870 align:middle line:84%
Windows, we can set
the actual shell

00:09:39.870 --> 00:09:44.490 align:middle line:84%
we want to use to CMD,
as Windows utilizes CMD.

00:09:44.490 --> 00:09:46.710 align:middle line:90%
So we can hit Enter.

00:09:46.710 --> 00:09:50.010 align:middle line:84%
And we can run this
particular exploit module.

00:09:50.010 --> 00:09:51.540 align:middle line:90%
So I'm going to let it run.

00:09:51.540 --> 00:09:54.420 align:middle line:84%
As you can see, it
says uploading payload.

00:09:54.420 --> 00:09:56.220 align:middle line:84%
If that doesn't work,
we can terminate--

00:09:56.220 --> 00:09:58.920 align:middle line:84%
we can actually terminate the
execution there and run it

00:09:58.920 --> 00:10:00.960 align:middle line:84%
again, as this
particular exploit

00:10:00.960 --> 00:10:03.880 align:middle line:84%
module will take a few tries
in order for it to work.

00:10:03.880 --> 00:10:06.000 align:middle line:84%
And as you can see, it
says, uploading payload,

00:10:06.000 --> 00:10:08.940 align:middle line:84%
payload executed, start
the bind TCP handler

00:10:08.940 --> 00:10:13.060 align:middle line:84%
against our actual IP address
here, or in this case,

00:10:13.060 --> 00:10:14.070 align:middle line:90%
the target IP.

00:10:14.070 --> 00:10:17.110 align:middle line:84%
And we get a command shell
session on the target system.

00:10:17.110 --> 00:10:19.170 align:middle line:84%
So if we hit Enter,
you can see we now

00:10:19.170 --> 00:10:21.600 align:middle line:84%
have a command prompt
session on the target system,

00:10:21.600 --> 00:10:24.180 align:middle line:84%
not a Meterpreter
session, but we can still

00:10:24.180 --> 00:10:25.480 align:middle line:90%
run Windows commands.

00:10:25.480 --> 00:10:28.500 align:middle line:84%
So we can type in
dir or systeminfo.

00:10:28.500 --> 00:10:31.020 align:middle line:84%
Or we can actually get
our current privileges

00:10:31.020 --> 00:10:33.180 align:middle line:84%
by typing in the
get user ID command.

00:10:33.180 --> 00:10:35.940 align:middle line:84%
But because we're not working
in a Meterpreter session,

00:10:35.940 --> 00:10:38.200 align:middle line:84%
we will need to run
the whoami command.

00:10:38.200 --> 00:10:41.400 align:middle line:84%
And as you can see, we have NT
authority system privileges,

00:10:41.400 --> 00:10:43.260 align:middle line:84%
which means we have
the highest privileges

00:10:43.260 --> 00:10:45.610 align:middle line:90%
available on a Windows system.

00:10:45.610 --> 00:10:48.180 align:middle line:84%
However, this is
not a convenient way

00:10:48.180 --> 00:10:49.320 align:middle line:90%
of accessing the target.

00:10:49.320 --> 00:10:52.740 align:middle line:84%
We typically want to obtain
an Meterpreter session because

00:10:52.740 --> 00:10:56.850 align:middle line:84%
of all of the functionality that
Meterpreter affords or provides

00:10:56.850 --> 00:10:58.140 align:middle line:90%
to us.

00:10:58.140 --> 00:11:02.760 align:middle line:84%
So because this is a
command shell session,

00:11:02.760 --> 00:11:06.720 align:middle line:84%
we can put it in the background
using the Control and the Z

00:11:06.720 --> 00:11:08.190 align:middle line:90%
keys on your keyboard.

00:11:08.190 --> 00:11:09.970 align:middle line:84%
As you can see, that's
going to tell you,

00:11:09.970 --> 00:11:11.803 align:middle line:84%
do you want to put this
into the background?

00:11:11.803 --> 00:11:14.730 align:middle line:84%
We're going to hit
Yes and hit Enter.

00:11:14.730 --> 00:11:16.920 align:middle line:84%
If we list out our
sessions, you can

00:11:16.920 --> 00:11:19.480 align:middle line:84%
see that we have the
actual session here.

00:11:19.480 --> 00:11:22.860 align:middle line:84%
However, the type-- the
actual type of payload

00:11:22.860 --> 00:11:24.990 align:middle line:84%
is specified as
Java Linux, which

00:11:24.990 --> 00:11:29.040 align:middle line:84%
means even if we try and
actually change or upgrade

00:11:29.040 --> 00:11:32.010 align:middle line:84%
our shell into a Meterpreter
session through the use

00:11:32.010 --> 00:11:36.190 align:middle line:84%
of a built in post exploitation
module, this will not work.

00:11:36.190 --> 00:11:38.250 align:middle line:90%
So what can we do here?

00:11:38.250 --> 00:11:41.940 align:middle line:84%
And this is where the
technique that we actually

00:11:41.940 --> 00:11:44.550 align:middle line:84%
covered during the client-side
exploitation section

00:11:44.550 --> 00:11:45.720 align:middle line:90%
will come into handy.

00:11:45.720 --> 00:11:48.270 align:middle line:84%
And that is the technique
of generating payloads

00:11:48.270 --> 00:11:49.470 align:middle line:90%
with MSFvenom.

00:11:49.470 --> 00:11:52.140 align:middle line:84%
So what we're going to do
is generate a Meterpreter--

00:11:52.140 --> 00:11:54.870 align:middle line:84%
a Windows Meterpreter
payload with MSFvenom

00:11:54.870 --> 00:11:58.020 align:middle line:84%
and then upload it to the
target through our command shell

00:11:58.020 --> 00:11:58.800 align:middle line:90%
session.

00:11:58.800 --> 00:12:01.720 align:middle line:84%
And we are then going to
execute it on the target system.

00:12:01.720 --> 00:12:03.750 align:middle line:84%
And we should receive
a Meterpreter session

00:12:03.750 --> 00:12:04.620 align:middle line:90%
on our handler.

00:12:04.620 --> 00:12:07.500 align:middle line:84%
So we'll also have
to set up a handler.

00:12:07.500 --> 00:12:08.000 align:middle line:90%
All right.

00:12:08.000 --> 00:12:11.350 align:middle line:84%
So in order to do this, we want
to persist this MSF console

00:12:11.350 --> 00:12:11.850 align:middle line:90%
session.

00:12:11.850 --> 00:12:14.780 align:middle line:84%
So we are going to open up a new
tab within the terminal here.

00:12:14.780 --> 00:12:18.150 align:middle line:84%
And on our desktop or our
current working directory,

00:12:18.150 --> 00:12:21.320 align:middle line:84%
which is under root, we are
just going to say msfvenom.

00:12:21.320 --> 00:12:23.330 align:middle line:84%
And before we do
that, we actually

00:12:23.330 --> 00:12:26.270 align:middle line:84%
need to get the IP address
of the Kali Linux system

00:12:26.270 --> 00:12:30.170 align:middle line:84%
here, which we can do by typing
in ifconfig and heading over

00:12:30.170 --> 00:12:31.700 align:middle line:90%
to the Ethernet 1 interface.

00:12:31.700 --> 00:12:33.440 align:middle line:90%
So we can copy that IP.

00:12:33.440 --> 00:12:37.640 align:middle line:84%
And then we can say
msfvenom, specify the payload

00:12:37.640 --> 00:12:42.480 align:middle line:84%
as a
windows/meterpreter/reverse_tcp.

00:12:42.480 --> 00:12:46.155 align:middle line:84%
Of course, you can utilize any
of the Meterpreter payloads--

00:12:46.155 --> 00:12:47.820 align:middle line:84%
Meterpreter payload
types in regards

00:12:47.820 --> 00:12:51.190 align:middle line:84%
to the architecture and the
protocol that you want to use.

00:12:51.190 --> 00:12:53.490 align:middle line:84%
In this case, we're
utilizing reverse TCP.

00:12:53.490 --> 00:12:57.060 align:middle line:84%
We then need to specify the
Kali Linux IP address where

00:12:57.060 --> 00:12:59.070 align:middle line:90%
the handler will be listening.

00:12:59.070 --> 00:13:01.320 align:middle line:84%
And that's, of course,
specified through the use

00:13:01.320 --> 00:13:02.580 align:middle line:90%
of the LHOST option.

00:13:02.580 --> 00:13:04.470 align:middle line:84%
We then specify
the LPORT option.

00:13:04.470 --> 00:13:07.650 align:middle line:84%
In this case, we are going
to utilize the port 1234.

00:13:07.650 --> 00:13:10.110 align:middle line:84%
And then the format
is going to be exe.

00:13:10.110 --> 00:13:14.850 align:middle line:84%
And we'll output this into a
file called meterpreter.exe.

00:13:14.850 --> 00:13:15.810 align:middle line:90%
We hit Enter.

00:13:15.810 --> 00:13:18.880 align:middle line:84%
That's going to generate
the payload for us.

00:13:18.880 --> 00:13:22.650 align:middle line:84%
So we'll give that
a few seconds.

00:13:22.650 --> 00:13:25.410 align:middle line:84%
Once the payload is generated,
you can see that we have it

00:13:25.410 --> 00:13:26.760 align:middle line:90%
here.

00:13:26.760 --> 00:13:29.010 align:middle line:90%
There it is, meterpreter.exe.

00:13:29.010 --> 00:13:33.360 align:middle line:84%
We actually need to transfer
this meterpreter.exe payload

00:13:33.360 --> 00:13:34.930 align:middle line:90%
onto the target system.

00:13:34.930 --> 00:13:36.190 align:middle line:90%
So how can we do this?

00:13:36.190 --> 00:13:38.250 align:middle line:84%
Well, one of the techniques
that we can utilize

00:13:38.250 --> 00:13:42.480 align:middle line:84%
is the technique of setting up
a web server on the Kali Linux

00:13:42.480 --> 00:13:45.210 align:middle line:84%
system to host this
file and then download

00:13:45.210 --> 00:13:49.710 align:middle line:84%
the file on the actual target
through an in-built Windows

00:13:49.710 --> 00:13:52.390 align:middle line:84%
utility, because, as you know,
we don't have a Meterpreter

00:13:52.390 --> 00:13:52.890 align:middle line:90%
session.

00:13:52.890 --> 00:13:54.540 align:middle line:84%
That's what we're
trying to establish.

00:13:54.540 --> 00:13:56.850 align:middle line:84%
So we can set up a
simple web server

00:13:56.850 --> 00:13:59.010 align:middle line:84%
within our current
working directory

00:13:59.010 --> 00:14:01.260 align:middle line:84%
to host the
meterpreter.exe payload

00:14:01.260 --> 00:14:04.440 align:middle line:90%
by typing in sudo python -m.

00:14:04.440 --> 00:14:06.900 align:middle line:84%
And we're going to
utilize the python m--

00:14:06.900 --> 00:14:10.320 align:middle line:84%
or rather, the actual simple
HTTP server module that's

00:14:10.320 --> 00:14:12.750 align:middle line:90%
afforded to us by Python.

00:14:12.750 --> 00:14:14.970 align:middle line:84%
So we're going to
say SimpleHTTPServer.

00:14:14.970 --> 00:14:17.430 align:middle line:84%
And we're going to
host this on port 80.

00:14:17.430 --> 00:14:18.240 align:middle line:90%
We hit Enter.

00:14:18.240 --> 00:14:19.865 align:middle line:84%
As you can see, it's
going to tell you,

00:14:19.865 --> 00:14:23.860 align:middle line:84%
serving HTTP on the Kali
Linux IP on port 80.

00:14:23.860 --> 00:14:26.220 align:middle line:84%
So if we head back
to our first tab

00:14:26.220 --> 00:14:29.430 align:middle line:84%
here, where we have access to
the actual target via command

00:14:29.430 --> 00:14:33.570 align:middle line:84%
shell, we can interact with the
session by saying sessions 1.

00:14:33.570 --> 00:14:36.312 align:middle line:84%
And if we hit Enter, you
can see we are currently--

00:14:36.312 --> 00:14:37.770 align:middle line:84%
we currently have
a command prompt,

00:14:37.770 --> 00:14:41.100 align:middle line:84%
and we are working within the
Tomcat 8.5 directory, which

00:14:41.100 --> 00:14:43.420 align:middle line:90%
is perfectly fine in our case.

00:14:43.420 --> 00:14:47.580 align:middle line:84%
So in order to download this
particular meterpreter.exe

00:14:47.580 --> 00:14:51.245 align:middle line:84%
payload from the Kali Linux
system or the Kali Linux web

00:14:51.245 --> 00:14:52.620 align:middle line:84%
server that we
have set up, we're

00:14:52.620 --> 00:14:55.530 align:middle line:84%
going to utilize an in-built
Windows utility called

00:14:55.530 --> 00:14:58.410 align:middle line:84%
certutil, which can
allow us, in this case,

00:14:58.410 --> 00:15:00.510 align:middle line:84%
to download files
from remote systems.

00:15:00.510 --> 00:15:03.030 align:middle line:84%
So we're going to say
certutil, and then we

00:15:03.030 --> 00:15:07.410 align:middle line:84%
are going to utilize the URL
cache flag as well as the file

00:15:07.410 --> 00:15:07.980 align:middle line:90%
flag.

00:15:07.980 --> 00:15:10.920 align:middle line:84%
We then need to specify
the actual web server IP

00:15:10.920 --> 00:15:13.720 align:middle line:84%
address, which in this
case is the Kali Linux IP.

00:15:13.720 --> 00:15:15.780 align:middle line:84%
So we'll just copy
the Kali Linux IP

00:15:15.780 --> 00:15:17.920 align:middle line:90%
that we specified there.

00:15:17.920 --> 00:15:20.092 align:middle line:84%
And then we want to
paste that in there.

00:15:20.092 --> 00:15:22.050 align:middle line:84%
And the name of the file
that we're downloading

00:15:22.050 --> 00:15:24.090 align:middle line:90%
is meterpreter.exe.

00:15:24.090 --> 00:15:27.730 align:middle line:84%
We then need to provide an
output file that is, again,

00:15:27.730 --> 00:15:30.632 align:middle line:84%
going to be-- or rather, an
output file name for the file

00:15:30.632 --> 00:15:31.590 align:middle line:90%
that we're downloading.

00:15:31.590 --> 00:15:33.630 align:middle line:84%
So we're going to
say meterpreter.exe.

00:15:33.630 --> 00:15:36.220 align:middle line:84%
So we're just going to
maintain the same file name.

00:15:36.220 --> 00:15:37.170 align:middle line:90%
We then hit Enter.

00:15:37.170 --> 00:15:40.425 align:middle line:90%


00:15:40.425 --> 00:15:42.050 align:middle line:84%
As you can see, it's
going to tell you,

00:15:42.050 --> 00:15:45.450 align:middle line:84%
certutil URL cache command
completed successfully.

00:15:45.450 --> 00:15:48.120 align:middle line:84%
If we type out the
contents of this directory,

00:15:48.120 --> 00:15:50.900 align:middle line:84%
you can see we have the
meterpreter.exe payload

00:15:50.900 --> 00:15:52.340 align:middle line:90%
downloaded successfully.

00:15:52.340 --> 00:15:53.270 align:middle line:90%
Fantastic.

00:15:53.270 --> 00:15:55.520 align:middle line:84%
So we can now terminate
the web server

00:15:55.520 --> 00:15:58.940 align:middle line:84%
that we set up by using
the Control and C keyboard

00:15:58.940 --> 00:16:00.080 align:middle line:90%
combination.

00:16:00.080 --> 00:16:02.960 align:middle line:84%
And once that is
done, again, we need

00:16:02.960 --> 00:16:06.440 align:middle line:84%
to set up our handler to
receive the connection once we

00:16:06.440 --> 00:16:09.480 align:middle line:84%
execute our interpreter
payload on the target system.

00:16:09.480 --> 00:16:12.980 align:middle line:84%
So in order to do this, we can
create a simple Metasploit RC

00:16:12.980 --> 00:16:14.330 align:middle line:90%
script, which we covered.

00:16:14.330 --> 00:16:15.770 align:middle line:84%
And in order to
do that, I'm going

00:16:15.770 --> 00:16:17.270 align:middle line:90%
to use the Vim text editor.

00:16:17.270 --> 00:16:19.753 align:middle line:84%
So I'm going to
say vim handler.rc.

00:16:19.753 --> 00:16:21.170 align:middle line:84%
And within this,
we are just going

00:16:21.170 --> 00:16:23.510 align:middle line:84%
to say we want to
use the multihandler.

00:16:23.510 --> 00:16:27.510 align:middle line:90%


00:16:27.510 --> 00:16:29.490 align:middle line:84%
And then we're going
to set the payload

00:16:29.490 --> 00:16:31.990 align:middle line:84%
to
windows/meterpreter/reverse_tcp.

00:16:31.990 --> 00:16:37.010 align:middle line:90%


00:16:37.010 --> 00:16:39.890 align:middle line:84%
We're then going to set the
LHOST option to the Kali Linux

00:16:39.890 --> 00:16:42.860 align:middle line:84%
IP and then set the
LPORT option to the port

00:16:42.860 --> 00:16:45.560 align:middle line:84%
that we specified when
we were generating

00:16:45.560 --> 00:16:49.010 align:middle line:84%
our payload with MSFvenom,
which in this case was 1234.

00:16:49.010 --> 00:16:51.350 align:middle line:84%
And we're just going to
hit run so that we actually

00:16:51.350 --> 00:16:55.070 align:middle line:84%
run this particular multihandler
to wait for the connection.

00:16:55.070 --> 00:16:58.400 align:middle line:84%
So I'm going to write and quit
with Vim to save this file.

00:16:58.400 --> 00:17:01.460 align:middle line:84%
We're then going to
say msfconsole -r

00:17:01.460 --> 00:17:05.210 align:middle line:84%
to load the resource
script and say handler.rc.

00:17:05.210 --> 00:17:08.067 align:middle line:84%
That's going to set up our
listener for us automatically.

00:17:08.067 --> 00:17:10.400 align:middle line:84%
You can, of course, go through
the process of doing this

00:17:10.400 --> 00:17:13.970 align:middle line:84%
manually, but it's always
good to, again, utilize

00:17:13.970 --> 00:17:15.530 align:middle line:84%
the various
automation techniques

00:17:15.530 --> 00:17:16.920 align:middle line:90%
that we've learned so far.

00:17:16.920 --> 00:17:19.310 align:middle line:84%
So as you can see, it
says use multihandler,

00:17:19.310 --> 00:17:22.460 align:middle line:84%
set the payload to
windows/meterpreter/reverse_tcp.

00:17:22.460 --> 00:17:26.450 align:middle line:84%
It sets the Kali Linux IP as
the LHOST option and the port,

00:17:26.450 --> 00:17:28.790 align:middle line:84%
and it starts the
reverse TCP handler.

00:17:28.790 --> 00:17:32.180 align:middle line:84%
So we can now execute the
meterpreter.exe payload

00:17:32.180 --> 00:17:36.050 align:middle line:84%
on the target system by
moving onto our first tab

00:17:36.050 --> 00:17:38.270 align:middle line:84%
and then specifying
the full stop

00:17:38.270 --> 00:17:41.060 align:middle line:84%
and forward slash or
backslash command,

00:17:41.060 --> 00:17:43.010 align:middle line:84%
and then specifying
the name of the file

00:17:43.010 --> 00:17:44.090 align:middle line:90%
that we want to execute.

00:17:44.090 --> 00:17:46.780 align:middle line:84%
In this case, it's
meterpreter.exe.

00:17:46.780 --> 00:17:47.840 align:middle line:90%
We hit Enter.

00:17:47.840 --> 00:17:50.340 align:middle line:84%
As you can see, it's
executed successfully.

00:17:50.340 --> 00:17:52.680 align:middle line:84%
And if we head over
to our second tab,

00:17:52.680 --> 00:17:55.430 align:middle line:84%
you can see that we get a
Meterpreter session opened

00:17:55.430 --> 00:17:56.580 align:middle line:90%
on the target system.

00:17:56.580 --> 00:17:59.680 align:middle line:84%
So we're going to wait for
that to actually open up.

00:17:59.680 --> 00:18:02.470 align:middle line:84%
As you can see, the
Meterpreter session opens up.

00:18:02.470 --> 00:18:06.790 align:middle line:84%
And we can type in sysinfo,
and we now have a Meterpreter

00:18:06.790 --> 00:18:08.720 align:middle line:90%
session on the target system.

00:18:08.720 --> 00:18:11.230 align:middle line:84%
And if I type in
get user ID, you

00:18:11.230 --> 00:18:13.270 align:middle line:84%
can see that the permissions
we have available

00:18:13.270 --> 00:18:15.520 align:middle line:84%
are NT authority system,
which are the highest

00:18:15.520 --> 00:18:16.880 align:middle line:90%
level of privileges.

00:18:16.880 --> 00:18:20.500 align:middle line:84%
And of course, we've been able
to obtain a Meterpreter session

00:18:20.500 --> 00:18:22.930 align:middle line:84%
by utilizing an
exploit module that

00:18:22.930 --> 00:18:25.840 align:middle line:84%
did not allow us to specify
a Meterpreter payload.

00:18:25.840 --> 00:18:28.360 align:middle line:84%
So that's how to utilize
all of the techniques

00:18:28.360 --> 00:18:30.730 align:middle line:84%
that we've learned so far
in regards to creating

00:18:30.730 --> 00:18:32.907 align:middle line:84%
or generating payloads
with MSFvenom.

00:18:32.907 --> 00:18:34.990 align:middle line:84%
And of course, you've
learned a few new techniques

00:18:34.990 --> 00:18:39.130 align:middle line:84%
like how to transfer
files from a Linux system

00:18:39.130 --> 00:18:41.680 align:middle line:84%
onto a Windows system
through the use

00:18:41.680 --> 00:18:43.490 align:middle line:90%
of the certutil utility.

00:18:43.490 --> 00:18:45.640 align:middle line:84%
So we've gained access
to the target system

00:18:45.640 --> 00:18:49.330 align:middle line:84%
by exploiting the Apache
Tomcat web server.

00:18:49.330 --> 00:18:52.000 align:middle line:84%
And then, we of course,
utilized our knowledge

00:18:52.000 --> 00:18:54.970 align:middle line:84%
of generating payloads to
generate a Meterpreter payload,

00:18:54.970 --> 00:18:58.090 align:middle line:84%
transfer it over to the
target, set up our handler,

00:18:58.090 --> 00:19:00.640 align:middle line:84%
execute the payload on the
target through our command

00:19:00.640 --> 00:19:03.980 align:middle line:84%
shell session in order to
receive a Meterpreter session,

00:19:03.980 --> 00:19:07.670 align:middle line:84%
which is much better than
having a command shell session.

00:19:07.670 --> 00:19:09.190 align:middle line:84%
So that is going
to be it in regards

00:19:09.190 --> 00:19:13.410 align:middle line:84%
to the practical
demonstration for this video.

00:19:13.410 --> 00:19:15.230 align:middle line:84%
In the next video,
we are going to be

00:19:15.230 --> 00:19:18.470 align:middle line:84%
exploring the process of
exploiting a vulnerable FTP

00:19:18.470 --> 00:19:19.100 align:middle line:90%
server.

00:19:19.100 --> 00:19:20.930 align:middle line:84%
More specifically,
we're going to get

00:19:20.930 --> 00:19:24.570 align:middle line:84%
into the process of exploiting
services on Linux systems.

00:19:24.570 --> 00:19:27.570 align:middle line:84%
So we're going to start off
by exploiting a vulnerable FTP

00:19:27.570 --> 00:19:28.070 align:middle line:90%
server.

00:19:28.070 --> 00:19:30.403 align:middle line:84%
And then we'll take a look
at some of the other services

00:19:30.403 --> 00:19:31.340 align:middle line:90%
that we can exploit.

00:19:31.340 --> 00:19:34.120 align:middle line:90%
So I'll see you there.

00:19:34.120 --> 00:19:35.000 align:middle line:90%