SQL Injection
What is SQL Injection
SQL Injection is a type of cybersecurity vulnerability where an attacker manipulates a SQL query by injecting malicious SQL code into user inputs (e.g., login forms, search boxes) that are not properly sanitized. This allows the attacker to bypass authentication, access, modify, or delete database data, or even execute administrative operations on the database. SQL injection exploits occur when applications fail to validate or escape user-supplied input, making it possible to alter the intended behavior of SQL queries.
Video explaination
Types of SQL Injection

SQL Injection during code review
Below you can find examples of unsafe code leading to SQL Injection.
If you want to correct the sanatize the input and do not use string concatenation.
Exploiting SQL Injection
Fuzz String
Most of the time SQL Injections differ from the regular ones. Do not paste payloads thoughtlessly - match them to your specific case.
STACKED QUERIES
UNION Keyword
It has to contain same amount of columns as the original query.
The data types need to be compatible between each column.
You can try to cast string as int e.g. in PostgreSQL
Determine number of columns with order by (increase the number until it fails):
Sample final query:
If application does not return the output from given command it can me data type mismatch try to change the place of executed command.
Dumping other tables example
IN KEYWORD
BOOLEAN BASED
If outputs of the payloads differ application is probably vulnerable to SQL Injection.
Payload 1:
Payload 2:
TIME BASED
Change response times to avoid false positives.
Useful SQL commands
Additional info about hidden system tables in MSSQL:
Manual Code Execution
Common locations: ('/var/www/, /var/www/html, /var/www/htdocs, /usr/local/apache2/htdocs, /usr/local/www/data, /var/apache2/htdocs, /var/www/nginx-default, /srv/www/htdocs, /usr/local/var/www')
INTO OUTFILE
In some cases you can spawn the webshell using SQL Injection.
You can try to turn on xp_cmdshell using oneliner ; EXECUTE sp_configure 'show advanced options', 1; RECONFIGURE; EXECUTE sp_configure 'xp_cmdshell', 1; RECONFIGURE; -- -
If xp_cmdshell is set to True we are able to execute shell commands on the system.
You can obtain reverse shell using COPY TO method (by providing malicious file and saving it to the system):
Another way to obtain RCE is uploading compiled malicious extension (.dll):
// TODO
Last updated