Security operations

SQL Injection Types: In-Band, Blind, Out-of-Band and Second-Order

SQL injection is one flaw with several faces. Learn how each type returns data, what it looks like in practice, and the one fix that stops them all.

Cysoro Security TeamPublished · 7 min read
SELECT * FROM users WHERE name = ' ' OR '1'='1 -- ' Injected as code SECURITY OPERATIONS SQLinjection Every type, and the one fix.
Quick answer

SQL injection types differ by how the attacker gets data back: in-band injection returns data in the same web response, blind injection infers data from page changes or response times, out-of-band injection exfiltrates data over a separate channel such as DNS, and second-order injection stores a payload that fires later. All types share the same root cause — untrusted input treated as SQL code — and all are prevented by parameterized queries.

Key takeaways

  • SQL injection types differ by how data comes back, not by the root cause.
  • In-band injection is fast and direct; blind injection is slow but works when nothing is shown.
  • Parameterized queries stop every type; input validation and least privilege are second layers, not fixes.

SQL injection is one of the oldest web flaws, and it is still in the OWASP Top 10. The fix has been known for decades, yet the flaw keeps appearing — partly because it wears several different disguises.

What is SQL injection?

SQL injection is a flaw where an application builds a database query out of untrusted input, letting an attacker change what the query does. Input that should be treated as data is instead treated as part of the SQL command.

A classic example is a login form. The application might build a query like SELECT * FROM users WHERE username = 'admin' AND password = '...' by pasting the typed values into the string. If an attacker types ' OR '1'='1 into the username field, the query's logic changes and it can return rows it should never return.

The flaw maps to CWE-89, improper neutralization of special elements used in an SQL command. In the OWASP Top 10:2025, injection — the category that includes SQL injection — is ranked A05:2025. It was A03 in 2021 and A01 in 2017.

MITRE's CWE-89 definition describes the flaw in full technical detail.

How do SQL injection types differ?

SQL injection types differ by how the attacker gets the answer back, not by the root cause. The injection mechanism is the same in every case: untrusted input crosses into the query and is parsed as code.

OWASP's Web Security Testing Guide groups the flaw into three classes: in-band, inferential (blind) and out-of-band. Second-order injection is a fourth pattern that describes when the payload fires rather than how data returns.

TypeHow data comes backSpeedClassic signal
In-band, UNION-basedExtra rows in the application's own outputFastData from other tables appears on the page
In-band, error-basedInside a database error messageFastDatabase error text appears in the response
Blind, boolean-basedInferred from true or false page differencesSlowPage changes between true and false conditions
Blind, time-basedInferred from response timeSlowResponse is delayed only when a condition holds
Out-of-bandOver a separate channel such as DNS or HTTPVariesDatabase contacts an outside host
Second-orderLater, when stored input is reused in a queryDelayedPayload fires on a different page or action
How input becomes code User inputsearch box, login,URL parameter String concatenationinput pasted intothe SQL string Database runs itdata is parsedas SQL code The fix: parameterized queries — data can never be parsed as codeThe query structure is fixed first; values are bound separately.
How untrusted input becomes SQL code — and why parameterized queries stop it. Illustration by Cysoro.

What is in-band SQL injection?

In-band SQL injection is the most direct type: the attacker sends the payload and reads the result in the same HTTP response. It is the fastest type to exploit and the easiest to spot in logs.

UNION-based injection

UNION-based injection appends a second SELECT to the original query with the UNION operator, so rows from another table appear in the application's own output. A typical payload looks like ' UNION SELECT username, password FROM users--.

It works best when the application displays query results, such as a product list or a search page. The attacker first works out how many columns the original query returns, then crafts a UNION SELECT with matching columns.

Error-based injection

Error-based injection forces the database to print data inside an error message. Functions that fail on a crafted value can leak table names, column names or even data values in the error text.

This type depends on the application showing database errors to the user. Hiding errors does not fix the flaw — it just pushes the attacker toward blind techniques — but it does remove a useful source of information.

What is blind SQL injection?

Blind SQL injection, which OWASP calls inferential injection, happens when the application is vulnerable but shows neither query results nor database errors. The attacker reconstructs data by asking yes-or-no questions and watching the application's behavior.

Boolean-based blind injection

Boolean-based blind injection uses conditions that change the page. The attacker sends ' AND 1=1-- and then ' AND 1=2-- and compares the two responses: one is true, one is false, and the page differs.

By repeating that trick character by character — for example, asking whether the first character of a password is "a" — an attacker can extract data slowly. It is tedious by hand, which is why tools such as sqlmap automate it.

Time-based blind injection

Time-based blind injection works even when every page looks identical. The attacker adds a delay function, such as AND SLEEP(5), that only runs when a condition is true. If the response takes five seconds, the condition was true.

This type is the slowest of all, because each yes-or-no question costs seconds. It is also noisy in a different way: a flood of slow requests stands out in performance monitoring, even if no error ever appears.

What is out-of-band SQL injection?

Out-of-band SQL injection uses a different channel to get data out. Some database features can make DNS lookups or HTTP requests, and an attacker can abuse them to send query results to a server they control.

For example, a payload might trigger a DNS lookup for a hostname that contains the stolen data, such as a username embedded in a subdomain. The attacker watches their own DNS server and reads the data from the incoming requests.

This type needs the database to have network egress and the right features enabled, so it does not work everywhere. Where it does work, it bypasses an application that shows nothing at all, which is why outbound network controls on database servers matter.

What is second-order SQL injection?

Second-order SQL injection stores a payload on entry and executes it later, when a different query reuses the stored value. The injection happens at save time; the damage happens at read time.

