WEBVTT

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


00:00:10.260 --> 00:00:12.500 align:middle line:90%
Exploiting sudo privileges.

00:00:12.500 --> 00:00:14.250 align:middle line:84%
In this video, we're
going to be exploring

00:00:14.250 --> 00:00:18.510 align:middle line:84%
the process of identifying
binaries or executables

00:00:18.510 --> 00:00:23.190 align:middle line:84%
with really poor or
misconfigured sudo

00:00:23.190 --> 00:00:26.430 align:middle line:84%
privileges that can be
used to essentially elevate

00:00:26.430 --> 00:00:29.130 align:middle line:84%
our privileges on
a Linux system.

00:00:29.130 --> 00:00:31.500 align:middle line:84%
All right, so
again, this video is

00:00:31.500 --> 00:00:35.040 align:middle line:84%
going to follow the same
flow as the previous video,

00:00:35.040 --> 00:00:38.790 align:middle line:84%
and that the lab environment
attached to this video

00:00:38.790 --> 00:00:41.760 align:middle line:84%
will essentially provide you
with access on the target

00:00:41.760 --> 00:00:45.180 align:middle line:84%
system, so you don't need to go
through the exploitation phase.

00:00:45.180 --> 00:00:46.797 align:middle line:84%
All you need to do
is just fire it up,

00:00:46.797 --> 00:00:48.630 align:middle line:84%
and you can follow along
with the techniques

00:00:48.630 --> 00:00:50.130 align:middle line:90%
that I'll be highlighting.

00:00:50.130 --> 00:00:52.560 align:middle line:84%
So I'll just switch over
to the lab environment,

00:00:52.560 --> 00:00:58.020 align:middle line:84%
and we can get started with
the practical demonstration.

00:00:58.020 --> 00:01:00.527 align:middle line:84%
All right, so I'm back
within the lab environment.

00:01:00.527 --> 00:01:02.360 align:middle line:84%
And as I said, you don't
need to gain access

00:01:02.360 --> 00:01:04.040 align:middle line:90%
to the target system.

00:01:04.040 --> 00:01:05.930 align:middle line:84%
Again, the actual
state of the lab

00:01:05.930 --> 00:01:09.140 align:middle line:84%
is that it will
automatically give you access

00:01:09.140 --> 00:01:11.660 align:middle line:84%
to a user account, a
non-privileged user

00:01:11.660 --> 00:01:13.490 align:middle line:90%
account on the target system.

00:01:13.490 --> 00:01:16.550 align:middle line:84%
And in this case, the user
account is called student.

00:01:16.550 --> 00:01:18.320 align:middle line:84%
So again, you can
go ahead and perform

00:01:18.320 --> 00:01:21.890 align:middle line:84%
your typical enumeration,
like identifying what

00:01:21.890 --> 00:01:23.490 align:middle line:90%
other users are on the system.

00:01:23.490 --> 00:01:25.290 align:middle line:90%
So cat/etc/passwd.

00:01:25.290 --> 00:01:27.350 align:middle line:84%
And you can see, the
only other user account

00:01:27.350 --> 00:01:28.790 align:middle line:90%
is the root user here.

00:01:28.790 --> 00:01:31.500 align:middle line:84%
The rest of them are
all service accounts.

00:01:31.500 --> 00:01:33.720 align:middle line:84%
So again, as I
said, in this video,

00:01:33.720 --> 00:01:35.210 align:middle line:84%
we're primarily
going to be focused

00:01:35.210 --> 00:01:39.530 align:middle line:84%
on identifying misconfigured
sudo privileges

00:01:39.530 --> 00:01:41.910 align:middle line:90%
or permissions, if you will.

00:01:41.910 --> 00:01:45.800 align:middle line:84%
Now, in order to
identify what commands

00:01:45.800 --> 00:01:50.070 align:middle line:84%
we can essentially run, we
can utilize the sudo L option,

00:01:50.070 --> 00:01:50.570 align:middle line:90%
right?

00:01:50.570 --> 00:01:52.610 align:middle line:90%
So sudo -l.

00:01:52.610 --> 00:01:54.800 align:middle line:84%
And you can see
right over here, it's

00:01:54.800 --> 00:01:57.920 align:middle line:84%
going to essentially give
you a list of commands

00:01:57.920 --> 00:01:59.570 align:middle line:90%
the student user can run.

00:01:59.570 --> 00:02:01.370 align:middle line:84%
So you can see it
says, User student

00:02:01.370 --> 00:02:04.070 align:middle line:84%
may run the following
commands on attackdefense.

