WEBVTT

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


00:00:03.944 --> 00:00:07.888 align:middle line:90%
[MUSIC PLAYING]

00:00:07.888 --> 00:00:10.210 align:middle line:90%


00:00:10.210 --> 00:00:13.310 align:middle line:84%
Establishing Persistence
on Linux-- in this video,

00:00:13.310 --> 00:00:16.030 align:middle line:84%
we will be exploring the
various techniques and models

00:00:16.030 --> 00:00:20.080 align:middle line:84%
that we can utilize to establish
persistence on a Linux target

00:00:20.080 --> 00:00:23.230 align:middle line:84%
once we have gained access
and elevated our privileges.

00:00:23.230 --> 00:00:26.770 align:middle line:84%
So again, this is going to be
very similar to the Windows

00:00:26.770 --> 00:00:29.260 align:middle line:84%
video where we explored
the process of establishing

00:00:29.260 --> 00:00:30.939 align:middle line:90%
persistence on Windows.

00:00:30.939 --> 00:00:32.439 align:middle line:84%
And of course, in
this case, we will

00:00:32.439 --> 00:00:34.570 align:middle line:84%
be exploring some of
the best techniques

00:00:34.570 --> 00:00:37.780 align:middle line:84%
that you can utilize when
it comes down to, again,

00:00:37.780 --> 00:00:40.530 align:middle line:84%
ensuring that you have
persistent access on a Linux

00:00:40.530 --> 00:00:41.030 align:middle line:90%
target.

00:00:41.030 --> 00:00:43.090 align:middle line:84%
So again, persistence
essentially

00:00:43.090 --> 00:00:45.820 align:middle line:84%
consists of techniques that
adversaries or attackers

00:00:45.820 --> 00:00:49.300 align:middle line:84%
use to keep access to systems
across restarts, change

00:00:49.300 --> 00:00:51.460 align:middle line:84%
credentials, and
other interruptions

00:00:51.460 --> 00:00:53.030 align:middle line:90%
that could cut off their access.

00:00:53.030 --> 00:00:56.800 align:middle line:84%
So once we've obtained
an initial foothold

00:00:56.800 --> 00:00:59.860 align:middle line:84%
on the target system,
that's really not enough,

00:00:59.860 --> 00:01:02.620 align:middle line:84%
because at any
given point in time,

00:01:02.620 --> 00:01:04.540 align:middle line:90%
our connection could drop.

00:01:04.540 --> 00:01:07.060 align:middle line:84%
Or the credentials that
we use to gain access

00:01:07.060 --> 00:01:07.970 align:middle line:90%
could be changed.

00:01:07.970 --> 00:01:09.700 align:middle line:84%
Or the system
could be restarted,

00:01:09.700 --> 00:01:11.530 align:middle line:84%
or the system
could be shut down.

00:01:11.530 --> 00:01:15.130 align:middle line:84%
And furthermore, if we
gained access through the use

00:01:15.130 --> 00:01:18.730 align:middle line:84%
of or via exploiting a
vulnerable service and that

00:01:18.730 --> 00:01:20.650 align:middle line:84%
service is then
patched or fixed,

00:01:20.650 --> 00:01:23.260 align:middle line:84%
then that would essentially
mean that we cannot access

00:01:23.260 --> 00:01:24.050 align:middle line:90%
the system again.

00:01:24.050 --> 00:01:26.560 align:middle line:84%
So once we've got access
to a target system,

00:01:26.560 --> 00:01:28.780 align:middle line:84%
we need to ensure
that we will continue

00:01:28.780 --> 00:01:30.190 align:middle line:90%
to have access to the system.

00:01:30.190 --> 00:01:32.320 align:middle line:84%
And that, of course,
is facilitated

00:01:32.320 --> 00:01:33.670 align:middle line:90%
through persistence.

00:01:33.670 --> 00:01:37.480 align:middle line:84%
Now, the persistence
techniques that we can utilize

00:01:37.480 --> 00:01:39.670 align:middle line:84%
will depend on the
target configuration.

00:01:39.670 --> 00:01:43.930 align:middle line:84%
And this is more so in
the case of Linux targets

00:01:43.930 --> 00:01:47.260 align:middle line:84%
because when you're talking
about Linux targets,

00:01:47.260 --> 00:01:49.840 align:middle line:84%
there's going to be a
lot of configuration

00:01:49.840 --> 00:01:52.510 align:middle line:84%
differences between
Ubuntu, Debian,

00:01:52.510 --> 00:01:55.840 align:middle line:84%
as well as Red Hat,
CentOS, fedora, et cetera.

00:01:55.840 --> 00:01:59.380 align:middle line:84%
And in terms of the techniques
that we will be utilizing

00:01:59.380 --> 00:02:02.350 align:middle line:84%
or that we can
try to utilize, we

00:02:02.350 --> 00:02:05.890 align:middle line:84%
need to be very cognizant
of what distribution release

00:02:05.890 --> 00:02:08.080 align:middle line:84%
version is running
on the target as well

00:02:08.080 --> 00:02:11.750 align:middle line:84%
as important information like
the init system being used,

00:02:11.750 --> 00:02:12.850 align:middle line:90%
so on, and so forth.

00:02:12.850 --> 00:02:15.820 align:middle line:84%
So we can utilize various
post-exploitation persistence

00:02:15.820 --> 00:02:18.490 align:middle line:84%
modules to ensure that
we always have access

00:02:18.490 --> 00:02:19.450 align:middle line:90%
to the target system.

00:02:19.450 --> 00:02:22.210 align:middle line:84%
And we'll also be exploring
some manual techniques

00:02:22.210 --> 00:02:23.230 align:middle line:90%
that we can utilize.

00:02:23.230 --> 00:02:27.400 align:middle line:84%
And of course, this is primarily
in the case of Linux targets.

00:02:27.400 --> 00:02:29.853 align:middle line:84%
All right, so as for
the lab environment,

00:02:29.853 --> 00:02:32.020 align:middle line:84%
we're going to be utilizing
the same lab environment

00:02:32.020 --> 00:02:34.900 align:middle line:84%
we utilized when we were
elevating our privileges

00:02:34.900 --> 00:02:35.960 align:middle line:90%
on a Linux target.

00:02:35.960 --> 00:02:40.030 align:middle line:84%
So we'll be gaining access
via the SSH credentials.

00:02:40.030 --> 00:02:42.040 align:middle line:84%
We'll then elevate
our privileges

00:02:42.040 --> 00:02:45.400 align:middle line:84%
via the chkrootkit
vulnerability, after which we

00:02:45.400 --> 00:02:48.130 align:middle line:84%
can take a look at how
to establish persistence

00:02:48.130 --> 00:02:51.730 align:middle line:84%
on that system so that we can
have access to it whenever

00:02:51.730 --> 00:02:52.960 align:middle line:90%
we want to essentially.

00:02:52.960 --> 00:02:55.490 align:middle line:84%
So I'll start up
the lab environment.

00:02:55.490 --> 00:02:57.790 align:middle line:84%
And I'll see you within
the lab environment.

00:02:57.790 --> 00:02:58.780 align:middle line:90%
And we can get started.

00:02:58.780 --> 00:03:01.757 align:middle line:90%


00:03:01.757 --> 00:03:03.840 align:middle line:84%
All right, so I'm back
within the lab environment.

00:03:03.840 --> 00:03:06.660 align:middle line:84%
And of course, the first step
involves identifying the target

00:03:06.660 --> 00:03:07.510 align:middle line:90%
IP address.

00:03:07.510 --> 00:03:11.955 align:middle line:84%
So we can type in ifconfig, head
over to the interface ethernet

00:03:11.955 --> 00:03:13.620 align:middle line:90%
1, and we just copy this.

00:03:13.620 --> 00:03:15.810 align:middle line:84%
And of course, the
target IP is going

00:03:15.810 --> 00:03:18.640 align:middle line:84%
to be on the next IP
address within the subnet.

00:03:18.640 --> 00:03:20.410 align:middle line:84%
So it's going to
be the third IP.

00:03:20.410 --> 00:03:21.630 align:middle line:90%
So just copy that.

00:03:21.630 --> 00:03:24.900 align:middle line:84%
We will then say service
Postgresql start.

00:03:24.900 --> 00:03:27.240 align:middle line:84%
And we'll also start
up a msfconsole

