WEBVTT

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


00:00:10.150 --> 00:00:13.930 align:middle line:84%
Welcome to the Linux persistence
section of this course.

00:00:13.930 --> 00:00:16.059 align:middle line:84%
In this section, we're
going to be exploring

00:00:16.059 --> 00:00:18.910 align:middle line:84%
the process of establishing
persistent access

00:00:18.910 --> 00:00:23.440 align:middle line:84%
or on or to a Linux system
that you have compromised.

00:00:23.440 --> 00:00:25.030 align:middle line:84%
In this specific
video, we're going

00:00:25.030 --> 00:00:28.090 align:middle line:84%
to be exploring the process
of establishing persistence

00:00:28.090 --> 00:00:31.330 align:middle line:90%
via the use of SSH keys, right?

00:00:31.330 --> 00:00:33.370 align:middle line:84%
So before we
actually get started

00:00:33.370 --> 00:00:35.020 align:middle line:84%
with the practical
demonstration, let's

00:00:35.020 --> 00:00:38.320 align:middle line:84%
get an understanding of
how SSH this works in terms

00:00:38.320 --> 00:00:39.880 align:middle line:90%
of authentication, right?

00:00:39.880 --> 00:00:44.530 align:middle line:84%
And when I'm making a reference
to persistence via SSH keys,

00:00:44.530 --> 00:00:46.203 align:middle line:84%
if you have never
used or configured

00:00:46.203 --> 00:00:48.370 align:middle line:84%
as I say to yourself, then
you might be a little bit

00:00:48.370 --> 00:00:49.990 align:middle line:90%
confused, right?

00:00:49.990 --> 00:00:51.680 align:middle line:84%
Now, in order to
understand this,

00:00:51.680 --> 00:00:55.420 align:middle line:84%
we need to understand where
Linux is typically deployed

00:00:55.420 --> 00:00:58.480 align:middle line:84%
and how SSH is
typically used, right?

00:00:58.480 --> 00:01:02.830 align:middle line:84%
So Linux is typically deployed
as a server operating system.

00:01:02.830 --> 00:01:06.970 align:middle line:84%
And I'm specifically
referring to the deployment

00:01:06.970 --> 00:01:10.340 align:middle line:84%
within an enterprise or
corporate environment.

00:01:10.340 --> 00:01:13.370 align:middle line:84%
I know that you can install
Ubuntu as a desktop operating

00:01:13.370 --> 00:01:13.870 align:middle line:90%
system.

00:01:13.870 --> 00:01:18.610 align:middle line:84%
I know you can use Linux as
a standard desktop or laptop

00:01:18.610 --> 00:01:20.840 align:middle line:84%
operating system
without any problems.

00:01:20.840 --> 00:01:23.710 align:middle line:84%
However, in a corporate
or enterprise environment,

00:01:23.710 --> 00:01:26.950 align:middle line:84%
Linux is typically deployed
as a server operating system

00:01:26.950 --> 00:01:30.250 align:middle line:84%
to host specific web
applications, databases,

00:01:30.250 --> 00:01:31.990 align:middle line:90%
services, et cetera.

00:01:31.990 --> 00:01:34.690 align:middle line:84%
As a result, Linux
servers are typically

00:01:34.690 --> 00:01:39.450 align:middle line:84%
accessed remotely via services
or protocols, such SSH.

00:01:39.450 --> 00:01:41.810 align:middle line:84%
Now, I'll give you
an example here.

00:01:41.810 --> 00:01:44.680 align:middle line:84%
Let's say you've been assigned
to perform a penetration

00:01:44.680 --> 00:01:46.630 align:middle line:90%
test on a client's network.

00:01:46.630 --> 00:01:50.750 align:middle line:84%
And in addition to the
actual client's network,

00:01:50.750 --> 00:01:53.860 align:middle line:84%
they also provide you
with details regarding

00:01:53.860 --> 00:01:55.540 align:middle line:84%
their public-facing
infrastructure,

00:01:55.540 --> 00:02:00.190 align:middle line:84%
like their website as well as a
few web applications that they

00:02:00.190 --> 00:02:01.780 align:middle line:90%
host for their customers.

00:02:01.780 --> 00:02:04.480 align:middle line:84%
And these web
applications or websites

00:02:04.480 --> 00:02:07.540 align:middle line:84%
are going to be typically
hosted on a Linux server, right?

00:02:07.540 --> 00:02:10.060 align:middle line:84%
So that is public-facing
infrastructure.

00:02:10.060 --> 00:02:13.840 align:middle line:84%
Now, if we exploit that
web application that's

00:02:13.840 --> 00:02:17.440 align:middle line:84%
being hosted, and we gain
access to that Linux server,

