WEBVTT

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


00:00:10.170 --> 00:00:11.700 align:middle line:90%
Targeting Samba.

00:00:11.700 --> 00:00:13.410 align:middle line:84%
In this video, we're
going to be taking

00:00:13.410 --> 00:00:17.110 align:middle line:84%
a look at how to exploit Samba
running on the Linux target.

00:00:17.110 --> 00:00:19.680 align:middle line:84%
So again, I've already
explained what Samba is.

00:00:19.680 --> 00:00:21.990 align:middle line:84%
It's essentially the open
source implementation

00:00:21.990 --> 00:00:26.130 align:middle line:84%
of SMB for Linux, and it
works exactly the same

00:00:26.130 --> 00:00:29.340 align:middle line:84%
or very similar to how
SMB works on Windows.

00:00:29.340 --> 00:00:31.993 align:middle line:84%
So in terms of
exploiting Samba, again,

00:00:31.993 --> 00:00:33.660 align:middle line:84%
what we're going to
be taking a look at,

00:00:33.660 --> 00:00:37.290 align:middle line:84%
specifically, is the process
of identifying vulnerabilities

00:00:37.290 --> 00:00:41.460 align:middle line:84%
within or a vulnerability within
the specific version of Samba

00:00:41.460 --> 00:00:44.310 align:middle line:84%
that's running on the target
and how to exploit it in order

00:00:44.310 --> 00:00:47.940 align:middle line:84%
to obtain access to the target
system via a reverse shell

00:00:47.940 --> 00:00:50.080 align:middle line:90%
or even a Meterpreter session.

00:00:50.080 --> 00:00:54.000 align:middle line:84%
So I'm going to just switch
over to my lab environment,

00:00:54.000 --> 00:00:57.900 align:middle line:84%
and we can get started with
taking a look at the techniques

00:00:57.900 --> 00:01:00.840 align:middle line:84%
that will allow us to
essentially exploit

00:01:00.840 --> 00:01:04.390 align:middle line:84%
Samba and, consequently, gain
access to the target system.

00:01:04.390 --> 00:01:07.080 align:middle line:84%
So I'll see you within
the lab environment.

00:01:07.080 --> 00:01:10.230 align:middle line:90%


00:01:10.230 --> 00:01:13.000 align:middle line:84%
All right, so I am back
within the lab environment,

00:01:13.000 --> 00:01:16.290 align:middle line:84%
and I have performed an Nmap
scan on the target system,

00:01:16.290 --> 00:01:20.820 align:middle line:84%
more specifically a service
version scan on port 445, which

00:01:20.820 --> 00:01:25.050 align:middle line:84%
is, again, appropriate for the
SMB service or rather Samba

00:01:25.050 --> 00:01:27.900 align:middle line:84%
because we're now dealing
with a Linux target.

00:01:27.900 --> 00:01:31.500 align:middle line:84%
And again, if we take a look at
the version information here,

00:01:31.500 --> 00:01:36.210 align:middle line:84%
we can see that it tells us
it's running Samba smbd version

00:01:36.210 --> 00:01:40.920 align:middle line:84%
3.X to 4.X. So it doesn't give
us any additional information

00:01:40.920 --> 00:01:43.513 align:middle line:84%
regarding the exact
version of Samba that's

00:01:43.513 --> 00:01:44.430 align:middle line:90%
running on the target.

00:01:44.430 --> 00:01:48.450 align:middle line:84%
Now, even if we were to
perform some banner grabbing

00:01:48.450 --> 00:01:51.690 align:middle line:84%
on the target
system on port 445,

00:01:51.690 --> 00:01:55.150 align:middle line:84%
we would not be able to get
the exact version of Samba.

00:01:55.150 --> 00:01:57.850 align:middle line:84%
So let's actually try this out,
and let's see what happens.

00:01:57.850 --> 00:02:00.600 align:middle line:90%
So when I hit Enter--

00:02:00.600 --> 00:02:02.670 align:middle line:84%
and let me just
use the nv option

00:02:02.670 --> 00:02:05.010 align:middle line:84%
because it's not
displaying anything there.

00:02:05.010 --> 00:02:08.229 align:middle line:84%
So Netcat nv, as you can
see, we connect successfully.

00:02:08.229 --> 00:02:09.699 align:middle line:90%
However, we don't get a banner.

00:02:09.699 --> 00:02:12.952 align:middle line:84%
So how can we enumerate
the exact version of Samba

