SQL Injection
Presented by :
Oumaima EZZEBDI Iliass AIT EL KOUCH Mohamed ACHKOUR Marouane BOUJRANI
Anass OUAZZANI CHAHIDI
Supervised by:
Pascal LAFOURCADE
Agenda
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici
JAN. FÉVR.
MARS
- Brief History
- What is SQL Injection?
- How does SQL Injection work?
- Types of SQL Injection attack
- What damages SQL Injection may cause?
- How to “prevent” SQL injection attack?
- Demo
Introduction
● Brief History
● Definition
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici
JAN. FÉVR. MARS
● Building websites was straightforward
● The web gained popularity
● The development of CGI and server-side
● Websites started storing in databases
● Scripting languages added support for SQL databases
● Hackers discovered SQL Injection attack vectors
Brief History
Attack vector that uses SQL code for database manipulation Access confidential information
Impact:
Deletion of tables
Gaining administrative rights to a database
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici
JAN. FÉVR. MARS
Definition
How do SQL
Injection work?
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici
JAN. FÉVR. MARS
select * from user_table
where username = 'EtudiantUCA' and password = 'mypassword';
How do SQL Injection work?
How do SQL Injection work?
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici
JAN. FÉVR. MARS
// Connect to SQL database
$db_query = "select * from user_table where username = '".$user."'
AND password = '".$password."';";
// Execute query
select * from user_table where
username = 'admin';--' and password = 'mypassword'
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici
JAN. FÉVR. MARS
select * from user_table where username = 'admin' and
password = 'password' or 1=1;--';
How do SQL Injection work?
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici Insérez votre texte ici Insérez votre texte ici.
Insérez votre texte ici
JAN. FÉVR. MARS
How do SQL Injection work?
Types of SQL
Injection attack
SQL Injection can be classified into three major categories – In-band SQLi, Inferential SQLi and Out-of-band SQLi.
In-band SQLi (Classic SQLi)
● Error-based SQLi
● Union-based SQLi
1. Error-based SQLi :
the attacker performs actions that cause the database to produce error messages. The attacker can potentially use the data provided by these error messages to gather information about the structure of the
database.
2. Union-based SQLi
Union-based SQLi is an in-band SQL injection technique that leverages the UNION SQL operator to combine the results of two or more SELECT
statements into a single result which is then returned as part of the HTTP response.
2. Union-based SQLi
The UNION keyword lets you execute one or more additional SELECT queries and append the results to the original query. For example:
SELECT a, b FROM table1 UNION SELECT c, d FROM table2
For a UNION query to work, two key requirements must be met:
1. The individual queries must return the same number of columns.
2. The data types in each column must be compatible between the individual queries.
The two types of inferential SQL Injection are : Boolean-based (content-based)
Time-based Blind SQLi
II- Inferential SQLi (Blind SQLi)
1. Boolean-based (content-based) :
Boolean-based SQL Injection is an inferential SQL Injection technique that relies on sending an SQL query to the database which forces the
application to return a different result depending on whether the query returns a TRUE or FALSE result.
2. Time-based Blind SQLi :
Time-based SQL Injection is an inferential SQL Injection technique that relies on sending an SQL query to the database which forces the database to wait for a specified amount of time (in seconds) before responding. The response time will indicate to the attacker whether the result of the query is TRUE or FALSE.
III- Out-of-band SQLi
Out-of-band SQLi is performed when the attacker can’t use the same channel to launch the attack and gather information, or when a server is too slow or unstable for these actions to be performed. These techniques count on the capacity of the server to create DNS or HTTP requests to transfer data to an attacker.
III- Out-of-band SQLi
SQL Impacts
● Retrieve sensitive information
● Manipulate Data
● attack the internal network
Retrieve sensitive information :
•Usernames/ Passwords
What can SQL Injection do?
•Credit Card information
❖ Manipulate Data :
What can SQL Injection do?
❖ Attack the internal network behind a firewall.
SQLi Prevention
● No immune protection
● Coding best practices
● Pentesting
Web security risk number one
Security risk
Prepared statement
Code best practices
Code best practices
ORM
Pentesting
SQLmap