Classification
- CWE-89 SQL Injection (parent: CWE-74 Injection).
- OWASP Top 10 2021: A03 Injection.
- The OWASP API Security Top 10 2023 has no dedicated injection category; injection was API8 in the 2019 edition.
Detection techniques
- Error-based: a stray quote produces a database error that reveals the query context.
- Union-based: the attacker's SELECT is appended and its results appear in the page.
- Boolean-based blind: the response differs between a true condition (AND 1=1) and a false one (AND 1=2).
- Time-based blind: an injected delay such as SLEEP(5) or pg_sleep(5) changes the response time.
- Out-of-band: the database makes a DNS or HTTP request to infrastructure the tester controls.
- Second-order: input stored safely but later used unsafely in another query.
What counts as proof
Proof should exclude coincidence. For boolean-based injection, show consistent different responses for true and false conditions across repeated requests. For time-based injection, a single slow response proves little because networks are noisy; stronger evidence is a delay that scales with the injected value (2, 4 and 8 seconds) while a baseline stays fast. Extracting a harmless value such as the database version is conclusive. Avoid dumping real data.
Remediation
Use parameterised queries or prepared statements everywhere, including in ORMs' raw-query escape hatches. Where identifiers such as column names must be dynamic, map them through an allow-list rather than escaping. Run the application's database user with least privilege. Input validation and WAFs reduce noise but do not fix the root cause.
How Pentest-Swarm tests for SQL injection
SQL injection is one of the classes Pentest-Swarm proves with an external timing oracle, not a model's assessment.
- sqlmap detects candidate injection points; the injection place, parameter and DBMS are read from sqlmap's structured output.
- A timing oracle in ladder mode re-proves blind SQLi with a DBMS-appropriate SLEEP, WAITFOR or PG_SLEEP payload: the induced latency must scale with the injected delay and clear the target's noise floor.
- NoSQL injection is covered too, with differential proof of operator-object authentication bypass.
- A safe, non-weaponised verify chain exists for MOVEit Transfer SQL injection (CVE-2023-34362).
Where it falls short
Automated SQLi testing finds injection in parameters it discovers; second-order injection and injection behind complex multi-step state are harder and may need a manual tester or source review with SAST. Highly variable network latency can leave a timing proof Inconclusive rather than Proven. Always test against non-production data where possible.
Questions
Do ORMs prevent SQL injection?
Mostly, when you use their query builders. Raw-query functions and string-built ORDER BY or filter clauses can still be injectable.
Does a WAF stop SQL injection?
It blocks common patterns but can often be bypassed. It is a mitigation, not a fix.
What is blind SQL injection?
Injection where the query result is not shown, so the tester infers it from response differences or timing.