00:02:12.952 --> 00:02:14.160 align:middle line:90%
that's running on the target?

00:02:14.160 --> 00:02:16.020 align:middle line:84%
Well, we can do
this through the use

00:02:16.020 --> 00:02:17.970 align:middle line:84%
of very useful
Metasploit framework

00:02:17.970 --> 00:02:20.670 align:middle line:90%
module called SMB version.

00:02:20.670 --> 00:02:25.680 align:middle line:84%
That is not just applicable
to Samba, but also to SMB

00:02:25.680 --> 00:02:26.260 align:middle line:90%
on Windows.

00:02:26.260 --> 00:02:28.080 align:middle line:84%
So again, this can
work both ways.

00:02:28.080 --> 00:02:29.850 align:middle line:84%
I, actually, recommend
that you run it

00:02:29.850 --> 00:02:32.520 align:middle line:84%
whenever you're trying to
target SMB on a Windows system

00:02:32.520 --> 00:02:33.250 align:middle line:90%
as well.

00:02:33.250 --> 00:02:34.740 align:middle line:90%
So I'll search for the module.

00:02:34.740 --> 00:02:37.800 align:middle line:90%
It is smb_version.

00:02:37.800 --> 00:02:39.570 align:middle line:90%
And we'll say, use.

00:02:39.570 --> 00:02:42.580 align:middle line:84%
And we're going to
use the module ID, so

00:02:42.580 --> 00:02:46.910 align:middle line:90%
use 0, show options.

00:02:46.910 --> 00:02:49.820 align:middle line:84%
We only need to set the
RHOSTS option, which,

00:02:49.820 --> 00:02:51.060 align:middle line:90%
again, is the target IP.

00:02:51.060 --> 00:02:53.430 align:middle line:90%
So set RHOSTS.

00:02:53.430 --> 00:02:54.310 align:middle line:90%
There we go.

00:02:54.310 --> 00:02:56.550 align:middle line:84%
So that's set up,
and we can hit run.

00:02:56.550 --> 00:02:58.590 align:middle line:84%
And this should tell
us the exact version

00:02:58.590 --> 00:03:02.588 align:middle line:84%
of SMB running on the target
or rather Samba, if you will.

00:03:02.588 --> 00:03:05.130 align:middle line:84%
So in this case, you could see
it tells us the host could not

00:03:05.130 --> 00:03:06.010 align:middle line:90%
be identified.

00:03:06.010 --> 00:03:09.270 align:middle line:84%
However, it prints out the
exact version of Samba that's

00:03:09.270 --> 00:03:10.720 align:middle line:90%
running on the target system.

00:03:10.720 --> 00:03:13.560 align:middle line:84%
And in this case, it looks like
the target system is running

00:03:13.560 --> 00:03:19.980 align:middle line:84%
Samba 3.0.20 So we can
perform a quick searchshploit

00:03:19.980 --> 00:03:23.610 align:middle line:84%
query to try and identify
whether this specific version

00:03:23.610 --> 00:03:26.400 align:middle line:84%
of Samba is vulnerable
to any exploits, right?

00:03:26.400 --> 00:03:28.110 align:middle line:90%
So we'll say, samba--

00:03:28.110 --> 00:03:31.320 align:middle line:84%
and the exact version
in this case is 3--

00:03:31.320 --> 00:03:35.520 align:middle line:90%
I believe it was 3.2.10--

00:03:35.520 --> 00:03:40.520 align:middle line:90%
3.0.20.

00:03:40.520 --> 00:03:46.290 align:middle line:84%
So 3.0.-- sorry, that is
searchshploit, not search.

00:03:46.290 --> 00:03:47.490 align:middle line:90%
So searchshploit.

00:03:47.490 --> 00:03:50.040 align:middle line:84%
And let me type
that in correctly.

00:03:50.040 --> 00:03:52.435 align:middle line:90%
For some reason-- here we are.

00:03:52.435 --> 00:03:54.730 align:middle line:90%
So searchshploit.

00:03:54.730 --> 00:03:57.408 align:middle line:84%
And it looks like we
have a few exploits here.

00:03:57.408 --> 00:03:59.200 align:middle line:84%
So I'm just going to
drag this to the side,

00:03:59.200 --> 00:04:00.530 align:middle line:90%
so you can see what's going on.

00:04:00.530 --> 00:04:02.980 align:middle line:84%
And I'll just run that again,
so that the ASCII output

00:04:02.980 --> 00:04:04.730 align:middle line:90%
is printed out correctly.