00:02:17.440 --> 00:02:20.860 align:middle line:84%
then what happens here
is we've compromised

00:02:20.860 --> 00:02:23.740 align:middle line:84%
a part of the company's
digital infrastructure.

00:02:23.740 --> 00:02:27.200 align:middle line:84%
But that's really not part of
the internal infrastructure,

00:02:27.200 --> 00:02:27.700 align:middle line:90%
right?

00:02:27.700 --> 00:02:31.600 align:middle line:84%
So that server is essentially
exposed to the internet,

00:02:31.600 --> 00:02:35.200 align:middle line:84%
whereas the internal systems
are part of an internal network

00:02:35.200 --> 00:02:40.270 align:middle line:84%
and may not or really cannot
be accessed externally or via

00:02:40.270 --> 00:02:40.960 align:middle line:90%
the internet.

00:02:40.960 --> 00:02:43.030 align:middle line:90%
That's perfectly fine.

00:02:43.030 --> 00:02:47.470 align:middle line:84%
Now, given the fact that Linux
servers are typically deployed

00:02:47.470 --> 00:02:50.860 align:middle line:84%
or Linux is typically
deployed as a server, that

00:02:50.860 --> 00:02:52.930 align:middle line:84%
means that in most
cases, the server

00:02:52.930 --> 00:02:55.480 align:middle line:84%
is either going to be
deployed on the Cloud,

00:02:55.480 --> 00:02:59.200 align:middle line:84%
on AWS or Azure or
Linode, for example,

00:02:59.200 --> 00:03:03.970 align:middle line:84%
or it could be deployed on
a company-owned data center

00:03:03.970 --> 00:03:06.070 align:middle line:90%
somewhere around the world.

00:03:06.070 --> 00:03:08.260 align:middle line:84%
And as a result,
in order to access

00:03:08.260 --> 00:03:12.190 align:middle line:84%
these Linux servers remotely,
the protocol of choice

00:03:12.190 --> 00:03:13.360 align:middle line:90%
is going to be SSH.

00:03:13.360 --> 00:03:15.910 align:middle line:84%
So whenever you
compromise a Linux system,

00:03:15.910 --> 00:03:18.760 align:middle line:84%
I can almost guarantee
that if it's public-facing,

00:03:18.760 --> 00:03:22.630 align:middle line:84%
you are going to have SSH
running on that target system,

00:03:22.630 --> 00:03:23.140 align:middle line:90%
right?

00:03:23.140 --> 00:03:26.470 align:middle line:84%
Now, if SSH is enabled and
running on a Linux system

00:03:26.470 --> 00:03:28.180 align:middle line:84%
that you have
compromised, you can

00:03:28.180 --> 00:03:30.730 align:middle line:84%
take advantage of
the SSH configuration

00:03:30.730 --> 00:03:34.237 align:middle line:84%
to establish persistent
access on the target system.

00:03:34.237 --> 00:03:36.070 align:middle line:84%
And you might be a
little bit confused here.

00:03:36.070 --> 00:03:37.487 align:middle line:84%
You might be
thinking to yourself,

00:03:37.487 --> 00:03:40.480 align:middle line:84%
well, OK, SSH authentication
utilizes a username

00:03:40.480 --> 00:03:41.950 align:middle line:90%
and password combination.

00:03:41.950 --> 00:03:45.100 align:middle line:84%
Well, in addition to a username
and password combination,

00:03:45.100 --> 00:03:50.230 align:middle line:84%
SSH can also utilize key-based
authentication, whereby

00:03:50.230 --> 00:03:52.870 align:middle line:84%
the end user or the
person wants to connect

00:03:52.870 --> 00:03:55.540 align:middle line:84%
to the Linux server
via SSH does not

00:03:55.540 --> 00:03:57.550 align:middle line:90%
utilize a username or password.

00:03:57.550 --> 00:04:00.550 align:middle line:84%
They instead utilize
a private key, right?

00:04:00.550 --> 00:04:03.160 align:middle line:84%
So the way this
typically works is

00:04:03.160 --> 00:04:05.920 align:middle line:84%
let's say I am a
system administrator,

00:04:05.920 --> 00:04:08.320 align:middle line:84%
and I've been told to
set up a Linux server.

00:04:08.320 --> 00:04:11.140 align:middle line:84%
And I'm the only one who should
have access to that server.

00:04:11.140 --> 00:04:14.170 align:middle line:84%
And I don't want to utilize
password-based authentication

00:04:14.170 --> 00:04:17.290 align:middle line:84%
primarily because of the
threat of brute force attacks.

