WEBVTT

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


00:00:03.423 --> 00:00:06.846 align:middle line:90%
[AUDIO LOGO]

00:00:06.846 --> 00:00:10.180 align:middle line:90%


00:00:10.180 --> 00:00:13.090 align:middle line:84%
Exploiting a
Vulnerable SSH Server.

00:00:13.090 --> 00:00:15.250 align:middle line:84%
In this video, we are
going to be exploring

00:00:15.250 --> 00:00:19.060 align:middle line:84%
the process of exploiting a
vulnerable SSH server running

00:00:19.060 --> 00:00:20.560 align:middle line:90%
on a Linux target.

00:00:20.560 --> 00:00:23.930 align:middle line:84%
Now, during the enumeration
section of this course,

00:00:23.930 --> 00:00:25.990 align:middle line:84%
we explored the
process of enumerating

00:00:25.990 --> 00:00:29.480 align:middle line:84%
as much information as
possible from an SSH server

00:00:29.480 --> 00:00:32.740 align:middle line:84%
and we also explored the process
of performing a brute force

00:00:32.740 --> 00:00:36.910 align:middle line:84%
attack in order to gain access
to the target system via SSH.

00:00:36.910 --> 00:00:40.570 align:middle line:84%
However, in this case, instead
of focusing on a brute force

00:00:40.570 --> 00:00:44.350 align:middle line:84%
attack or performing an
attack that essentially takes

00:00:44.350 --> 00:00:46.810 align:middle line:84%
advantage of a
misconfiguration, we

00:00:46.810 --> 00:00:49.210 align:middle line:84%
are going to be exploring
the process of exploiting

00:00:49.210 --> 00:00:53.020 align:middle line:84%
an inherent vulnerability
within an SSH server running

00:00:53.020 --> 00:00:54.470 align:middle line:90%
on a Linux target.

00:00:54.470 --> 00:00:57.360 align:middle line:84%
So first and
foremost, what is SSH?

00:00:57.360 --> 00:00:59.710 align:middle line:90%
SSH stands for Secure Shell.

00:00:59.710 --> 00:01:01.990 align:middle line:84%
It is a remote
administration protocol

00:01:01.990 --> 00:01:04.959 align:middle line:84%
that offers encryption and
is the successor to Telnet.

00:01:04.959 --> 00:01:07.330 align:middle line:84%
So it's typically
used for remote access

00:01:07.330 --> 00:01:09.260 align:middle line:84%
to servers and systems,
and, of course,

00:01:09.260 --> 00:01:12.680 align:middle line:84%
we explored what SSH was
during the enumeration section.

00:01:12.680 --> 00:01:16.240 align:middle line:84%
So again, we don't need to
get into that right now.

00:01:16.240 --> 00:01:17.800 align:middle line:84%
The only thing that
you need to know

00:01:17.800 --> 00:01:22.600 align:middle line:84%
is that SSH utilizes TCP
port 22 by default. However,

00:01:22.600 --> 00:01:24.580 align:middle line:84%
like other services,
it can be configured

00:01:24.580 --> 00:01:27.940 align:middle line:84%
to use any other open TCP
port, and that's something

00:01:27.940 --> 00:01:30.410 align:middle line:84%
that you need to be
cognizant or aware of.

00:01:30.410 --> 00:01:31.960 align:middle line:84%
Now, in this
particular video, we

00:01:31.960 --> 00:01:33.730 align:middle line:84%
are going to be
targeting or exploiting

00:01:33.730 --> 00:01:37.150 align:middle line:90%
an SSH server running libSSH.

00:01:37.150 --> 00:01:40.690 align:middle line:84%
All right, so libSSH is a
multi-platform C library

00:01:40.690 --> 00:01:44.590 align:middle line:84%
that implements the SSH version
2 protocol on the client

00:01:44.590 --> 00:01:45.830 align:middle line:90%
and server side.

00:01:45.830 --> 00:01:50.650 align:middle line:84%
Now, libSSH version
0.6.0 to 0.8.0

00:01:50.650 --> 00:01:53.110 align:middle line:84%
is vulnerable to an
authentication bypass

00:01:53.110 --> 00:01:55.750 align:middle line:84%
vulnerability in
the libSSH server

00:01:55.750 --> 00:01:58.330 align:middle line:84%
code that can be exploited
to execute commands

00:01:58.330 --> 00:01:59.660 align:middle line:90%
on the target server.