00:03:27.240 --> 00:03:29.970 align:middle line:84%
as we will require the
Metasploit framework

00:03:29.970 --> 00:03:31.560 align:middle line:90%
database in this case.

00:03:31.560 --> 00:03:32.320 align:middle line:90%
So there we are.

00:03:32.320 --> 00:03:35.010 align:middle line:84%
That's going to start the
PostgreSQL database server.

00:03:35.010 --> 00:03:38.460 align:middle line:84%
It's then going to start up
msfconsole for us, after which

00:03:38.460 --> 00:03:40.110 align:middle line:90%
we can create a workspace.

00:03:40.110 --> 00:03:44.880 align:middle line:84%
And in this case, I'm just going
to call this Linux_persistence.

00:03:44.880 --> 00:03:45.510 align:middle line:90%
There we are.

00:03:45.510 --> 00:03:48.210 align:middle line:84%
And we'll set the global
variable for the RHOSTS option

00:03:48.210 --> 00:03:49.380 align:middle line:90%
to the target IP.

00:03:49.380 --> 00:03:52.710 align:middle line:84%
So again, remember to
change the 2 to a 3.

00:03:52.710 --> 00:03:54.360 align:middle line:90%
And we hit Enter.

00:03:54.360 --> 00:03:58.080 align:middle line:84%
And again, in this case, or
as we explored previously

00:03:58.080 --> 00:04:01.480 align:middle line:84%
within the Linux privilege
escalation video,

00:04:01.480 --> 00:04:03.780 align:middle line:84%
the lab documentation
already provides us

00:04:03.780 --> 00:04:06.820 align:middle line:84%
with the SSH credentials that
we can use to gain access.

00:04:06.820 --> 00:04:11.520 align:middle line:84%
So we will search for
the SSH login module.

00:04:11.520 --> 00:04:12.610 align:middle line:90%
There we are.

00:04:12.610 --> 00:04:14.530 align:middle line:90%
And we can then say use.

00:04:14.530 --> 00:04:16.050 align:middle line:90%
Paste that in there.

00:04:16.050 --> 00:04:18.660 align:middle line:84%
And the only options
that we need to specify

00:04:18.660 --> 00:04:20.190 align:middle line:84%
are the username
and the password

00:04:20.190 --> 00:04:21.399 align:middle line:90%
because we already have them.

00:04:21.399 --> 00:04:26.760 align:middle line:84%
So I'm going to say set
the username to Jackie

00:04:26.760 --> 00:04:33.580 align:middle line:84%
and set the password
to "password."

00:04:33.580 --> 00:04:36.990 align:middle line:84%
And then we can
hit Exploit or Run.

00:04:36.990 --> 00:04:40.930 align:middle line:84%
That is going to open up
a command shell for us.

00:04:40.930 --> 00:04:42.450 align:middle line:84%
So if we type in
sessions, you can

00:04:42.450 --> 00:04:45.330 align:middle line:84%
see that we get a command
shell with the credentials we

00:04:45.330 --> 00:04:45.870 align:middle line:90%
specified.

00:04:45.870 --> 00:04:48.510 align:middle line:84%
We can upgrade that session
into an meterpreter session

00:04:48.510 --> 00:04:51.780 align:middle line:84%
by saying sessions upgrade
and then specifying

00:04:51.780 --> 00:04:53.110 align:middle line:90%
the actual session ID.

00:04:53.110 --> 00:04:54.600 align:middle line:90%
So we hit Enter.

00:04:54.600 --> 00:04:56.550 align:middle line:84%
That's going to give us
a meterpreter session.

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

00:04:58.005 --> 00:05:03.428 align:middle line:90%


00:05:03.428 --> 00:05:05.220 align:middle line:84%
All right, so we get
a meterpreter session.

00:05:05.220 --> 00:05:07.980 align:middle line:84%
And that's going
to be sessions 2.

00:05:07.980 --> 00:05:10.080 align:middle line:84%
And the privileges
that we obtained

00:05:10.080 --> 00:05:12.660 align:middle line:84%
are still going to
be the user Jackie.

00:05:12.660 --> 00:05:14.530 align:middle line:84%
So we need to elevate
our privileges.

00:05:14.530 --> 00:05:16.710 align:middle line:84%
And of course, we have
explored the process

00:05:16.710 --> 00:05:19.350 align:middle line:84%
of elevating our privileges
within this lab environment.

00:05:19.350 --> 00:05:23.760 align:middle line:84%
And that is via the
chkrootkit utility.

00:05:23.760 --> 00:05:26.760 align:middle line:84%
And primarily, what we're
going to be doing is exploiting

00:05:26.760 --> 00:05:30.210 align:middle line:84%
a vulnerability within
chkrootkit 0.49,

00:05:30.210 --> 00:05:33.600 align:middle line:90%
or versions prior to 0.50.

00:05:33.600 --> 00:05:38.730 align:middle line:84%
OK, so what we'll do is we
will search for chkrootkit.

00:05:38.730 --> 00:05:40.140 align:middle line:90%
And we'll hit Enter.

00:05:40.140 --> 00:05:42.250 align:middle line:84%
And of course, this is the
module right over here.

00:05:42.250 --> 00:05:43.320 align:middle line:90%
So we'll say use.

00:05:43.320 --> 00:05:44.790 align:middle line:90%
Paste that in there.

00:05:44.790 --> 00:05:45.765 align:middle line:90%
Show the options.

00:05:45.765 --> 00:05:48.580 align:middle line:90%


00:05:48.580 --> 00:05:51.310 align:middle line:84%
And we will set the
session to session 2.

00:05:51.310 --> 00:05:54.850 align:middle line:84%
And we also need to set
the path, the actual path,

00:05:54.850 --> 00:05:58.210 align:middle line:84%
to chkrootkit by
saying set chkrootkit.

00:05:58.210 --> 00:05:59.770 align:middle line:90%
And we'll say /bin/chkrootkit.

00:05:59.770 --> 00:06:02.650 align:middle line:90%


00:06:02.650 --> 00:06:05.060 align:middle line:84%
We can then, of course,
set the payload options.

00:06:05.060 --> 00:06:07.520 align:middle line:84%
And if we just hit
Exploit, for example,

00:06:07.520 --> 00:06:10.000 align:middle line:84%
you can see that that
will start up on--

00:06:10.000 --> 00:06:12.610 align:middle line:84%
it'll actually provide
us with the ability

00:06:12.610 --> 00:06:14.750 align:middle line:90%
to modify the payload options.

00:06:14.750 --> 00:06:18.100 align:middle line:84%
So the default payload is
the CMD Unix reverse payload.

00:06:18.100 --> 00:06:20.450 align:middle line:90%
We can set the LHOST option.

00:06:20.450 --> 00:06:23.740 align:middle line:84%
So I'll say ifconfig, and we'll
copy our IP address there.

00:06:23.740 --> 00:06:28.510 align:middle line:84%
And we'll say set LHOST
to the value of Ethernet 1

00:06:28.510 --> 00:06:31.510 align:middle line:84%
or the actual IP on the
Ethernet 1 interface.

00:06:31.510 --> 00:06:34.250 align:middle line:84%
If we show the
options again here,

00:06:34.250 --> 00:06:36.430 align:middle line:84%
you can see we also can
configure the LPORT.

00:06:36.430 --> 00:06:38.890 align:middle line:84%
So we list out our
sessions just to make sure

00:06:38.890 --> 00:06:41.320 align:middle line:84%
that we actually
aren't conflicting

00:06:41.320 --> 00:06:43.210 align:middle line:90%
with any other sessions.

00:06:43.210 --> 00:06:49.000 align:middle line:84%
You can see that these sessions
are not utilizing port 4444.

00:06:49.000 --> 00:06:49.910 align:middle line:90%
So that's good.

00:06:49.910 --> 00:06:52.250 align:middle line:90%
So we can hit Exploit.

00:06:52.250 --> 00:06:55.300 align:middle line:84%
And that's going to take a few
seconds to probably a couple

00:06:55.300 --> 00:06:58.060 align:middle line:84%
of minutes because it's going
to wait for the cron job

00:06:58.060 --> 00:07:00.970 align:middle line:84%
to execute which will
consequently give us a command

00:07:00.970 --> 00:07:04.000 align:middle line:84%
shell, which we can then upgrade
to an meterpreter session.