00:04:17.290 --> 00:04:20.410 align:middle line:84%
Well, I can generate
an SSH key pair, right?

00:04:20.410 --> 00:04:23.380 align:middle line:84%
And I can then transfer the
public key onto the Linux

00:04:23.380 --> 00:04:27.400 align:middle line:84%
server and consequently use my
private key for authentication

00:04:27.400 --> 00:04:28.420 align:middle line:90%
with that server.

00:04:28.420 --> 00:04:33.370 align:middle line:84%
The caveat here is that the
individual with the private key

00:04:33.370 --> 00:04:35.530 align:middle line:90%
can log onto that target system.

00:04:35.530 --> 00:04:37.880 align:middle line:84%
Without the private
key, no one can get in.

00:04:37.880 --> 00:04:41.770 align:middle line:84%
So even if I lose it, I pretty
much cannot get in unless I

00:04:41.770 --> 00:04:45.430 align:middle line:84%
actually physically
head over to the system,

00:04:45.430 --> 00:04:49.670 align:middle line:84%
and then reconfigure or
change the password manually.

00:04:49.670 --> 00:04:52.450 align:middle line:84%
So nowadays, you'll
typically see

00:04:52.450 --> 00:04:56.200 align:middle line:84%
that Linux servers will have
key-based authentication

00:04:56.200 --> 00:04:58.480 align:middle line:84%
enabled for the
SSH service, which

00:04:58.480 --> 00:05:00.700 align:middle line:84%
allows users to access
the Linux system remotely

00:05:00.700 --> 00:05:02.740 align:middle line:90%
without the need of a password.

00:05:02.740 --> 00:05:05.090 align:middle line:84%
So after gaining access
to a Linux system,

00:05:05.090 --> 00:05:10.430 align:middle line:84%
we can transfer the SSH private
key of a specific user account

00:05:10.430 --> 00:05:13.130 align:middle line:84%
onto our system and use
that SSH private key

00:05:13.130 --> 00:05:15.710 align:middle line:84%
for all future
authentication and access.

00:05:15.710 --> 00:05:17.480 align:middle line:84%
The objective here
is to try and see

00:05:17.480 --> 00:05:21.050 align:middle line:84%
whether we can find any
private key that is already

00:05:21.050 --> 00:05:24.140 align:middle line:90%
available on that Linux server.

00:05:24.140 --> 00:05:26.210 align:middle line:84%
And we can then transfer
it to our system

00:05:26.210 --> 00:05:28.520 align:middle line:84%
and use that private
key for authentication

00:05:28.520 --> 00:05:29.870 align:middle line:90%
to the Linux system.

00:05:29.870 --> 00:05:33.410 align:middle line:84%
And this is important in
the context of persistence

00:05:33.410 --> 00:05:36.930 align:middle line:84%
primarily because a user
account password can be changed,

00:05:36.930 --> 00:05:40.700 align:middle line:84%
which means if SSH
authentication to the Linux

00:05:40.700 --> 00:05:43.700 align:middle line:84%
server utilizes a
password as well

00:05:43.700 --> 00:05:45.740 align:middle line:84%
and if the user account
password is changed,

00:05:45.740 --> 00:05:47.310 align:middle line:84%
then you're going
to be locked out.

00:05:47.310 --> 00:05:49.230 align:middle line:84%
However, if you have
the private key,

00:05:49.230 --> 00:05:52.297 align:middle line:84%
then you essentially maintain
access to the target system.

00:05:52.297 --> 00:05:54.380 align:middle line:84%
Now, as I said, you might
be a little bit confused

00:05:54.380 --> 00:05:58.220 align:middle line:84%
when I gave you an example of
me setting up an SSH key pair

00:05:58.220 --> 00:06:02.420 align:middle line:84%
and saying I transferred the
public key onto the server,

00:06:02.420 --> 00:06:04.850 align:middle line:90%
that's just one example.

00:06:04.850 --> 00:06:07.820 align:middle line:84%
In most cases, you can also
generate a new key pair.

00:06:07.820 --> 00:06:11.270 align:middle line:84%
And you can also transfer
that public key onto the Linux

00:06:11.270 --> 00:06:13.653 align:middle line:84%
server that you've compromised
and use the private key

00:06:13.653 --> 00:06:14.570 align:middle line:90%
that you've generated.

00:06:14.570 --> 00:06:17.540 align:middle line:84%
Alternatively,
you can also find,

00:06:17.540 --> 00:06:21.500 align:middle line:84%
in some cases, private keys that
have been stored on that Linux

00:06:21.500 --> 00:06:27.380 align:middle line:84%
server to access other servers,
and so on and so forth.

