WEBVTT

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


00:00:10.140 --> 00:00:12.750 align:middle line:84%
Exploiting
Misconfigured Cron Jobs.

00:00:12.750 --> 00:00:14.700 align:middle line:84%
In this video, we
will be exploring

00:00:14.700 --> 00:00:18.210 align:middle line:84%
the process of searching
for and identifying

00:00:18.210 --> 00:00:20.670 align:middle line:84%
misconfigured Cron jobs,
and taking a look at how

00:00:20.670 --> 00:00:23.460 align:middle line:84%
we can essentially
exploit them in order

00:00:23.460 --> 00:00:25.170 align:middle line:90%
to elevate our privileges.

00:00:25.170 --> 00:00:28.620 align:middle line:84%
Now, before we get started
with the actual exploitation

00:00:28.620 --> 00:00:30.210 align:middle line:84%
process, let's get
an understanding

00:00:30.210 --> 00:00:31.940 align:middle line:90%
of what Cron jobs are.

00:00:31.940 --> 00:00:33.060 align:middle line:90%
What is Cron?

00:00:33.060 --> 00:00:36.210 align:middle line:84%
Well, Linux implements
task scheduling

00:00:36.210 --> 00:00:38.820 align:middle line:84%
through a utility
called Cron, all right?

00:00:38.820 --> 00:00:41.160 align:middle line:84%
Now, Cron is a
time based service

00:00:41.160 --> 00:00:44.040 align:middle line:84%
that runs applications,
scripts, and other commands

00:00:44.040 --> 00:00:46.770 align:middle line:84%
repeatedly on a
specified schedule.

00:00:46.770 --> 00:00:48.540 align:middle line:84%
An application or
script that has

00:00:48.540 --> 00:00:50.910 align:middle line:84%
been configured to run
repeatedly with Cron

00:00:50.910 --> 00:00:52.890 align:middle line:90%
is known as a Cron job.

00:00:52.890 --> 00:00:55.050 align:middle line:84%
Cron can be used to
automate or repeat

00:00:55.050 --> 00:00:57.780 align:middle line:84%
a wide variety of
functions on a Linux system

00:00:57.780 --> 00:01:01.600 align:middle line:84%
from daily backups to
system upgrades and patches.

00:01:01.600 --> 00:01:06.420 align:middle line:84%
So Cron jobs is really an
element of the Linux operating

00:01:06.420 --> 00:01:08.160 align:middle line:84%
system that you will
be running across,

00:01:08.160 --> 00:01:11.550 align:middle line:84%
especially if the Linux target
that you're dealing with

00:01:11.550 --> 00:01:13.380 align:middle line:84%
is actually a Linux
server, right?

00:01:13.380 --> 00:01:15.420 align:middle line:90%
So why are they created?

00:01:15.420 --> 00:01:16.470 align:middle line:90%
What is a Cron job?

00:01:16.470 --> 00:01:20.100 align:middle line:84%
Well, a Cron job is essentially
in the context of Windows

00:01:20.100 --> 00:01:22.710 align:middle line:84%
what you might consider
a scheduled task, right?

00:01:22.710 --> 00:01:24.390 align:middle line:84%
So it's a task that
has been configured

00:01:24.390 --> 00:01:27.060 align:middle line:90%
to run on a specified schedule.

00:01:27.060 --> 00:01:29.250 align:middle line:84%
Now, the way system
administrators

00:01:29.250 --> 00:01:33.240 align:middle line:84%
utilize Cron jobs is to repeat
otherwise repetitive tasks

00:01:33.240 --> 00:01:37.230 align:middle line:84%
like taking backups of specific
folders, updating packages,

00:01:37.230 --> 00:01:39.570 align:middle line:84%
and anything else that they
would like to automate.

00:01:39.570 --> 00:01:42.300 align:middle line:84%
And the great thing with Cron
is that you can essentially

00:01:42.300 --> 00:01:47.310 align:middle line:84%
have a particular task or
script or command executed

00:01:47.310 --> 00:01:48.660 align:middle line:90%
on a specified schedule.

00:01:48.660 --> 00:01:51.180 align:middle line:84%
So I can repeat a
Cron job or I can

00:01:51.180 --> 00:01:53.850 align:middle line:84%
set a Cron job to
run every one minute

00:01:53.850 --> 00:01:58.110 align:middle line:84%
of every hour of every day
of every week of every month.

00:01:58.110 --> 00:02:01.020 align:middle line:84%
Or I can set it to
run once every week

00:02:01.020 --> 00:02:03.030 align:middle line:84%
or once every month,
et cetera, et cetera.

00:02:03.030 --> 00:02:06.480 align:middle line:84%
It's really, really limitless
in terms of the schedule

00:02:06.480 --> 00:02:09.400 align:middle line:84%
that you can set up for
a specific Cron job.

00:02:09.400 --> 00:02:09.900 align:middle line:90%
All right.

00:02:09.900 --> 00:02:13.980 align:middle line:84%
So as I said, the typical
scenario that you would have

00:02:13.980 --> 00:02:16.590 align:middle line:84%
is where you have a
system administrator who

00:02:16.590 --> 00:02:20.940 align:middle line:84%
wants to automate a specific
repeated or repetitive task

00:02:20.940 --> 00:02:24.390 align:middle line:84%
like taking a backup of
a user's home directory

00:02:24.390 --> 00:02:26.530 align:middle line:84%
or any directory
for that matter.

00:02:26.530 --> 00:02:30.210 align:middle line:84%
Well, they can create a Cron job
that executes the command that