00:07:04.000 --> 00:07:05.440 align:middle line:84%
So we'll give this
a few seconds.

00:07:05.440 --> 00:07:07.853 align:middle line:90%


00:07:07.853 --> 00:07:09.270 align:middle line:84%
All right, so after
a few seconds,

00:07:09.270 --> 00:07:11.430 align:middle line:90%
we get the command session here.

00:07:11.430 --> 00:07:13.830 align:middle line:84%
And of course, we can cat
out the contents of the flag,

00:07:13.830 --> 00:07:16.480 align:middle line:84%
but that really isn't
necessary at this point.

00:07:16.480 --> 00:07:19.000 align:middle line:84%
What we'll do is we'll put
this in the background.

00:07:19.000 --> 00:07:20.700 align:middle line:84%
And if we list out
our sessions, we

00:07:20.700 --> 00:07:22.530 align:middle line:84%
want to upgrade
session 3, which is

00:07:22.530 --> 00:07:25.680 align:middle line:84%
privileged, or that we currently
have access to as the root

00:07:25.680 --> 00:07:26.310 align:middle line:90%
user.

00:07:26.310 --> 00:07:30.000 align:middle line:90%
We will say sessions 3.

00:07:30.000 --> 00:07:31.360 align:middle line:90%
We want to upgrade that.

00:07:31.360 --> 00:07:33.570 align:middle line:90%
So we'll say sessions upgrade 3.

00:07:33.570 --> 00:07:35.940 align:middle line:84%
And that'll give us
a meterpreter session

00:07:35.940 --> 00:07:37.110 align:middle line:90%
with root privileges.

00:07:37.110 --> 00:07:39.840 align:middle line:84%
So we'll give that a
couple of seconds as well.

00:07:39.840 --> 00:07:40.560 align:middle line:90%
There we are.

00:07:40.560 --> 00:07:42.330 align:middle line:90%
meterpreter session 4 opened.

00:07:42.330 --> 00:07:43.500 align:middle line:90%
So we say sessions.

00:07:43.500 --> 00:07:46.050 align:middle line:84%
You can see that we have
two meterpreter sessions.

00:07:46.050 --> 00:07:48.870 align:middle line:84%
One of them is utilizing
the user Jackie,

00:07:48.870 --> 00:07:51.600 align:middle line:84%
or one has access as
the user Jackie, which

00:07:51.600 --> 00:07:53.520 align:middle line:90%
is an unprivileged user.

00:07:53.520 --> 00:07:56.620 align:middle line:84%
We then have the
meterpreter session 4 here,

00:07:56.620 --> 00:08:00.540 align:middle line:84%
which has access with the root
user or has root privileges.

00:08:00.540 --> 00:08:04.380 align:middle line:84%
So if we say sessions 4
and we say get user ID,

00:08:04.380 --> 00:08:06.180 align:middle line:84%
you can see we are
currently the root user.

00:08:06.180 --> 00:08:09.480 align:middle line:84%
And that, of course, we
actually determine that

00:08:09.480 --> 00:08:11.505 align:middle line:84%
through the user ID,
which is set to 0.

00:08:11.505 --> 00:08:16.140 align:middle line:84%
Of course, we can say shell
and then /bin/bash -i.

00:08:16.140 --> 00:08:18.352 align:middle line:84%
And if we say
whoami, you can see

00:08:18.352 --> 00:08:19.560 align:middle line:90%
we are currently root, right?

00:08:19.560 --> 00:08:22.950 align:middle line:84%
So in order to essentially
establish persistence

00:08:22.950 --> 00:08:25.530 align:middle line:84%
or in order to utilize some
of the persistence modules

00:08:25.530 --> 00:08:29.160 align:middle line:84%
for Linux, you will require
root privileges in most cases.

00:08:29.160 --> 00:08:31.410 align:middle line:90%
OK, so we can put this.

00:08:31.410 --> 00:08:32.820 align:middle line:90%
We can terminate that.

00:08:32.820 --> 00:08:36.480 align:middle line:84%
And we can head back into
our meterpreter session.

00:08:36.480 --> 00:08:38.490 align:middle line:84%
The first technique we
are going to be exploring

00:08:38.490 --> 00:08:39.690 align:middle line:90%
is a manual technique.

00:08:39.690 --> 00:08:41.909 align:middle line:84%
And it is the technique
or the process

00:08:41.909 --> 00:08:45.900 align:middle line:84%
of creating a backdoor user
that can provide us with access

00:08:45.900 --> 00:08:47.700 align:middle line:90%
whenever we require it, right?

00:08:47.700 --> 00:08:52.410 align:middle line:84%
Now, this will only work if
the target server is running

00:08:52.410 --> 00:08:56.520 align:middle line:84%
SSH or a remote access protocol
that can provide us with access

00:08:56.520 --> 00:08:58.050 align:middle line:90%
whenever we need access.

00:08:58.050 --> 00:09:01.410 align:middle line:84%
Consequently, the
protocol should also

00:09:01.410 --> 00:09:04.170 align:middle line:84%
be able to provide
us access, primarily

00:09:04.170 --> 00:09:05.920 align:middle line:90%
through a username and password.

00:09:05.920 --> 00:09:08.250 align:middle line:84%
So in order to create
a backdoor user,

00:09:08.250 --> 00:09:10.260 align:middle line:84%
we can open up a
shell session here.

00:09:10.260 --> 00:09:13.080 align:middle line:84%
And I'm just going
to say /bin/bash -i.

00:09:13.080 --> 00:09:14.890 align:middle line:84%
And we currently
have root privileges.

00:09:14.890 --> 00:09:17.170 align:middle line:84%
And we list out the current
users on the system.

00:09:17.170 --> 00:09:21.470 align:middle line:84%
So if I say cat /etc/password,
you can see that we have

00:09:21.470 --> 00:09:22.340 align:middle line:90%
the user Jackie.

00:09:22.340 --> 00:09:24.140 align:middle line:90%
We also have the user root here.

00:09:24.140 --> 00:09:26.330 align:middle line:84%
And the rest of them
are service accounts.

00:09:26.330 --> 00:09:29.150 align:middle line:84%
Now, when it comes down to
creating a backdoor user,

00:09:29.150 --> 00:09:31.640 align:middle line:84%
the first thing that you need
to take into consideration

00:09:31.640 --> 00:09:34.850 align:middle line:84%
is the fact that the
user should not or should

00:09:34.850 --> 00:09:38.430 align:middle line:84%
be as clandestine as
possible and should blend in.

00:09:38.430 --> 00:09:40.460 align:middle line:84%
So what I would
typically recommend

00:09:40.460 --> 00:09:43.700 align:middle line:84%
is actually providing the user
name or the account username

00:09:43.700 --> 00:09:47.360 align:middle line:84%
as something as a
name that is really

00:09:47.360 --> 00:09:49.590 align:middle line:90%
very difficult to identify.

00:09:49.590 --> 00:09:52.700 align:middle line:84%
So what you don't want to do
is create a user or a backdoor

00:09:52.700 --> 00:09:55.760 align:middle line:84%
user with the username
set to act or backdoor

00:09:55.760 --> 00:09:58.250 align:middle line:84%
access or backdoor or
anything like that.

00:09:58.250 --> 00:10:00.080 align:middle line:84%
What I would recommend
doing is creating

00:10:00.080 --> 00:10:03.660 align:middle line:84%
a user account that sort of
looks like a service account,

00:10:03.660 --> 00:10:04.160 align:middle line:90%
right?

00:10:04.160 --> 00:10:07.790 align:middle line:84%
So what we can do in this
case is we can say useradd.

00:10:07.790 --> 00:10:09.950 align:middle line:84%
And we can create
a home directory

00:10:09.950 --> 00:10:13.850 align:middle line:84%
because I'll also be exploring
the technique of creating

00:10:13.850 --> 00:10:18.350 align:middle line:84%
or setting up a SSH key so that
we can authenticate to the root

00:10:18.350 --> 00:10:20.990 align:middle line:84%
user as well as other users
without providing a password.

00:10:20.990 --> 00:10:23.030 align:middle line:90%
So I can say useradd -m.

00:10:23.030 --> 00:10:25.370 align:middle line:84%
And we'll just call
this user FTP, right?