00:06:27.380 --> 00:06:29.640 align:middle line:84%
This video has a lab
environment attached to it,

00:06:29.640 --> 00:06:32.120 align:middle line:84%
so all you need to do
is just fire it up.

00:06:32.120 --> 00:06:34.700 align:middle line:84%
Now, the way we're going to
be going through it, this lab

00:06:34.700 --> 00:06:37.040 align:middle line:84%
environment is set
up in a way where

00:06:37.040 --> 00:06:40.470 align:middle line:84%
we are going to be provided
with a terminal-based Kali Linux

00:06:40.470 --> 00:06:40.970 align:middle line:90%
system.

00:06:40.970 --> 00:06:44.840 align:middle line:84%
And then we need to log in
to the target system via SSH.

00:06:44.840 --> 00:06:49.550 align:middle line:84%
Therefore essentially simulating
the stage of exploitation.

00:06:49.550 --> 00:06:51.860 align:middle line:84%
Once you have gained access
to the target system,

00:06:51.860 --> 00:06:55.130 align:middle line:84%
we can identify the private
key, transfer it over

00:06:55.130 --> 00:06:56.960 align:middle line:90%
to our Kali Linux system.

00:06:56.960 --> 00:07:00.622 align:middle line:84%
And I'll then take it from there
and show you a few really cool

00:07:00.622 --> 00:07:02.330 align:middle line:84%
things that we did in
the lab environment

00:07:02.330 --> 00:07:05.570 align:middle line:84%
to show you what can
happen if the user account

00:07:05.570 --> 00:07:07.130 align:middle line:84%
password that you
have compromised

00:07:07.130 --> 00:07:09.050 align:middle line:84%
or the user account
that you compromised

00:07:09.050 --> 00:07:10.490 align:middle line:90%
has its password changed.

00:07:10.490 --> 00:07:15.360 align:middle line:84%
So I'll see you in
the lab environment.

00:07:15.360 --> 00:07:18.150 align:middle line:84%
All right, so I'm back
within the lab environment.

00:07:18.150 --> 00:07:19.650 align:middle line:84%
And as you can see,
we are currently

00:07:19.650 --> 00:07:21.480 align:middle line:90%
on the Kali Linux system.

00:07:21.480 --> 00:07:26.050 align:middle line:84%
That, of course, is denoted by
the root@attackdefense here.

00:07:26.050 --> 00:07:28.290 align:middle line:84%
So the first step
is going to involve

00:07:28.290 --> 00:07:30.660 align:middle line:84%
identifying the target
IP address, which we

00:07:30.660 --> 00:07:33.388 align:middle line:90%
can do by typing in ifconfig.

00:07:33.388 --> 00:07:33.930 align:middle line:90%
There we are.

00:07:33.930 --> 00:07:36.585 align:middle line:84%
And we take a look at
the interface ethernet 1.

00:07:36.585 --> 00:07:38.450 align:middle line:90%
This is our Kali Linux IP.

00:07:38.450 --> 00:07:40.440 align:middle line:84%
In you case, it's
going to be different.

00:07:40.440 --> 00:07:43.500 align:middle line:84%
All you need to do is just
copy this value here and change

00:07:43.500 --> 00:07:45.030 align:middle line:90%
the two to a 3 at the end.

00:07:45.030 --> 00:07:47.290 align:middle line:84%
And that's the
target IP address.

00:07:47.290 --> 00:07:49.710 align:middle line:84%
So once that is
done, we can actually

00:07:49.710 --> 00:07:52.420 align:middle line:84%
log onto the target
system via SSH.

00:07:52.420 --> 00:07:55.390 align:middle line:84%
So this is going to essentially
simulate the exploitation

00:07:55.390 --> 00:07:55.890 align:middle line:90%
phase.

00:07:55.890 --> 00:07:58.020 align:middle line:84%
And again, the reason
we are doing it this way

00:07:58.020 --> 00:08:00.630 align:middle line:84%
is to showcase how
SSH works in addition

00:08:00.630 --> 00:08:03.630 align:middle line:84%
to showing you how you
can establish persistence

00:08:03.630 --> 00:08:05.650 align:middle line:90%
through SSH keys.

00:08:05.650 --> 00:08:07.440 align:middle line:90%
So we can say SSH.

00:08:07.440 --> 00:08:09.850 align:middle line:84%
And let's say we compromise
the student account.

00:08:09.850 --> 00:08:13.080 align:middle line:84%
So I'm going to
say ssh student@--

00:08:13.080 --> 00:08:14.790 align:middle line:90%
I'll paste the target IP.

00:08:14.790 --> 00:08:19.510 align:middle line:84%
Remember to change the 2 to
a 3, and we can hit Enter.

