1.2 SQL-slides
1.2 SQL-slides
Attack
SQL-slides Page 1
Outline
❖ Reading: Chapter 12
❖ Lab: SQL Injection Attack Lab
SQL-slides Page 2
Web Application Architecture
SQL-slides Page 3
Lab Setup
The Labsetup/ Folder
SQL-slides Page 4
End
SQL-slides Page 5
Tutorial on SQL
and Database
SQL-slides Page 6
The Database Container
❖ The Database's Dockerfile
SQL-slides Page 7
Database Setup
❖ Log into MySQL
# mysql -u root -pdees
mysql>
❖ Create a database
❖ Create a table
SQL-slides Page 8
❖ Insert records
SQL-slides Page 9
Query Database
❖ SELECT statement
USE test_db
SELECT * FROM mytable;
SQL-slides Page 10
SELECT * FROM mytable WHERE Name='Alice' OR Salary>8000;
❖ A special condition
SELECT * FROM mytable WHERE 1=1;
SQL-slides Page 11
Update Records
❖ The UPDATE statement
SQL-slides Page 12
Comments
❖ Comments in SQL statement
SQL-slides Page 13
End
SQL-slides Page 14
SQL Injection
Attack
SQL-slides Page 15
How Web Application Interacts with Database
Browser
Application Server
Database
SQL-slides Page 16
Logging In Without Password 1
❖ Attack objective
Can you log into Alice's account without knowing her password?
❖ SQL statement
SQL-slides Page 17
Logging In Without Password 2
❖ Attack objective
You don't know any name, can you log into the database?
❖ SQL Statement
SQL-slides Page 18
End
SQL-slides Page 19
Modify Database
SQL-slides Page 20
Change Your Own Salary
❖ Attack objective
You are not happy with the salary that you get. You want to change your own salary?
SQL-slides Page 21
Change Your Own Salary
❖ Attack objective
Your boss (Ted) did not increase your salary, you want to punish him
by changing his salary to $1.
SQL-slides Page 22
Run an Arbitrary SQL Statement
❖ Attack objective
Use SQL injection vulnerability to run an arbitrary SQL statement?
❖ SQL Statement
SQL-slides Page 23
SQL Injection Comic Strip
(Source: https://xkcd.com/327/)
SQL-slides Page 24
End
SQL-slides Page 25
Similarity with
Other
Vulnerabilities
SQL-slides Page 26
SQL Injection and Cross-Site Scripting
❖ SQL Injection
SQL-slides Page 27
Similarity with system()
❖ Vulnerability in using system() function (Shell Script Injection)
SQL-slides Page 28
End
SQL-slides Page 29
Countermeasures
SQL-slides Page 30
Turning Code Into Data
Encoding Special Characters
❖ Apache's configuration
SQL-slides Page 31
Solving the Fundamental Problem
❖ Defense against the attacks on system()
SQL-slides Page 32
Prepared Statements
❖ Motivation behind prepared statements
SQL-slides Page 33
SQL-slides Page 34
Defense Using Prepared Statement
❖ The vulnerable approach
SQL-slides Page 35
SQL-slides Page 36
End
SQL-slides Page 37
Review Questions
and Summary
SQL-slides Page 38
Review Question 1
SQL-slides Page 39
Review Question 2
SQL-slides Page 40
Summary
❖ SQL statement
❖ SQL injection
❖ Countermeasures
SQL-slides Page 41
End
SQL-slides Page 42