00:02:30.210 --> 00:02:31.740 align:middle line:90%
actually performs that backup.

00:02:31.740 --> 00:02:37.200 align:middle line:84%
So the command could be
copy home user and copy it

00:02:37.200 --> 00:02:39.810 align:middle line:84%
to another directory maybe
under the /var directory,

00:02:39.810 --> 00:02:43.770 align:middle line:84%
under backups, or they could--
and this is what is typically

00:02:43.770 --> 00:02:46.950 align:middle line:84%
done-- they could create a
shell script that contains those

00:02:46.950 --> 00:02:47.620 align:middle line:90%
commands.

00:02:47.620 --> 00:02:49.740 align:middle line:84%
And again, that
Cron job will then

00:02:49.740 --> 00:02:54.270 align:middle line:84%
execute that particular shell
script on a specified schedule

00:02:54.270 --> 00:02:57.930 align:middle line:84%
so it could be done every
1 minute or every week,

00:02:57.930 --> 00:02:59.310 align:middle line:90%
et cetera, et cetera, right?

00:02:59.310 --> 00:03:03.510 align:middle line:84%
Now, the crontab file
is a configuration file

00:03:03.510 --> 00:03:06.450 align:middle line:84%
that is used by the Cron
utility to store and track

00:03:06.450 --> 00:03:08.910 align:middle line:84%
Cron jobs that
have been created.

00:03:08.910 --> 00:03:10.650 align:middle line:84%
So if you're ever
on a Linux system

00:03:10.650 --> 00:03:13.230 align:middle line:84%
and want to identify what
Cron jobs are currently

00:03:13.230 --> 00:03:16.050 align:middle line:84%
active and configured,
you can essentially

00:03:16.050 --> 00:03:18.330 align:middle line:84%
display the content
of the crontab file,

00:03:18.330 --> 00:03:20.760 align:middle line:84%
and that should display
the Cron jobs that

00:03:20.760 --> 00:03:23.490 align:middle line:84%
have been configured for
that specific user account

00:03:23.490 --> 00:03:25.245 align:middle line:90%
that you have access to.

00:03:25.245 --> 00:03:25.860 align:middle line:90%
All right.

00:03:25.860 --> 00:03:29.790 align:middle line:84%
Now, in terms of exploiting
misconfigured Cron jobs,

00:03:29.790 --> 00:03:32.430 align:middle line:84%
it's very important to note
that Cron jobs can also be

00:03:32.430 --> 00:03:34.450 align:middle line:90%
run as any user on the system.

00:03:34.450 --> 00:03:37.270 align:middle line:84%
So let me just break
this down a little bit.

00:03:37.270 --> 00:03:39.300 align:middle line:84%
So again, a current
job can really

00:03:39.300 --> 00:03:41.500 align:middle line:84%
be set up by any
user on the system.

00:03:41.500 --> 00:03:44.280 align:middle line:84%
However, in the context
of privilege escalation,

00:03:44.280 --> 00:03:46.500 align:middle line:84%
we are going to be
targeting Cron jobs

00:03:46.500 --> 00:03:49.920 align:middle line:84%
that have been created or that
have been scheduled by the root

00:03:49.920 --> 00:03:50.490 align:middle line:90%
user, right?

00:03:50.490 --> 00:03:53.010 align:middle line:84%
Because Cron jobs that have
been created or scheduled

00:03:53.010 --> 00:03:56.830 align:middle line:84%
by the root user will
run with root privileges.

00:03:56.830 --> 00:03:57.330 align:middle line:90%
All right.

00:03:57.330 --> 00:03:59.520 align:middle line:84%
So as I said, this is
a very important thing

00:03:59.520 --> 00:04:01.320 align:middle line:90%
to keep in mind.

00:04:01.320 --> 00:04:03.840 align:middle line:84%
This is primarily because
any script or command that

00:04:03.840 --> 00:04:05.610 align:middle line:90%
is being run by a Cron job--

00:04:05.610 --> 00:04:07.950 align:middle line:84%
so if a shell
script is being run,

00:04:07.950 --> 00:04:11.370 align:middle line:84%
then it will run as the root
user or with root privileges.

00:04:11.370 --> 00:04:14.580 align:middle line:84%
And if we find a way
of taking advantage

00:04:14.580 --> 00:04:18.029 align:middle line:84%
of a shell script for example,
a misconfigured shell script

00:04:18.029 --> 00:04:21.120 align:middle line:84%
then we can get it to
execute any other commands

00:04:21.120 --> 00:04:23.550 align:middle line:84%
that we would like it to
execute with root privileges.

00:04:23.550 --> 00:04:26.910 align:middle line:84%
So we could connect
to a Netcat listener,

00:04:26.910 --> 00:04:29.550 align:middle line:84%
and that is going to
provide us with privileges

00:04:29.550 --> 00:04:31.840 align:middle line:90%
or we could run other commands.

00:04:31.840 --> 00:04:35.340 align:middle line:84%
For example, we could add
a specific command to add

00:04:35.340 --> 00:04:39.210 align:middle line:84%
the current user that we have
access to the sudoers file

00:04:39.210 --> 00:04:43.170 align:middle line:84%
consequently allowing us
to perform tasks that would

00:04:43.170 --> 00:04:46.560 align:middle line:84%
require root privileges or that
require root privileges without

00:04:46.560 --> 00:04:49.110 align:middle line:84%
having to provide
a password, right ?

00:04:49.110 --> 00:04:52.560 align:middle line:84%
So really, the
crux of this really

00:04:52.560 --> 00:04:55.650 align:middle line:84%
revolves around the ability
to find and identify

00:04:55.650 --> 00:04:58.440 align:middle line:84%
Cron jobs that have been
scheduled by the root user

00:04:58.440 --> 00:05:01.140 align:middle line:84%
or the files being
processed by the Cron job.

00:05:01.140 --> 00:05:03.430 align:middle line:84%
So as I said, in
this context, we

00:05:03.430 --> 00:05:07.360 align:middle line:84%
are going to be taking a look
at a Cron job that essentially

00:05:07.360 --> 00:05:09.460 align:middle line:90%
runs a specific shell script.

00:05:09.460 --> 00:05:11.680 align:middle line:84%
Now, you might be thinking
to yourself, well,

00:05:11.680 --> 00:05:14.410 align:middle line:84%
if the shell script has been
created by the root user

00:05:14.410 --> 00:05:17.140 align:middle line:84%
and the Cron job has been
created by the root user, well,

00:05:17.140 --> 00:05:19.600 align:middle line:84%
how do we exploit or
what misconfigurations

00:05:19.600 --> 00:05:20.870 align:middle line:90%
are we looking for?

00:05:20.870 --> 00:05:24.820 align:middle line:84%
Well, if that shell script
has improper permissions,

00:05:24.820 --> 00:05:27.700 align:middle line:84%
meaning that shell
script essentially

00:05:27.700 --> 00:05:30.830 align:middle line:84%
can be edited by any
user on the system,

00:05:30.830 --> 00:05:32.980 align:middle line:84%
then that means that
we can essentially

00:05:32.980 --> 00:05:34.720 align:middle line:84%
input any commands
that we would like

00:05:34.720 --> 00:05:36.710 align:middle line:90%
executed into that shell script.

00:05:36.710 --> 00:05:40.930 align:middle line:84%
And once that Cron job is run,
that particular shell script

00:05:40.930 --> 00:05:43.060 align:middle line:84%
will be executed
with root privileges.

00:05:43.060 --> 00:05:44.980 align:middle line:84%
And the command
that we specified

00:05:44.980 --> 00:05:48.550 align:middle line:84%
within that shell script will be
executed with root privileges.

00:05:48.550 --> 00:05:52.660 align:middle line:84%
Now, as I said, there's
multiple misconfigurations

00:05:52.660 --> 00:05:55.360 align:middle line:84%
that surround Cron
jobs or Cron that

00:05:55.360 --> 00:05:57.190 align:middle line:84%
can be used to elevate
your privileges.

00:05:57.190 --> 00:05:59.065 align:middle line:84%
In this case, we're
going to be taking a look

00:05:59.065 --> 00:06:01.960 align:middle line:84%
at a very simple scenario
that will again, explain

00:06:01.960 --> 00:06:06.280 align:middle line:84%
this vulnerability and will give
you an idea as to how one can

00:06:06.280 --> 00:06:09.190 align:middle line:84%
find ingenious ways of
elevating your privileges

00:06:09.190 --> 00:06:13.000 align:middle line:84%
through misconfigured Cron
jobs or the files or scripts

00:06:13.000 --> 00:06:14.980 align:middle line:90%
associated with a Cron job.

00:06:14.980 --> 00:06:17.500 align:middle line:84%
And of course, this is a
vulnerability or privilege

00:06:17.500 --> 00:06:21.310 align:middle line:84%
escalation vector that we will
be exploring in the privilege

00:06:21.310 --> 00:06:22.955 align:middle line:90%
escalation course in depth.

00:06:22.955 --> 00:06:25.330 align:middle line:84%
And we'll be taking a look at
the various techniques that

00:06:25.330 --> 00:06:28.570 align:middle line:84%
can be used to elevate your
privileges by exploiting

00:06:28.570 --> 00:06:30.200 align:middle line:90%
misconfigured Cron jobs.

00:06:30.200 --> 00:06:30.700 align:middle line:90%
All right.

00:06:30.700 --> 00:06:31.810 align:middle line:90%
So let's get started.

00:06:31.810 --> 00:06:34.790 align:middle line:84%
This video already has a lab
environment attached to it.

00:06:34.790 --> 00:06:36.928 align:middle line:84%
So all you need to
do is just fire it up

00:06:36.928 --> 00:06:38.470 align:middle line:84%
and I'll take you
through the process

00:06:38.470 --> 00:06:40.280 align:middle line:90%
of exploiting the Cron job.

00:06:40.280 --> 00:06:43.450 align:middle line:84%
And by the end of it, we should
have elevated our privileges.

00:06:43.450 --> 00:06:48.290 align:middle line:84%
So I'll see you within
the lab environment.

00:06:48.290 --> 00:06:48.790 align:middle line:90%
All right.

00:06:48.790 --> 00:06:50.990 align:middle line:84%
So I'm back within
the lab environment.

00:06:50.990 --> 00:06:53.230 align:middle line:84%
And within this lab
environment, you

00:06:53.230 --> 00:06:56.830 align:middle line:84%
are not required to exploit or
gain access to a Linux system.

00:06:56.830 --> 00:07:00.130 align:middle line:84%
You already provided with
access on the target system

00:07:00.130 --> 00:07:03.050 align:middle line:84%
as the user student who
is an unprivileged user.

00:07:03.050 --> 00:07:06.430 align:middle line:84%
So again, if I say who am I,
you can see that is student.