00:08:19.510 --> 00:08:21.190 align:middle line:84%
The password for
the student account

00:08:21.190 --> 00:08:23.780 align:middle line:84%
is just password, so
do keep that in mind.

00:08:23.780 --> 00:08:24.670 align:middle line:90%
I'll hit Enter.

00:08:24.670 --> 00:08:27.220 align:middle line:84%
And you can see, we have logged
on as the student account.

00:08:27.220 --> 00:08:30.160 align:middle line:84%
The operating system or
distribution is Ubuntu,

00:08:30.160 --> 00:08:35.679 align:middle line:84%
and the distribution release
version is open to 18.04.2 LTS.

00:08:35.679 --> 00:08:38.630 align:middle line:84%
The actual hostname of
the system is victim-1.

00:08:38.630 --> 00:08:39.130 align:middle line:90%
All right?

00:08:39.130 --> 00:08:40.690 align:middle line:90%
So let's clear that out.

00:08:40.690 --> 00:08:44.020 align:middle line:84%
And let's list out the
contents of the student's home

00:08:44.020 --> 00:08:45.050 align:middle line:90%
directory.

00:08:45.050 --> 00:08:47.440 align:middle line:84%
So if I list out the contents
of the home directory,

00:08:47.440 --> 00:08:49.840 align:middle line:84%
you can see that we have
a few folders here, right?

00:08:49.840 --> 00:08:51.350 align:middle line:90%
So you have the ssh folder.

00:08:51.350 --> 00:08:53.620 align:middle line:84%
This is the dot
configuration folder.

00:08:53.620 --> 00:08:56.830 align:middle line:84%
And we have a binary
here called wait.

00:08:56.830 --> 00:08:59.050 align:middle line:84%
Now, I'll explain
what this binary does.

00:08:59.050 --> 00:09:02.410 align:middle line:84%
This was set up to
show you or to simulate

00:09:02.410 --> 00:09:07.780 align:middle line:84%
what would happen if the user
account password was changed,

00:09:07.780 --> 00:09:08.290 align:middle line:90%
right?

00:09:08.290 --> 00:09:11.290 align:middle line:84%
So if I kept the contents
of the wait binary,

00:09:11.290 --> 00:09:13.360 align:middle line:84%
you can see that will
say delete this file

00:09:13.360 --> 00:09:15.250 align:middle line:90%
to trigger the connection reset.

00:09:15.250 --> 00:09:18.130 align:middle line:84%
And it says delete it only
after planting the backdoor.

00:09:18.130 --> 00:09:20.090 align:middle line:84%
So we essentially
going to be doing that.

00:09:20.090 --> 00:09:24.070 align:middle line:84%
So once we're done, we will
delete the actual wait binary

00:09:24.070 --> 00:09:24.710 align:middle line:90%
here.

00:09:24.710 --> 00:09:27.640 align:middle line:84%
And that is going to change
the student account's password

00:09:27.640 --> 00:09:31.090 align:middle line:84%
to simulate the fact that
the account's password has

00:09:31.090 --> 00:09:32.440 align:middle line:90%
been changed.

00:09:32.440 --> 00:09:35.630 align:middle line:84%
After which, it will also
display a flag for us here.

00:09:35.630 --> 00:09:36.130 align:middle line:90%
All right?

00:09:36.130 --> 00:09:38.980 align:middle line:84%
So what we need to do now is
if we take a look at the ssh

00:09:38.980 --> 00:09:42.310 align:middle line:90%
directory, so I'll say cd ssh.

00:09:42.310 --> 00:09:45.200 align:middle line:84%
Within this directory, we
have the private key here.

00:09:45.200 --> 00:09:45.700 align:middle line:90%
All right?

00:09:45.700 --> 00:09:47.710 align:middle line:84%
So whenever you
generate a key pair,

00:09:47.710 --> 00:09:52.785 align:middle line:84%
if it's generated on the
system, whenever you generate

00:09:52.785 --> 00:09:54.910 align:middle line:84%
an associated key pair,
you'll have the private key

00:09:54.910 --> 00:09:56.030 align:middle line:90%
and the public key.

00:09:56.030 --> 00:10:00.970 align:middle line:84%
So this is the private key here
because when you generate a SSH

00:10:00.970 --> 00:10:06.130 align:middle line:84%
key pair with ssh-keygen
or the ssh-keygen utility,

00:10:06.130 --> 00:10:07.550 align:middle line:90%
it'll generate two files.

00:10:07.550 --> 00:10:10.120 align:middle line:84%
One of them is going
to be called id_rsa.

