WEBVTT

00:00.880 --> 00:07.390
Now that we know how to discover and exploit Exaro vulnerabilities, let's talk about how to protect

00:07.570 --> 00:08.740
websites from them.

00:09.700 --> 00:18.790
So if we just go back now to DVDs and send the security to high, you'll see that they have a very simple

00:18.970 --> 00:20.350
way to protect against it.

00:20.350 --> 00:21.640
But this way actually works.

00:21.970 --> 00:24.950
And what they do is they ask you for the current password.

00:25.360 --> 00:31.060
So even if we get this form and we do all the forging and all the stuff that we were doing and then

00:31.330 --> 00:36.850
send it to the target person, we can't actually hide this and get it to automatically submit because

00:36.850 --> 00:38.330
we don't know the current password.

00:38.590 --> 00:43.120
So it asks for the current password and then it allows you to add a new password.

00:43.750 --> 00:49.810
So this is a really good solution for this case only, though, because what if the form actually doesn't

00:49.810 --> 00:50.630
change a password?

00:50.650 --> 00:54.670
What if we're just going to send messages pretending to be that person?

00:54.850 --> 00:57.800
What if we're going to post things to that person's wall?

00:57.910 --> 01:04.800
What if we're going to post things into that person's blog so Sarraf can be exploited to do many things,

01:04.810 --> 01:06.310
as I said in previous videos.

01:06.490 --> 01:09.940
And this method will only protect against changing the password.

01:10.540 --> 01:15.660
You can't really ask the person for their password every time that they want to post something or to

01:15.700 --> 01:16.990
do something with their profile.

01:18.600 --> 01:25.080
Now, newer versions of DVDs that don't come with me to exploit the will to actually have a more secure

01:25.110 --> 01:29.310
option that will implement the method that I'm going to talk to you about it now, it's actually called

01:29.310 --> 01:31.950
impossible instead of high, but it doesn't matter.

01:31.950 --> 01:35.460
It's not exploitable anyway, so we don't really need to have it installed.

01:36.900 --> 01:42.150
So let's talk about how you could actually prevent these vulnerabilities from happen without asking

01:42.150 --> 01:48.450
the user to re-enter information or to re-enter the password, if you think of it, the way we were

01:48.450 --> 01:55.470
able to exploit this is we were able to just copy the form that the website uses and send it to the

01:55.470 --> 02:01.200
target person and get that person to run it or automatically run on the target person's computer.

02:02.460 --> 02:08.580
So once the request is sent to the server, the server wasn't doing any type of validation to ensure

02:08.580 --> 02:11.580
that the user actually wants to change their password.

02:12.660 --> 02:20.220
So the best way to prevent this RF is to make sure that the user is submitting data through a page that

02:20.220 --> 02:24.840
was served to him by the Web application and not by anyone else.

02:25.890 --> 02:30.120
A good way of implementing that is to use synchronizing tokens.

02:31.200 --> 02:35.020
Now, I know the name sounds complicated, but the idea is very simple.

02:35.720 --> 02:41.460
Basically, we want to generate a unique and random token at the server side.

02:42.300 --> 02:47.790
Then when the page is loaded, when the form is loaded, we're going to embed this already generated

02:47.790 --> 02:51.270
token into that page as a hidden form.

02:52.020 --> 02:57.780
Then when the form is submitted, we're going to make sure that the form was submitted with that token

02:57.900 --> 03:00.400
that we sent to that specific user.

03:00.810 --> 03:07.470
So basically we give the user a token and then we wait for him to submit the form with the token that

03:07.470 --> 03:08.060
we gave him.

03:08.460 --> 03:12.000
That way, the token that the hacker gets will only work for him.

03:12.390 --> 03:18.150
So even if he generates a page and send it to the target and the target runs the page, the form will

03:18.150 --> 03:18.870
be submitted.

03:19.020 --> 03:24.360
Well, it will be refused by the server because it did not give that token to that user.

03:24.360 --> 03:26.340
It gave that token to the hacker.

03:27.330 --> 03:34.860
Say, for example, we have this user here and here costs Facebook dot com passwords, BHB, it goes

03:34.860 --> 03:39.530
to the server, the server is going to generate a response for that request.

03:40.020 --> 03:46.350
So it's going to return the HTML page that represents password up in that page.

03:46.560 --> 03:49.170
It's going to include a unique token.

03:49.830 --> 03:55.950
So when the page is loaded at the client site, it's going to already have the form that the user is

03:55.950 --> 04:00.450
looking for, plus a unique token that was generated by the server.

04:01.770 --> 04:08.440
Then when the user submits whatever they want to submit, the server will only accept the form and will

04:08.440 --> 04:14.100
or will only response to what the user is asking if the user returns the same token.

04:14.910 --> 04:19.170
Now, if this isn't implemented properly, it can still be exploited.

04:19.180 --> 04:26.220
So if the token was predictable or if the same token was being used, then the hacker can discover what

04:26.220 --> 04:30.480
the token is embedded in the HTML code and send it to the user.

04:31.700 --> 04:37.700
So the focus needs to have certain characteristics so that it's secure and basically the main things