00:07:06.430 --> 00:07:09.800 align:middle line:84%
And if I list out the groups
that this user is a part of.

00:07:09.800 --> 00:07:11.020 align:middle line:90%
So I can say--

00:07:11.020 --> 00:07:15.110 align:middle line:84%
let me type that in correctly--
so I can say groups student.

00:07:15.110 --> 00:07:17.750 align:middle line:84%
You can see that it's a
part of its own group here

00:07:17.750 --> 00:07:19.340 align:middle line:84%
and is not part of
the pseudo group.

00:07:19.340 --> 00:07:22.192 align:middle line:84%
So this is an
unprivileged user account.

00:07:22.192 --> 00:07:23.900 align:middle line:84%
And of course, we are
going to be looking

00:07:23.900 --> 00:07:27.140 align:middle line:84%
to elevate our privileges
and obtain permissions,

00:07:27.140 --> 00:07:31.280 align:middle line:84%
the permissions associated
with the root user account.

00:07:31.280 --> 00:07:33.680 align:middle line:84%
We really don't need to gain
access to the root account

00:07:33.680 --> 00:07:37.130 align:middle line:84%
if we can essentially
obtain pseudo permissions.

00:07:37.130 --> 00:07:39.470 align:middle line:84%
Then that means that
we can execute commands

00:07:39.470 --> 00:07:42.140 align:middle line:84%
that require root privileges
without having to provide

00:07:42.140 --> 00:07:43.800 align:middle line:90%
a password for example.

00:07:43.800 --> 00:07:46.910 align:middle line:84%
So as I said, this is
really the target account.

00:07:46.910 --> 00:07:49.010 align:middle line:84%
All the privileges
that we're looking for

00:07:49.010 --> 00:07:51.570 align:middle line:84%
are associated with
the root account.

00:07:51.570 --> 00:07:52.070 align:middle line:90%
All right.

00:07:52.070 --> 00:07:55.340 align:middle line:84%
So as I said, you can
identify the Cron jobs

00:07:55.340 --> 00:07:57.740 align:middle line:84%
that have been scheduled
for this particular user

00:07:57.740 --> 00:07:59.727 align:middle line:90%
by saying crontab-l.

00:07:59.727 --> 00:08:01.310 align:middle line:84%
And you can see it's
going to tell us,

00:08:01.310 --> 00:08:02.630 align:middle line:90%
no crontab for student.

00:08:02.630 --> 00:08:05.210 align:middle line:84%
Well, how do we
find out whether we

00:08:05.210 --> 00:08:08.050 align:middle line:84%
have any Cron jobs that have
been scheduled by the root

00:08:08.050 --> 00:08:08.550 align:middle line:90%
user?

00:08:08.550 --> 00:08:11.750 align:middle line:84%
Well, really it's going to
require a lot of enumeration

00:08:11.750 --> 00:08:12.740 align:middle line:90%
and searching.

00:08:12.740 --> 00:08:16.460 align:middle line:84%
However, in this lab
environment the actual technique

00:08:16.460 --> 00:08:19.850 align:middle line:84%
or the scenario has been
made much simpler so that you

00:08:19.850 --> 00:08:21.420 align:middle line:90%
understand what's going on.

00:08:21.420 --> 00:08:25.310 align:middle line:84%
So if we list out the contents
of the students home directory,

00:08:25.310 --> 00:08:27.680 align:middle line:84%
you can see that we have
a file called message

00:08:27.680 --> 00:08:30.260 align:middle line:84%
that is owned by the
root account, which

00:08:30.260 --> 00:08:33.860 align:middle line:84%
is very interesting because
we are working within the home

00:08:33.860 --> 00:08:34.700 align:middle line:90%
student directory.

00:08:34.700 --> 00:08:37.520 align:middle line:84%
So why would the root
user count store a file

00:08:37.520 --> 00:08:40.520 align:middle line:90%
within the student account?

00:08:40.520 --> 00:08:44.030 align:middle line:84%
So this file potentially be
associated with a Cron job?

00:08:44.030 --> 00:08:47.300 align:middle line:84%
Well, if we try and cut out the
content of the message file,

00:08:47.300 --> 00:08:49.700 align:middle line:84%
you'll see it's going to
tell us, permission denied,

00:08:49.700 --> 00:08:53.360 align:middle line:84%
which makes sense because it's
owned by the actual root user.

00:08:53.360 --> 00:08:55.380 align:middle line:84%
And you can see the
actual permissions here.

00:08:55.380 --> 00:08:58.550 align:middle line:84%
So only the root user can
read and write or make changes

00:08:58.550 --> 00:09:02.330 align:middle line:84%
to it, whereas every other user
account and group on the system

00:09:02.330 --> 00:09:06.850 align:middle line:84%
doesn't have the privileges
associated or required

00:09:06.850 --> 00:09:09.200 align:middle line:84%
to actually read the
contents of this file

00:09:09.200 --> 00:09:11.530 align:middle line:90%
or make changes to it.

00:09:11.530 --> 00:09:12.030 align:middle line:90%
All right.

00:09:12.030 --> 00:09:14.040 align:middle line:90%
So we do know one thing.

00:09:14.040 --> 00:09:16.560 align:middle line:84%
We know that this
particular file

00:09:16.560 --> 00:09:20.100 align:middle line:84%
is being stored within the
student's home directory.

00:09:20.100 --> 00:09:23.160 align:middle line:84%
So we know that the file
is under /home/student,

00:09:23.160 --> 00:09:25.020 align:middle line:90%
and the file name is message.