00:10:10.120 --> 00:10:14.830 align:middle line:84%
That's the private key and
id_rsa.pub or dot public,

00:10:14.830 --> 00:10:16.120 align:middle line:90%
which is the public key.

00:10:16.120 --> 00:10:17.800 align:middle line:84%
In this case, we're
able to see that we

00:10:17.800 --> 00:10:20.710 align:middle line:90%
have a private key here, right?

00:10:20.710 --> 00:10:23.080 align:middle line:84%
And if we cut out the
content of the private key,

00:10:23.080 --> 00:10:26.810 align:middle line:84%
you can see it says this is
the content of the private key.

00:10:26.810 --> 00:10:31.040 align:middle line:84%
So it says begin RSA private
key and end RSA private key.

00:10:31.040 --> 00:10:34.630 align:middle line:84%
Now, if we list out the other
contents within this directory,

00:10:34.630 --> 00:10:37.210 align:middle line:84%
we also have the
authorized keys file,

00:10:37.210 --> 00:10:43.270 align:middle line:84%
which contains the authorized
keys for specific private keys,

00:10:43.270 --> 00:10:46.700 align:middle line:84%
et cetera, which by this
point, you should already know.

00:10:46.700 --> 00:10:51.700 align:middle line:84%
So what we need to do is we need
to copy this id_rsa private key

00:10:51.700 --> 00:10:52.970 align:middle line:90%
onto our system.

00:10:52.970 --> 00:10:53.930 align:middle line:90%
So how can we do this?

00:10:53.930 --> 00:10:59.080 align:middle line:84%
Well, we'll go back into
our Kali Linux system here.

00:10:59.080 --> 00:11:01.810 align:middle line:84%
And we can utilize
the scp utility,

00:11:01.810 --> 00:11:03.820 align:middle line:84%
which allows us
to download a file

00:11:03.820 --> 00:11:06.490 align:middle line:84%
or to transfer a file
from the target system

00:11:06.490 --> 00:11:09.670 align:middle line:84%
to our Kali Linux
system via SSH.

00:11:09.670 --> 00:11:15.610 align:middle line:84%
So we can say scp student@,
and we paste in the target IP.

00:11:15.610 --> 00:11:18.100 align:middle line:84%
I'll change the 2 to
a 3 there, and then we

00:11:18.100 --> 00:11:21.100 align:middle line:84%
use a colon to specify what
file we want to download.

00:11:21.100 --> 00:11:24.610 align:middle line:84%
So we're downloading the
file from the home directory

00:11:24.610 --> 00:11:25.970 align:middle line:90%
of the student account.

00:11:25.970 --> 00:11:30.850 align:middle line:84%
So we use the tilde icon,
forward slash dot ssh.

00:11:30.850 --> 00:11:31.880 align:middle line:90%
That's the directory.

00:11:31.880 --> 00:11:33.850 align:middle line:90%
And we're downloading id_rsa.

00:11:33.850 --> 00:11:37.100 align:middle line:84%
And we want to download it or
copy it into this directory.

00:11:37.100 --> 00:11:38.860 align:middle line:90%
So I'll use the full stop there.

00:11:38.860 --> 00:11:39.910 align:middle line:90%
Hit Enter.

00:11:39.910 --> 00:11:42.170 align:middle line:84%
It's going to ask us for
the student's password.

00:11:42.170 --> 00:11:43.720 align:middle line:90%
So that is just password.

00:11:43.720 --> 00:11:44.680 align:middle line:90%
Hit Enter.

00:11:44.680 --> 00:11:46.900 align:middle line:84%
And you can see
transferred successfully.

00:11:46.900 --> 00:11:49.240 align:middle line:84%
We should now have it on
our Kali Linux system.

00:11:49.240 --> 00:11:51.250 align:middle line:90%
There we are, id_rsa.

00:11:51.250 --> 00:11:54.640 align:middle line:84%
And we can now provide it
with the necessary permissions

00:11:54.640 --> 00:11:57.730 align:middle line:84%
that you typically associate
with a private key, which

00:11:57.730 --> 00:12:02.830 align:middle line:90%
is chmod 400 and id_rsa.

00:12:02.830 --> 00:12:03.330 align:middle line:90%
All right?

00:12:03.330 --> 00:12:05.460 align:middle line:84%
So now that is
done, what we can do

00:12:05.460 --> 00:12:08.700 align:middle line:84%
is we can log back into
the system via SSH.

00:12:08.700 --> 00:12:11.310 align:middle line:84%
So I'll say ssh student
at the target IP

00:12:11.310 --> 00:12:13.350 align:middle line:90%
and log in with a password now.

