Turning Blind Error Based SQL Injection into Exploitable Boolean One
A parameter was vulnerable to blind error-based SQL injection on a Microsoft SQL Server back end, but the application only returned generic error or access-denied pages. By using a conditional conversion trick, the attacker turned the blind error into a boolean oracle and extracted the database name character by character.
While I was recently hunting on a promising host target, from my well configured (only checking SQLi) active scan results, I found out a parameter could be vulnerable to SQL injection, within the payloads:
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
The target was a host the author describes only as a promising one, reached during a bug bounty hunt. The application ran on IIS and used .aspx extensions, and the vulnerable parameter was called name. The report does not name the program or the host, and does not describe what the name parameter normally does beyond the fact that it is passed into a back-end SQL query.
Because of the IIS and ASP.NET stack, the author reasoned that the back-end database management system was likely Microsoft SQL Server, since companies using those technologies commonly use MSSQL as well. He is explicit that this is not a necessity but a common behaviour.
Setup
The work was done with a well configured active scanner restricted to checking for SQL injection only, plus manual testing in Burp Intruder and attempts with sqlmap. The author also went back to his own previously accepted MSSQL injection reports to collect payloads. No account, role or credential details are given.
Two constraints shaped the whole exercise:
- The application did not return verbose database errors. A broken query produced a redirect to
/Error.aspx, and a query that ran but was rejected by application logic produced a redirect to/AccessDenied.aspx. - The
nameparameter had a limit of 100 characters, which broke longer queries.
Finding it
The active scan flagged the name parameter. The first payloads showed a clear difference between an odd and an even number of single quotes:
name=' -> Redirecting to /Error.aspx page
name='' -> Redirecting to /AccessDenied.aspx page
Manual confirmation followed the same pattern:
name=''' -> Redirecting to /Error.aspx page
name='''' -> Redirecting to /AccessDenied.aspx page
name=''''' -> Redirecting to /Error.aspx page
name='''''' -> Redirecting to /AccessDenied.aspx page
A singular count of single quotes broke the SQL query on the back end, a plural count did not. That is the classic signature of string concatenation into a query.
However, sqlmap and manual fuzzing with the Burp Intruder Fuzzing - SQL injection payload list sent every payload to Error.aspx. Simple payloads such as ' AND '1'='1 or ';WAITFOR DELAY '0:0:5'-- all broke the query. The injection looked either not exploitable or hard to exploit.
Since single quotes produced errors and doubling them fixed the error, the author considered error based SQL injection: if error messages were displayed, the parameter would be error based. They were not displayed verbosely, so the question became whether this was a blind error based SQL injection.
Exploitation
Step 1: confirm that a query runs and its result can be observed
The MSSQL payload '+convert(int,db_name())+' returns db_name as an error when a parameter is vulnerable to error based SQLi on MSSQL: the database name is a string, converting it to an integer fails, and the request errors while leaking the name. The author tried it together with a char variant:
'+convert(int,db_name())+' -> Redirecting to /Error.aspx page
'+convert(char,db_name())+' -> Redirecting to /AccessDenied.aspx page
The int version errored, but the char version reached AccessDenied.aspx. That redirect was the useful signal: it confirmed the injected query was running successfully, even though no data was returned to the attacker.
Step 2: work around the missing output channel
Out-of-band techniques did not work, probably because internet access from the web server is limited. The 100 character limit on the parameter also ruled out long queries. The author needed to turn the query into a boolean or time based one.
Step 3: build a boolean oracle with IIF and convert
MSSQL has an IIF function, usable as SELECT IIF(1>2,"YES","NO"): if the first statement is true it returns the first value, otherwise the second. The idea was to place IIF inside convert so that the success or failure of the conversion encodes a boolean answer. After some experimentation with data type conversion, the payload was:
'+convert(char,(SELECT IIF(SUBSTRING(DB_NAME(),1,1)='A',3,@@VERSION)))+' -> Redirecting to /AccessDenied.aspx
It works as follows:
- Take a substring of the database name starting at the first character, one character long, and compare it with
'A'. - If the character equals
'A', return3as an integer. - Converting
3tocharsucceeds and the request returns without error, meaning the condition is true. - If the character does not equal
'A', return@@VERSION. - Converting the
@@VERSIONresult tocharfails and the request goes toError.aspx, meaning the condition is false.

The screenshot shows the @@VERSION branch failing: converting the version result to char is not successful and returns the Error.aspx page, so the tested condition was false.
Step 4: automate the extraction in Burp Intruder
The payload was run in Burp Intruder with the Cluster Bomb attack type. Payload set #1 held numbers covering the length of DB_NAME:

Payload set #2 held characters from A to Z, digits 0 to 9, and some special characters such as _:

The location header was used as the grep match, so that a redirect to AccessDenied.aspx marked a true condition and a redirect to Error.aspx marked a false one:

This recovered the current database name:

Step 5: reuse the oracle for other data
The author lists additional payloads for further manual data dump on MSSQL. The main query for blind error based injection is:
'%2bconvert(char,(SELECT IIF(SUBSTRING((***query_here***),1,1)='d',3,@@VERSION)))%2b
Queries to place inside the main query:
-> select db_name() <- Returns current database name
-> select host_name() <- Returns hostname
-> select top 1 table_name from INFORMATION_SCHEMA.tables <- Returns the first table from Information Schema
-> select top 1 column_name from INFORMATION_SCHEMA.columns <- Returns the first column from Information Schema
-> select ***column_name*** from ***table_name*** ORDER BY ***column_name*** OFFSET 2 ROW FETCH FIRST 1 ROW ONLY <- Returns the data of the second row from selected column/table.
Root cause
A single quote breaks the SQL query on the back end and a doubled quote does not, the signature of string concatenation into a query. A broken query produced a redirect to Error.aspx, and a query that ran produced a redirect to AccessDenied.aspx. Neither page shows the database error text, so the injection is blind with respect to error messages.
The oracle exists because the two branches of IIF behave differently: an integer converts to char cleanly, while converting the @@VERSION result to char fails. The application's own error handling then turns a type conversion failure into an observable difference in the redirect target.
Impact
Under the conditions of this target, the redirect target can serve as a boolean answer, and the author recovered the current database name one character at a time. The author demonstrates recovery of the current database name and provides queries for the host name, table names, column names and row data. The 100 character parameter limit constrains how much can be asked in a single request, and out-of-band channels were not available, so extraction is slow and request-heavy. The report does not state which data was ultimately retrieved beyond the database name, nor the bounty amount.
The author notes that some programs restrict or forbid data gathering on SQL injection vulnerabilities, while Synack encourages it for full payouts. Whether data gathering was permitted on this specific target is not stated.
Fix
The measure that removes the vulnerability class is to stop concatenating the parameter into SQL and use parameterised queries or stored procedures with typed parameters, so that quotes in the input cannot change the statement structure. Hiding error pages is not a fix on its own: as this case shows, the difference between two error paths is still an oracle.
Variants to test
- Odd/even quote counting. Send one, two, three and four quotes in a parameter and compare responses. A positive result is a consistent split between error and non-error responses that follows the parity.
- Type conversion oracle on MSSQL. Try
'+convert(int,db_name())+'and'+convert(char,db_name())+'. A positive result is one variant erroring and the other returning normally, which confirms the query executes. IIFboolean oracle. Use'+convert(char,(SELECT IIF(SUBSTRING(DB_NAME(),1,1)='A',3,@@VERSION)))+'and vary the compared character. A positive result is a stable difference between the true branch and the@@VERSIONbranch, visible in status code, redirect target or response length.- Redirect target as the signal. Where errors are hidden, grep the
Locationheader in Burp Intruder across a Cluster Bomb of positions and characters. A positive result is a clean separation of the two redirect destinations per guessed character. - Other metadata queries through the same oracle. Substitute
host_name(),top 1 table_name from INFORMATION_SCHEMA.tablesortop 1 column_name from INFORMATION_SCHEMA.columnsinto theSUBSTRINGexpression. A positive result is a recoverable string that matches the expected metadata format. - Row extraction with
OFFSET ... FETCH. UseORDER BY ... OFFSET 2 ROW FETCH FIRST 1 ROW ONLYinside the oracle to walk rows. A positive result is successive values recovered from the same column. - Length limits. Where a parameter caps input length, shorten the payload with URL-encoded
%2band minimal subqueries, and check whether the shortened form still reaches the true branch.
What happened, in plain words
A security researcher was hunting for bugs on a website as part of a bug bounty programme. A bug bounty is an arrangement where companies pay people to find security problems in their systems and report them privately instead of exploiting them. The researcher found a parameter whose value ended up inside a database query on the server, which is a serious mistake. The site tried to hide its error messages, so at first the problem looked useless: every malicious input just sent the browser to an error page. By being patient and creative, the researcher turned that hidden error into a yes/no signal, and then used that signal to read the name of the database one character at a time. This article walks through the whole story from zero, explaining every term as it appears.
The target and why it looked like Microsoft SQL Server
The report does not name the programme or the host. It only says the target was a promising host found during a hunt. The application ran on IIS, which is Microsoft's web server software, the program that sits on a computer and answers requests from browsers. The pages ended in .aspx, which is the file extension used by ASP.NET, Microsoft's framework for building web pages. The vulnerable parameter was called name. A parameter is a named value sent with a request, for example the part after the ? in a web address. The report does not say what the name parameter normally does, only that its value ends up inside a database query on the server.
Because the site used IIS and .aspx, the researcher reasoned that the database behind it was probably Microsoft SQL Server, often shortened to MSSQL. A database is an organised store of information, and a database management system (DBMS) is the software that runs it and answers queries. The researcher is careful to say this is not a necessity but a common behaviour: companies that pick Microsoft web technology often pick Microsoft's database too. This guess mattered because different databases speak slightly different query languages, and the tricks that work on one may not work on another.
The tools used
The work was done with three things:
- An active scanner, a tool that automatically sends many test inputs to a website and flags anything suspicious. The researcher had configured it to check only for SQL injection, so it would not waste time on other bug classes.
- Burp Intruder, a feature of the Burp Suite testing tool that takes a request and automatically repeats it many times, swapping in different values at marked positions. Think of it as a machine that fills in a form thousands of times with different answers and records what comes back.
sqlmap, a well-known free tool that automates SQL injection testing.
The researcher also went back to his own previously accepted MSSQL injection reports to collect payloads. A payload is the piece of text an attacker sends to try to trigger a bug. No account, role or credential details are given in the report.
Two constraints shaped the whole exercise:
- The application did not return verbose database errors. A broken query produced a redirect to
/Error.aspx, and a query that ran but was rejected by the application's own logic produced a redirect to/AccessDenied.aspx. A redirect is when the server answers a request by telling the browser to go to a different page instead. So the only visible difference between "the database choked" and "the database answered but the app said no" was which of two pages the browser landed on. - The
nameparameter had a limit of 100 characters, which broke longer queries. A query is the instruction sent to the database, and long instructions simply would not fit.
Finding it: the odd and even quote trick
The active scan flagged the name parameter. The first payloads showed a clear difference between an odd and an even number of single quotes:
name=' -> Redirecting to /Error.aspx page
name='' -> Redirecting to /AccessDenied.aspx page
Line by line: the first line sends a single quote as the value of name, and the server redirects to the error page. The second line sends two single quotes, and the server redirects to the access denied page. A single quote is the character ', and in SQL it is used to mark the beginning and end of a piece of text. If the application builds a query by gluing text together, an extra quote closes the text early and leaves the rest of the query malformed, so the database complains. Two quotes, by contrast, are the standard way of writing one literal quote inside a string, so the query stays intact.
Manual confirmation followed the same pattern:
name=''' -> Redirecting to /Error.aspx page
name='''' -> Redirecting to /AccessDenied.aspx page
name=''''' -> Redirecting to /Error.aspx page
name='''''' -> Redirecting to /AccessDenied.aspx page
Line by line: three quotes produce an error, four quotes do not, five quotes produce an error, six quotes do not. A singular count of single quotes broke the SQL query on the back end, a plural count did not. That is the classic signature of string concatenation into a query. Concatenation means joining pieces of text end to end, like taping words together to form a sentence. If the sentence is built by taping the user's input into the middle of a fixed instruction, the user can change the grammar of the instruction.
However, sqlmap and manual fuzzing with the Burp Intruder Fuzzing - SQL injection payload list sent every payload to Error.aspx. Fuzzing means throwing lots of varied inputs at a target and watching for differences. Simple payloads such as ' AND '1'='1 or ';WAITFOR DELAY '0:0:5'-- all broke the query. The first tries to make the condition always true; the second asks the database to pause for five seconds, which would reveal the bug through a delay. Neither worked. The injection looked either not exploitable or hard to exploit.
Since single quotes produced errors and doubling them fixed the error, the researcher considered error based SQL injection. Error based SQL injection is a variant where the attacker deliberately causes the database to produce an error message that contains data, so the error itself becomes the leak. If error messages were displayed, the parameter would be error based. They were not displayed verbosely, so the question became whether this was a blind error based SQL injection. Blind means the attacker cannot see the database's answer directly and has to infer it from side effects, such as which page loads or how long the response takes.
Exploitation
Step 1: confirm that a query runs and its result can be observed
The MSSQL payload '+convert(int,db_name())+' returns db_name as an error when a parameter is vulnerable to error based SQLi on MSSQL. Here is why: db_name() is a built-in function that returns the name of the current database, which is text. convert(int, ...) asks the database to turn that text into a whole number. Turning a word like shop into a number is impossible, so the conversion fails and the request errors, and in a normal error based bug the database name would appear inside the error message. The researcher tried it together with a char variant:
'+convert(int,db_name())+' -> Redirecting to /Error.aspx page
'+convert(char,db_name())+' -> Redirecting to /AccessDenied.aspx page
Line by line: the first line wraps the database name in a conversion to an integer, and the server redirects to the error page. The second line wraps it in a conversion to char, which means a text character, and the server redirects to the access denied page. The int version errored, but the char version reached AccessDenied.aspx. That redirect was the useful signal: it confirmed the injected query was running successfully, even though no data was returned to the attacker. In other words, the researcher had found a way to ask the database a question and tell, from the redirect alone, whether the question had been answered.
Step 2: work around the missing output channel
Out-of-band techniques did not work, probably because internet access from the web server is limited. Out-of-band means getting data out through a separate channel, for example by making the server contact an external machine the attacker controls. If the server cannot reach the internet, that channel is closed. The 100 character limit on the parameter also ruled out long queries. The researcher needed to turn the query into a boolean or time based one. Boolean means yes/no: the attacker asks a question whose answer is true or false and learns one bit of information per request. Time based means the attacker learns the answer from how long the server takes to respond.
Step 3: build a boolean oracle with IIF and convert
MSSQL has an IIF function, usable as SELECT IIF(1>2,"YES","NO"). IIF takes three things: a condition, a value to return if the condition is true, and a value to return if it is false. The idea was to place IIF inside convert so that the success or failure of the conversion encodes a boolean answer. An oracle, in security jargon, is any observable behaviour that reliably answers a yes/no question about hidden data. After some experimentation with data type conversion, the payload was:
'+convert(char,(SELECT IIF(SUBSTRING(DB_NAME(),1,1)='A',3,@@VERSION)))+' -> Redirecting to /AccessDenied.aspx
It works as follows:
- Take a substring of the database name starting at the first character, one character long, and compare it with
'A'.SUBSTRINGis a function that cuts out part of a piece of text; here it takes one character starting at position 1. - If the character equals
'A', return3as an integer. - Converting
3tocharsucceeds and the request returns without error, meaning the condition is true. - If the character does not equal
'A', return@@VERSION.@@VERSIONis a built-in MSSQL value that reports the version and build details of the database server, and it is a long piece of text. - Converting the
@@VERSIONresult tocharfails and the request goes toError.aspx, meaning the condition is false.
So the payload is a machine that answers one question: is the first character of the database name equal to A? If yes, the browser lands on the access denied page. If no, it lands on the error page. The researcher can read the answer from the redirect target alone, without ever seeing a database error message.

