Sql Injection Scanner: How It Works and How to Find It
A SQL injection scanner sends crafted input to every parameter it can reach, then watches how the application and database respond. A database error, a changed page, a delayed response or extra rows in the output all indicate that your input became part of the SQL query instead of staying data. Scanners are good at finding the obvious cases quickly and bad at the ones that need application context, which is why a clean scan is not proof of safety.
This post explains what a SQL injection scanner actually does, the four detection techniques behind it, where it fails, and how to fix what it finds. Only test systems you own or are explicitly authorized to test.
What SQL injection is, in one paragraph
OWASP defines SQL injection as inserting a SQL query through client input so that the application runs it. It happens when untrusted data enters the program and is then used to build a SQL query dynamically. Depending on privileges, the result can be reading data, modifying it, running administrative operations on the database, and in some cases running commands on the operating system. OWASP's own summary of the root cause: SQL makes no real distinction between the control plane and the data plane. The fix is therefore structural, not about filtering "bad" characters.
Injection is also third on the OWASP Top 10:2021, which reports that 94% of tested applications were checked for some form of injection and maps CWE-89 (SQL injection) into the category.
How a SQL injection scanner works
Every scanner follows the same loop:
- Discover inputs. Crawl pages and read API definitions to collect parameters: query strings, form fields, JSON bodies, cookies and headers. OWASP's A03 guidance recommends testing all of these, not just URL parameters.
- Establish a baseline. Request the normal page and record status code, length, content and response time.
- Inject probes. Send a quote, a boolean condition, a sleep or a UNION fragment in each input, one at a time.
- Compare. Decide whether the response differs from the baseline in a way that only SQL execution would explain.
- Confirm. Re-send variations to rule out noise, then report the parameter, payload and evidence.
Step 4 is where scanners differ: telling real injection from a flaky server is the hard part.
The four detection techniques
Error-based
The scanner breaks the query syntax on purpose and looks for a database error in the response. OWASP's own example shows the idea: a name like evil'ex makes the database complain about incorrect syntax near the quote.
GET /items?id=2'
A response containing a SQL syntax error, a stack trace or a driver exception is a strong signal. It is also the technique most easily hidden: production apps that return a generic 500 page show nothing, which pushes you into the blind techniques below.
Boolean-based (content-based blind)
When errors are hidden, the scanner asks true/false questions and compares pages. OWASP's blind SQL injection page uses this pair:
/items.php?id=2 and 1=2 -> false condition
/items.php?id=2 and 1=1 -> true condition
If the true page matches the original and the false page differs, the database is evaluating attacker-controlled logic. A good scanner repeats the pair with different values to avoid being fooled by pages that change on every load (ads, timestamps, CSRF tokens).
Time-based
If the page looks identical either way, the scanner makes the database pause and measures the delay. OWASP documents the principle with database-specific forms, such as waitfor delay '00:00:10' for Microsoft SQL Server, and the A03 page shows a SLEEP(10) payload for MySQL. The scanner compares the delay against baseline timing across several requests, because a slow network can look like a hit.
Time-based testing is the most reliable on hardened apps and the slowest to run. It is also the technique that produces false positives on overloaded servers.
UNION-based
When query results are rendered on the page, a scanner can append a UNION SELECT to pull data from another table into the output. It first works out how many columns the original query returns, then which columns accept strings, and only then places a marker value to see it reflected. The A03 page's example payload begins with ' UNION SELECT SLEEP(10);--, showing that UNION and timing probes are often combined.
| Technique | Needs visible error? | Needs visible output? | Speed | Typical failure |
|---|---|---|---|---|
| Error-based | Yes | No | Fast | Generic error pages |
| Boolean-based | No | Page must differ | Medium | Dynamic pages cause noise |
| Time-based | No | No | Slow | Network jitter, WAF delays |
| UNION-based | No | Yes | Fast | Output not reflected |
What scanners miss
Scanner coverage is the question that matters, and the honest answer is "less than the report implies." Common blind spots:
- Second-order injection. The payload is stored safely on one request and used unsafely later. OWASP's prevention cheat sheet notes that malicious data can come from the database itself, not just an HTTP request, and that parameterization applies to previously stored data too. A scanner that injects and checks only the immediate response never sees the second request that triggers it. Example (hypothetical): a signup form stores the username
bob'--safely, and a nightly admin report later concatenates that username into a query. - Authenticated and multi-step flows. If the scanner cannot log in, stay logged in, or complete a checkout, it never reaches parameters behind those steps.
- Unusual input locations. Headers, cookies, JSON fields nested several levels deep and GraphQL variables are skipped by simpler crawlers.
- Injection in structure, not values. Table names, column names and sort direction cannot be parameterized, so apps that let users pick them are exposed. OWASP's A03 page flags this as common in report-writing software.
- Stored procedures with dynamic SQL. OWASP notes that binding a procedure's arguments protects the call, not dynamic SQL built inside the procedure.
- ORM query languages. HQL and JPQL injection looks different from raw SQL; OWASP's cheat sheet gives HQL examples.
This is why OWASP's A03 page says source code review is the best method of detecting injection, with automated testing of all inputs strongly encouraged alongside it. The two approaches find different things. For how static and dynamic testing split the work, see SAST vs DAST.
How to find SQL injection on your own system
Work in this order, on staging or on systems you own:
- Run a dynamic scan. A deep security scan runs a full CVE assessment with 25,000+ templates covering XSS, SQLi and logic flaws against domains you have verified you own. For an open-source option, see our overview of the Nuclei scanner.
- Audit the code. Grep for string-built queries. A codebase auditor helps you find them at scale, but read the hits yourself.
``bash # Read-only: find SQL built with string concatenation or f-strings (Python example) grep -rnE "execute\(.*(\+|%|\.format|f\")" --include="*.py" . ``
Adjust the pattern for your language. Expect false positives and misses; this is a starting list, not a verdict.
- Test the API, not just the UI. Many injectable parameters exist only in JSON endpoints. See the API security testing guide.
- Probe manually where it counts. Login, search, filters, sorting and anything that accepts an ID. Add a single quote and compare responses against a baseline.
- Use a dedicated tool deliberately. sqlmap's usage documentation shows it accepts a target URL (
-u), a saved HTTP request (-r), POST data (--data) and cookies (--cookie), which lets it test authenticated flows. It sends many injected requests, so run it against a staging copy you own, never production data you cannot afford to disturb, and never a third party's site.
The web application penetration testing checklist shows where injection testing sits in a full test.
How to fix SQL injection
OWASP's cheat sheet is direct: define the SQL structure separately from its data values, then bind values through the database API. Parameterized queries are the primary defense. Escaping by hand is "strongly discouraged."
Vulnerable (Python, string concatenation):
# UNSAFE: user input becomes part of the SQL text
cur.execute("SELECT id, email FROM users WHERE email = '" + email + "'")
Fixed (parameterized):
# SAFE: the driver sends the value separately from the query
cur.execute("SELECT id, email FROM users WHERE email = %s", (email,))
Placeholder syntax varies by driver (%s, ?, $1, :name), but the principle is the same. For parts of a query that cannot be bound, such as sort order or table name, use an allow-list. Map the user's choice to fixed values in your code:
SORT_COLUMNS = {"price": "price", "name": "name"}
order_by = SORT_COLUMNS.get(request_sort, "name") # unknown input falls back to a default
query = f"SELECT id, name, price FROM products ORDER BY {order_by}"
Here the f-string is safe only because order_by can only be one of two constants you wrote.
Add these on top:
- Least privilege. OWASP says not to give application accounts DBA or admin access.
- Validation as a complement. OWASP states it does not replace parameter binding.
- Second-order cases. Parameterize every query, even when the value came from your own database.
- Retest with the same scan and manual probes after the patch.
Scanner, code review or pentest?
Scanners cover obvious parameters; second-order and business-logic paths need a human. On that gap, read automated vs manual penetration testing. For where scanning ends and testing begins, see vulnerability assessment vs penetration testing.
To run a scan against a domain you own, start a scan. If you need engineer-verified findings and a report your customers will accept, see the Startup Pentest, which covers only systems you own or are authorized to test.
Frequently asked questions
What is a SQL injection scanner?
It is a tool that sends crafted inputs to a web application's parameters and analyzes responses for signs that the input was executed as SQL. It looks for database errors, differences between true and false conditions, response delays and reflected UNION output. It automates the discovery step, not the judgment about impact.
Can a scanner find all SQL injection?
No. Scanners miss second-order injection, flows behind complex authentication, injection through user-chosen table or column names, and flaws inside stored procedures that build dynamic SQL. OWASP names source code review as the best detection method and recommends automated testing alongside it.
Is sqlmap a SQL injection scanner?
Sqlmap is an open-source tool that detects and exploits SQL injection from a target URL, a saved request file, POST data or cookies. Because it actively sends injected requests, treat it as a testing tool and use it only on systems you own or have written permission to test.
What is the best way to prevent SQL injection?
Use parameterized queries so data values are bound separately from the SQL structure. For table names, column names and sort order, which cannot be parameterized, map user choices to a fixed allow-list. Add least-privilege database accounts as a second layer.
How often should I scan for SQL injection?
Scan after changes to code that touches the database and on a regular schedule, since new endpoints introduce new inputs. Running a scan in your delivery pipeline catches regressions earlier than a yearly test.