WEBVTT

00:00.420 --> 00:07.020
So local full inclusion is really good because they allow us to read files in the server and we might

00:07.020 --> 00:13.710
be able to read files with passwords or sensitive information, what would be really great is if we

00:13.710 --> 00:20.940
can actually gain full access or full control over the target server using local file inclusion vulnerabilities.

00:21.540 --> 00:27.720
So in this lecture, we'll see how we can get a reverse shell by exploiting the local file inclusion

00:27.720 --> 00:30.320
vulnerability that we've seen in the previous lecture.

00:31.110 --> 00:37.470
So because they allow us to read files on the server, we managed to write anything on that server,

00:37.680 --> 00:43.470
then we can write some malicious code and then browse it and get that code to be executed.

00:44.220 --> 00:46.560
So this is exactly what we're going to try to do.

00:46.590 --> 00:48.840
There is a number of methods to achieve that.

00:49.530 --> 00:55.650
Usually it's done using the log files because the log files usually register or write stuff that happens

00:55.650 --> 00:56.340
on the server.

00:56.550 --> 00:59.520
So you can try to log in with a username.

00:59.520 --> 01:05.700
But instead of putting a username, you put a zip code or you can try to send an email and then instead

01:05.700 --> 01:12.600
of the email, put a code and then try to browse these log files and the BHP code will be executed.

01:13.260 --> 01:18.580
The first method that we're going to have a look on, though, it's going to exploit the environ variable.

01:18.840 --> 01:25.940
So this is basically a file that contains an array of information about the current environment.

01:26.610 --> 01:28.860
So let's just have an example of this quickly.

01:29.040 --> 01:31.080
Right here I am on my Calli machine.

01:31.080 --> 01:32.160
I'm not taking anything.

01:32.160 --> 01:36.280
I'm not on any server, and I'm just going to see what's the content of that file.

01:36.300 --> 01:39.570
So this file exists in all Linux operating systems.

01:39.930 --> 01:43.110
So I'm just going to open that file right now using the card command.

01:46.820 --> 01:52.250
And as you can see, you'll see a number of environmental variables that are related to the current

01:52.250 --> 01:52.840
environment.

01:53.690 --> 01:59.750
So what we're going to do now is we're going to try to open this file here and my brother instead of

01:59.780 --> 02:00.860
the password.

02:02.520 --> 02:04.740
So it's going to be in prox self environ.

02:07.580 --> 02:08.810
OK, going to enter.

02:10.660 --> 02:16.090
And as you can see, again, we can see an array of variables about the current environment.

02:17.040 --> 02:22.230
What's interesting here is this variable so we can see that the user agent.

02:23.360 --> 02:26.910
Is being sent and it's being displayed right here.

02:27.380 --> 02:31.370
Now, the user agent basically is the current browser used by the user.

02:31.560 --> 02:34.580
The website thinks that I'm using Firefox, which is correct.

02:34.730 --> 02:40.940
And that's because Firefox, every time you open a website, it actually tells the website what browser

02:40.940 --> 02:41.180
it is.

02:41.210 --> 02:42.590
So this happens on our website.

02:42.980 --> 02:48.910
So this is actually sent from the client so we can actually modify this value.

02:49.160 --> 02:55.670
And what we're going to try to do is we're going to modify the user agent value and we're going to place

02:55.670 --> 02:57.860
code that will give us reverse shelp.

02:58.790 --> 03:02.820
Before we do that, let's make sure that the code will be executed on the server.

03:03.020 --> 03:08.920
So we're going to send just a normal code that will display information.

03:09.800 --> 03:12.010
So I'm going to turn on my interceptor now.

03:12.050 --> 03:14.120
I showed you how to set up a proxy.

03:14.130 --> 03:18.540
So if you don't know how to do that, go back to that lecture and see how you can set up a proxy.

03:18.950 --> 03:22.970
So I just turned on the interceptor and I'm going to browse the exact same URL.

