SQLi and Cheat Sheet

It has been collected by compiling many sources. For personal notes purposes only.

SQL injection is the ability of attackers to execute their SQL queries using the web application. It may be necessary to briefly know the information about SQL and DBMS. The following SQL queries may return different results on different DBMS.

▪ SQL can perform arithmetic operations. Also, it can perform bitwise operations and many more.

The output: 1
The output: 3

▪ The quotation mark specifies the string.

SELECT '3-2';
The output: 3-2

▪ DBMS can do typecasting. However, it returns 0 when doing type casting for character values to integer values.

SELECT '3' - 'b';
The output: 3

▪ DBMS does not trim() when inserting data, but it performs trim() when searching data in the database. If the exact match is not checked, it creates a vulnerability.

And much more functionality occurs in DBMS.

The goal should be to push the limits of the program with queries until a vulnerability is discovered. In the discovery part, an expected response or behavior should be selected as a base situation. If we can reach the base situation by performing our queries, this means that we can run queries in the database.

When we get into the exploitation part -after the discovery part-, the intent should be to write our SELECT queries. The best way to do that is to use the UNION operand. The most important limitation is that the number of columns should be equal in both SELECT queries.


If we want to see only our response after the SQL query, we need to give a value that will return the empty result to the parameter that contains a vulnerability.


Also, you can run SQL helper functions on vulnerable parameters.


We can easily view it by using the codes that the databases’ workbenches use to pull the data from the database.




Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store