SQL Injection (SQLi) is a security vulnerability that occurs when a web application inserts user input directly into an SQL query. Attackers inject malicious SQL code into input fields (login forms, search boxes, etc.) to cause unintended queries to be executed. Since it was first reported in 1998, it has remained one of the most dangerous web vulnerabilities, consistently ranking near the top of the OWASP Top 10.
The main types of SQL Injection are In-band SQLi, Blind SQLi, and Out-of-band SQLi. In-band SQLi is the most basic form, in which the results are displayed directly on the screen. Union-based extracts additional data using the UNION operator, and Error-based extracts information from error messages. In Blind SQLi, the results are not visible, but data is inferred from differences in true/false responses (Boolean-based) or from response time (Time-based).
If an attack succeeds, the damage is severe. An attacker can access an administrator account by bypassing authentication, or extract the entire contents of the database (Data Exfiltration). They can also delete data with DROP TABLE, or take over the server by executing operating system commands through features such as xp_cmdshell (MS SQL). In the 2017 Equifax hack, the personal information of 140 million people was leaked through SQL Injection.
The core of the defense is the Prepared Statement (Parameterized Query). By separating the SQL query structure from the data, user input is not interpreted as SQL syntax and is processed purely as data. Using an ORM (Object-Relational Mapping), the principle of least privilege (restricting DB account permissions), input validation (whitelisting), and applying a WAF (Web Application Firewall) are also important layers of defense.