WEBVTT

00:01.250 --> 00:07.310
As you have seen so far, Eskil, injections are very dangerous and also they're very easy to occur

00:07.310 --> 00:08.690
and very easy to find.

00:08.840 --> 00:10.220
You'll find them everywhere.

00:10.220 --> 00:17.180
And some really famous websites, people try to prevent these vulnerabilities using filters.

00:17.540 --> 00:20.420
Filters can make it look like there is no exploits.

00:20.600 --> 00:27.170
But if you actually try harder by using encodings, different types of encoding or using a proxy, then

00:27.170 --> 00:29.770
you'll be able to bypass most of these filters.

00:30.680 --> 00:32.500
Some programmers use a blacklist.

00:32.510 --> 00:35.420
So, for example, they prevent the use of union.

00:35.510 --> 00:37.920
They prevent the use of insert and stuff like that.

00:38.180 --> 00:41.080
Again, it's not 100 percent secure.

00:41.120 --> 00:43.940
It can be bypassed using a whitelist.

00:43.940 --> 00:46.180
Exactly the same issues as the blacklist.

00:47.180 --> 00:54.800
The best way to do it is to program your Web application in a way that it does not allow code to be

00:54.800 --> 00:57.020
injected into it and then execute it.

00:58.130 --> 01:05.660
So the best way to do that is to do to use parameterized statements where the data and the code is separated.

01:06.050 --> 01:09.500
And the best way to show you what I mean by that is using an example.

01:11.640 --> 01:16.440
I'm keeping the least amount of programming in this example, I don't want it to be a programming example,

01:16.620 --> 01:21.360
there's actually mistakes in the programming in there, but I'm trying to give you the concept more

01:21.360 --> 01:22.620
than how to program it.

01:23.580 --> 01:29.190
So the vulnerable code that we were looking at used to do this, so it used to do select staff from

01:29.190 --> 01:33.240
accounts where username is equal to whatever we put into Xbox One.

01:33.960 --> 01:36.300
And then we used to put an Xbox One.

01:37.450 --> 01:38.460
Let's just put it here.

01:44.570 --> 01:48.530
We used to say admen and then close the quote.

01:50.490 --> 01:59.400
And then we're able to do a union, select and execute something else, and then once we're done, we

01:59.400 --> 02:04.330
used to add the comment, which basically ignores everything that comes in after it.

02:04.710 --> 02:06.000
So when you copy this.

02:08.430 --> 02:09.720
And you pasted in here.

02:12.350 --> 02:16.700
You'll see what's happening, so it's selection now let's just get rid of this.

02:17.860 --> 02:22.240
Because this is just making the colors not nice, I'm actually going to just put a comment on this.

02:23.790 --> 02:24.330
So.

02:25.270 --> 02:30.910
That's going to do a select staff from accounts where user name is equal to admin, union, select and

02:30.910 --> 02:32.770
execute whatever we want to do.

02:33.400 --> 02:36.190
This is very bad and it's very hard to protect against.

02:36.190 --> 02:39.760
As I said, using filters and stuff will only hide.

02:39.790 --> 02:41.220
The problem will not fix it.

02:42.210 --> 02:47.910
The best way to do this is using the parameterized statements, just like so so this is the safe way

02:47.910 --> 02:48.350
to do it.

02:48.990 --> 02:51.120
First of all, you prepare your statement.

02:51.330 --> 02:54.720
Most languages like you and all of them, they actually have a function like that.

02:55.110 --> 03:02.040
And you can prepare select star from accounts where username is equal to questionmark.

03:03.710 --> 03:12.080
And then you send the values so BHP now knows the Ezekial statement is select staff from accounts where

03:12.080 --> 03:17.150
username is equal to something and then it's going to take the value of the Xbox One.

03:17.540 --> 03:22.190
So even if we come in and we use our very sneaky statement right here.

03:24.310 --> 03:25.920
And pasted in there.

03:27.240 --> 03:34.410
The Web application will know that the value for this is admen union select, so it will actually try

03:34.410 --> 03:40.530
to go and select staff from accounts where the user name and then it actually it'll add its own quotes

03:40.770 --> 03:44.490
and they try to find a username with the following username.

03:44.550 --> 03:48.060
So this whole thing will be executed like soap.

03:54.800 --> 04:01.220
So it will be selected from accounts where user name is equal to admen union, select this hash hashtag

04:01.430 --> 04:04.760
so it'll never whatever you put in your.

04:06.010 --> 04:11.470
Textbooks will be sent as a value and the Web application will know that this is a value, it's not

04:11.470 --> 04:13.490
a code, and it'll never executed.

04:14.110 --> 04:17.860
Therefore, this will protect you against Ezekial injections.

04:18.790 --> 04:21.880
You can use the filters as second line of defense.

04:22.060 --> 04:27.340
And I also advise that you use the least privileges possible.

04:27.520 --> 04:33.760
So use for each database, use one user with the least amount of privileges they want.

04:33.760 --> 04:36.900
So do not allow the users to do anything that they won't allow them.

04:37.040 --> 04:43.120
If it's a simple website that only the selection that only allow the user to select, if it only needs

04:43.120 --> 04:46.270
to select an insert, then only allow them to select and insert.

04:46.390 --> 04:50.720
And this is a rule you should keep with everything, even within the system, to make sure the with

04:50.740 --> 04:53.410
the permissions are always as least as possible.

04:53.410 --> 04:57.100
Each user does not have any extra permissions that they don't need.
