SQL Injection Lab: Bypass a Login Without the Password

✨ AI Summary
MiniMail's login page takes your username and password and glues them straight into a SQL query. That one shortcut lets you log in as the administrator without knowing the password. SQL injection is older than most of the people learning it, and it still turns up in real applications, so this is the web lab every beginner should do first.
Lab at a glance: Beginner · 70 XP · about 10 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

SQL injection happens when user input becomes part of a database query’s code instead of staying data. Once that happens, the attacker can change what the query means, not just what it searches for.

How MiniMail's login works

The login builds a query by string concatenation, roughly:

SELECT * FROM users WHERE username='[your input]' AND password='[your input]'

If a row comes back, you are logged in as that user. The lab is solved when you are logged in as admin.

The attack approach

  • Your input sits inside single quotes. A quote of your own closes that string early.
  • After closing it, you are writing SQL. Your goal is to make the WHERE clause match the admin row without checking the password.
  • SQL comments make the database ignore the rest of the line, including the password check.

Full walkthrough (spoiler)

Stuck after a few attempts? Open the steps below. Solving it yourself first is worth more XP, and more learning.

Show the step-by-step solution
  1. In the username field, type the admin username, then a single quote to close the string, then a SQL comment marker (two dashes and a space).
  2. Type anything as the password.
  3. The query becomes “find the user called admin”, and everything after the comment, including the password check, is ignored. You are logged in as admin.

Why it works

The database cannot tell which characters came from the developer and which came from you, because they were joined into one string before it ever saw them. Your quote ended their string; your comment deleted their password check.

Core principleNever build queries by joining strings with user input. Send input as parameters.

Where this happens in the real world

SQL injection has driven some of the largest breaches on record, and injection still sits in the OWASP Top 10. In 2023 a SQL injection in the MOVEit Transfer file-sharing product was exploited at mass scale, affecting thousands of organisations.

How to defend against it

  • Use parameterised queries (prepared statements) everywhere. This is the real fix.
  • Use an ORM or query builder correctly, without raw string queries.
  • Run the database account with least privilege.
  • Do not rely on blocklists of quotes or keywords; they get bypassed.
Mr Elite tip: After you solve it, try to explain to a non-technical friend why one apostrophe broke the login. If you can, you understand injection, and that understanding transfers directly to prompt injection.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own phrasing before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is SQL injection?
A vulnerability where user input is inserted into a SQL query in a way that lets the attacker change the query's logic, for example to bypass logins or read data.
Why does the comment trick work?
The comment tells the database to ignore the rest of the query line, which removes the password check.
How do I fix SQL injection?
Use parameterised queries so input is always sent as data, never as part of the SQL text.
What should I try next?
The reflected XSS and IDOR labs, then our SQL injection for bug bounty guide.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *