This tutorial teaches SQL injection from foundational concepts through practical exploitation and defense, using DVWA (Damn Vulnerable Web Application) as a safe lab environment. It covers why SQL injection remains one of the most consistently dangerous vulnerabilities in the OWASP Top 10 since its inception, demonstrates manual testing methodology and UNION-based data extraction, and explains how to automate exploitation with SQLmap. The article emphasizes that SQL injection stems from developers concatenating user input directly into SQL queries without proper sanitization, and that understanding both attack and remediation techniques is essential for effective cybersecurity work.
- SQL injection persists through string concatenationThe article identifies three primary causes of SQL injection in 2026: direct string concatenation of user input into SQL queries without escaping (identified as the #1 cause worldwide), legacy codebases written before prepared statements were standard (such as PHP/MySQL code from 2005 still running in production), and developers using ORMs but writing raw SQL queries for complex operations, bypassing the ORM's built-in protections. String concatenation allows attackers to inject SQL syntax characters that modify query logic rather than being treated as pure data.
- Single quote breaks query logic immediatelyThe tutorial demonstrates that entering a single quote (') into user input causes a MySQL syntax error, confirming the injection point. The attacker can then use the quote to break out of the string context, followed by SQL comment syntax (-- -) to neutralize remaining query logic. The example shows how 'admin'-- - transforms a login query by commenting out the password check, allowing authentication bypass with any password entered after the injection point.
- Manual testing confirms injection through boolean conditionsThe article outlines a four-step manual testing workflow: Step 1 triggers an error with a single quote to identify the injection point; Step 2 confirms control by inputting boolean conditions (1' AND '1'='1 returns results, while 1' AND '1'='2 returns nothing), proving conditional response differences indicate SQLi; Step 3 uses ORDER BY to count columns in the query (incrementing until an error occurs); Step 4 uses UNION SELECT with string values to identify which columns display in the application output, essential for data extraction.
- UNION-based extraction dumps entire databases systematicallyOnce the column count and visible columns are identified, attackers can chain UNION SELECT queries to extract: database version via version() function, current database name via database() function, table names from information_schema.tables, column names from information_schema.columns, and finally user credentials. The article demonstrates extracting an MD5 password hash from the users table, which can then be cracked with hashcat using wordlists like rockyou.txt, converting a hash like 5f4dcc3b5aa765d61d8327deb882cf99 into plaintext.
- SQLmap automates extraction after manual confirmationThe article emphasizes that manual confirmation should precede SQLmap use to avoid false positives and unnecessary target traffic. SQLmap is then invoked with the vulnerable URL, session cookies, and parameters like --dbs (enumerate databases), -D dvwa --tables (enumerate specific database tables), and -D dvwa -T users --dump (extract table contents). The article notes that passing Burp Suite saved request files with -r request.txt handles complex authentication and POST-based injection points automatically.
- Four distinct SQL injection attack types existIn-band SQLi returns data directly in HTTP responses through either error-based exploitation (using database error messages) or UNION-based techniques (appending UNION SELECT queries). Blind boolean-based SQLi extracts data character by character through yes/no conditional responses when no data is returned directly. Blind time-based SQLi infers data from response timing variations using SLEEP() or WAITFOR DELAY functions. Out-of-band SQLi exfiltrates data through separate channels like DNS lookups or HTTP requests to attacker-controlled servers, requiring specific database features like MySQL
- Parameterized queries eliminate SQL injection entirelyThe article identifies parameterized queries (prepared statements) as the primary defense that separates query structure from user data, making it impossible for user input to modify query logic. Every programming language supports this approach. Secondary defenses include input validation using whitelists for expected formats (a user ID field accepting only integers), and least-privilege database accounts limited to SELECT/INSERT/UPDATE operations without DROP TABLE, GRANT, or file operation permissions, which limits the blast radius if exploitation occurs.
- Historical breaches demonstrate real-world impactThe article cites concrete examples of SQL injection damage: a 2009 Heartland Payment Systems attack exposed 130 million credit card numbers, and a 2017 Equifax breach affecting 147 million people involved an SQLi vulnerability in a partner portal. SQL injection has appeared in every edition of the OWASP Top 10 security risks list since its creation, establishing it as a consistently dangerous and consistently findable vulnerability in web application security across decades.
Bottom line: SQL injection remains exploitable in 2026 because developers continue concatenating user input directly into SQL queries without sanitization, and while manual testing confirms the vulnerability through quote injection and boolean conditions followed by UNION-based data extraction, the single most important prevention is implementing parameterized queries (prepared statements), which eliminate SQLi entirely by separating query structure from user data.
In 2009, a single SQL injection attack against Heartland Payment Systems exposed 130 million credit card numbers. In 2017, an SQLi vulnerability in an Equifax partner portal contributed to a breach affecting 147 million people. SQL injection has appeared in the OWASP Top 10 security risks in every single edition since the list was created. It remains one of the most consistently dangerous and consistently findable vulnerabilities in web application security — and it starts with a single quote. Lets start our SQL Injection tutorial for deep dive learning.
This tutorial teaches SQL injection from first principles — what it is, why it works, how to test for it manually step by step, how to extract data using UNION-based payloads, and how to automate the process with SQLmap. Everything is practised on DVWA, your own local intentionally vulnerable application. By the end, you will understand SQLi well enough to find it in real applications during authorised testing.
What Is SQL Injection?
SQL injection is a vulnerability that occurs when user-supplied input is inserted directly into a SQL query without proper sanitisation. An attacker can insert SQL syntax characters that modify the query’s logic — turning a legitimate search into an instruction to reveal data, bypass authentication, or destroy the database.
The simplest possible example. A login form’s SQL query normally looks like:
SELECT * FROM users WHERE username = ‘admin’ AND password = ‘secret123’;
# Attacker enters: username=admin’– -, password=anything
SELECT * FROM users WHERE username = ‘admin’— –‘ AND password = ‘anything’;
# Everything after — is a comment. Password check is bypassed. Login succeeds.
The single quote ' breaks out of the string context. The double dash -- comments out the rest of the query. This is SQL injection at its most basic — and variations of this exact technique affect real applications in 2026. Explore more in our SQL Injection Attacks guide.
Why SQL Injection Still Works in 2026
SQLi exists because developers build SQL queries by concatenating strings — combining static query text with dynamic user input. When user input is not treated as pure data (but as executable SQL), the vulnerability is present. Three common causes:
Lab Setup — DVWA on Kali Linux
DVWA (Damn Vulnerable Web Application) is the standard practice target for learning SQL injection. It runs in your local environment — completely isolated, completely legal to attack. The fastest setup on Kali Linux uses Docker:
sudo apt install docker.io -y
sudo systemctl start docker
# Run DVWA container
sudo docker run –rm -it -p 80:80 vulnerables/web-dvwa
# Open in browser
http://localhost/ ← Default credentials: admin / password
DVWA Security → Set to “Low” → Submit
Navigate: SQL Injection
Already have DVWA set up from a previous exercise? See our full lab guide: DVWA Setup Tutorial Day 1 and DVWA Labs hub.
Manual SQL Injection Testing — Step by Step
' in the input field. A MySQL or database error means the single quote broke the query syntax — input is being concatenated directly into SQL. This is your primary injection indicator.UNION-Based Data Extraction — From Columns to Credentials
SQLmap — Automate the Extraction
After confirming SQL injection manually, SQLmap handles the systematic extraction automatically. Always confirm manually first — SQLmap on a false positive wastes time and generates unnecessary traffic against the target.
sqlmap -u “http://localhost/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit” \
–cookie=“PHPSESSID=abc123; security=low” –dbs
# ─── Enumerate tables in dvwa database ────────────────────────
sqlmap -u “http://localhost/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit” \
–cookie=“PHPSESSID=abc123; security=low” -D dvwa –tables
# ─── Dump the users table ─────────────────────────────────────
sqlmap -u “http://localhost/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit” \
–cookie=“PHPSESSID=abc123; security=low” -D dvwa -T users –dump
# ─── From Burp saved request file ─────────────────────────────
sqlmap -r request.txt –dbs –level=5 –risk=3
-r request.txt. This handles complex authentication and POST-based injection points automatically. More on Burp: Burp Suite Beginner Guide.4 Types of SQL Injection You Will Encounter
SLEEP(5) or WAITFOR DELAY to infer data from response timing. Slowest SQLi type but works even on hardened applications.LOAD_FILE and INTO OUTFILE). Less common but high impact when it works.Deep dive on all attack types: SQL Injection category | DVWA Day 4: SQL Injection Deep Dive | Day 13: SQL Injection Tutorial (Ethical Hacking Course)
Defence — How to Prevent SQL Injection
Understanding how to prevent SQLi is as important as finding it — this knowledge helps you write better bug bounty reports and gives you credibility with development teams reviewing your findings. Also check out Day 4: OWASP Top 10 Explained for broader web security defence context.
Frequently Asked Questions
SQL injection was one of the first vulnerabilities I found in a real application during an authorised assessment. A single quote in a search box, a MySQL error in the response, and twenty minutes later I had the entire user table. The remediation recommendation — parameterised queries — was one line of code change. Understanding both the attack and the fix is what makes your reports valuable. Practise on DVWA. Find it in the real world responsibly.