00:10:25.370 --> 00:10:29.270 align:middle line:84%
So we can make the account look
like the FTP service account.

00:10:29.270 --> 00:10:31.490 align:middle line:84%
And again, make
sure that an account

00:10:31.490 --> 00:10:33.120 align:middle line:90%
called FTP doesn't exist.

00:10:33.120 --> 00:10:34.590 align:middle line:90%
And in this case, it doesn't.

00:10:34.590 --> 00:10:37.160 align:middle line:84%
And then we can specify
the shell as bin/bash.

00:10:37.160 --> 00:10:38.750 align:middle line:84%
Now, if you're
utilizing or if you're

00:10:38.750 --> 00:10:41.000 align:middle line:84%
trying to make it as
clandestine as possible,

00:10:41.000 --> 00:10:43.460 align:middle line:84%
then you probably want to
set the actual terminal

00:10:43.460 --> 00:10:46.580 align:middle line:84%
session or the actual
terminal for that user account

00:10:46.580 --> 00:10:52.970 align:middle line:84%
as user/sbin/nologin, because
that's primarily how service

00:10:52.970 --> 00:10:54.080 align:middle line:90%
accounts are configured.

00:10:54.080 --> 00:10:57.200 align:middle line:84%
And of course, we can also
specify the actual home

00:10:57.200 --> 00:11:00.870 align:middle line:84%
directory for this
particular account.

00:11:00.870 --> 00:11:03.590 align:middle line:84%
But in this case, we'll
leave it as the default.

00:11:03.590 --> 00:11:06.710 align:middle line:84%
And again, you can
also say useradd -m.

00:11:06.710 --> 00:11:08.450 align:middle line:84%
So that's to create
the home directory.

00:11:08.450 --> 00:11:11.240 align:middle line:84%
And then we can either
say the home directory is

00:11:11.240 --> 00:11:14.300 align:middle line:90%
in /var/www/HTML, for example.

00:11:14.300 --> 00:11:16.430 align:middle line:84%
And that makes sense
in the case of FTP.

00:11:16.430 --> 00:11:18.650 align:middle line:90%
So we can say useradd -m.

00:11:18.650 --> 00:11:20.420 align:middle line:90%
We'll just call the user FTP.

00:11:20.420 --> 00:11:24.020 align:middle line:84%
And then the shell, in this
case, we'll just say bin/bash.

00:11:24.020 --> 00:11:24.962 align:middle line:90%
And we hit Enter.

00:11:24.962 --> 00:11:26.420 align:middle line:84%
So that's going to
create the user.

00:11:26.420 --> 00:11:32.210 align:middle line:84%
We can then say passwd FTP to
create a password for the user.

00:11:32.210 --> 00:11:34.965 align:middle line:84%
And we'll say password123
just to keep things simple.

00:11:34.965 --> 00:11:37.340 align:middle line:84%
Of course, I would recommend
using something a little bit

00:11:37.340 --> 00:11:38.720 align:middle line:90%
more complex than that.

00:11:38.720 --> 00:11:39.750 align:middle line:90%
And we hit Enter.

00:11:39.750 --> 00:11:42.830 align:middle line:84%
And now if we say
cat /etc/passwd,

00:11:42.830 --> 00:11:44.900 align:middle line:84%
you can see that we have
the FTP account here.

00:11:44.900 --> 00:11:47.390 align:middle line:84%
And it actually looks
like a service account.

00:11:47.390 --> 00:11:49.800 align:middle line:90%
And it blends in quite well.

00:11:49.800 --> 00:11:52.130 align:middle line:84%
Now, the other thing that
I would recommend doing

00:11:52.130 --> 00:11:54.770 align:middle line:84%
is actually providing
the FTP user account

00:11:54.770 --> 00:11:56.900 align:middle line:84%
with administrative
or root privileges.

00:11:56.900 --> 00:11:59.000 align:middle line:84%
Right now, if I
list all the groups

00:11:59.000 --> 00:12:00.950 align:middle line:84%
that the root user
is a part of, you

00:12:00.950 --> 00:12:02.540 align:middle line:84%
can see it's part
of the root group.

00:12:02.540 --> 00:12:06.080 align:middle line:84%
So if we add the FTP
account into the root group,

00:12:06.080 --> 00:12:08.540 align:middle line:84%
then it will inherit the
permissions associated

00:12:08.540 --> 00:12:10.520 align:middle line:84%
with the root group,
which pretty much gives us

00:12:10.520 --> 00:12:11.570 align:middle line:90%
a root access, right?

00:12:11.570 --> 00:12:17.370 align:middle line:84%
So we can say usermod
add group, and then we

00:12:17.370 --> 00:12:19.230 align:middle line:84%
say root and then
the account that we

00:12:19.230 --> 00:12:21.330 align:middle line:84%
want to add to the
actual root group.

00:12:21.330 --> 00:12:23.190 align:middle line:90%
In this case, we'll say FTP.

00:12:23.190 --> 00:12:24.030 align:middle line:90%
We hit Enter.

00:12:24.030 --> 00:12:27.390 align:middle line:84%
And now if we say
groups FTP, we can

00:12:27.390 --> 00:12:29.620 align:middle line:84%
see that FTP is part
of the root group.

00:12:29.620 --> 00:12:32.820 align:middle line:84%
So what we can do now
in this particular case

00:12:32.820 --> 00:12:36.750 align:middle line:84%
is utilize this backdoor user
to essentially authenticate

00:12:36.750 --> 00:12:39.360 align:middle line:84%
legitimately to the
target system via SSH

00:12:39.360 --> 00:12:42.020 align:middle line:84%
whenever we need to gain
access to the target system.

00:12:42.020 --> 00:12:44.520 align:middle line:84%
And of course, we're going to
have administrative privileges

00:12:44.520 --> 00:12:48.460 align:middle line:84%
because we've just added the
user account to the actual root

00:12:48.460 --> 00:12:48.960 align:middle line:90%
group.

00:12:48.960 --> 00:12:51.090 align:middle line:84%
All right, so that's
one manual technique

00:12:51.090 --> 00:12:52.740 align:middle line:90%
that I would really recommend.

00:12:52.740 --> 00:12:54.990 align:middle line:84%
Now, of course, there's
plenty of other techniques

00:12:54.990 --> 00:12:57.660 align:middle line:84%
that you can explore that we can
also take a look at right now,

00:12:57.660 --> 00:13:01.080 align:middle line:84%
like the process of creating
a persistent service or a cron

00:13:01.080 --> 00:13:03.570 align:middle line:84%
job, or my personal
favorite, which

00:13:03.570 --> 00:13:07.350 align:middle line:84%
is adding an SSH key
to the actual SSH

00:13:07.350 --> 00:13:10.920 align:middle line:84%
directory within the user's
home directory for the user

00:13:10.920 --> 00:13:15.240 align:middle line:84%
accounts, like the root user
as well as Jackie or FTP.

00:13:15.240 --> 00:13:19.320 align:middle line:84%
You can also modify the
backdoor user's user ID

00:13:19.320 --> 00:13:22.080 align:middle line:84%
to make it look like
it just wasn't created

00:13:22.080 --> 00:13:25.470 align:middle line:84%
or that it just was created a
few seconds or a few minutes

00:13:25.470 --> 00:13:28.860 align:middle line:84%
ago or recently, because you
can see that the accounts that

00:13:28.860 --> 00:13:32.760 align:middle line:84%
have just been created will
get a user ID right over here.

00:13:32.760 --> 00:13:34.440 align:middle line:84%
That, of course,
reflects the fact

00:13:34.440 --> 00:13:38.400 align:middle line:84%
that it was actually
created the most recently

00:13:38.400 --> 00:13:40.470 align:middle line:84%
or was actually
created recently.

00:13:40.470 --> 00:13:44.040 align:middle line:84%
So in order to do this, we can
say usermod and then specify

00:13:44.040 --> 00:13:45.460 align:middle line:90%
the user ID that we want.

00:13:45.460 --> 00:13:48.420 align:middle line:84%
And in this case, we can
say maybe a user ID like 15

00:13:48.420 --> 00:13:50.310 align:middle line:84%
and then specify
the account name.

00:13:50.310 --> 00:13:57.310 align:middle line:84%
And now if we say you
know cat /etc/passwd,

00:13:57.310 --> 00:14:00.160 align:middle line:84%
you can see that it now
has the use ID of 15.

