How Blind SQL Injection Works: Boolean and Time-Based Explained
Blind SQL injection is SQL injection where the application never shows database output or error messages, so an attacker cannot read data directly. Instead, they ask the database yes-or-no questions through a vulnerable input and infer the answer from how the application behaves. In boolean-based blind injection, the clue is a page that looks different for true and false conditions.
Topic: Web & API Security in Cybersecurity & Ethical Hacking · Explainer
Also covers: Ethical Hacking
Quick answer: Blind SQL injection is SQL injection where the application never shows database output or error messages, so an attacker cannot read data directly. Instead, they ask the database yes-or-no questions through a vulnerable input and infer the answer from how the application behaves. In boolean-based blind injection, the clue is a page that looks different for true and false conditions. In time-based blind injection, the clue is a response delay the attacker makes the database add when a condition is true. Data leaks one bit at a time, slowly but completely. Parameterised queries stop it, as they stop all SQL injection (CWE-89).
Key takeaways
- Blind does not mean safe: data can still be extracted.
- Boolean-based uses page differences; time-based uses delays.
- Hiding errors does not fix the flaw.
- Parameterised queries are the primary defence.
- High request volume and consistent latency spikes are detection clues.
Table of Contents
- What Makes SQL Injection Blind?
- How Do Boolean-Based and Time-Based Blind Injection Differ?
- What Does a Time-Based Scenario Look Like?
- How Can Defenders Detect Blind SQL Injection?
- What Do Vulnerable and Safe Queries Look Like?
- Which Extra Defences Reduce the Damage?
- How Should Teams Test for It Safely?
- References
What Makes SQL Injection Blind?
In classic SQL injection, query results or database errors appear on the page. Many apps hide errors and show only generic content, so developers assume they are protected. The OWASP blind SQL injection page explains that the root flaw remains: user input is concatenated into SQL. The attacker just needs another signal. MITRE lists the pattern as CAPEC-7 under weakness CWE-89.
How Do Boolean-Based and Time-Based Blind Injection Differ?
| Aspect | Boolean-based | Time-based |
|---|---|---|
| Signal | Page content, status code or length changes | Response time changes |
| Needs visible difference | Yes | No |
| Speed | Faster | Slower; each question waits |
| Noise in logs | Many similar requests | Many requests with long durations |
| Fix | Parameterised queries | Parameterised queries |
A related out-of-band variant makes the database contact an external server, which egress filtering on database hosts prevents.
What Does a Time-Based Scenario Look Like?
Imagine an online shop with a product page that reads an ID from the URL and builds SQL by string concatenation. Errors are hidden and every response looks identical. An attacker appends a condition that tells the database to pause only if a statement is true, for example whether the first letter of the admin user name comes after M in the alphabet. If the page takes several seconds longer, the answer is yes. Repeating such questions, a script narrows down each character, then each value, until table names, password hashes or customer emails are recovered. No error message was ever shown. We deliberately do not show the strings involved.
How Can Defenders Detect Blind SQL Injection?
- Bursts of hundreds of near-identical requests to one parameter from one source.
- Response times that cluster at a fixed extra delay.
- Database slow-query logs showing unusual sleep or wait functions.
- WAF alerts on SQL keywords in parameters.
# Nginx: log request time, then list slowest requests by URL
# log_format timed '$remote_addr $request $status $request_time';
awk '{print $NF, $2}' /var/log/nginx/access_timed.log | sort -rn | head -20
Turning on the MySQL slow query log or PostgreSQL log_min_duration_statement helps correlate.
What Do Vulnerable and Safe Queries Look Like?
The OWASP SQL Injection Prevention Cheat Sheet lists parameterised queries as the first defence.
# UNSAFE (Python): input becomes part of the SQL text
cur.execute('SELECT name, price FROM products WHERE id = ' + product_id)
# SAFE: input is sent separately as a bound parameter
cur.execute('SELECT name, price FROM products WHERE id = %s', (product_id,))
// SAFE (PHP PDO prepared statement)
$stmt = $pdo->prepare('SELECT name, price FROM products WHERE id = ?');
$stmt->execute([$productId]);
With binding, the database treats the value as data only, so no condition can be added. See the Query Parameterization Cheat Sheet for other languages.
Which Extra Defences Reduce the Damage?
| Control | Effect |
|---|---|
| Least-privilege database account | Limits which tables can be read |
| Query timeouts (for example MySQL max_execution_time) | Caps delays and resource use |
| Allow-list validation of IDs | Rejects non-numeric input early |
| WAF and rate limiting | Slows automated inference |
| No egress from database servers | Blocks out-of-band variants |
CISA and the FBI's March 2024 Secure by Design alert urges vendors to eliminate SQL injection through parameterised queries.
How Should Teams Test for It Safely?
Follow OWASP WSTG-INPV-05 on your own staging systems, combine static analysis with code review, and test only with written authorisation; unauthorised testing breaches Sections 43 and 66 of the IT Act 2000. Start with our SQL injection basics and the FortiWeb SQL injection patch guide. WebAsha offers web application security training.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0