AI pentesting guides / Vulnerability classes

Injection

SQL injection testing

SQL injection testing checks whether input sent to an application can change the structure of a database query, letting an attacker read, modify or delete data or bypass logins. It is CWE-89 (Improper Neutralization of Special Elements used in an SQL Command) and part of OWASP Top 10 2021 A03: Injection.

SQL injection is old but not gone. Parameterised queries prevent it, yet it still appears in dynamic sorting and filtering, report builders, stored procedures that build SQL strings and legacy code. Because many modern cases are blind, testing relies on inference rather than visible errors.

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.

With Pentest-Swarm

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.

Sources

  1. CWE-89
  2. OWASP A03:2021 Injection
  3. OWASP SQL Injection Prevention Cheat Sheet