WEBVTT

00:00.920 --> 00:06.110
In this lecture, we're going to go and have a look on the high security level and we'll see why it's

00:06.110 --> 00:06.880
an injectable.

00:07.820 --> 00:11.090
So let's go ahead first and set the security level too high.

00:13.930 --> 00:16.270
Now, I'm going to go back to my school injection.

00:17.870 --> 00:22.430
And let's make sure that the page works first, so I'm just going to put no one like we always did.

00:25.320 --> 00:27.160
And as you can see now, the page works.

00:27.180 --> 00:32.610
Now let's try to inject it after the one after the ID parameter like we always did, and I am going

00:32.610 --> 00:33.000
to pull it.

00:33.000 --> 00:36.270
And one is equal to one sample and a true statement.

00:36.540 --> 00:38.790
And as you can see now, the page does not really work.

00:39.610 --> 00:45.170
So let's try to put a single quote here to close it like we did with the lower level.

00:45.360 --> 00:47.820
And again, this injection doesn't work either.

00:47.820 --> 00:52.790
Even though we're given a true statement that shouldn't interfere with the current request.

00:53.190 --> 00:56.190
We usually don't look at the code when we're trying to hack.

00:56.190 --> 00:57.890
But as I said, this is an injectable.

00:58.080 --> 01:03.450
So let's have a look on the code and we're going to compare it with the code used for the medium security

01:03.450 --> 01:03.810
level.

01:04.230 --> 01:09.920
And we'll see what the difference is between the two codes so that we can learn how to secure our website.

01:10.260 --> 01:15.810
So I'm going to change the security level to medium here just so that we can compare the two codes and

01:15.810 --> 01:17.670
are going to go back to the Ezekial injection.

01:19.420 --> 01:21.600
And I'm going to view the source as well.

01:23.800 --> 01:25.680
And God put them beside each other.

01:28.640 --> 01:35.960
So in here, in the medium security level, you can see that the ID is being read in here and it's being

01:35.960 --> 01:41.610
stored in the ID variable, and then they're using a function called My Ezekial the Real Escape.

01:42.050 --> 01:47.870
So what this function does, it will go through every character in the ID variable and will look for

01:47.870 --> 01:51.590
a special character such as single quotes and double quotes and remove them.

01:52.160 --> 01:58.880
Therefore, any quotation marks used or injected in the idea variable will actually be removed at this

01:58.880 --> 02:02.870
line because of the use of the mask, the real escape string.

02:03.770 --> 02:10.070
Now, the thing is, once we go down to the squad statement, you'll see that we actually don't need

02:10.070 --> 02:13.850
to use any quotes to inject code into the statement.

02:13.850 --> 02:19.970
So our statement is select first name, last name from users where user ID is equal to ID.

02:20.510 --> 02:23.200
So we actually don't need to close any quotes.

02:23.210 --> 02:25.990
We don't need to inject quotes in the ID variable.

02:26.210 --> 02:32.150
All we have to do is just put any idea like we did in the last video so we can put just number one and

02:32.150 --> 02:35.310
then inject code straight away after the number one.

02:35.690 --> 02:41.570
So when we use this code right here, we're basically we we didn't use the quotes in the media.

02:41.840 --> 02:47.120
So we are literally just giving the idea as number one and then we're saying union select column name,

02:47.120 --> 02:49.460
whatever from information schema tables.

02:49.820 --> 02:53.360
So the code is just being injected straight away after the ID.

02:54.180 --> 02:57.690
And then the database will read it and execute it.

02:58.260 --> 03:02.680
No need to use quotes again because the code doesn't use any single quotes.

03:02.680 --> 03:05.530
So the code just says user I.D. is equal to it.

03:06.420 --> 03:11.580
Now, comparing this with the code that we have for the high security level, you'll see that it uses

03:11.580 --> 03:16.920
the same function to keep special characters, but it's implemented in the right way.