00:12:13.350 --> 00:12:16.320 align:middle line:84%
And we can get rid of
the wait binary, right?

00:12:16.320 --> 00:12:17.820 align:middle line:90%
So we can say remove wait.

00:12:17.820 --> 00:12:19.470 align:middle line:84%
Now, before you
remove this binary,

00:12:19.470 --> 00:12:22.620 align:middle line:84%
make sure you've downloaded
the private key, as this will

00:12:22.620 --> 00:12:25.530 align:middle line:84%
essentially reset the connection
and change the student

00:12:25.530 --> 00:12:29.580 align:middle line:84%
account's password, essentially
preventing you from logging in.

00:12:29.580 --> 00:12:31.080 align:middle line:90%
So I'll say remove wait.

00:12:31.080 --> 00:12:33.630 align:middle line:84%
And after a few seconds,
you'll see that the connection

00:12:33.630 --> 00:12:34.860 align:middle line:90%
will be reset.

00:12:34.860 --> 00:12:35.580 align:middle line:90%
There we are.

00:12:35.580 --> 00:12:39.450 align:middle line:84%
So we try and log in again
with the same credentials.

00:12:39.450 --> 00:12:43.470 align:middle line:84%
So ssh student at the target
IP, and I type in password.

00:12:43.470 --> 00:12:45.880 align:middle line:84%
You will see that password
is not working anymore.

00:12:45.880 --> 00:12:47.640 align:middle line:84%
So this will set
up to simulate what

00:12:47.640 --> 00:12:50.700 align:middle line:84%
would happen if you gained
access to a Linux target

00:12:50.700 --> 00:12:51.360 align:middle line:90%
system.

00:12:51.360 --> 00:12:53.442 align:middle line:84%
And if you didn't
set up assistance,

00:12:53.442 --> 00:12:55.150 align:middle line:84%
then you would
essentially be locked out.

00:12:55.150 --> 00:12:59.700 align:middle line:84%
So it really doesn't matter what
you exploited initially to gain

00:12:59.700 --> 00:13:01.350 align:middle line:90%
access to the target system.

00:13:01.350 --> 00:13:03.630 align:middle line:84%
After you gain an
initial foothold,

00:13:03.630 --> 00:13:08.100 align:middle line:84%
always be sure to make sure
that you can always gain access,

00:13:08.100 --> 00:13:11.730 align:middle line:84%
or you can always access the
target system whenever you want

00:13:11.730 --> 00:13:15.600 align:middle line:84%
or have persistent access
to that target system.

00:13:15.600 --> 00:13:18.000 align:middle line:84%
But it really doesn't
matter because we

00:13:18.000 --> 00:13:19.420 align:middle line:90%
copied the private key.

00:13:19.420 --> 00:13:21.060 align:middle line:84%
So to log in with
the private key

00:13:21.060 --> 00:13:22.860 align:middle line:84%
without providing a
password because we

00:13:22.860 --> 00:13:26.250 align:middle line:84%
don't need to know what the
new student user accounts

00:13:26.250 --> 00:13:31.050 align:middle line:84%
password is, if we have a
private key, we can say ssh,

00:13:31.050 --> 00:13:35.190 align:middle line:84%
and we say -i and specify the
name of the private key, which

00:13:35.190 --> 00:13:36.090 align:middle line:90%
is id_rsa.

00:13:36.090 --> 00:13:41.160 align:middle line:84%
We then say student@ and specify
the target IP or change the 2

00:13:41.160 --> 00:13:42.090 align:middle line:90%
to a 3.

00:13:42.090 --> 00:13:43.050 align:middle line:90%
Hit Enter.

00:13:43.050 --> 00:13:45.120 align:middle line:84%
And we're logged on
to the target system

00:13:45.120 --> 00:13:46.440 align:middle line:90%
without providing a password.

00:13:46.440 --> 00:13:48.480 align:middle line:84%
It doesn't matter
whether the user account

00:13:48.480 --> 00:13:49.680 align:middle line:90%
password was changed.

00:13:49.680 --> 00:13:51.610 align:middle line:90%
We pretty much have access.

00:13:51.610 --> 00:13:55.410 align:middle line:84%
So this is something that,
again, is quite important.

00:13:55.410 --> 00:13:57.990 align:middle line:84%
Now, as I said, this really
isn't the typical flow

00:13:57.990 --> 00:14:01.770 align:middle line:84%
that you would utilize if you
are trying to essentially set

00:14:01.770 --> 00:14:03.930 align:middle line:90%
up assistance via SSH keys.

00:14:03.930 --> 00:14:09.300 align:middle line:84%
What you would ideally do is you
would generate an SSH key pair