00:01:59.660 --> 00:02:01.420 align:middle line:84%
And in this case,
we'll be taking a look

00:02:01.420 --> 00:02:05.470 align:middle line:84%
at how to exploit libSSH
running on the Linux target.

00:02:05.470 --> 00:02:08.680 align:middle line:84%
And furthermore, we'll
also be exploring

00:02:08.680 --> 00:02:10.720 align:middle line:84%
the process of
obtaining a meterpreter

00:02:10.720 --> 00:02:13.720 align:middle line:84%
session on the target
system by utilizing

00:02:13.720 --> 00:02:16.000 align:middle line:84%
an exploit module that
allows us to exploit

00:02:16.000 --> 00:02:17.840 align:middle line:90%
this particular vulnerability.

00:02:17.840 --> 00:02:20.300 align:middle line:84%
So let's get started
with the lab environment.

00:02:20.300 --> 00:02:23.260 align:middle line:84%
So again, you can follow along
with the techniques highlighted

00:02:23.260 --> 00:02:26.290 align:middle line:84%
within this particular video
by starting up your lab

00:02:26.290 --> 00:02:28.510 align:middle line:84%
environment, and
I'll start up mine,

00:02:28.510 --> 00:02:32.860 align:middle line:84%
and I'll see you within
the lab environment.

00:02:32.860 --> 00:02:35.150 align:middle line:84%
All right, so I'm back
within the lab environment.

00:02:35.150 --> 00:02:37.360 align:middle line:84%
And the first step
that we need to perform

00:02:37.360 --> 00:02:40.090 align:middle line:84%
is, of course, obtaining the
target IP address, which can

00:02:40.090 --> 00:02:42.580 align:middle line:90%
be done by typing in ifconfig.

00:02:42.580 --> 00:02:45.620 align:middle line:84%
You then want to head over
to the ethernet1 interface.

00:02:45.620 --> 00:02:50.470 align:middle line:84%
And in this particular
subnet here, this

00:02:50.470 --> 00:02:54.040 align:middle line:84%
is the subnet that the target
server or the target system

00:02:54.040 --> 00:02:54.860 align:middle line:90%
is currently on.

00:02:54.860 --> 00:02:57.440 align:middle line:84%
So this is the Kali
Linux IP address,

00:02:57.440 --> 00:02:59.650 align:middle line:84%
which means that the target
IP address is going to be

00:02:59.650 --> 00:03:02.800 align:middle line:90%
192.40.32.3.

00:03:02.800 --> 00:03:06.680 align:middle line:84%
So it's going to be the next
IP address within this subnet.

00:03:06.680 --> 00:03:10.480 align:middle line:84%
So once you've copied that IP
address, what we need to do

00:03:10.480 --> 00:03:14.110 align:middle line:84%
is start up the PostgreSQL
Database Service, which

00:03:14.110 --> 00:03:16.210 align:middle line:84%
will essentially
allow us to interact

00:03:16.210 --> 00:03:19.690 align:middle line:84%
with the MySQL or the
Metasploit framework database.

00:03:19.690 --> 00:03:24.780 align:middle line:84%
So we'll say service
Postgres start we then

00:03:24.780 --> 00:03:27.580 align:middle line:84%
start up the Metasploit
framework console.

00:03:27.580 --> 00:03:28.995 align:middle line:84%
So we'll give that
a few seconds.

00:03:28.995 --> 00:03:35.150 align:middle line:90%


00:03:35.150 --> 00:03:37.100 align:middle line:84%
We then want to
create a workspace

00:03:37.100 --> 00:03:40.110 align:middle line:84%
that we will be utilizing
in this particular scenario.

00:03:40.110 --> 00:03:41.690 align:middle line:84%
And in this case,
we'll just call

00:03:41.690 --> 00:03:46.020 align:middle line:84%
it libSSH because we're going
to be exploiting libSSH.

00:03:46.020 --> 00:03:47.900 align:middle line:84%
The next step that
we need to perform

00:03:47.900 --> 00:03:50.450 align:middle line:84%
is, of course, setting
up the global variable

00:03:50.450 --> 00:03:54.170 align:middle line:84%
for RHOSTS option, which we are
going to set to the target IP.

00:03:54.170 --> 00:03:58.820 align:middle line:84%
So we changed the 2 into a
3, and this will essentially

00:03:58.820 --> 00:04:02.180 align:middle line:84%
prevent us or save us
the time or save us