A common example is a username or profile field. The value is stored safely, but a later admin page or report builds a query by concatenating that stored value. The payload then fires in a context the attacker never touched directly.

This type is easy to miss in testing, because the vulnerable request and the visible result are in different places. OWASP's prevention guidance applies whether data comes from an HTTP request, another service or previously stored data.

How do you detect SQL injection?

Detection starts with the signs each type leaves behind. In-band injection shows database errors or unexpected rows. Blind injection shows unusual patterns of true-or-false requests or slow responses. Out-of-band injection shows unexpected outbound DNS or HTTP traffic from the database server.

For defenders, the practical checks are code review, automated scanning and logging. Review every place a query is built, especially raw queries and dynamic sorting. Run a scanner such as OWASP ZAP against staging, and confirm findings by hand.

Log database errors, slow queries and repeated failed requests from one source. A single error is noise; a burst of crafted requests with SQL keywords from one IP address is a probe. Alert on the pattern, not the single event.

Which type is it? A quick comparison Data appears on the page?In-band — UNION or error-based Page changes, but no data?Blind boolean-based Only the timing changes?Blind time-based Database calls out to the internet?Out-of-band Nothing happens now, but it fires later on another page?Second-order — the payload was stored, then reused in a query All five share one root cause and one primary fix.
How to tell SQL injection types apart by what the attacker can see. Illustration by Cysoro.

How do you prevent SQL injection?

Use parameterized queries, also called prepared statements, for every database query. OWASP puts it plainly: the use of prepared statements with variable binding is how all developers should first be taught to write database queries.

Parameterization works because the query structure is sent to the database first, and the values are bound separately. A value can never change the SQL syntax, whatever characters it contains. That stops every type in this article, because every type depends on input becoming code.

Add second layers, but do not mistake them for the fix. Validate input against an allowlist where you can, use least-privilege database accounts so a compromised query cannot drop tables, and hide database errors from users. A web application firewall can block known payloads, but attackers bypass filters with encoding and alternative syntax.

If you use an ORM, use its parameterized methods and avoid raw queries built by string concatenation. Check dynamic sorting, filtering and search features in particular, because those are the places raw SQL most often creeps back in.

For a wider view of protecting a web application, our small business cybersecurity checklist covers patching, backups and access control alongside application security.

OWASP's SQL Injection Prevention Cheat Sheet is the authoritative guide to parameterized queries.

You can also check your site's TLS setup with the free SSL checker as part of a basic site review.

Why does SQL injection still matter?

SQL injection still matters because it gives an attacker direct access to the data behind an application: user accounts, passwords, payment records and internal data. A single injectable search box can become a full database dump.

The flaw also keeps appearing in new code. Legacy systems, rushed features and AI-generated code that concatenates strings all recreate the same bug. The OWASP Top 10:2025 notes more than 14,000 CVEs in the injection category, which shows how widespread the underlying pattern remains.

Practice only in a lab. Testing these techniques against systems without explicit permission is illegal in most jurisdictions, so use a deliberately vulnerable application such as OWASP Juice Shop or DVWA on your own machine.

The bottom line

SQL injection types differ only in how data comes back. In-band is fast, blind is slow and patient, out-of-band uses a side channel, and second-order waits for a later query.

The fix is the same for all of them: parameterize every query, validate input as a second layer, and give the database account the least privilege it needs. Check your site's basic security posture with the free security headers checker while you review your queries.

Frequently asked questions

What is SQL injection in simple terms?

SQL injection is a flaw where an application builds a database query out of user input, so an attacker can change what the query does. Instead of a search term being treated as data, it is treated as part of the SQL command.

How many types of SQL injection are there?

OWASP groups SQL injection into three classes by how data returns: in-band, inferential or blind, and out-of-band. Second-order injection is a fourth pattern that describes when a stored payload fires rather than how data returns.

What is the most common type of SQL injection?

In-band injection, especially UNION-based injection, is the most common in practice because it is fast and returns data directly in the page. Blind injection is common where applications hide errors and results.

Is SQL injection still a problem in 2026?

Yes. Injection, the category that includes SQL injection, is ranked A05 in the OWASP Top 10:2025, and OWASP notes more than 14,000 CVEs in that category. Old code, legacy systems and rushed features keep the flaw alive.

Can a web application firewall stop SQL injection?

A web application firewall can block many known payloads, but it is a filter, not a fix. Attackers bypass filters with encoding and alternative syntax, so a WAF should sit behind parameterized queries, not replace them.

Does using an ORM prevent SQL injection?

An ORM helps when you use its parameterized methods, but it does not guarantee safety. Raw queries, string concatenation inside an ORM, and unsafe sorting or filtering options can still be injectable.

What is the difference between blind and out-of-band SQL injection?

Blind injection infers data from the application's behavior, such as a page change or a delay, without seeing the data directly. Out-of-band injection makes the database send the data out over a separate channel, such as a DNS lookup, to a server the attacker controls.

How do you test for SQL injection safely?

Test only on systems you own or have written permission to test, such as a staging environment or a deliberately vulnerable lab like OWASP Juice Shop. Use a scanner such as OWASP ZAP or sqlmap against staging, and confirm findings by hand before reporting them.

Sources

  1. OWASP — Web Security Testing Guide: Testing for SQL Injection
  2. OWASP — SQL Injection Prevention Cheat Sheet
  3. OWASP Top 10:2025 — A05 Injection
  4. MITRE CWE-89 — Improper Neutralization of Special Elements used in an SQL Command
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the OWASP Web Security Testing Guide, the OWASP SQL Injection Prevention Cheat Sheet and MITRE CWE-89.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free