00:02:04.070 --> 00:02:07.610 align:middle line:84%
In this case, it says, as the
user root without providing

00:02:07.610 --> 00:02:10.220 align:middle line:84%
a password, the
student user account

00:02:10.220 --> 00:02:12.590 align:middle line:84%
can execute the
following binary.

00:02:12.590 --> 00:02:14.270 align:middle line:84%
All right, so the
binary, in this case,

00:02:14.270 --> 00:02:17.420 align:middle line:84%
that we can execute
with sudo privileges

00:02:17.420 --> 00:02:19.190 align:middle line:90%
is the man binary, all right?

00:02:19.190 --> 00:02:22.940 align:middle line:84%
So man on Linux is
essentially the manual utility

00:02:22.940 --> 00:02:25.460 align:middle line:84%
that essentially
provides you with access

00:02:25.460 --> 00:02:28.310 align:middle line:84%
or allows you to
essentially view

00:02:28.310 --> 00:02:30.470 align:middle line:90%
the manual files for utilities.

00:02:30.470 --> 00:02:34.340 align:middle line:84%
Now, this is very interesting
because the man utility,

00:02:34.340 --> 00:02:37.640 align:middle line:84%
if actually configured
or misconfigured

00:02:37.640 --> 00:02:41.430 align:middle line:84%
with sudo privileges,
and in this case,

00:02:41.430 --> 00:02:44.040 align:middle line:84%
you can see the no password
option has been set,

00:02:44.040 --> 00:02:45.440 align:middle line:90%
this is very dangerous, right?

00:02:45.440 --> 00:02:49.380 align:middle line:84%
Because it means that the
unprivileged student user

00:02:49.380 --> 00:02:53.450 align:middle line:84%
account can run this
binary, the man binary,

00:02:53.450 --> 00:02:55.670 align:middle line:84%
with sudo privileges,
which means

00:02:55.670 --> 00:02:58.550 align:middle line:84%
root privileges, without
providing the password

00:02:58.550 --> 00:03:00.620 align:middle line:90%
of the root user, which is--

00:03:00.620 --> 00:03:02.570 align:middle line:84%
Essentially, if I can
compare it to Windows,

00:03:02.570 --> 00:03:05.810 align:middle line:84%
it's like executing a
program as administrator

00:03:05.810 --> 00:03:08.510 align:middle line:84%
through a non-privileged
user account that is not

00:03:08.510 --> 00:03:10.940 align:middle line:84%
part of the local
administrators group

00:03:10.940 --> 00:03:13.070 align:middle line:84%
and not providing
a password, right?

00:03:13.070 --> 00:03:17.570 align:middle line:84%
Which is, again, as you can
tell, this is literally like--

00:03:17.570 --> 00:03:22.070 align:middle line:84%
this is bypassing
the entire concept

00:03:22.070 --> 00:03:24.230 align:middle line:90%
of permissions and privileges.

00:03:24.230 --> 00:03:26.750 align:middle line:84%
And again, you might
be asking yourself,

00:03:26.750 --> 00:03:29.400 align:middle line:84%
another question is,
why is this the case?

00:03:29.400 --> 00:03:32.240 align:middle line:84%
Well, on a Linux
system, in some cases,

00:03:32.240 --> 00:03:34.220 align:middle line:84%
the administrator
may need to provide

00:03:34.220 --> 00:03:36.800 align:middle line:84%
this functionality
or this privilege

00:03:36.800 --> 00:03:38.660 align:middle line:90%
for specific binaries.

00:03:38.660 --> 00:03:40.490 align:middle line:84%
And in this case, it
looks harmless, right?

00:03:40.490 --> 00:03:43.430 align:middle line:84%
The man utility,
again, is really

00:03:43.430 --> 00:03:47.210 align:middle line:84%
only used to view the
manual the manual files

00:03:47.210 --> 00:03:49.820 align:middle line:84%
or the documentation
of other utilities.

00:03:49.820 --> 00:03:53.330 align:middle line:84%
So the administrator may be
thinking to themselves, well,

00:03:53.330 --> 00:03:56.060 align:middle line:84%
I don't really see what the
problem with this is, right?

00:03:56.060 --> 00:03:59.780 align:middle line:84%
And that's where they get it
wrong because the actual man

00:03:59.780 --> 00:04:03.920 align:middle line:84%
utility can allow
users to spawn a bash

00:04:03.920 --> 00:04:08.270 align:middle line:84%
session or a shell session
from within the utility, right?

00:04:08.270 --> 00:04:10.860 align:middle line:84%
And let me show you
how this can be done.

00:04:10.860 --> 00:04:15.550 align:middle line:84%
So as an example, let's get an
understanding of how man works.

00:04:15.550 --> 00:04:18.110 align:middle line:84%
So if you're not
familiar with Linux,

00:04:18.110 --> 00:04:21.769 align:middle line:84%
if I wanted to get the manual
pages for a specific command,

00:04:21.769 --> 00:04:25.220 align:middle line:84%
let's say, I don't know how to
use a specific command like ls,

00:04:25.220 --> 00:04:28.130 align:middle line:84%
I can type in man ls,
and this will open up

00:04:28.130 --> 00:04:31.640 align:middle line:84%
the manual pages or the manual
for that particular command.

00:04:31.640 --> 00:04:35.950 align:middle line:84%
A manual is, as
the name suggests,

00:04:35.950 --> 00:04:39.380 align:middle line:84%
an instruction manual on how
to use a specific utility.

00:04:39.380 --> 00:04:43.040 align:middle line:84%
Now, I just ran the man command
without providing the sudo

00:04:43.040 --> 00:04:46.800 align:middle line:84%
prefix or without running
it with sudo privileges.

00:04:46.800 --> 00:04:50.510 align:middle line:84%
Now, the way an attacker can
exploit this is, again, they

00:04:50.510 --> 00:04:51.230 align:middle line:90%
can--

00:04:51.230 --> 00:04:53.840 align:middle line:84%
let's see if we can actually
run it with sudo privileges.

00:04:53.840 --> 00:04:56.930 align:middle line:84%
So if the permissions
or the privileges

00:04:56.930 --> 00:05:00.360 align:middle line:84%
that we were able to enumerate
earlier were correct,

00:05:00.360 --> 00:05:04.010 align:middle line:84%
then I can say, sudo man ls,
for example, or sudo man cat,

00:05:04.010 --> 00:05:08.600 align:middle line:84%
and it should execute the man
binary or utility with sudo

00:05:08.600 --> 00:05:11.420 align:middle line:84%
privileges without prompting
me to enter the root user's

00:05:11.420 --> 00:05:12.200 align:middle line:90%
password.

00:05:12.200 --> 00:05:14.690 align:middle line:84%
And in this case, you can see
it works because it displays

00:05:14.690 --> 00:05:19.100 align:middle line:84%
the documentation for the cat
command or the cat utility,

00:05:19.100 --> 00:05:20.070 align:middle line:90%
if you will.

00:05:20.070 --> 00:05:22.970 align:middle line:84%
So what we can do
is, as I said, there

00:05:22.970 --> 00:05:26.550 align:middle line:84%
is a vulnerability that
can be exploited here.

00:05:26.550 --> 00:05:29.630 align:middle line:84%
So if we open up-- if
we say, for example,

00:05:29.630 --> 00:05:32.990 align:middle line:90%
sudo man ls, right?

00:05:32.990 --> 00:05:35.090 align:middle line:84%
Or any other command
for that matter,

00:05:35.090 --> 00:05:38.300 align:middle line:84%
you can see that it allows you
to scroll through the content

00:05:38.300 --> 00:05:39.080 align:middle line:90%
of the manual.

00:05:39.080 --> 00:05:43.310 align:middle line:84%
However, we can essentially
spawn a bash session

00:05:43.310 --> 00:05:45.570 align:middle line:84%
by utilizing the
exclamation marks.

00:05:45.570 --> 00:05:48.710 align:middle line:84%
So on your keyboard, just
type in the exclamation mark.

00:05:48.710 --> 00:05:51.470 align:middle line:90%
You can then say, !/bin/bash.

00:05:51.470 --> 00:05:54.620 align:middle line:84%
And because the man
utility or the man binary

00:05:54.620 --> 00:05:57.830 align:middle line:84%
is running with sudo or
root privileges, whatever

00:05:57.830 --> 00:06:00.320 align:middle line:84%
we execute from
within man will be

00:06:00.320 --> 00:06:02.220 align:middle line:90%
executed with those privileges.

00:06:02.220 --> 00:06:05.690 align:middle line:84%
So in this case, we should
receive a bash session

00:06:05.690 --> 00:06:06.950 align:middle line:90%
with root privileges.

00:06:06.950 --> 00:06:09.410 align:middle line:84%
So hit let Enter,
and there you go.

00:06:09.410 --> 00:06:12.170 align:middle line:84%
We have elevated our
privileges successfully.