00:09:25.020 --> 00:09:27.660 align:middle line:84%
So we could try
and identify where

00:09:27.660 --> 00:09:31.470 align:middle line:84%
this particular string of text
or where the path is specified.

00:09:31.470 --> 00:09:34.223 align:middle line:84%
And in order to do this,
we can utilize a utility.

00:09:34.223 --> 00:09:35.640 align:middle line:84%
So what we're going
to do is we're

00:09:35.640 --> 00:09:39.360 align:middle line:84%
going to utilize the
actual grep utility.

00:09:39.360 --> 00:09:41.670 align:middle line:84%
And we are going to
look for all occurrences

00:09:41.670 --> 00:09:44.520 align:middle line:84%
of the path
specified to the file

00:09:44.520 --> 00:09:47.040 align:middle line:84%
and try and see whether we
have any occurrences of it

00:09:47.040 --> 00:09:50.280 align:middle line:84%
within a shell script or any
other file for that matter.

00:09:50.280 --> 00:09:54.090 align:middle line:84%
That may shed a light on
what exactly is being done

00:09:54.090 --> 00:09:57.600 align:middle line:84%
or why this file exists within
the student home directory.

00:09:57.600 --> 00:10:00.960 align:middle line:84%
So I'll just navigate to the
root of the Linux file system.

00:10:00.960 --> 00:10:03.270 align:middle line:84%
And we can use the grep
utility, and we're going

00:10:03.270 --> 00:10:06.510 align:middle line:90%
to search recursively within--

00:10:06.510 --> 00:10:08.730 align:middle line:84%
we can start off with
the user directory.

00:10:08.730 --> 00:10:10.800 align:middle line:84%
So this is typically
where you would find

00:10:10.800 --> 00:10:12.780 align:middle line:90%
shell scripts being stored.

00:10:12.780 --> 00:10:15.900 align:middle line:84%
And what we're looking for
is, again any occurrence

00:10:15.900 --> 00:10:18.720 align:middle line:84%
of the path in a
/home/student/message.

00:10:18.720 --> 00:10:23.400 align:middle line:90%


00:10:23.400 --> 00:10:26.410 align:middle line:84%
And I'm just going to
close that up there.

00:10:26.410 --> 00:10:28.840 align:middle line:84%
So again, just to reiterate
what I said earlier,

00:10:28.840 --> 00:10:32.040 align:middle line:84%
we are essentially utilizing
the grep utility to find any

00:10:32.040 --> 00:10:34.770 align:middle line:84%
occurrences of the path
/home/student/message

00:10:34.770 --> 00:10:37.840 align:middle line:84%
because if there is a shell
script that is being used,

00:10:37.840 --> 00:10:41.610 align:middle line:84%
then it is very likely that
it contains the actual path

00:10:41.610 --> 00:10:44.550 align:middle line:84%
or rather the actual path to
this particular file or where

00:10:44.550 --> 00:10:46.180 align:middle line:90%
this file is being stored.

00:10:46.180 --> 00:10:48.270 align:middle line:84%
So we can hit enter,
and let's see whether we

00:10:48.270 --> 00:10:49.590 align:middle line:90%
are able to identify anything.

00:10:49.590 --> 00:10:50.940 align:middle line:90%
Well, that's interesting.

00:10:50.940 --> 00:10:55.800 align:middle line:84%
So it looks like we find a
shell script called copy.sh,

00:10:55.800 --> 00:10:57.960 align:middle line:84%
and it's under
/local/user/share.

00:10:57.960 --> 00:11:01.650 align:middle line:84%
And the occurrence of the
string as you can see here

00:11:01.650 --> 00:11:05.430 align:middle line:84%
tells us that this file is been
copied into the temp directory.

00:11:05.430 --> 00:11:09.580 align:middle line:84%
So if we list out the contents
of the temp directory,

00:11:09.580 --> 00:11:11.840 align:middle line:84%
you can see, indeed we
have the message fall here.

00:11:11.840 --> 00:11:16.847 align:middle line:84%
So if I cut out the message
file within the temp directory,

00:11:16.847 --> 00:11:19.180 align:middle line:84%
you can see it's going to
tell us, hey, you're not root.

00:11:19.180 --> 00:11:22.210 align:middle line:84%
So again, this is just a simple
example or a scenario that

00:11:22.210 --> 00:11:23.840 align:middle line:90%
was used to highlight this.

00:11:23.840 --> 00:11:25.930 align:middle line:84%
So let's take a look
at this shell script,

00:11:25.930 --> 00:11:28.870 align:middle line:84%
and let's see what
exactly is being done.

00:11:28.870 --> 00:11:30.940 align:middle line:84%
However, before
we do that, let's

00:11:30.940 --> 00:11:33.310 align:middle line:84%
actually check the permissions
for this shell script.

00:11:33.310 --> 00:11:35.620 align:middle line:84%
Can we actually
modify it and get

00:11:35.620 --> 00:11:37.900 align:middle line:84%
it to run with root
privileges or get

00:11:37.900 --> 00:11:41.590 align:middle line:84%
it to execute any of our own
commands with root privileges?

00:11:41.590 --> 00:11:44.800 align:middle line:84%
In order to do this, I'm
going to use the LSAL command,

00:11:44.800 --> 00:11:48.490 align:middle line:84%
and say we want to list all the
permissions of the shell script

00:11:48.490 --> 00:11:52.190 align:middle line:90%
under /usr/local/share/copy.sh.