00:04:02.180 --> 00:04:08.630 align:middle line:84%
time for essentially putting
in or typing in the target IP

00:04:08.630 --> 00:04:10.970 align:middle line:84%
address whenever
we load a module.

00:04:10.970 --> 00:04:13.790 align:middle line:84%
So I'm going to set the global
variable for the RHOSTS value

00:04:13.790 --> 00:04:14.640 align:middle line:90%
there.

00:04:14.640 --> 00:04:17.540 align:middle line:84%
We can then perform a Nmap
scan on the target system

00:04:17.540 --> 00:04:21.320 align:middle line:84%
to verify that SSH is indeed
running on the target system

00:04:21.320 --> 00:04:23.790 align:middle line:84%
and that libSSH is
also running as well.

00:04:23.790 --> 00:04:27.680 align:middle line:84%
So we'll perform a SYN scan,
as well as a service version

00:04:27.680 --> 00:04:30.980 align:middle line:84%
detection scan and an operating
system detection scan.

00:04:30.980 --> 00:04:32.630 align:middle line:90%
We'll paste in the target IP.

00:04:32.630 --> 00:04:34.910 align:middle line:84%
So make sure to
change the 2 to a 3

00:04:34.910 --> 00:04:37.370 align:middle line:84%
and the db_nmap
command again allows

00:04:37.370 --> 00:04:40.550 align:middle line:84%
us to perform an Nmap scan from
within the Metasploit framework

00:04:40.550 --> 00:04:43.760 align:middle line:84%
console and consequently
saves the Nmap scan results

00:04:43.760 --> 00:04:45.560 align:middle line:84%
into the Metasploit
framework database

00:04:45.560 --> 00:04:47.240 align:middle line:90%
within our current workspace.

00:04:47.240 --> 00:04:48.380 align:middle line:90%
So we'll hit Enter.

00:04:48.380 --> 00:04:52.080 align:middle line:84%
And I'm just going to wait for
this Nmap scan to complete.

00:04:52.080 --> 00:04:54.140 align:middle line:84%
All right, so the
Nmap scan is complete

00:04:54.140 --> 00:04:57.530 align:middle line:84%
and we can see that SSH is
indeed running on the target

00:04:57.530 --> 00:04:59.360 align:middle line:90%
system on port 22.

00:04:59.360 --> 00:05:01.250 align:middle line:84%
And right over here
from the banner,

00:05:01.250 --> 00:05:03.920 align:middle line:84%
we can see that we
have libSSH running

00:05:03.920 --> 00:05:06.620 align:middle line:90%
and it is version 0.8.3.

00:05:06.620 --> 00:05:10.730 align:middle line:84%
So again, we can target this
system or this SSH service

00:05:10.730 --> 00:05:12.240 align:middle line:90%
to see if it's vulnerable.

00:05:12.240 --> 00:05:15.470 align:middle line:84%
And again, you can always
access these services

00:05:15.470 --> 00:05:17.460 align:middle line:84%
by typing in the
services command.

00:05:17.460 --> 00:05:19.550 align:middle line:84%
And as you can see, it
says it's running SSH,

00:05:19.550 --> 00:05:21.800 align:middle line:84%
but it doesn't give
us that exact banner.

00:05:21.800 --> 00:05:24.740 align:middle line:84%
So in order to test or to
check whether the system

00:05:24.740 --> 00:05:28.880 align:middle line:84%
or the actual SSH service is
vulnerable, what we can do

00:05:28.880 --> 00:05:31.100 align:middle line:84%
is search for the
actual module that we're

00:05:31.100 --> 00:05:33.050 align:middle line:84%
going to be utilizing,
and the module

00:05:33.050 --> 00:05:37.380 align:middle line:84%
is the libSSH auth
bypass module.

00:05:37.380 --> 00:05:41.030 align:middle line:84%
So we're just going to
search for it directly.

00:05:41.030 --> 00:05:42.920 align:middle line:90%
And this is the module here.

00:05:42.920 --> 00:05:44.140 align:middle line:90%
So we can copy it.

00:05:44.140 --> 00:05:46.720 align:middle line:84%
As you can see, that's
an auxiliary module.

00:05:46.720 --> 00:05:50.060 align:middle line:84%
And we can then say use, paste
in the module name there.

00:05:50.060 --> 00:05:51.820 align:middle line:84%
We can then show
the options required

00:05:51.820 --> 00:05:54.170 align:middle line:90%
by this particular module.