00:14:00.160 --> 00:14:03.490 align:middle line:84%
And then, of course, we
can modify the actual group

00:14:03.490 --> 00:14:06.730 align:middle line:84%
that it belongs to or
the actual group ID to,

00:14:06.730 --> 00:14:07.730 align:middle line:90%
of course, reflect that.

00:14:07.730 --> 00:14:10.147 align:middle line:84%
But in this case, we're really
not going to get into that.

00:14:10.147 --> 00:14:11.680 align:middle line:84%
But again, the
whole objective here

00:14:11.680 --> 00:14:16.000 align:middle line:84%
is to make the user account
look as clandestine as possible

00:14:16.000 --> 00:14:17.830 align:middle line:90%
in order to avoid detection.

00:14:17.830 --> 00:14:20.500 align:middle line:84%
All right, so let's take a
look at some of the persistence

00:14:20.500 --> 00:14:22.930 align:middle line:84%
modules that we can
use for Linux targets.

00:14:22.930 --> 00:14:25.390 align:middle line:84%
So I'm just going to
terminate this channel.

00:14:25.390 --> 00:14:26.950 align:middle line:84%
And I'm going to
put the meterpreter

00:14:26.950 --> 00:14:28.390 align:middle line:90%
session in the background.

00:14:28.390 --> 00:14:30.040 align:middle line:90%
And we can then say search.

00:14:30.040 --> 00:14:33.070 align:middle line:84%
And the platform, in
this case, is Linux.

00:14:33.070 --> 00:14:35.530 align:middle line:84%
And then we can just
say persistence.

00:14:35.530 --> 00:14:38.320 align:middle line:84%
All right, so you can see that
we have quite a few persistence

00:14:38.320 --> 00:14:38.890 align:middle line:90%
modules.

00:14:38.890 --> 00:14:42.820 align:middle line:84%
And they all utilize or
leverage various elements

00:14:42.820 --> 00:14:46.090 align:middle line:84%
or various features
within the Linux operating

00:14:46.090 --> 00:14:49.520 align:middle line:84%
system or the Linux kernel in
order to establish persistence.

00:14:49.520 --> 00:14:52.120 align:middle line:84%
So you can see you have
persistence via the Aptitude

00:14:52.120 --> 00:14:53.140 align:middle line:90%
Package Manager.

00:14:53.140 --> 00:14:54.318 align:middle line:90%
So we can try that out.

00:14:54.318 --> 00:14:56.860 align:middle line:84%
And of course, I'm not going to
be going through all of them.

00:14:56.860 --> 00:14:59.230 align:middle line:84%
As I said, it
really is important

00:14:59.230 --> 00:15:01.750 align:middle line:84%
that you, again, test
them and understand

00:15:01.750 --> 00:15:03.250 align:middle line:90%
how your target is configured.

00:15:03.250 --> 00:15:06.760 align:middle line:84%
So we can copy that,
and we can say use

00:15:06.760 --> 00:15:08.240 align:middle line:90%
and paste that in there.

00:15:08.240 --> 00:15:09.800 align:middle line:90%
Show options here.

00:15:09.800 --> 00:15:12.190 align:middle line:84%
And in this case, what
we'll need to configure

00:15:12.190 --> 00:15:14.080 align:middle line:90%
is the actual session ID.

00:15:14.080 --> 00:15:17.750 align:middle line:84%
We can also specify the
HOOKNAME and the backdoor name,

00:15:17.750 --> 00:15:19.810 align:middle line:84%
which is the name of
the binary to write.

00:15:19.810 --> 00:15:22.730 align:middle line:84%
And in order to learn more
about this particular module,

00:15:22.730 --> 00:15:23.753 align:middle line:90%
we can type in info.

00:15:23.753 --> 00:15:25.420 align:middle line:84%
And as you can see,
it says "this module

00:15:25.420 --> 00:15:28.570 align:middle line:84%
will run a payload when the
package manager is used.

00:15:28.570 --> 00:15:30.820 align:middle line:84%
No handler is run
automatically, so you

00:15:30.820 --> 00:15:34.300 align:middle line:84%
must configure an appropriate
exploit handler or multi

00:15:34.300 --> 00:15:35.410 align:middle line:90%
handler to connect."

00:15:35.410 --> 00:15:38.110 align:middle line:84%
Now, as I said, this is really
not what we're looking for.

00:15:38.110 --> 00:15:40.720 align:middle line:84%
Because, again, we always
want to have access

00:15:40.720 --> 00:15:41.650 align:middle line:90%
to the target system.

00:15:41.650 --> 00:15:45.520 align:middle line:84%
And we don't want to rely on
instances or situations that

00:15:45.520 --> 00:15:49.210 align:middle line:84%
involve the execution
of elements or utilities

00:15:49.210 --> 00:15:50.320 align:middle line:90%
like the package manager.

00:15:50.320 --> 00:15:53.390 align:middle line:84%
So I'm not going to be utilizing
this particular module.

00:15:53.390 --> 00:15:56.110 align:middle line:84%
So we can say search
and again list out

00:15:56.110 --> 00:15:57.880 align:middle line:90%
the assistance modules.

00:15:57.880 --> 00:15:59.740 align:middle line:84%
The one that I
recommend testing out

00:15:59.740 --> 00:16:02.530 align:middle line:84%
is going to be the cron
persistence module, which

00:16:02.530 --> 00:16:05.860 align:middle line:84%
allows you to set up a cron job
that, again, will continuously

00:16:05.860 --> 00:16:07.390 align:middle line:90%
connect to your handler.

00:16:07.390 --> 00:16:09.950 align:middle line:84%
And of course, again, this
is entirely up to you.

00:16:09.950 --> 00:16:14.500 align:middle line:84%
But in my case, this is probably
my second recommended module,

00:16:14.500 --> 00:16:17.140 align:middle line:84%
primarily because
cron jobs can easily

00:16:17.140 --> 00:16:19.400 align:middle line:84%
be detected by
administrators on the system.

00:16:19.400 --> 00:16:21.400 align:middle line:84%
And if it looks
suspicious, then of course,

00:16:21.400 --> 00:16:22.930 align:middle line:84%
they can get rid
of that cron job.

00:16:22.930 --> 00:16:26.350 align:middle line:84%
And it may, of course,
indicate compromise.

00:16:26.350 --> 00:16:28.120 align:middle line:84%
Or it may be an
indicator of compromise.

00:16:28.120 --> 00:16:30.670 align:middle line:84%
So you want to be
very, very assured

00:16:30.670 --> 00:16:33.940 align:middle line:84%
of what module you're
using and the effects

00:16:33.940 --> 00:16:35.410 align:middle line:84%
and artifacts that
it'll actually

00:16:35.410 --> 00:16:36.860 align:middle line:90%
leave on the target system.

00:16:36.860 --> 00:16:40.840 align:middle line:84%
So if I say show options,
you can set the timing.

00:16:40.840 --> 00:16:42.850 align:middle line:84%
And in this case, the
default timing option

00:16:42.850 --> 00:16:48.280 align:middle line:84%
is set to be executed every 60
seconds, or every one minute.

00:16:48.280 --> 00:16:50.830 align:middle line:84%
And then of course, we can
set the session as well as

00:16:50.830 --> 00:16:53.540 align:middle line:84%
the username to run the
cron or cron job as.

00:16:53.540 --> 00:16:55.990 align:middle line:84%
So I'm going to say
set session to 4.

00:16:55.990 --> 00:16:58.240 align:middle line:84%
And we can then
hit Run or Exploit.

00:16:58.240 --> 00:16:59.890 align:middle line:90%
We're going to hit Enter.

00:16:59.890 --> 00:17:03.850 align:middle line:84%
And in this case, it says a
fail to open /etc/cron.allow,

00:17:03.850 --> 00:17:07.010 align:middle line:84%
/etc/cron.deny, et
cetera, et cetera.

00:17:07.010 --> 00:17:10.000 align:middle line:84%
And then it says waiting
90 seconds for execution.

00:17:10.000 --> 00:17:12.849 align:middle line:84%
All right, now if we terminate
that and show the options

00:17:12.849 --> 00:17:16.300 align:middle line:84%
in order to take a look at
what payload is being used,

00:17:16.300 --> 00:17:18.550 align:middle line:84%
you can see that the payload
being used in this case

