SQLi
Last updated
Last updated
SQL Injection (SQLi) is a security vulnerability that allows attackers to inject malicious SQL code into queries sent to a database. This can lead to unauthorized access to data, data manipulation, or even full control over the database. SQL is a standard language for managing data held in relational database management systems (RDBMS), including MySQL, Oracle, SQL Server, and others.
Basis to tackle SQLi (Below)
An SQL query is a command used to get data out of a database.
Basic SQL syntax:
SELECT
Extracts data from the given table.
--
Comments out the remainder of the line. The code after --
is ignored.
ORDER BY
Orders the results obtained from SELECT in a specific manner. For example, if one has a table of countries and their populations, one can select the countries starting with the letter R and then order them by their population.
UNION
clause allows you to group multiple queries together.
JOIN
Joins data from two tables depending on a certain characteristic on the table. For example, if there's a table with customer IDs and their addresses and another table with customer IDs and their purchases, you can join both tables so that the customer addresses match their purchases.
DELETE, INSERT
Allows you to delete data or add new data to a table.
AND, OR
Allows you to modify queries so that they return information depending on multiple categories.
MIN, MAX
They return the smallest or largest value of a query.
User input from textbox, URL parameters, etc may be used to construct a SQL query in the backend.
Code below directly adds in input as a part of the query, as a result, the attacker can 'inject' their own code here and execute it.
and ...