Injection
Attacks
If a website builds its database commands from what users type, an attacker can turn a simple login box into a way to read or change every record. Today we'll use that trick to log in without a password.
What You'll Learn
By the end of this topic, you'll be able to spot, exploit, and prevent one of the most critical web vulnerabilities.
SQL Injection
When user input is dropped directly into a database query, attackers can change the structure of that query—turning data into code.
') ends a string, and two hyphens
(--) start a SQL comment. Combine them, and the rest of the query—including the
password check—becomes a note the database ignores.The attacker closes the username string
with a quote, then uses -- to comment out the password check. The database returns the
first matching user—often administrator.
The 5‑Step Injection
From normal input to unauthorized access: how a tester probes for SQL injection.
- App accepts input from a form (username, password, search)
- Input is concatenated directly into a database query on the server
- Attacker enters
administrator'--to terminate the quoted field - Payload changes query structure, not just values
- Injected input is parsed as SQL, not stored as literal
- Comment markers (
--or#) remove the rest of the query
- Database runs altered statement without complaint
- Password verification skipped (commented out)
- Attacker logged in as first matching user (administrator)
- System treats all subsequent requests as that privileged account
# Step 1: Try a normal login
Username: admin Password: 1234 (any wrong password)
→ Expected: Login fails ("invalid credentials")
# Step 2: Inject the payload
Username: administrator'-- Password: anything
(Note: single quote, two hyphens, then a space)
→ Expected: You are logged in as administrator. Lab solved.
# The payload, anatomized
administrator'--
→ Closes the username string, comments out password check
Troubleshooting
Test Your Knowledge
administrator'--, what is the purpose of the two
hyphens?admin'-- but nothing happens. What is the most likely
mistake?Now Do It Yourself
administrator'-- (with a space after
hyphens).| COMMAND / PAYLOAD | WHAT IT DOES | WHEN TO USE |
|---|---|---|
administrator'-- |
Comments out password check | Login bypass when username known |
' OR 1=1-- |
Makes WHERE condition always true | Login bypass when username unknown |
' OR '1'='1-- |
Boolean-based always‑true variant | Basic auth bypass, alternate syntax |
'-- |
Truncates query early | Probing if field is injectable |
' OR 1=1# |
MySQL comment alternative | When -- is stripped or fails |
Go Deeper
PortSwigger: SQL Injection
Interactive labs and real attack scenarios to practice and deepen understanding.
OWASP SQL Injection Prevention Cheat Sheet
Industry‑standard defensive techniques and secure coding practices.
OWASP Top 10: Injection
High‑level overview of why injection remains critical and how it impacts real systems.
Injection Attacks Handout (PDF)
Full workshop packet with the Day 3 reference notes and cheatsheet.