00:11:52.190 --> 00:11:52.690 align:middle line:90%
All right.

00:11:52.690 --> 00:11:58.750 align:middle line:84%
So we can see that this script
is owned by the root account

00:11:58.750 --> 00:11:59.772 align:middle line:90%
right over here.

00:11:59.772 --> 00:12:01.480 align:middle line:84%
But if we take a look
at the permissions,

00:12:01.480 --> 00:12:04.660 align:middle line:84%
you can see that every user
count in group on the system

00:12:04.660 --> 00:12:07.750 align:middle line:84%
has read, write, and
execute permissions,

00:12:07.750 --> 00:12:10.870 align:middle line:84%
which means we can execute
this or rather we can edit it.

00:12:10.870 --> 00:12:13.930 align:middle line:84%
But if we execute it with
our current privileges,

00:12:13.930 --> 00:12:16.150 align:middle line:84%
then we really are not
going to get anywhere.

00:12:16.150 --> 00:12:18.490 align:middle line:84%
What we want it to
do or what we want

00:12:18.490 --> 00:12:22.660 align:middle line:84%
to happen here is we want
to add a line of code

00:12:22.660 --> 00:12:25.450 align:middle line:84%
within this particular
shell script, right?

00:12:25.450 --> 00:12:31.030 align:middle line:84%
And we want to essentially have
the Cron job executed this.

00:12:31.030 --> 00:12:33.810 align:middle line:84%
And we really aren't aware of
the schedule behind the Cron

00:12:33.810 --> 00:12:34.310 align:middle line:90%
job.

00:12:34.310 --> 00:12:36.070 align:middle line:84%
But again, as I said,
this lab environment

00:12:36.070 --> 00:12:40.270 align:middle line:84%
will execute the current
job every 1 minute.

00:12:40.270 --> 00:12:43.460 align:middle line:84%
So after 1 minute, this
script will be executed.

00:12:43.460 --> 00:12:46.780 align:middle line:84%
And so if we can get it to
execute a specific command,

00:12:46.780 --> 00:12:50.260 align:middle line:84%
command maybe that will
add us to the sudoers group

00:12:50.260 --> 00:12:53.170 align:middle line:84%
or added to the sudoers file,
consequently providing us

00:12:53.170 --> 00:12:55.750 align:middle line:84%
with elevated privileges
or root privileges,

00:12:55.750 --> 00:12:57.760 align:middle line:84%
then that will be
very, very helpful.

00:12:57.760 --> 00:13:00.580 align:middle line:84%
So because we can edit
it, if I can just cut out

00:13:00.580 --> 00:13:01.880 align:middle line:90%
the contents of the file.

00:13:01.880 --> 00:13:04.615 align:middle line:84%
So this is under
/usr/local/share/copy.sh.

00:13:04.615 --> 00:13:08.297 align:middle line:90%


00:13:08.297 --> 00:13:09.880 align:middle line:84%
You can see that
this is what it does.

00:13:09.880 --> 00:13:12.010 align:middle line:90%
So it's a bash script here.

00:13:12.010 --> 00:13:15.280 align:middle line:84%
And all that it does is
it just copies the message

00:13:15.280 --> 00:13:17.740 align:middle line:84%
from the home directory
of the student,

00:13:17.740 --> 00:13:20.080 align:middle line:84%
and it copies it into
the temp directory

00:13:20.080 --> 00:13:22.360 align:middle line:84%
under the same file
name, which is message.

00:13:22.360 --> 00:13:25.000 align:middle line:84%
And then modifies
the permissions

00:13:25.000 --> 00:13:27.700 align:middle line:84%
of the message file that's
stored within the temp

00:13:27.700 --> 00:13:29.960 align:middle line:84%
directory so that
any user can read it,

00:13:29.960 --> 00:13:32.500 align:middle line:84%
which is why we were
able to read it,

00:13:32.500 --> 00:13:34.340 align:middle line:84%
we were able to read
the message file that's

00:13:34.340 --> 00:13:36.100 align:middle line:90%
stored in the temp directory.

00:13:36.100 --> 00:13:37.910 align:middle line:84%
So it's essentially
the same file.

00:13:37.910 --> 00:13:40.730 align:middle line:84%
All it's all that's happening
is the Cron job or this shell

00:13:40.730 --> 00:13:43.900 align:middle line:84%
script is copying the
message file from the home

00:13:43.900 --> 00:13:46.600 align:middle line:84%
directory of the student
into the temp directory

00:13:46.600 --> 00:13:49.160 align:middle line:84%
and then changing
the permissions.

00:13:49.160 --> 00:13:49.660 align:middle line:90%
OK.

00:13:49.660 --> 00:13:52.330 align:middle line:84%
So let's find a way
of modifying it.

00:13:52.330 --> 00:13:55.690 align:middle line:84%
We don't have any text editors
within this particular lab

00:13:55.690 --> 00:13:56.660 align:middle line:90%
environment.

00:13:56.660 --> 00:13:59.390 align:middle line:84%
So we're going to have to
use an ingenious technique.

00:13:59.390 --> 00:14:02.110 align:middle line:84%
So in order to do this,
what we're going to do

00:14:02.110 --> 00:14:04.480 align:middle line:84%
is we are going to use
the printf command.

00:14:04.480 --> 00:14:07.600 align:middle line:84%
So printf and we are
then going to specify

00:14:07.600 --> 00:14:12.010 align:middle line:84%
that we want-- this is a
bash shell or a bash script.

00:14:12.010 --> 00:14:16.230 align:middle line:84%
So we'll specify the
environment variable bin/bash.

00:14:16.230 --> 00:14:16.730 align:middle line:90%
All right.

00:14:16.730 --> 00:14:20.370 align:middle line:90%
So we'll say bin/bash.

00:14:20.370 --> 00:14:21.390 align:middle line:90%
There we are.

00:14:21.390 --> 00:14:25.440 align:middle line:84%
And we then want to create a
new line and then say echo.

00:14:25.440 --> 00:14:28.260 align:middle line:84%
So we're now echoing
or redirecting text.

00:14:28.260 --> 00:14:30.120 align:middle line:84%
And the text that
we want to redirect

00:14:30.120 --> 00:14:32.410 align:middle line:84%
is going to involve
the student account.

00:14:32.410 --> 00:14:35.400 align:middle line:84%
So we're saying students
should have all permissions

00:14:35.400 --> 00:14:37.260 align:middle line:90%
without providing the password.

00:14:37.260 --> 00:14:39.750 align:middle line:90%
So we can say no password.

00:14:39.750 --> 00:14:42.480 align:middle line:84%
And this again comes down
to Linux permissions,

00:14:42.480 --> 00:14:44.970 align:middle line:84%
but I'm going to be
explaining it as we go on.

00:14:44.970 --> 00:14:46.740 align:middle line:84%
And again, all
permissions, right?

00:14:46.740 --> 00:14:50.430 align:middle line:84%
So what we're saying here is
we're echoing or redirecting

00:14:50.430 --> 00:14:52.740 align:middle line:84%
the following output
into the sudoers file.

00:14:52.740 --> 00:14:54.450 align:middle line:84%
And we're seeing
the student account

00:14:54.450 --> 00:14:56.370 align:middle line:84%
should have all
privileges and does not

00:14:56.370 --> 00:14:58.360 align:middle line:90%
need to specify a password.

00:14:58.360 --> 00:15:00.900 align:middle line:84%
And again, this particular
command requires

00:15:00.900 --> 00:15:03.390 align:middle line:84%
or the ability to
edit the sudoers file

00:15:03.390 --> 00:15:05.680 align:middle line:90%
requires root privileges.

00:15:05.680 --> 00:15:09.210 align:middle line:84%
So again, this will only
be executed once the shell

00:15:09.210 --> 00:15:10.870 align:middle line:90%
script is executed.

00:15:10.870 --> 00:15:13.020 align:middle line:84%
So we close the
quotation marks there,

00:15:13.020 --> 00:15:18.240 align:middle line:84%
and we are going to append
it to the etc sudoers file.

00:15:18.240 --> 00:15:21.810 align:middle line:84%
And we can then close
the single quotes there.

00:15:21.810 --> 00:15:25.860 align:middle line:84%
And we are going to then
output or essentially save this

00:15:25.860 --> 00:15:30.060 align:middle line:84%
or redirect this entire command
into the actual shell script

00:15:30.060 --> 00:15:32.310 align:middle line:84%
that is being executed
by the Cron job,

00:15:32.310 --> 00:15:34.944 align:middle line:84%
which is under
/usr/local/share/copy.sh.

00:15:34.944 --> 00:15:38.670 align:middle line:90%


00:15:38.670 --> 00:15:41.680 align:middle line:84%
So we hit Enter, and that
was done successfully.

00:15:41.680 --> 00:15:44.970 align:middle line:84%
So we can now cut out the
content of the shell script.

00:15:44.970 --> 00:15:49.630 align:middle line:84%
So we can say
/usr/local/share/copy.sh.

00:15:49.630 --> 00:15:54.300 align:middle line:84%
And you can see that is the
actual shell script there

00:15:54.300 --> 00:15:55.140 align:middle line:90%
or bash script.

00:15:55.140 --> 00:15:58.920 align:middle line:84%
So it essentially outputs or
echoes the following string

00:15:58.920 --> 00:16:04.020 align:middle line:84%
of text, "student all no
password all" into etc sudoers

00:16:04.020 --> 00:16:05.980 align:middle line:90%
and that is pretty much it.

00:16:05.980 --> 00:16:06.480 align:middle line:90%
OK.

00:16:06.480 --> 00:16:09.360 align:middle line:84%
So now, we are just going to
wait for a couple of minutes.

00:16:09.360 --> 00:16:12.780 align:middle line:84%
And we can view the
members or we can actually

00:16:12.780 --> 00:16:16.500 align:middle line:84%
view the users that are
part of the sudoers group

00:16:16.500 --> 00:16:17.370 align:middle line:90%
by saying sudo-l.

00:16:17.370 --> 00:16:21.720 align:middle line:84%
And you can see right
over here, user student

00:16:21.720 --> 00:16:25.500 align:middle line:84%
may run the following commands
on the attack defense system.

00:16:25.500 --> 00:16:28.110 align:middle line:84%
And right away you can
see no password all.

00:16:28.110 --> 00:16:32.310 align:middle line:84%
Before they could actually
interact with the Cron utility,

00:16:32.310 --> 00:16:34.680 align:middle line:84%
and now they can run
any commands here

00:16:34.680 --> 00:16:36.840 align:middle line:90%
without providing any password.

00:16:36.840 --> 00:16:40.170 align:middle line:84%
So the Cron job has run, and
it has add the student account

00:16:40.170 --> 00:16:41.800 align:middle line:90%
to the sudoers group.

00:16:41.800 --> 00:16:44.970 align:middle line:84%
So that means that we can
pretty much do whatever we want

