Skip to main content

SQL Injection

SQL Injection is an attack technique that exploits vulnerabilities in application input validation to execute malicious code in databases. This attack occurs when security controls are insufficient or when variables are not properly filtered, affecting any programming language or script involved.

SQL Injection manifests itself when an attacker inserts malicious SQL code through non-validated entries. For example, consider the parameter "username" in a vulnerable SQL query:

SELECT * FROM usuarios WHERE nombre = '" + nombreUsuario + "';

If the value of "username" is simply "Alice", the query works as expected. However, an attacker could enter a malicious value such as:

Alicia'; DROP TABLE usuarios; SELECT * FROM datos WHERE nombre LIKE '%

This would transform the original query into a dangerous script:

SELECT * FROM usuarios WHERE nombre = 'Alicia'; DROP TABLE usuarios; SELECT * FROM datos WHERE nombre LIKE '%';

This attack can result in record exposure, table deletion and data manipulation.

To prevent SQL Injection, it is essential to implement prepared queries and rigorous input validation. These secure programming practices are essential to protect databases and maintain system integrity.