00:04:04.730 --> 00:04:11.110 align:middle line:84%
So as you can see, we have
an exploit here that affects

00:04:11.110 --> 00:04:15.303 align:middle line:84%
or that is actually specific
to the version that's

00:04:15.303 --> 00:04:16.220 align:middle line:90%
running on the target.

00:04:16.220 --> 00:04:23.170 align:middle line:84%
So you can see Samba 3.0.20 and
versions lower than 3.0.25rc3.

00:04:23.170 --> 00:04:25.330 align:middle line:84%
This is the
'Username' map script'

00:04:25.330 --> 00:04:28.070 align:middle line:84%
Command Execution
(Metasploit) module.

00:04:28.070 --> 00:04:30.110 align:middle line:84%
So let's actually
utilize this module,

00:04:30.110 --> 00:04:31.670 align:middle line:84%
and let's see what
it does exactly.

00:04:31.670 --> 00:04:32.930 align:middle line:90%
Or let's learn more about it.

00:04:32.930 --> 00:04:34.270 align:middle line:90%
So we're done with that.

00:04:34.270 --> 00:04:36.110 align:middle line:84%
I'm just going to
close that there.

00:04:36.110 --> 00:04:41.800 align:middle line:84%
And we can say, search
samba 3.0.20, right?

00:04:41.800 --> 00:04:43.480 align:middle line:90%
So I'll hit Enter.

00:04:43.480 --> 00:04:46.270 align:middle line:84%
And the exact module
is displayed here.

00:04:46.270 --> 00:04:48.190 align:middle line:84%
And the rank is
excellent, so it has

00:04:48.190 --> 00:04:50.420 align:middle line:90%
a very good chance of success.

00:04:50.420 --> 00:04:52.750 align:middle line:90%
So I'll say, use 0.

00:04:52.750 --> 00:04:56.080 align:middle line:90%
And we can show the info here.

00:04:56.080 --> 00:04:58.740 align:middle line:84%
As you can see, this module
exploits a command execution

00:04:58.740 --> 00:05:05.490 align:middle line:84%
vulnerability in Samba version
3.0.20 through 3.0.25rc3 when

00:05:05.490 --> 00:05:09.420 align:middle line:84%
using the non-default 'Username
map script' configuration

00:05:09.420 --> 00:05:10.110 align:middle line:90%
option.

00:05:10.110 --> 00:05:13.170 align:middle line:84%
By specifying a username
containing shell meta

00:05:13.170 --> 00:05:16.320 align:middle line:84%
characters, attackers can
execute arbitrary commands.

00:05:16.320 --> 00:05:19.470 align:middle line:84%
No authentication is needed
to exploit this vulnerability

00:05:19.470 --> 00:05:22.110 align:middle line:84%
since this option is used
to map usernames prior

00:05:22.110 --> 00:05:22.990 align:middle line:90%
to authentication.

00:05:22.990 --> 00:05:25.770 align:middle line:84%
So this is a very, very
serious vulnerability

00:05:25.770 --> 00:05:27.210 align:middle line:90%
in the context of Samba.

00:05:27.210 --> 00:05:31.240 align:middle line:84%
So the only option we need to
set here is the RHOSTS option.

00:05:31.240 --> 00:05:33.450 align:middle line:84%
So I'll set that
to the target IP,

00:05:33.450 --> 00:05:36.610 align:middle line:84%
and it'll provide us with
a netcat reverse shell.

00:05:36.610 --> 00:05:38.250 align:middle line:84%
If we take a look at
the payload here--

00:05:38.250 --> 00:05:40.530 align:middle line:90%
let me just show the options--

00:05:40.530 --> 00:05:43.890 align:middle line:84%
the default payload is
cmd/unix/reverse_netcat.

00:05:43.890 --> 00:05:47.250 align:middle line:84%
So we can utilize the
actual reverse shell

00:05:47.250 --> 00:05:48.930 align:middle line:90%
that we will be provided with.

00:05:48.930 --> 00:05:52.260 align:middle line:84%
Alternatively, we
can also upgrade that

00:05:52.260 --> 00:05:54.450 align:middle line:84%
into a Meterpreter session,
which will actually take

00:05:54.450 --> 00:05:56.440 align:middle line:90%
a look at in a few seconds.

00:05:56.440 --> 00:05:59.070 align:middle line:84%
So I'll type in
exploit, and we'll

00:05:59.070 --> 00:06:00.460 align:middle line:90%
give this a couple of seconds.

00:06:00.460 --> 00:06:04.650 align:middle line:84%
And if successful, we should be
able to obtain a reverse shell.

00:06:04.650 --> 00:06:06.600 align:middle line:84%
There we are-- Command
shell 1 opened.

00:06:06.600 --> 00:06:08.940 align:middle line:90%
And I can say ls -al.

00:06:08.940 --> 00:06:09.540 align:middle line:90%
There we go.

00:06:09.540 --> 00:06:11.650 align:middle line:84%
And we currently have
access to the target system,

00:06:11.650 --> 00:06:14.980 align:middle line:84%
so I can verify this by
saying cat/etc/*issue.

00:06:14.980 --> 00:06:17.880 align:middle line:84%
And you can see that this
is on Metasploitable2.

00:06:17.880 --> 00:06:23.200 align:middle line:84%
And I can also do that
for cat/etc/*release.

00:06:23.200 --> 00:06:25.550 align:middle line:90%
There we go-- Ubuntu 8.04.

00:06:25.550 --> 00:06:28.190 align:middle line:84%
So I'll put this
in the background.

00:06:28.190 --> 00:06:31.240 align:middle line:84%
And we can now list
out our sessions.

00:06:31.240 --> 00:06:33.640 align:middle line:84%
And in order to upgrade a
session to a Meterpreter

00:06:33.640 --> 00:06:37.540 align:middle line:84%
session, we can
say, sessions -u 1.

00:06:37.540 --> 00:06:39.370 align:middle line:90%
So we specify the session ID.

00:06:39.370 --> 00:06:42.430 align:middle line:84%
In this case, the
session has an ID of 1.

00:06:42.430 --> 00:06:44.370 align:middle line:90%
So I'll hit Enter.

00:06:44.370 --> 00:06:46.590 align:middle line:84%
And this should give us
a Meterpreter session

00:06:46.590 --> 00:06:48.420 align:middle line:90%
on the target system.

00:06:48.420 --> 00:06:49.030 align:middle line:90%
There we are.

00:06:49.030 --> 00:06:49.980 align:middle line:90%
It sends the stage.

00:06:49.980 --> 00:06:52.630 align:middle line:84%
And indeed, we do receive
a Meterpreter session.

00:06:52.630 --> 00:06:54.610 align:middle line:84%
So if I list out
my sessions now,

00:06:54.610 --> 00:06:57.690 align:middle line:84%
you can see that on session
ID 2, we have an Meterpreter.

00:06:57.690 --> 00:07:01.290 align:middle line:84%
And not only that, we also
have obtained root access

00:07:01.290 --> 00:07:02.500 align:middle line:90%
on the target system.

00:07:02.500 --> 00:07:05.760 align:middle line:84%
So if I switch
over to session 2--

00:07:05.760 --> 00:07:07.458 align:middle line:84%
you can see, if I
type in sysinfo info,

00:07:07.458 --> 00:07:09.000 align:middle line:84%
it'll be displayed
right over there--

00:07:09.000 --> 00:07:10.800 align:middle line:90%
Ubuntu 8.04.

00:07:10.800 --> 00:07:14.370 align:middle line:90%
And I can say, getuid.

00:07:14.370 --> 00:07:16.620 align:middle line:84%
We currently root, so
we have root access

00:07:16.620 --> 00:07:18.390 align:middle line:84%
on the target system,
which means we don't

00:07:18.390 --> 00:07:20.380 align:middle line:90%
need to elevate our privileges.

00:07:20.380 --> 00:07:23.760 align:middle line:84%
And apart from the actual
bind shell listener

00:07:23.760 --> 00:07:25.350 align:middle line:84%
that we were able
to gain access to

00:07:25.350 --> 00:07:27.150 align:middle line:84%
in the first video
in this section,

00:07:27.150 --> 00:07:30.450 align:middle line:84%
this is the only exploit that
has given us root access right

00:07:30.450 --> 00:07:31.440 align:middle line:90%
out of the box.

00:07:31.440 --> 00:07:33.930 align:middle line:84%
And I wanted to highlight
it for that reason,

00:07:33.930 --> 00:07:37.080 align:middle line:84%
primarily because
you can essentially

00:07:37.080 --> 00:07:40.560 align:middle line:84%
go over or skip over the
privilege escalation section

00:07:40.560 --> 00:07:43.350 align:middle line:84%
if you are essentially
able to exploit

00:07:43.350 --> 00:07:46.300 align:middle line:84%
the target via this
exploit module.

00:07:46.300 --> 00:07:48.400 align:middle line:90%
So it is extremely useful.

00:07:48.400 --> 00:07:50.670 align:middle line:84%
So we can pretty much
do whatever we want now.

00:07:50.670 --> 00:07:55.240 align:middle line:84%
So I can list out the users on
the system, so cat/etc/passwd.

00:07:55.240 --> 00:07:58.380 align:middle line:84%
And you can see we have all
these service accounts right

00:07:58.380 --> 00:08:01.740 align:middle line:84%
over here, apart from
the service account

00:08:01.740 --> 00:08:03.370 align:middle line:90%
that we had used previously.

00:08:03.370 --> 00:08:06.810 align:middle line:84%
The rest of which are
really service accounts.

00:08:06.810 --> 00:08:08.250 align:middle line:84%
And now, that we've
gotten access,

00:08:08.250 --> 00:08:10.480 align:middle line:84%
we can also dump
hashes, for example.

00:08:10.480 --> 00:08:13.640 align:middle line:90%
So cat/etc/shadow.

00:08:13.640 --> 00:08:14.250 align:middle line:90%
There we are.

00:08:14.250 --> 00:08:16.763 align:middle line:84%
And we can crack these,
as these are in MD5.

00:08:16.763 --> 00:08:18.680 align:middle line:84%
And of course, I've
covered the process of how

00:08:18.680 --> 00:08:23.030 align:middle line:90%
to crack Linux MD5 hashes.

00:08:23.030 --> 00:08:25.400 align:middle line:90%
It really is very, very simple.

00:08:25.400 --> 00:08:27.470 align:middle line:84%
And yeah, so that
is going to conclude

00:08:27.470 --> 00:08:30.155 align:middle line:84%
the practical demonstration
side of this video.

00:08:30.155 --> 00:08:33.900 align:middle line:90%


00:08:33.900 --> 00:08:37.460 align:middle line:84%
All right, so that concludes
the Linux exploitation section

00:08:37.460 --> 00:08:38.630 align:middle line:90%
of this course.

00:08:38.630 --> 00:08:42.020 align:middle line:84%
And furthermore, it also
concludes the Linux Black Box

00:08:42.020 --> 00:08:43.309 align:middle line:90%
penetration test.

00:08:43.309 --> 00:08:46.280 align:middle line:84%
And hopefully, you were able
to gain access to the target

00:08:46.280 --> 00:08:47.450 align:middle line:90%
system without the videos.

00:08:47.450 --> 00:08:49.190 align:middle line:90%
If not, that's perfectly fine.

00:08:49.190 --> 00:08:50.360 align:middle line:90%
That's why you're here.

00:08:50.360 --> 00:08:51.540 align:middle line:90%
You're here to learn.

00:08:51.540 --> 00:08:53.930 align:middle line:84%
And again, there's
still other services,

00:08:53.930 --> 00:08:56.210 align:middle line:84%
other vulnerable services
on the target system

00:08:56.210 --> 00:08:59.750 align:middle line:84%
that can be exploited, so
definitely give it a few goes.

00:08:59.750 --> 00:09:02.510 align:middle line:84%
And you should be able to
find more than, I think,

00:09:02.510 --> 00:09:05.480 align:middle line:84%
more than five services that
you can exploit in order

00:09:05.480 --> 00:09:07.230 align:middle line:84%
to gain access to
the target system.

00:09:07.230 --> 00:09:08.810 align:middle line:90%
So hopefully, you enjoyed that.

00:09:08.810 --> 00:09:10.310 align:middle line:84%
And hopefully,
you learned a lot.

00:09:10.310 --> 00:09:13.250 align:middle line:84%
And as I said, you always
have to keep on practicing.

00:09:13.250 --> 00:09:16.470 align:middle line:84%
So use these videos
as reference points,

00:09:16.470 --> 00:09:19.730 align:middle line:84%
and take note of what I did in
regards to the tools I used,

00:09:19.730 --> 00:09:21.650 align:middle line:84%
as well as the techniques
that I performed,

00:09:21.650 --> 00:09:24.200 align:middle line:84%
and integrate them with
your future assessments

00:09:24.200 --> 00:09:25.598 align:middle line:90%
or engagements.

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

00:09:27.140 --> 00:09:29.820 align:middle line:84%
to move over to the next
section of the course.

00:09:29.820 --> 00:09:32.260 align:middle line:90%
And I'll be seeing you there.

00:09:32.260 --> 00:09:33.000 align:middle line:90%