The screenshot shows the @@VERSION branch failing: converting the version result to char is not successful and returns the Error.aspx page, so the tested condition was false.
Step 4: automate the extraction in Burp Intruder
The payload was run in Burp Intruder with the Cluster Bomb attack type. Cluster Bomb is an attack mode where Burp takes several lists of values and tries every combination of them, like a lock with several dials where every dial position is tested against every other. Payload set #1 held numbers covering the length of DB_NAME:

Payload set #2 held characters from A to Z, digits 0 to 9, and some special characters such as _:

The location header was used as the grep match, so that a redirect to AccessDenied.aspx marked a true condition and a redirect to Error.aspx marked a false one. A header is a small piece of metadata sent alongside a web response; the Location header is the one that tells the browser where to go when a redirect happens. Grep here means telling Burp to search each response for a particular string and flag the ones that contain it, so the researcher could sort thousands of responses by which page they pointed to.

This recovered the current database name:

Step 5: reuse the oracle for other data
The researcher lists additional payloads for further manual data dump on MSSQL. The main query for blind error based injection is:
'%2bconvert(char,(SELECT IIF(SUBSTRING((***query_here***),1,1)='d',3,@@VERSION)))%2b
Line by line: %2b is the URL-encoded form of the plus sign +, and in a web address the plus sign has a special meaning, so it has to be encoded. The plus sign is used here to join pieces of text together. ***query_here*** is a placeholder where the researcher drops in whichever query he wants to test. The rest is the same IIF and convert trick as before, comparing the first character of the inner query's result with d.
Queries to place inside the main query:
-> select db_name() <- Returns current database name
-> select host_name() <- Returns hostname
-> select top 1 table_name from INFORMATION_SCHEMA.tables <- Returns the first table from Information Schema
-> select top 1 column_name from INFORMATION_SCHEMA.columns <- Returns the first column from Information Schema
-> select ***column_name*** from ***table_name*** ORDER BY ***column_name*** OFFSET 2 ROW FETCH FIRST 1 ROW ONLY <- Returns the data of the second row from selected column/table.
Line by line: select db_name() asks for the current database name. select host_name() asks for the name of the machine the database runs on. INFORMATION_SCHEMA is a built-in catalogue that lists the tables and columns in a database, like a library's index cards; top 1 means return only the first result. The last line uses ORDER BY to sort rows, OFFSET 2 ROW to skip the first two rows, and FETCH FIRST 1 ROW ONLY to return just the next one, which is a way of walking through a table row by row.
Root cause
A single quote breaks the SQL query on the back end and a doubled quote does not, the signature of string concatenation into a query. Parameterisation means passing user input to the database as a separate, typed value rather than gluing it into the query text, so the input can never change the query's grammar. A broken query produced a redirect to Error.aspx, and a query that ran produced a redirect to AccessDenied.aspx. Neither page shows the database error text, so the injection is blind with respect to error messages.
The oracle exists because the two branches of IIF behave differently: an integer converts to char cleanly, while converting the @@VERSION result to char fails. The application's own error handling then turns a type conversion failure into an observable difference in the redirect target. Hiding the error message was like covering the smoke alarm but leaving the fire door open: the evidence still showed.
Impact
Under the conditions of this target, the redirect target can serve as a boolean answer, and the author recovered the current database name one character at a time. The researcher demonstrates recovery of the current database name and provides queries for the host name, table names, column names and row data. The 100 character parameter limit constrains how much can be asked in a single request, and out-of-band channels were not available, so extraction is slow and request-heavy.
The researcher notes that some programmes restrict or forbid data gathering on SQL injection vulnerabilities, while Synack encourages it for full payouts. Whether data gathering was permitted on this specific target is not stated.
Fix
The measure that removes the vulnerability class is to stop concatenating the parameter into SQL and use parameterised queries or stored procedures with typed parameters, so that quotes in the input cannot change the statement structure. Hiding error pages is not a fix on its own: as this case shows, the difference between two error paths is still an oracle.
Variants to test
- Odd/even quote counting. Send one, two, three and four quotes in a parameter and compare responses. A positive result is a consistent split between error and non-error responses that follows the parity.
- Type conversion oracle on MSSQL. Try
'+convert(int,db_name())+'and'+convert(char,db_name())+'. A positive result is one variant erroring and the other returning normally, which confirms the query executes. IIFboolean oracle. Use'+convert(char,(SELECT IIF(SUBSTRING(DB_NAME(),1,1)='A',3,@@VERSION)))+'and vary the compared character. A positive result is a stable difference between the true branch and the@@VERSIONbranch, visible in status code, redirect target or response length.- Redirect target as the signal. Where errors are hidden, grep the
Locationheader in Burp Intruder across a Cluster Bomb of positions and characters. A positive result is a clean separation of the two redirect destinations per guessed character. - Other metadata queries through the same oracle. Substitute
host_name(),top 1 table_name from INFORMATION_SCHEMA.tablesortop 1 column_name from INFORMATION_SCHEMA.columnsinto theSUBSTRINGexpression. A positive result is a recoverable string that matches the expected metadata format. - Row extraction with
OFFSET ... FETCH. UseORDER BY ... OFFSET 2 ROW FETCH FIRST 1 ROW ONLYinside the oracle to walk rows. A positive result is successive values recovered from the same column. - Length limits. Where a parameter caps input length, shorten the payload with URL-encoded
%2band minimal subqueries, and check whether the shortened form still reaches the true branch.
Glossary
- Active scanner: a tool that automatically sends many test inputs to a website and flags suspicious responses.
- ASP.NET: Microsoft's framework for building web applications, usually served with
.aspxpages. - Blind SQL injection: SQL injection where the attacker cannot see the database's answer directly and must infer it from side effects such as redirects or delays.
- Boolean: a value that is either true or false; a boolean oracle answers one yes/no question per request.
- Bug bounty: a programme where companies pay people to find and privately report security problems.
- Burp Intruder: a Burp Suite feature that repeats a request many times with different values in marked positions.
- Cluster Bomb: a Burp Intruder attack type that tries every combination of values from several payload lists.
- Concatenation: joining pieces of text end to end; unsafe concatenation of user input into a query causes injection.
- Database: an organised store of information managed by a database management system (DBMS).
- DBMS: database management system, the software that runs a database and answers queries.
- Error based SQL injection: a variant where the attacker causes a database error whose message contains data.
- Fuzzing: sending lots of varied inputs to a target and watching for differences in the responses.
- Grep (in Burp): telling Burp to search each response for a particular string and flag matches.
- Header: a small piece of metadata sent alongside a web request or response; the
Locationheader carries a redirect target. - IIS: Microsoft's web server software.
IIF: an MSSQL function that returns one value if a condition is true and another if it is false.INFORMATION_SCHEMA: a built-in catalogue listing the tables and columns in a database.- MSSQL: Microsoft SQL Server, Microsoft's database management system.
- Oracle (in security): any observable behaviour that reliably answers a yes/no question about hidden data.
- Out-of-band: getting data out through a separate channel, such as making the server contact an external machine.
- Parameter: a named value sent with a web request, for example after the
?in a URL. - Parameterisation: passing user input to a database as a separate typed value rather than gluing it into the query text.
- Payload: the piece of text an attacker sends to try to trigger a bug.
- Query: the instruction sent to a database.
- Redirect: a server response that tells the browser to go to a different page.
- SQL: the language used to talk to relational databases.
- SQL injection: a bug where user input changes the structure of a database query.
sqlmap: a free tool that automates SQL injection testing.SUBSTRING: a function that cuts out part of a piece of text.- Time based SQL injection: a blind variant where the attacker learns the answer from how long the server takes to respond.
- URL encoding: replacing characters that have special meaning in a URL with a
%code, such as%2bfor+. @@VERSION: a built-in MSSQL value reporting the database server's version and build details.