00:06:12.170 --> 00:06:15.020 align:middle line:84%
And in this case, there is
a flag for you to capture,

00:06:15.020 --> 00:06:19.820 align:middle line:84%
so I'll head over to the home
directory of the root user.

00:06:19.820 --> 00:06:22.530 align:middle line:84%
And I can say, cat
flag, and there you go.

00:06:22.530 --> 00:06:25.820 align:middle line:84%
So we've successfully been
able to elevate our privileges

00:06:25.820 --> 00:06:27.630 align:middle line:90%
on a Linux system.

00:06:27.630 --> 00:06:29.720 align:middle line:84%
Now, the reason why
I wanted to showcase

00:06:29.720 --> 00:06:32.450 align:middle line:84%
this particular
vulnerability is primarily

00:06:32.450 --> 00:06:34.460 align:middle line:84%
because this is
one that you will

00:06:34.460 --> 00:06:38.840 align:middle line:84%
run across quite a lot and not
really for the main utility.

00:06:38.840 --> 00:06:41.090 align:middle line:84%
What typically
happens is, as I said,

00:06:41.090 --> 00:06:44.420 align:middle line:84%
the administrator
of the system will

00:06:44.420 --> 00:06:47.840 align:middle line:84%
be informed by other users
that are also using the Linux

00:06:47.840 --> 00:06:50.150 align:middle line:84%
server, and they
will essentially

00:06:50.150 --> 00:06:54.770 align:middle line:84%
ask him to, essentially,
set specific sudo privileges

00:06:54.770 --> 00:06:57.140 align:middle line:84%
for specific binaries
that they need

00:06:57.140 --> 00:06:59.060 align:middle line:90%
to run with sudo privileges.

00:06:59.060 --> 00:07:01.520 align:middle line:84%
However, that's really
not the issue here.

00:07:01.520 --> 00:07:06.080 align:middle line:84%
Because from the perspective
of the system administrator,

00:07:06.080 --> 00:07:06.770 align:middle line:90%
when--

00:07:06.770 --> 00:07:10.160 align:middle line:84%
so if we actually go back to
the student accounts, if I say,

00:07:10.160 --> 00:07:16.130 align:middle line:84%
su student right over here,
and I say, /bin/bash -I,

00:07:16.130 --> 00:07:17.310 align:middle line:90%
you can see we're back here.

00:07:17.310 --> 00:07:18.785 align:middle line:90%
So I'll just type in sudo -l.

00:07:18.785 --> 00:07:21.200 align:middle line:84%
You can see that the
administrator really

00:07:21.200 --> 00:07:23.180 align:middle line:84%
didn't do anything
wrong in his mind

00:07:23.180 --> 00:07:26.810 align:middle line:84%
because for the
sake of convenience,

00:07:26.810 --> 00:07:30.980 align:middle line:84%
he doesn't want the other
users on the system to ask him

00:07:30.980 --> 00:07:34.910 align:middle line:84%
or her for the root
user account password.

00:07:34.910 --> 00:07:37.250 align:middle line:90%
So it says, (ROOT) NOPASSWD.

00:07:37.250 --> 00:07:39.750 align:middle line:84%
And they can only execute
the following binary.

00:07:39.750 --> 00:07:41.570 align:middle line:84%
So he's limiting
those permissions

00:07:41.570 --> 00:07:43.140 align:middle line:90%
to a specific binary.

00:07:43.140 --> 00:07:47.810 align:middle line:84%
So the issue here is with
specific binaries on Linux.

00:07:47.810 --> 00:07:51.410 align:middle line:84%
In addition to performing
the functionality that they

00:07:51.410 --> 00:07:53.690 align:middle line:84%
were developed
for, they can also

00:07:53.690 --> 00:07:56.090 align:middle line:84%
be used to execute
specific commands.

00:07:56.090 --> 00:07:59.360 align:middle line:84%
And in the case of man,
we are able to execute

00:07:59.360 --> 00:08:01.370 align:middle line:90%
or to launch a bash session.

00:08:01.370 --> 00:08:03.800 align:middle line:84%
And if the man
utility, or binary,

00:08:03.800 --> 00:08:06.230 align:middle line:84%
or rather any binary
that has been configured

00:08:06.230 --> 00:08:08.510 align:middle line:84%
with the following
sudo privileges

00:08:08.510 --> 00:08:12.590 align:middle line:84%
runs with those privileges, then
that means whatever we execute

