WEBVTT

1
00:00:00.450 --> 00:00:02.660
SQL injection is still one of the

2
00:00:02.660 --> 00:00:04.760
most common serious web bugs.

3
00:00:04.930 --> 00:00:07.320
It happens when something a user typed

4
00:00:07.320 --> 00:00:08.470
is read as code.

5
00:00:09.320 --> 00:00:11.930
Many apps build a database query by

6
00:00:11.930 --> 00:00:15.140
gluing your input into a sentence of SQL.

7
00:00:15.310 --> 00:00:17.940
Type a normal ID, and the database

8
00:00:17.940 --> 00:00:19.860
gets a normal question.

9
00:00:20.030 --> 00:00:21.610
One row comes back.

10
00:00:22.460 --> 00:00:24.670
But if the input contains a quote,

11
00:00:24.670 --> 00:00:26.450
the data part ends early.

12
00:00:26.620 --> 00:00:29.100
Whatever follows is read as SQL,

13
00:00:29.100 --> 00:00:30.180
not as data.

14
00:00:30.350 --> 00:00:32.370
Now the user is writing part of

15
00:00:32.370 --> 00:00:33.170
the query.

16
00:00:33.340 --> 00:00:35.170
And the database answers:

17
00:00:35.170 --> 00:00:37.070
every row, not just one.

18
00:00:37.920 --> 00:00:39.510
In the lab, you do it by

19
00:00:39.510 --> 00:00:42.080
hand first, to see exactly what breaks,

20
00:00:42.080 --> 00:00:42.760
and why.

21
00:00:42.930 --> 00:00:45.570
Then a tool like sqlmap repeats the

22
00:00:45.570 --> 00:00:47.520
same idea automatically.

23
00:00:47.690 --> 00:00:49.270
Understanding first.

24
00:00:49.270 --> 00:00:50.440
Tools second.

25
00:00:51.290 --> 00:00:53.450
The fix is a prepared statement.

26
00:00:53.620 --> 00:00:55.960
The shape of the query is fixed first.

27
00:00:56.130 --> 00:00:58.200
Your input is sent separately,

28
00:00:58.200 --> 00:01:00.140
and can only ever be data.

29
00:01:00.310 --> 00:01:02.780
Also check input, and give the app's

30
00:01:02.780 --> 00:01:05.880
database user as little access as it needs.

31
00:01:06.730 --> 00:01:08.080
So: input is data.

32
00:01:08.080 --> 00:01:10.100
Never let it become code.

33
00:01:10.270 --> 00:01:12.810
In the lab, on the training app

34
00:01:12.810 --> 00:01:15.360
DVWA, set to its easiest level,

35
00:01:15.360 --> 00:01:17.900
you pull out the users table by

36
00:01:17.900 --> 00:01:19.940
hand, then with sqlmap.

37
00:01:20.110 --> 00:01:22.650
Only on training apps, or systems you

38
00:01:22.650 --> 00:01:24.180
are allowed to test.
