Cybernetics

Diagnostic playbook

UNION-based SQL injection (classic string concatenation)

Injection / SQL Injection

Knowledge identity

Definition and taxonomy

Summary

Classic UNION-based SQL injection: unparameterized string concatenation lets an attacker append SELECT clauses to extract arbitrary table data.

Severity rationale

No rationale recorded for this severity.

Aliases

Classic SQL injection,UNION SQLi,String concatenation SQLi

Standards

CWE-89,CWE-209 A03:2021-Injection

CVSS vector

CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N

1. First Signal

What should make an agent suspicious

Symptoms

Single quote in parameter produces raw DB syntax error; ORDER BY N succeeds/fails to reveal column count; UNION SELECT reflects attacker-chosen columns

Prerequisites

App builds SQL by concatenating unsanitized input; attacker has a parameterized input surface; DB error disclosure enabled

2. Recognition Logic

How to recognize this next time

If a quote in input triggers a DB error naming the source line, assume classic concatenation. Enumerate columns with ORDER BY, then UNION SELECT to confirm data reflection.

3. Diagnostic Procedure

Safe checks, in order

  1. Confirm authorized scope. 2. Baseline a normal value. 3. Send a single quote and observe error disclosure. 4. Use ORDER BY 1..N to find column count. 5. Use UNION SELECT with the correct column count. 6. Extract only authorized lab data. 7. Record invalidating conditions (prepared statements, escaping, WAF).

4. Proof

Evidence

DVWA Low: id=1' -> MySQL syntax error near ''1''; id=0 UNION SELECT user,password FROM users# -> 5 users with MD5 hashes returned in page.

5. Controls

Negative checks

At higher DVWA levels (medium/high) mysqli_real_escape_string or prepared statements prevent the UNION payload; the same marker should no longer return DB errors or reflected data.

6. Avoid Bad Memory

False positives and traps

Ordinary non-SQL echo of parameters is not SQLi; UNION returning no visible data needs the right column count/types; DB errors alone without data reflection are limited to info disclosure unless exploitable.

7. Why It Matters

Impact

Full read of the target database (rows, schemas, credentials). In the lab, unsalted MD5 hashes allow offline cracking leading to account takeover. High severity in real apps.

8. Why It Happened

Root cause

Unsafe query construction: user input concatenated into SQL string without prepared statements or escaping; DB errors returned to the client.

9. Fix

Remediation and prevention

Use parameterized queries/prepared statements. Validate input types. Disable verbose DB error messages in production. Use least-privilege DB accounts. Add WAF as defense in depth.

10. Re-test

Verification steps

  1. Send the same UNION payload after the fix - should return no data and no DB error. 2. Send a single quote - should be treated as literal text. 3. Confirm error pages are generic. 4. Add an automated regression test for the parameter.

Reference

Tools and sources

Tools used

curl for reproducible requests; docker exec for read-only source/database inspection

References

OWASP SQL Injection Prevention Cheat Sheet; CWE-89; CWE-209; DVWA sqli module

Intelligence

Products and history

Technologies

PHP,MariaDB,Apache

Affected products / versions

DVWA (Damn Vulnerable Web Application) current master

History

First documented in DVWA sqli module at Low security; previously unreported in this archive.

Exploit knowledge

Variants and references

Attack surface

User-controllable id parameter reaches SQL statement construction; no WAF/parameterization in front.

Exploit maturity

proof-of-concept

Known variants

Error-based extraction via GROUP BY/duplicate key,Boolean blind using OR 1=1 vs OR 1=2,Time-based blind via SLEEP(),Stacked queries if multiple statements allowed

Defensive signatures

Parameter value containing a single quote followed by SQL keywords,ORDER BY N probing requests,UNION SELECT keywords in query string,Raw DB error text in HTTP response body

Reproduction commands

No reproducible commands recorded.

Exploit references

Exact exploit: curl -s -b /tmp/dvwa_c.txt "http://127.0.0.1:4280/vulnerabilities/sqli/?id=0%27%20UNION%20SELECT%20user,password%20FROM%20users%23&Submit=Submit",Probe: curl -s -b /tmp/dvwa_c.txt "http://127.0.0.1:4280/vulnerabilities/sqli/?id=1%27&Submit=Submit",Column count: for n in 1 2 3; do curl -s -b /tmp/dvwa_c.txt "http://127.0.0.1:4280/vulnerabilities/sqli/?id=1%20ORDER%20BY%20$n%23&Submit=Submit"; done

Case provenance

Linked findings