00:08:12.590 --> 00:08:14.690 align:middle line:84%
will be executed
as the root user.

00:08:14.690 --> 00:08:16.970 align:middle line:84%
And in order to
elevate our privileges,

00:08:16.970 --> 00:08:20.030 align:middle line:84%
all that we needed
to do was just

00:08:20.030 --> 00:08:22.310 align:middle line:84%
say we want to launch
a bash session,

00:08:22.310 --> 00:08:23.690 align:middle line:90%
and it did that for us.

00:08:23.690 --> 00:08:28.160 align:middle line:84%
And because that command was
executed with root privileges,

00:08:28.160 --> 00:08:32.970 align:middle line:84%
it executed or opened up a bash
session with those privileges.

00:08:32.970 --> 00:08:34.880 align:middle line:84%
So it's fairly
simple to understand.

00:08:34.880 --> 00:08:37.440 align:middle line:84%
And again, we can just
recreate it one more time.

00:08:37.440 --> 00:08:40.940 align:middle line:84%
So sudo man, and we
can say cd this time.

00:08:40.940 --> 00:08:44.360 align:middle line:84%
And there's no manual entry
for cd, so we can say, nano.

00:08:44.360 --> 00:08:45.380 align:middle line:90%
Let's try that.

00:08:45.380 --> 00:08:46.760 align:middle line:90%
Nothing there.

00:08:46.760 --> 00:08:48.170 align:middle line:90%
Do we have vim installed?

00:08:48.170 --> 00:08:49.410 align:middle line:90%
Yes, that is installed.

00:08:49.410 --> 00:08:52.730 align:middle line:84%
So I can say,
!/bin/bash, hit Enter,

00:08:52.730 --> 00:08:56.180 align:middle line:84%
and we've successfully
elevated our privileges.

00:08:56.180 --> 00:08:59.270 align:middle line:84%
So that is going to conclude
the practical demonstration

00:08:59.270 --> 00:09:01.200 align:middle line:90%
side of this video.

00:09:01.200 --> 00:09:04.400 align:middle line:84%
All right, so that concludes
the Linux privilege escalation

00:09:04.400 --> 00:09:05.670 align:middle line:90%
section of this course.

00:09:05.670 --> 00:09:08.760 align:middle line:84%
As I said, this the main
focus of this course

00:09:08.760 --> 00:09:12.050 align:middle line:84%
is to go through all of the
post exploitation phases,

00:09:12.050 --> 00:09:14.060 align:middle line:84%
and privilege escalation
is one of them.

00:09:14.060 --> 00:09:17.480 align:middle line:84%
I have covered privilege
escalation in quite a few

00:09:17.480 --> 00:09:20.600 align:middle line:84%
courses, from system
and host-based attacks--

00:09:20.600 --> 00:09:22.910 align:middle line:84%
the system and
host-based attacks course

00:09:22.910 --> 00:09:24.410 align:middle line:84%
to the Metasploit
framework course.

00:09:24.410 --> 00:09:26.500 align:middle line:84%
And I've covered
multiple techniques

00:09:26.500 --> 00:09:28.250 align:middle line:84%
that you can also take
a look at if you're

00:09:28.250 --> 00:09:31.370 align:middle line:84%
interested in learning more
about privilege escalation.

00:09:31.370 --> 00:09:33.080 align:middle line:84%
With that being
said, we're now going

00:09:33.080 --> 00:09:36.260 align:middle line:84%
to move on to the next
section of this course, which

00:09:36.260 --> 00:09:39.780 align:middle line:84%
is focused on persistence,
both on Windows and Linux.

00:09:39.780 --> 00:09:42.620 align:middle line:84%
So we'll be starting off
with establishing persistence

00:09:42.620 --> 00:09:46.100 align:middle line:84%
on Windows, and we'll take a
look at a couple of techniques.

00:09:46.100 --> 00:09:48.870 align:middle line:84%
And then, we'll move on to
the Linux persistence section.

00:09:48.870 --> 00:09:51.440 align:middle line:84%
We'll explore a couple of
techniques that we can use,

00:09:51.440 --> 00:09:54.440 align:middle line:84%
and that is then going to
conclude the persistence

00:09:54.440 --> 00:09:54.980 align:middle line:90%
section.

00:09:54.980 --> 00:09:58.040 align:middle line:84%
And we can then move on to
the next section after that.

00:09:58.040 --> 00:10:02.380 align:middle line:84%
With that being said, I'll be
seeing you in the next video.

00:10:02.380 --> 00:10:03.000 align:middle line:90%