00:16:44.970 --> 00:16:46.980 align:middle line:84%
or rather we can execute
any commands that

00:16:46.980 --> 00:16:48.130 align:middle line:90%
require root privileges.

00:16:48.130 --> 00:16:51.510 align:middle line:84%
So for example, I
can say sudo su,

00:16:51.510 --> 00:16:55.260 align:middle line:84%
and we have elevated or
switched to the root user.

00:16:55.260 --> 00:16:57.180 align:middle line:84%
And of course, we've
elevated our privileges.

00:16:57.180 --> 00:16:58.870 align:middle line:90%
So I can say, who am I?

00:16:58.870 --> 00:17:00.270 align:middle line:90%
There we are.

00:17:00.270 --> 00:17:02.070 align:middle line:90%
So let me tap that incorrectly.

00:17:02.070 --> 00:17:04.079 align:middle line:90%
There we are, root user.

00:17:04.079 --> 00:17:06.630 align:middle line:84%
And we can navigate
to the root directory,

00:17:06.630 --> 00:17:10.619 align:middle line:84%
and we can get all the
contents of the flag, which

00:17:10.619 --> 00:17:12.510 align:middle line:90%
you are supposed to obtain.

00:17:12.510 --> 00:17:15.599 align:middle line:84%
So that is how to elevate
your privileges by exploiting

00:17:15.599 --> 00:17:17.430 align:middle line:90%
a misconfigured Cron job.

00:17:17.430 --> 00:17:19.680 align:middle line:84%
Now, as I said, this might
be a little bit confusing.

00:17:19.680 --> 00:17:21.900 align:middle line:84%
But as I said, I wanted
to demonstrate this now

00:17:21.900 --> 00:17:25.500 align:middle line:84%
before we actually get
into Cron jobs in depth

00:17:25.500 --> 00:17:28.050 align:middle line:84%
within the privilege
escalation course.

00:17:28.050 --> 00:17:30.690 align:middle line:84%
But I'll just highlight or
go over what we've done.

00:17:30.690 --> 00:17:33.570 align:middle line:84%
So the first step
essentially involved

00:17:33.570 --> 00:17:36.900 align:middle line:84%
identifying the
files or scripts that

00:17:36.900 --> 00:17:38.640 align:middle line:90%
are being used by Cron job.

00:17:38.640 --> 00:17:40.590 align:middle line:84%
And of course, we
really can be sure

00:17:40.590 --> 00:17:43.050 align:middle line:84%
when the Cron job or
the actual schedule

00:17:43.050 --> 00:17:45.270 align:middle line:90%
the Cron job is using to run.

00:17:45.270 --> 00:17:48.510 align:middle line:84%
So once we've identified
the shell script that

00:17:48.510 --> 00:17:50.820 align:middle line:84%
is being used or being
run by the Cron job,

00:17:50.820 --> 00:17:54.990 align:middle line:84%
we can then identify whether
that shell script can actually

00:17:54.990 --> 00:17:58.390 align:middle line:84%
be modified by an
unprivileged user for example,

00:17:58.390 --> 00:17:59.850 align:middle line:90%
which in this case, it was.

00:17:59.850 --> 00:18:03.030 align:middle line:84%
What we then did is
we then essentially

00:18:03.030 --> 00:18:06.180 align:middle line:84%
modified the shell script
and added a command that

00:18:06.180 --> 00:18:09.810 align:middle line:84%
would add our current
user to the sudoers file,

00:18:09.810 --> 00:18:12.930 align:middle line:84%
consequently allowing
us to essentially run

00:18:12.930 --> 00:18:15.570 align:middle line:84%
commands that require root
privileges without providing

00:18:15.570 --> 00:18:16.530 align:middle line:90%
a password.

00:18:16.530 --> 00:18:18.420 align:middle line:84%
And in this case,
as you saw, we were

00:18:18.420 --> 00:18:20.200 align:middle line:90%
able to switch to the root user.

00:18:20.200 --> 00:18:24.660 align:middle line:84%
So if I now say
crontab-l, you can

00:18:24.660 --> 00:18:27.460 align:middle line:84%
see the Cron job that was
created by the root user.

00:18:27.460 --> 00:18:29.760 align:middle line:84%
So you can see that it
runs every 1 minute,

00:18:29.760 --> 00:18:33.240 align:middle line:84%
and it essentially runs
the shell script copy.sh.

00:18:33.240 --> 00:18:35.520 align:middle line:84%
So I've actually confirmed
that indeed there

00:18:35.520 --> 00:18:39.300 align:middle line:84%
was a con job that was running
1 minute or every 1 minute,

00:18:39.300 --> 00:18:43.210 align:middle line:84%
and it was executing the
shell script copy.sh.

00:18:43.210 --> 00:18:43.710 align:middle line:90%
All right.

00:18:43.710 --> 00:18:46.920 align:middle line:84%
So that is going to conclude
the practical demonstration

00:18:46.920 --> 00:18:49.620 align:middle line:90%
side of this video.

00:18:49.620 --> 00:18:51.680 align:middle line:84%
In the next video,
we will be exploring

00:18:51.680 --> 00:18:54.715 align:middle line:84%
the process of
exploiting SUID binaries,

00:18:54.715 --> 00:18:56.090 align:middle line:84%
and taking a look
at how they can

00:18:56.090 --> 00:19:00.030 align:middle line:84%
be used to elevate our
privileges on a Linux system.

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

00:19:02.530 --> 00:19:04.000 align:middle line:90%