00:17:18.550 --> 00:17:20.500 align:middle line:90%
is CMD Unix reverse Perl.

00:17:20.500 --> 00:17:22.930 align:middle line:84%
And if we list out our
sessions, what we can do

00:17:22.930 --> 00:17:25.730 align:middle line:84%
is make sure that there isn't
a conflicting LPORT here.

00:17:25.730 --> 00:17:28.960 align:middle line:84%
So we'll say LPORT
is 4422 because it's

00:17:28.960 --> 00:17:31.060 align:middle line:84%
conflicting with
our command shell.

00:17:31.060 --> 00:17:35.680 align:middle line:84%
And we'll set the LHOST
to the IP on Ethernet 1.

00:17:35.680 --> 00:17:37.210 align:middle line:90%
So I'll say set LHOST.

00:17:37.210 --> 00:17:40.860 align:middle line:90%


00:17:40.860 --> 00:17:42.180 align:middle line:90%
And then we can hit Exploit.

00:17:42.180 --> 00:17:43.640 align:middle line:84%
And let's see
whether this works.

00:17:43.640 --> 00:17:46.710 align:middle line:84%
Now as I said, this is not a
guaranteed in terms of Linux.

00:17:46.710 --> 00:17:48.600 align:middle line:84%
On Windows, you have
a better chance,

00:17:48.600 --> 00:17:51.210 align:middle line:84%
or you have actually a
greater chance of success.

00:17:51.210 --> 00:17:54.300 align:middle line:84%
Because, again, Windows
systems are fairly similar in

00:17:54.300 --> 00:17:56.070 align:middle line:84%
regards to the
persistence techniques

00:17:56.070 --> 00:17:57.330 align:middle line:90%
that you can utilize.

00:17:57.330 --> 00:18:00.900 align:middle line:84%
However, with Linux,
cron jobs, or you

00:18:00.900 --> 00:18:03.870 align:middle line:84%
may not have access to
the actual crontab file.

00:18:03.870 --> 00:18:06.930 align:middle line:84%
As I said, you also want
to be wary of the fact

00:18:06.930 --> 00:18:09.670 align:middle line:84%
that this could be
detected quite easily.

00:18:09.670 --> 00:18:12.188 align:middle line:90%
So let's see if this does work.

00:18:12.188 --> 00:18:13.980 align:middle line:84%
I'm just going to wait
for about 90 seconds

00:18:13.980 --> 00:18:17.920 align:middle line:84%
to see whether it'll actually
execute the Cron job.

00:18:17.920 --> 00:18:19.960 align:middle line:84%
All right, so after
about 90 seconds,

00:18:19.960 --> 00:18:23.560 align:middle line:84%
it looks like the actual payload
or the module doesn't work.

00:18:23.560 --> 00:18:25.510 align:middle line:84%
And it says removing
the cron entry from

00:18:25.510 --> 00:18:28.360 align:middle line:90%
/var/spool/cron/crontabs/root.

00:18:28.360 --> 00:18:31.802 align:middle line:84%
And of course, we can
also test this out.

00:18:31.802 --> 00:18:33.760 align:middle line:84%
But in this case, it
looks like it didn't work.

00:18:33.760 --> 00:18:36.640 align:middle line:84%
So I will need to take a look
at some of the other persistence

00:18:36.640 --> 00:18:37.720 align:middle line:90%
modules that we can use.

00:18:37.720 --> 00:18:40.580 align:middle line:84%
Now, as I said, this may
work on a different target.

00:18:40.580 --> 00:18:42.290 align:middle line:84%
But in this case,
it didn't work.

00:18:42.290 --> 00:18:44.350 align:middle line:84%
And it's very important
that you understand

00:18:44.350 --> 00:18:47.975 align:middle line:84%
how to utilize the other modules
or rather the other techniques.

00:18:47.975 --> 00:18:50.350 align:middle line:84%
All right, the other one that
we're going to be exploring

00:18:50.350 --> 00:18:53.020 align:middle line:84%
is similar to the Windows
technique or the Windows module

00:18:53.020 --> 00:18:55.988 align:middle line:84%
that we used, which is
through a persistent service.

00:18:55.988 --> 00:18:57.280 align:middle line:90%
So I'm just going to copy that.

00:18:57.280 --> 00:18:58.810 align:middle line:90%
And we're going to say use.

00:18:58.810 --> 00:18:59.890 align:middle line:90%
Paste that in there.

00:18:59.890 --> 00:19:02.240 align:middle line:90%
Show the options.

00:19:02.240 --> 00:19:06.390 align:middle line:84%
And we can specify the actual
shell path, which in this case,

00:19:06.390 --> 00:19:09.260 align:middle line:84%
we know the shell path is
probably under /usr/local/bin

00:19:09.260 --> 00:19:10.760 align:middle line:90%
or /usr/bin.

00:19:10.760 --> 00:19:12.055 align:middle line:90%
So we'll leave that as is.

00:19:12.055 --> 00:19:14.180 align:middle line:84%
And then you can specify
the name of the shell file

00:19:14.180 --> 00:19:17.690 align:middle line:84%
to write, and then we can
specify the actual session.

00:19:17.690 --> 00:19:23.000 align:middle line:84%
So I'm going to say
set session to 4.

00:19:23.000 --> 00:19:24.320 align:middle line:90%
And then we hit Exploit.

00:19:24.320 --> 00:19:26.970 align:middle line:84%
And it'll probably tell us that
we haven't selected a payload.

00:19:26.970 --> 00:19:28.550 align:middle line:90%
So we'll say set payload.

00:19:28.550 --> 00:19:30.680 align:middle line:84%
And we can use the
Tab auto completion

00:19:30.680 --> 00:19:33.350 align:middle line:84%
feature to specify the
payloads that we can actually

00:19:33.350 --> 00:19:34.550 align:middle line:90%
use in this case.

00:19:34.550 --> 00:19:38.720 align:middle line:84%
So we can utilize CMD Unix
bind netcat reverse net cat

00:19:38.720 --> 00:19:41.790 align:middle line:84%
or reverse Python,
reverse Python SSL.

00:19:41.790 --> 00:19:47.130 align:middle line:84%
So let's try out the
reverse Python payload here.

00:19:47.130 --> 00:19:51.380 align:middle line:84%
And if we show the
options, you can

00:19:51.380 --> 00:19:55.210 align:middle line:84%
see that we need to set up the
actual LHOST and LPORT options.

00:19:55.210 --> 00:19:58.910 align:middle line:84%
So I'm just going to say set
LHOST or the LPORT option

00:19:58.910 --> 00:20:02.180 align:middle line:84%
to actually the other port
that we identified that was

00:20:02.180 --> 00:20:04.700 align:middle line:90%
currently open, which is 4422.

00:20:04.700 --> 00:20:08.350 align:middle line:90%
And we're going to hit Exploit.

00:20:08.350 --> 00:20:10.600 align:middle line:84%
All right, so as you can
see, this fails here.

00:20:10.600 --> 00:20:13.450 align:middle line:84%
This particular module,
if we type in info,

00:20:13.450 --> 00:20:15.970 align:middle line:84%
will essentially try and
create a service on the box

00:20:15.970 --> 00:20:17.790 align:middle line:90%
and mark it for auto-restart.

00:20:17.790 --> 00:20:20.410 align:middle line:84%
We need enough access to
write these service files

00:20:20.410 --> 00:20:22.840 align:middle line:84%
and potentially
restart services.

00:20:22.840 --> 00:20:25.540 align:middle line:84%
The target init systems
or the init systems

00:20:25.540 --> 00:20:29.260 align:middle line:84%
that this will work on are
System V and also systemd.

00:20:29.260 --> 00:20:31.270 align:middle line:84%
And then it provides
you the actual versions

00:20:31.270 --> 00:20:34.370 align:middle line:84%
of these distributions that
this will actually work on.

00:20:34.370 --> 00:20:38.260 align:middle line:84%
So in our case, the system
is running Ubuntu 18.04.

00:20:38.260 --> 00:20:40.030 align:middle line:84%
And in this case,
as you can see,

00:20:40.030 --> 00:20:44.350 align:middle line:84%
the only versions you
can see supported here

00:20:44.350 --> 00:20:50.350 align:middle line:84%
are Ubuntu 15, anything greater
than or equal to Ubuntu 15.04.

