PostSwigger SQL Injection Lab Walkthrough
"SQL Injection Vulnerability allowing login bypass"
Introduction:
SQL Injection (SQLI) is a critical vulnerability that allows attackers to manipulate database queries. In this blog, we will explore an SQL injection attack on a product filtering system where the WHERE clause is vulnerable.
Understanding the Vulnerability
A typical login form verifies user credentials using a SQL query like this:
SELECT * FROM users WHERE username = ‘admin’ AND password = ‘password’ ;
If the query returns a result, access is granted. Otherwise, access is denied.
Step-by-Step Solution
step 1: Accessing the Lab
Open the “SQL Injection vulnerability allowing login bypass” lab.
Click “Access the Lab” to launch the target application.
step 2: Testing for SQL Injection
Enter a random username and password.
If authentication fails, the app is checking credentials via SQL queries.
Test for SQL Injection using this payload in the username field:
step 3: Executing the Exploit
Use the following payload in the username field:
admin’ --
Leave the password empty and click Login.
step 4: Understanding the Exploit
This modifies the SQL query:
SELECT * FROM users WHERE username = ‘admin’ -- ‘ AND password = ‘ ‘ ;
Since -- comments out the password check, the attacker is logged in as admin.
step 5: Alternative Exploits
Using OR to always return true:
‘ OR ‘1’=’1’ --
Using # as a comment:
admin’ #
Before login :

It shows invalid username or password:

Replace the username with administrator’-- :

Now It’s login with the payload

Mitigations
To protect applications, developers should:
Use Prepared Statements
Implement Input Validation
Use Web Application Firewalls(WAF).
Limit Database Permissions.
Conclusion
This lab highlights the dangers of poorly secured authentication systems and the importance of secure coding practices.