00:14:09.300 --> 00:14:11.110 align:middle line:90%
on your Kali Linux system.

00:14:11.110 --> 00:14:14.190 align:middle line:84%
You then keep the private
key on your Kali Linux system

00:14:14.190 --> 00:14:19.590 align:middle line:84%
and transfer the public key onto
the target system in the home

00:14:19.590 --> 00:14:22.620 align:middle line:84%
directory of the user
account in the ssh directory,

00:14:22.620 --> 00:14:25.110 align:middle line:84%
and you add it under
authorized keys, right?

00:14:25.110 --> 00:14:27.330 align:middle line:84%
So that's typically
how you do that.

00:14:27.330 --> 00:14:29.470 align:middle line:84%
And there's multiple
ways you can do that.

00:14:29.470 --> 00:14:30.930 align:middle line:84%
But as I said, this
lab environment

00:14:30.930 --> 00:14:34.410 align:middle line:84%
was there to show you how
dangerous a private key is

00:14:34.410 --> 00:14:36.000 align:middle line:84%
because a private
key is essentially

00:14:36.000 --> 00:14:39.960 align:middle line:84%
like a key to a-- it's like a
master key to a huge locking

00:14:39.960 --> 00:14:43.140 align:middle line:84%
system, and it essentially
unlocks everything.

00:14:43.140 --> 00:14:45.030 align:middle line:84%
And the best part
about this is we

00:14:45.030 --> 00:14:48.010 align:middle line:84%
don't need to know when a user
account password is changed.

00:14:48.010 --> 00:14:49.980 align:middle line:84%
We don't need to know
what the new password is.

00:14:49.980 --> 00:14:52.410 align:middle line:84%
We pretty much gain access
to the target system

00:14:52.410 --> 00:14:53.380 align:middle line:90%
whenever we want.

00:14:53.380 --> 00:14:56.100 align:middle line:84%
So again, if we ever
tried to access it

00:14:56.100 --> 00:14:58.868 align:middle line:84%
without the private key,
it'll ask us for the password.

00:14:58.868 --> 00:15:00.660 align:middle line:84%
And because we don't
know the new password,

00:15:00.660 --> 00:15:04.120 align:middle line:84%
it'll tell us that that
password is incorrect.

00:15:04.120 --> 00:15:05.640 align:middle line:84%
However, if we have
the private key,

00:15:05.640 --> 00:15:07.960 align:middle line:90%
we gain access whenever we want.

00:15:07.960 --> 00:15:11.430 align:middle line:84%
So if I list of the contents of
the student's home directory,

00:15:11.430 --> 00:15:13.990 align:middle line:84%
you can now see that we
have the flag file here.

00:15:13.990 --> 00:15:16.500 align:middle line:84%
So I'll just get the flag,
which confirms that we've

00:15:16.500 --> 00:15:18.640 align:middle line:90%
completed this lab environment.

00:15:18.640 --> 00:15:19.140 align:middle line:90%
All right?

00:15:19.140 --> 00:15:21.870 align:middle line:84%
So that is going to conclude
the practical demonstration

00:15:21.870 --> 00:15:23.800 align:middle line:90%
side of this video.

00:15:23.800 --> 00:15:26.880 align:middle line:84%
All right, so that was how
to establish persistence

00:15:26.880 --> 00:15:29.760 align:middle line:84%
via or through the
use of SSH keys.

00:15:29.760 --> 00:15:32.100 align:middle line:84%
We are now going to move
on to the next persistence

00:15:32.100 --> 00:15:33.940 align:middle line:90%
technique within this section.

00:15:33.940 --> 00:15:37.350 align:middle line:84%
And that is going to involve
establishing persistence

00:15:37.350 --> 00:15:40.650 align:middle line:84%
through the use or
through the actual

00:15:40.650 --> 00:15:43.560 align:middle line:84%
or taking advantage of
cron jobs and the cron

00:15:43.560 --> 00:15:46.140 align:middle line:84%
functionality, where
we can essentially

00:15:46.140 --> 00:15:49.250 align:middle line:90%
have a reverse shell.

00:15:49.250 --> 00:15:52.410 align:middle line:84%
We can essentially establish
or set up a reverse shell

00:15:52.410 --> 00:15:55.380 align:middle line:84%
and have it connect
back to our listener

00:15:55.380 --> 00:15:58.200 align:middle line:84%
during or at a
specified duration.

00:15:58.200 --> 00:16:01.030 align:middle line:84%
And we can customize
the schedule for that.

00:16:01.030 --> 00:16:04.500 align:middle line:84%
So I'll be seeing you
in the next video.

00:16:04.500 --> 00:16:05.000 align:middle line:90%