00:05:54.170 --> 00:05:56.030 align:middle line:84%
So within this
particular module,

00:05:56.030 --> 00:05:58.900 align:middle line:84%
we need to specify the
RHOSTS option, which

00:05:58.900 --> 00:06:01.570 align:middle line:84%
is done for us because we
set up the global variable

00:06:01.570 --> 00:06:03.440 align:middle line:90%
for the RHOSTS option.

00:06:03.440 --> 00:06:05.680 align:middle line:84%
And then RPORT option,
which, again, you'll

00:06:05.680 --> 00:06:08.380 align:middle line:84%
need to change if SSH is
running on another port

00:06:08.380 --> 00:06:11.810 align:middle line:84%
apart from the default. In this
case, it's running on port 22.

00:06:11.810 --> 00:06:14.980 align:middle line:84%
So we don't need to change
that, and we can also, again,

00:06:14.980 --> 00:06:17.420 align:middle line:84%
execute or change
a few options here.

00:06:17.420 --> 00:06:19.780 align:middle line:84%
The option that we
want to change is the

00:06:19.780 --> 00:06:23.480 align:middle line:84%
or that we want to set
is the SPAWN_PTY option,

00:06:23.480 --> 00:06:26.230 align:middle line:84%
which will allow us to
spawn a terminal session.

00:06:26.230 --> 00:06:28.630 align:middle line:90%
So we can say set SPAWN_PTY.

00:06:28.630 --> 00:06:31.780 align:middle line:90%


00:06:31.780 --> 00:06:34.900 align:middle line:84%
And because that requires
a Boolean setting,

00:06:34.900 --> 00:06:38.110 align:middle line:84%
we're going to set it to True,
which is the opposite of false,

00:06:38.110 --> 00:06:41.380 align:middle line:90%
and we can hit run.

00:06:41.380 --> 00:06:43.270 align:middle line:84%
As you can see, it
says right over here,

00:06:43.270 --> 00:06:45.640 align:middle line:84%
attempting
authentication bypass.

00:06:45.640 --> 00:06:48.820 align:middle line:84%
It's then going to say command
shell session 1 opened,

00:06:48.820 --> 00:06:51.100 align:middle line:84%
and it then provides us
with the actual session.

00:06:51.100 --> 00:06:52.780 align:middle line:84%
If we list out our
sessions, you can

00:06:52.780 --> 00:06:55.240 align:middle line:84%
see that it opens
up the command shell

00:06:55.240 --> 00:06:56.630 align:middle line:90%
session in the background.

00:06:56.630 --> 00:06:59.080 align:middle line:84%
So we've successfully
been able to, again,

00:06:59.080 --> 00:07:02.590 align:middle line:84%
exploit the SSH server,
and we get a shell session

00:07:02.590 --> 00:07:03.640 align:middle line:90%
on the target system.

00:07:03.640 --> 00:07:04.225 align:middle line:90%
There we are.

00:07:04.225 --> 00:07:08.380 align:middle line:84%
So we can essentially
enumerate the user

00:07:08.380 --> 00:07:13.790 align:middle line:84%
that we currently are by
either typing in whoami, which

00:07:13.790 --> 00:07:15.040 align:middle line:90%
will tell us that we are root.

00:07:15.040 --> 00:07:17.050 align:middle line:84%
So we currently have
administrative privileges

00:07:17.050 --> 00:07:17.980 align:middle line:90%
on the target system.

00:07:17.980 --> 00:07:21.340 align:middle line:84%
We can also enumerate the actual
distribution release version