00:20:50.350 --> 00:20:52.690 align:middle line:84%
However, in this
case, it didn't work.

00:20:52.690 --> 00:20:55.720 align:middle line:84%
All right, so again,
these are the init systems

00:20:55.720 --> 00:20:57.290 align:middle line:90%
that it will try and use.

00:20:57.290 --> 00:21:02.650 align:middle line:84%
So we can also say
set target to systemd.

00:21:02.650 --> 00:21:04.525 align:middle line:84%
So let's try systemd
and hit Exploit.

00:21:04.525 --> 00:21:13.500 align:middle line:90%


00:21:13.500 --> 00:21:15.420 align:middle line:84%
As you can see, it
says exploit completed.

00:21:15.420 --> 00:21:17.230 align:middle line:90%
But no session was created.

00:21:17.230 --> 00:21:20.610 align:middle line:84%
So we can set the target
maybe to systemd user just

00:21:20.610 --> 00:21:21.510 align:middle line:90%
to see if that works.

00:21:21.510 --> 00:21:31.692 align:middle line:90%


00:21:31.692 --> 00:21:33.150 align:middle line:84%
And as you can see
in this case, it

00:21:33.150 --> 00:21:34.480 align:middle line:90%
doesn't look like it's working.

00:21:34.480 --> 00:21:38.020 align:middle line:84%
All right, so let's take a look
at the model or the technique

00:21:38.020 --> 00:21:41.110 align:middle line:84%
that I recommend whenever it
comes down to establishing

00:21:41.110 --> 00:21:43.190 align:middle line:90%
persistence on a Linux system.

00:21:43.190 --> 00:21:46.180 align:middle line:84%
And the reason for
that is fairly simple.

00:21:46.180 --> 00:21:48.160 align:middle line:84%
Whenever we set up
persistence, we also

00:21:48.160 --> 00:21:50.290 align:middle line:84%
want to be as
clandestine as possible

00:21:50.290 --> 00:21:52.300 align:middle line:84%
in regards to actually
being detected.

00:21:52.300 --> 00:21:54.310 align:middle line:84%
Now, the module that
I'm referring to here

00:21:54.310 --> 00:21:58.720 align:middle line:84%
is the post exploitation module
called SSH key persistence.

00:21:58.720 --> 00:22:01.090 align:middle line:84%
Now, the way this
module works is it

00:22:01.090 --> 00:22:05.800 align:middle line:84%
will essentially set up a
private and public SSH key pair

00:22:05.800 --> 00:22:10.570 align:middle line:84%
and will add the actual public
key into the home directories

00:22:10.570 --> 00:22:12.580 align:middle line:84%
of all the user
accounts on the system

00:22:12.580 --> 00:22:14.920 align:middle line:84%
and will then provide
us with the private key.

00:22:14.920 --> 00:22:16.720 align:middle line:84%
And we can utilize
that private key

00:22:16.720 --> 00:22:20.320 align:middle line:84%
to authenticate to any of the
user accounts on the system

00:22:20.320 --> 00:22:21.880 align:middle line:90%
without providing a password.

00:22:21.880 --> 00:22:25.300 align:middle line:84%
So again, we never want
to change the passwords

00:22:25.300 --> 00:22:27.470 align:middle line:84%
on the system in regards
to the user account.

00:22:27.470 --> 00:22:29.530 align:middle line:84%
So again, we also
have the ability

00:22:29.530 --> 00:22:31.570 align:middle line:84%
to change the root
user password.

00:22:31.570 --> 00:22:35.330 align:middle line:84%
But again, that would be a very
strong indicator of compromise.

00:22:35.330 --> 00:22:37.660 align:middle line:84%
So what we'll do
is we'll say copy,

00:22:37.660 --> 00:22:40.760 align:middle line:90%
and we'll paste that in there.

00:22:40.760 --> 00:22:42.530 align:middle line:90%
We'll show the options here.

00:22:42.530 --> 00:22:45.240 align:middle line:84%
And we need to
configure a few things.

00:22:45.240 --> 00:22:47.630 align:middle line:84%
One of the things
we need to configure

00:22:47.630 --> 00:22:51.560 align:middle line:84%
is the Create SSH folder,
which we want to set to true.

00:22:51.560 --> 00:22:53.510 align:middle line:84%
Because in some cases,
the target system

00:22:53.510 --> 00:22:56.990 align:middle line:84%
may not have the SSH
folder already created.

00:22:56.990 --> 00:23:02.090 align:middle line:84%
We then need to set the actual
session here to session 4,

00:23:02.090 --> 00:23:03.300 align:middle line:90%
in our case.

00:23:03.300 --> 00:23:06.170 align:middle line:84%
And we can also specify
the username or the user

00:23:06.170 --> 00:23:07.880 align:middle line:90%
to add an SSH key to.

00:23:07.880 --> 00:23:10.490 align:middle line:84%
By default it will add
all users on the box,

00:23:10.490 --> 00:23:14.100 align:middle line:84%
which is what we want because
we created the FTP user account.

00:23:14.100 --> 00:23:16.880 align:middle line:84%
And we also want this to work
for the root user as well

00:23:16.880 --> 00:23:18.990 align:middle line:90%
as Jackie and the FTP account.

00:23:18.990 --> 00:23:21.800 align:middle line:84%
So again, to learn more about
it, we can type in info.

00:23:21.800 --> 00:23:24.320 align:middle line:84%
As you can see, this
module will add an SSH key

00:23:24.320 --> 00:23:28.460 align:middle line:84%
to a specified user or all
to allow remote login via SSH

00:23:28.460 --> 00:23:29.430 align:middle line:90%
at any time.

00:23:29.430 --> 00:23:31.940 align:middle line:84%
Which is great, because
again, this is very difficult

00:23:31.940 --> 00:23:35.090 align:middle line:84%
to detect because the
SSH public key that's

00:23:35.090 --> 00:23:37.820 align:middle line:84%
been added to the home
directory of the users

00:23:37.820 --> 00:23:40.010 align:middle line:84%
is something that is
not frequently accessed

00:23:40.010 --> 00:23:41.680 align:middle line:90%
by the users on the system.

00:23:41.680 --> 00:23:46.640 align:middle line:84%
And again, this really
doesn't leave any indicator

00:23:46.640 --> 00:23:49.430 align:middle line:84%
of compromise in regards
to the process tree

00:23:49.430 --> 00:23:51.650 align:middle line:84%
or any other artifacts
apart from the fact

00:23:51.650 --> 00:23:54.500 align:middle line:84%
that a system administrator
can actually view

00:23:54.500 --> 00:23:55.860 align:middle line:90%
who is currently logged on.

00:23:55.860 --> 00:23:57.840 align:middle line:84%
But if we log in
as the root user,

00:23:57.840 --> 00:24:00.230 align:middle line:84%
then that may not be
suspicious at all.

00:24:00.230 --> 00:24:02.540 align:middle line:84%
Because, again, if they're
logging as the root user

00:24:02.540 --> 00:24:05.480 align:middle line:84%
and we log in as the
root user, then again,

00:24:05.480 --> 00:24:07.770 align:middle line:84%
we might be able to
again avoid detection.

00:24:07.770 --> 00:24:11.690 align:middle line:84%
So what we'll do is
we will hit Exploit.

00:24:11.690 --> 00:24:13.500 align:middle line:84%
And I'll just show
the options just

00:24:13.500 --> 00:24:15.500 align:middle line:84%
to make sure everything
is configured correctly.

00:24:15.500 --> 00:24:16.820 align:middle line:90%
And we'll say exploit here.

00:24:16.820 --> 00:24:22.730 align:middle line:90%


00:24:22.730 --> 00:24:25.520 align:middle line:84%
All right, so because
we specified the module

00:24:25.520 --> 00:24:29.780 align:middle line:84%
to run or to create
the SSH directory

00:24:29.780 --> 00:24:33.800 align:middle line:84%
or folder for all users as well
as add the actual public key

00:24:33.800 --> 00:24:36.938 align:middle line:84%
to all the user
account's home directory,

00:24:36.938 --> 00:24:37.980 align:middle line:90%
it will actually do that.

00:24:37.980 --> 00:24:40.550 align:middle line:84%
So it'll actually
add the public key

00:24:40.550 --> 00:24:43.850 align:middle line:84%
to the authorized keys file
under the home directory