03:17.550 --> 03:22.530
And that's by using single quotes in the school statement around the ID.

03:24.270 --> 03:29.970
Therefore, because the code is keeping the quotes that we put and because they're using quotes in there,

03:30.630 --> 03:36.600
any code that we try to inject in here will actually be considered as if it's part of the idea.

03:37.200 --> 03:43.410
So when we use this code right here, so if we just use the code as it is without a quote, then obviously

03:43.410 --> 03:48.590
it will just be inserted instead of the idea variable between the two single quotes.

03:48.930 --> 03:51.480
So it'll just be considered as the idea.

03:51.960 --> 03:57.890
Whereas if we inject that code in here, it will actually be executed as part of the Ezekial statement.

03:58.200 --> 04:03.900
So let's have a look on what the actual statement will look like when we inject our code in both in

04:03.900 --> 04:06.400
the medium and in the high security level.

04:06.780 --> 04:08.610
So I'm just going to bring down the text here.

04:09.960 --> 04:12.750
So we have this statement for the medium here.

04:14.750 --> 04:21.170
And the Ezekial statement for the high security level and we'll just try to inject and one is equal

04:21.170 --> 04:27.140
to one because as we've seen, if you can inject that, then you can inject anything you want really

04:27.140 --> 04:29.060
and get it executed on the database.

04:30.690 --> 04:32.760
OK, so looking at the medium statement.

04:34.610 --> 04:37.440
We're going to copy this code now.

04:37.460 --> 04:44.270
This code will actually go and pass through the MySQL real Escape character, so it will be removed

04:44.270 --> 04:46.780
from any single code that it has, but it has nothing.

04:47.110 --> 04:51.240
And the code will look like one and one is equal to one.

04:51.740 --> 04:56.270
So this statement is valid and one is equal to one will be injected.

04:56.690 --> 04:58.470
Now, looking at the high security level.

04:58.610 --> 05:05.090
Notice the use of the single quotes, which will mean that the user ID is equal to one and one is equal

05:05.090 --> 05:05.530
to one.

05:05.810 --> 05:10.910
So and one is equal to one will not be considered as part of the Ezekial statement, but it will be

05:10.910 --> 05:13.610
considered as part of the user ID.

05:15.220 --> 05:20.860
Now, let's try to add the single quote and see what effect would that have on the Ezekial statement?

05:21.870 --> 05:26.730
I'm actually going to get rid of this statement because we managed to inject it and we're only going

05:26.730 --> 05:30.290
to focus on the highs in the statement used in the high security level.

05:31.170 --> 05:36.070
So we're using a single quote here to close it and we're going to copy this.

05:36.360 --> 05:40.700
Now, this will actually pass through the and real escape strength.

05:41.100 --> 05:47.070
So the single quote that we're using here will actually be removed and this line will become.

05:48.120 --> 05:53.950
One and one is equal to one, so it's going to be equal or exactly the same as the line we used before.

05:54.830 --> 06:02.400
Now, once this is substituted in here, again, the one and one is equal to one will be considered

06:02.520 --> 06:08.220
as part of the issue of the user ID and it won't be considered as part of the Ezekial statement.

06:09.030 --> 06:12.720
From this we can see that the use of the Maisky are the real SCAP.

06:12.730 --> 06:13.880
Strange is not enough.

06:14.130 --> 06:16.710
It has to be used with the single quotes right here.

06:17.040 --> 06:23.550
And combined with that function, then this specific Ezekial and statement becomes an injectable.

06:24.790 --> 06:29.920
Now, in future lectures, we're actually going to discuss a better way to build Web applications so

06:29.920 --> 06:35.920
that they can't be injected with Ezekial statements, but if you needed a quick solution, then you

06:35.920 --> 06:37.980
can go for this until you have time.

06:37.990 --> 06:42.010
Then you can change the implementation of your website so that it can't be injected.