03:24.230 --> 03:30.740
And right here, if we go on beheaders, you'll see that Firefox is sending the user agent right here

03:30.890 --> 03:33.920
and it's sending it as Mozilla five, whatever.

03:35.890 --> 03:41.290
So what we're going to do is we're going to modify this value and we're going to put BHB code and the

03:41.290 --> 03:42.850
code I'm going to put is very simple.

03:42.850 --> 03:45.700
It'll basically just display information.

03:45.730 --> 03:48.580
So it's a function called BHP info.

03:50.260 --> 03:52.390
And then I'm going to forward this packet.

03:55.630 --> 04:02.470
And as you can see, the HP code got executed on the on the website, on the Target website.

04:02.650 --> 04:08.350
This means if we send malicious code to this website will actually be able to gain full access or we

04:08.350 --> 04:10.600
can get our code to be executed.

04:10.990 --> 04:13.720
Now, you can literally send any record you want.

04:13.900 --> 04:16.500
You can send code to list files.

04:16.510 --> 04:22.570
You can send code to upload a file, or you can send one of the codes that were used before to gain

04:22.570 --> 04:23.630
a reverse connection.

04:23.830 --> 04:24.870
So that's what I'm going to do.

04:24.880 --> 04:30.970
I'm going to use the exact same code that we used before and the previous lectures to gain full control

04:30.970 --> 04:32.260
over the target computer.

04:33.850 --> 04:37.660
So I'm actually just going to type it down here in terminal and then I'm going to copy it.

04:39.780 --> 04:41.850
So we're going to be using passthrough.

04:44.420 --> 04:45.650
And we're using Netcare.

04:50.810 --> 04:52.880
And then I'm going to put my IP address.

04:54.820 --> 04:59.710
And I'm going to use the port, which is I'm going in this attack, I'm going to use eight eight, eight,

04:59.710 --> 05:02.620
eight, and then we put the semicolon.

05:03.010 --> 05:03.880
So it's the same.

05:03.880 --> 05:05.410
It's just a function.

05:05.980 --> 05:08.200
We use that in the code execution next year.

05:08.210 --> 05:13.050
So I'm literally just going to copy this and I'm going to inject it as the user agent.

05:13.060 --> 05:17.640
Now, before I do that, I'm going to listen on Part eight eight eight eight four connections.

05:17.830 --> 05:20.030
So we're going to use the same code that we used before.

05:20.050 --> 05:21.190
Again, with Netcare.

05:26.090 --> 05:31.690
And now we're listening for connections, we have our interceptor on, I'm going to browse the website,

05:31.700 --> 05:35.960
I'm going to enter and I'm going to modify the user agent.

05:38.570 --> 05:42.770
Again, don't forget to put the question marks here, because I only put the code there, so we have

05:42.980 --> 05:49.460
the opening and the closing for HP and then we put our code, which is the pass through code.

05:49.460 --> 05:54.990
And she's been S.H., our IP, followed by the port that we're listening on.

05:55.700 --> 05:58.250
I'm going to enter and I'm going to forward.

05:59.540 --> 06:04.340
And as you can see, we got a connection back using the local file, inclusion vulnerability.

06:04.760 --> 06:06.020
Now I can browse files.

06:06.020 --> 06:14.000
I can do I can do Ellos, I can do ID and I can pretty much do anything I want on the server now that

06:14.000 --> 06:16.190
I have full access.

06:16.340 --> 06:23.360
So we were able to convert a local file inclusion vulnerability that can only show you files or can

06:23.360 --> 06:25.450
only allow you to read files on the server.

06:25.640 --> 06:33.590
We were able to convert that and exploit it to get full access to the target server all the possible,

06:33.710 --> 06:41.300
because we were able to write to the proc self environ variable, which displays our user agent, and

06:41.300 --> 06:46.760
by changing the user agent to our code, we were able to run any record that we want.