04:37.700 --> 04:45.530
that you want to keep in mind is that the token needs to be unpredictable and it cannot be reused regardless

04:45.530 --> 04:47.150
of the way you're going to implement this.

04:47.330 --> 04:52.400
These are the two main things that you want to keep in mind, because if it was predictable, then the

04:52.400 --> 04:57.800
hacker will be able to create their own tokens and then embed them in the code and run the attack.

04:58.640 --> 05:05.150
Same if the token can be reused, then the hacker can just use their token or someone else's token to

05:05.150 --> 05:06.230
target their target.

05:07.250 --> 05:13.250
So in order to make the token unpredictable and make it so that it can't be used, then the token needs

05:13.250 --> 05:20.390
to be a large value so that the hacker can't do a brute force attack and discover what the token is.

05:20.930 --> 05:25.700
The token needs to be random so that the hacker will not be able to create their own tokens.

05:26.630 --> 05:32.570
And it needs to be unique for each user because if users get the same token or similar tokens, then

05:32.690 --> 05:37.270
they can pass them around and then the tokens that works for the hacker will work for other people.

05:37.370 --> 05:39.440
So that'll divide the whole point.

05:40.700 --> 05:46.880
You can also increase the security of the token by including other factors and the token generation

05:46.880 --> 05:47.540
algorithm.

05:47.900 --> 05:54.140
So you can include, for example, the date and time, then combine it with a secure random generator

05:54.290 --> 05:55.610
and then encrypt that.

05:56.150 --> 05:59.000
All of this is obviously happening at the server side.

05:59.240 --> 06:04.880
So the hacker will not be able to know what algorithm you're using because the code will be executed

06:04.880 --> 06:05.990
at the server side.

06:06.650 --> 06:08.510
You don't necessarily have to do this.

06:08.720 --> 06:12.470
Using a secure, large and unique random number is enough.

06:12.740 --> 06:18.260
But if you want to increase the security, then you can just add other factors and encrypt the token

06:18.260 --> 06:19.790
before you send it to the user.

06:20.150 --> 06:24.890
This is actually implemented in Mattilda, so let me just show it to you in action.

06:25.830 --> 06:28.800
So I'm just going to go to Mattilda and here.

06:31.940 --> 06:36.710
And I'm going to go on our stand here, SRF and Autoblog.

06:38.570 --> 06:43.290
So this allows you to add a blog post so it doesn't allow you to change your password or anything.

06:43.310 --> 06:46.510
It actually allows anonymous people to add posts as well.

06:46.670 --> 06:48.740
So you can't really ask people for a password.

06:49.040 --> 06:54.790
I'm actually going to go and toggle security so that it's the highest because it's a zero right now.

06:58.850 --> 07:05.120
So now it's the most secure and if you right, click this and go on inspect element.

07:07.480 --> 07:08.710
Now, I'm going to scroll up.

07:10.840 --> 07:17.320
And as you can see, we have the forum here and we have a hidden input with a very long value and this

07:17.320 --> 07:18.070
is the token.

07:18.610 --> 07:24.490
So this has already been generated by the server and the server will refuse any request that we send

07:24.490 --> 07:27.510
to it unless it has this specific token.

07:28.120 --> 07:34.360
And if I use this form and send it to someone else, then again, the requests that they will send will

07:34.360 --> 07:37.270
be refused because they'll get a different token.

07:37.420 --> 07:40.420
This token was generated for me and for me only.

07:41.260 --> 07:43.780
So let me show you if I actually refresh right now.

07:45.210 --> 07:48.510
I'm going to get a different token and again, if I refresh again.

07:49.580 --> 07:56.120
I'll get a different token, and if I modify this, so let's say instead of the capital, I at the end

07:56.120 --> 07:57.320
I'm going to put a small I.

07:59.270 --> 08:00.830
And if I submit this now.

08:06.060 --> 08:10.420
It's given me an error, but let me not change this.

08:10.440 --> 08:14.310
So, again, I got a different token now and if I just submitted the way it is.

08:18.680 --> 08:25.880
It's going to work and now we have a blog entry called Test, so that's it, it's actually very, very

08:25.880 --> 08:26.350
simple.

08:26.360 --> 08:33.050
I didn't want to go into too much details about how to create random token and all that, because that's

08:33.050 --> 08:36.140
going to be specific depending on the programming language.

08:36.380 --> 08:38.620
That's the Web application is programmed in.

08:39.020 --> 08:46.070
But I was I just wanted to show you the concept or the idea of how to secure Web applications against

08:46.070 --> 08:47.410
this type of vulnerability.

08:47.780 --> 08:54.020
The whole idea is you want to make sure that the user submits their data through a page that you served

08:54.020 --> 08:58.050
to them and not by a page that was given to them by any other person.

08:58.460 --> 09:02.570
So in order to do that, we generate a token at the server side.

09:02.720 --> 09:06.200
This token needs to be long, random and unique.

09:06.830 --> 09:11.740
Send that token with the page, with the form and embedded as a hidden form.

09:12.170 --> 09:18.080
And then whenever a user submits the response, make sure that they submit the same token that was given

09:18.080 --> 09:18.650
to them.