00:24:43.850 --> 00:24:46.140 align:middle line:90%
under SSH and authorized keys.

00:24:46.140 --> 00:24:48.770 align:middle line:84%
And it does that for all
user accounts as well as,

00:24:48.770 --> 00:24:50.460 align:middle line:90%
in this case, the FTP user.

00:24:50.460 --> 00:24:52.430 align:middle line:90%
So we can identify.

00:24:52.430 --> 00:24:53.990 align:middle line:84%
As you can see, the
private key here

00:24:53.990 --> 00:24:57.050 align:middle line:84%
will be saved within
the following directory.

00:24:57.050 --> 00:24:58.970 align:middle line:84%
And it provides us with
the actual file name.

00:24:58.970 --> 00:25:02.040 align:middle line:84%
So we can say loot to
access the private key.

00:25:02.040 --> 00:25:05.040 align:middle line:84%
As you can see, this is
a OpenSSH Private Key.

00:25:05.040 --> 00:25:07.220 align:middle line:84%
So we can cat the
contents of the file.

00:25:07.220 --> 00:25:11.060 align:middle line:84%
I'm just going to say
copy, and I'll say cat.

00:25:11.060 --> 00:25:11.810 align:middle line:90%
Hit Enter.

00:25:11.810 --> 00:25:13.312 align:middle line:84%
And there's the
private key here.

00:25:13.312 --> 00:25:15.270 align:middle line:84%
All right, so you may be
asking yourself, well,

00:25:15.270 --> 00:25:18.440 align:middle line:84%
how can we utilize this to gain
access to the target system?

00:25:18.440 --> 00:25:20.330 align:middle line:90%
Well, we just need to copy it.

00:25:20.330 --> 00:25:23.450 align:middle line:84%
And I'm going to terminate all
my meterpreter sessions or all

00:25:23.450 --> 00:25:25.400 align:middle line:84%
the sessions that I have
active on the target.

00:25:25.400 --> 00:25:28.158 align:middle line:90%
And I can just say exit yes.

00:25:28.158 --> 00:25:29.450 align:middle line:90%
That will terminate everything.

00:25:29.450 --> 00:25:31.280 align:middle line:84%
And we're back within
the actual terminal.

00:25:31.280 --> 00:25:33.470 align:middle line:84%
We're not working
within MSF console.

00:25:33.470 --> 00:25:36.530 align:middle line:84%
I'll create a within
my current working

00:25:36.530 --> 00:25:39.320 align:middle line:90%
directory called SSH_key.

00:25:39.320 --> 00:25:42.080 align:middle line:84%
And I will paste in
the private key here.

00:25:42.080 --> 00:25:43.550 align:middle line:90%
And I'll write in quit.

00:25:43.550 --> 00:25:46.340 align:middle line:84%
And I'll then provide it with
the appropriate permissions

00:25:46.340 --> 00:25:48.120 align:middle line:90%
for an SSH private key.

00:25:48.120 --> 00:25:51.810 align:middle line:90%
So that's chmod 0400 ssh_key.

00:25:51.810 --> 00:25:53.900 align:middle line:84%
And then we can
authenticate to the target

00:25:53.900 --> 00:25:57.320 align:middle line:84%
system via any user we want
via SSH page, of course.

00:25:57.320 --> 00:25:58.580 align:middle line:90%
So I can say SSH.

00:25:58.580 --> 00:26:01.520 align:middle line:84%
We specify the key,
the actual private key,

00:26:01.520 --> 00:26:02.750 align:middle line:90%
using the -i option.

00:26:02.750 --> 00:26:04.880 align:middle line:84%
And in this case,
we'll say SSH key.

00:26:04.880 --> 00:26:08.420 align:middle line:84%
And then, for example, I can
say root@ and then I specify

00:26:08.420 --> 00:26:09.890 align:middle line:90%
the target IP address, right?

00:26:09.890 --> 00:26:13.760 align:middle line:84%
So we actually need to
identify the actual target IP.

00:26:13.760 --> 00:26:15.770 align:middle line:84%
So I'm just going
to type in ifconfig.

00:26:15.770 --> 00:26:17.870 align:middle line:84%
And we know that
it's on the third IP

00:26:17.870 --> 00:26:19.110 align:middle line:90%
address within the subnet.

00:26:19.110 --> 00:26:23.600 align:middle line:84%
So I'll say ssh
-i ssh_key root@.

00:26:23.600 --> 00:26:25.250 align:middle line:90%
Paste in the target IP.

00:26:25.250 --> 00:26:27.110 align:middle line:90%
Remember to change the 2 to a 3.

00:26:27.110 --> 00:26:28.070 align:middle line:90%
Hit Enter.

00:26:28.070 --> 00:26:30.530 align:middle line:84%
It's going to say whether
we want to accept.

00:26:30.530 --> 00:26:31.700 align:middle line:90%
We're going to say Yes.

00:26:31.700 --> 00:26:34.280 align:middle line:84%
And voila, we are
logged in as root.

00:26:34.280 --> 00:26:36.360 align:middle line:84%
And we didn't have to
provide the root password.

00:26:36.360 --> 00:26:38.027 align:middle line:84%
So we're not changing
the root password.

00:26:38.027 --> 00:26:41.900 align:middle line:84%
We're just gaining access via
SSH key authentication, right?

00:26:41.900 --> 00:26:44.060 align:middle line:90%
So that really is fantastic.

00:26:44.060 --> 00:26:48.530 align:middle line:84%
And now we have, again,
access via a typical terminal

00:26:48.530 --> 00:26:51.740 align:middle line:84%
or a typical Linux
command shell.

00:26:51.740 --> 00:26:54.620 align:middle line:84%
And of course, we can go through
the process of upgrading this

00:26:54.620 --> 00:26:55.370 align:middle line:90%
if we wanted to.

00:26:55.370 --> 00:27:00.050 align:middle line:84%
But for continuous or for
persistent access on the target

00:27:00.050 --> 00:27:02.120 align:middle line:84%
system, this is a
fantastic technique

00:27:02.120 --> 00:27:03.860 align:middle line:84%
because we're not
creating a service.

00:27:03.860 --> 00:27:05.930 align:middle line:84%
We're not creating a
cron job, et cetera.

00:27:05.930 --> 00:27:09.160 align:middle line:90%
So again, I can say exit.

00:27:09.160 --> 00:27:14.050 align:middle line:84%
And if we try and log in to the
user FTP here, we can say FTP.

00:27:14.050 --> 00:27:14.980 align:middle line:90%
hit Enter.

00:27:14.980 --> 00:27:16.990 align:middle line:84%
It's going to ask
us for the user FTP

00:27:16.990 --> 00:27:18.260 align:middle line:90%
password, which we created.

00:27:18.260 --> 00:27:19.990 align:middle line:90%
So password123.

00:27:19.990 --> 00:27:23.170 align:middle line:84%
Hit Enter, and we gain
access to the FTP user--

00:27:23.170 --> 00:27:24.010 align:middle line:90%
fantastic.

00:27:24.010 --> 00:27:26.830 align:middle line:84%
All right, so that
is going to conclude

00:27:26.830 --> 00:27:31.040 align:middle line:84%
the practical demonstration
side of this video.

00:27:31.040 --> 00:27:35.110 align:middle line:84%
All right, so that concludes the
Linux post exploitation section

00:27:35.110 --> 00:27:36.100 align:middle line:90%
of this course.

00:27:36.100 --> 00:27:38.450 align:middle line:84%
In the final section
of this course,

00:27:38.450 --> 00:27:40.930 align:middle line:84%
we will be exploring the
Metasploit graphical user

00:27:40.930 --> 00:27:41.620 align:middle line:90%
interfaces.

00:27:41.620 --> 00:27:44.170 align:middle line:84%
More specifically, we
will be taking a look

00:27:44.170 --> 00:27:47.140 align:middle line:84%
at how to utilize
Armitage for information

00:27:47.140 --> 00:27:49.510 align:middle line:84%
gathering, port scanning,
and enumeration,

00:27:49.510 --> 00:27:52.650 align:middle line:84%
as well as exploitation
and post exploitation.

00:27:52.650 --> 00:27:55.890 align:middle line:84%
So I'll see you in
the next section.

00:27:55.890 --> 00:27:57.000 align:middle line:90%