SQL Injection (SQLi) is a critical web security vulnerability that occurs when an attacker can manipulate a web application’s database queries by injecting malicious SQL code into input fields. This happens when applications directly concatenate user input into SQL queries without proper sanitization or parameterization. In this project, we demonstrate a vulnerable login endpoint that allows SQL injection attacks.
To test the SQL injection vulnerability:
/api/sqli_vuln/auth/login
)' OR '1'='1
admin' --
' UNION SELECT * FROM users --
Here is a request that takes advantage of an endpoint in the server that is vulnerable to SQL injection:
This example is convoluted and obviously staged, but it shows how an attacker may be able to insert characters into a request to manipulate the SQL query that the server is running. In this case, the attacker is able to insert a ‘ character into the request, which causes the SQL query to be malformed. The attacker can then use this to manipulate the query to return all of the users in the database, which is a huge security risk.
SQL injection vulnerabilities are among the most severe security risks because:
The impacts can include:
To prevent SQL injection:
The secure version of any database operation should never directly concatenate user input into SQL queries.