00:07:21.340 --> 00:07:25.880 align:middle line:90%
by typing in cat/etc/*release.

00:07:25.880 --> 00:07:28.660 align:middle line:84%
And as you can see, the
target is running Arch Linux.

00:07:28.660 --> 00:07:31.120 align:middle line:84%
We can also get or
enumerate the kernel version

00:07:31.120 --> 00:07:34.060 align:middle line:90%
by typing in uname -r.

00:07:34.060 --> 00:07:39.100 align:middle line:84%
And in this case, it's running
the kernel version 5.4.0.

00:07:39.100 --> 00:07:40.640 align:middle line:84%
So the next step
will, of course,

00:07:40.640 --> 00:07:44.740 align:middle line:84%
involve the process of
upgrading our command shell

00:07:44.740 --> 00:07:47.980 align:middle line:84%
or our shell session into a
meterpreter session, which

00:07:47.980 --> 00:07:51.400 align:middle line:84%
we can do first and foremost
by putting this current session

00:07:51.400 --> 00:07:55.150 align:middle line:84%
in the background using the
keyboard combination Control

00:07:55.150 --> 00:07:57.700 align:middle line:90%
and z, and then hitting Yes.

00:07:57.700 --> 00:08:00.340 align:middle line:84%
We can then search for the
post exploitation module

00:08:00.340 --> 00:08:02.245 align:middle line:90%
shell_to_meterpreter.

00:08:02.245 --> 00:08:06.220 align:middle line:90%


00:08:06.220 --> 00:08:07.690 align:middle line:90%
And that's the module there.

00:08:07.690 --> 00:08:10.570 align:middle line:84%
This will help us
upgrade our shell session

00:08:10.570 --> 00:08:13.490 align:middle line:84%
into a meterpreter session
as we've done previously.

00:08:13.490 --> 00:08:15.170 align:middle line:90%
So we show the options.

00:08:15.170 --> 00:08:17.260 align:middle line:84%
We then need to set the
LHOST option, which is

00:08:17.260 --> 00:08:19.150 align:middle line:90%
going to be the Kali Linux IP.

00:08:19.150 --> 00:08:21.460 align:middle line:84%
So to do that, we'll
just say set LHOST

00:08:21.460 --> 00:08:25.870 align:middle line:84%
to the ethernet1 IP address
or the ethernt1 interface IP

00:08:25.870 --> 00:08:26.590 align:middle line:90%
address.

00:08:26.590 --> 00:08:31.480 align:middle line:84%
And as you can see, it
sets that up for us.

00:08:31.480 --> 00:08:34.870 align:middle line:84%
The LPORT option we'll
leave as four 4433.

00:08:34.870 --> 00:08:38.140 align:middle line:84%
We then need to set the
session ID, which in this case

00:08:38.140 --> 00:08:41.620 align:middle line:84%
is going to be SESSION 1
because we only got one session,

00:08:41.620 --> 00:08:42.940 align:middle line:90%
and then we type in run.

00:08:42.940 --> 00:08:52.660 align:middle line:90%


00:08:52.660 --> 00:08:54.940 align:middle line:84%
All right, so when it
completes, as you can see,

00:08:54.940 --> 00:08:56.510 align:middle line:84%
it looks like we
have an error here.

00:08:56.510 --> 00:09:00.070 align:middle line:84%
So again, we don't need to
worry at this particular point

00:09:00.070 --> 00:09:00.650 align:middle line:90%
in time.

00:09:00.650 --> 00:09:02.860 align:middle line:84%
However, when we
type in sessions,

00:09:02.860 --> 00:09:05.200 align:middle line:84%
you can see that we have
the meterpreter session,

00:09:05.200 --> 00:09:08.200 align:middle line:84%
and we can switch to it
by typing in sessions 2,

00:09:08.200 --> 00:09:10.358 align:middle line:84%
and we have the
meterpreter session.

00:09:10.358 --> 00:09:10.900 align:middle line:90%
There we are.

00:09:10.900 --> 00:09:13.450 align:middle line:84%
We type in sysinfo, we
get the same information

00:09:13.450 --> 00:09:14.800 align:middle line:90%
that we were able to get.

00:09:14.800 --> 00:09:16.930 align:middle line:84%
Get user ID tells
us that we currently

00:09:16.930 --> 00:09:19.720 align:middle line:84%
have root privileges,
which consequently means

00:09:19.720 --> 00:09:23.500 align:middle line:84%
that we do not need to elevate
our privileges on the target

00:09:23.500 --> 00:09:24.260 align:middle line:90%
system.

00:09:24.260 --> 00:09:30.110 align:middle line:84%
So that concludes the
practical demonstration.

00:09:30.110 --> 00:09:33.580 align:middle line:84%
All right, so that is how
to exploit a vulnerable SSH

00:09:33.580 --> 00:09:34.310 align:middle line:90%
server.

00:09:34.310 --> 00:09:36.400 align:middle line:84%
In the next video,
we will be exploring

00:09:36.400 --> 00:09:40.390 align:middle line:84%
the process of exploiting a
vulnerable SMTP server running

00:09:40.390 --> 00:09:41.690 align:middle line:90%
on a Linux target.

00:09:41.690 --> 00:09:44.370 align:middle line:90%
So I'll see you there.

00:09:44.370 --> 00:09:45.000 align:middle line:90%