Why Blind SQL Injection?

Blind SQL Injection is used when a web application is vulnerable to an SQL injection, but the results of the injection are not visible to the attacker. The page with the vulnerability may not be one that displays data but will display differently depending on the results of a logical statement injected into the legitimate SQL statement called for that page. This type of attack can become time-intensive because a new statement must be crafted for each bit recovered.

How Blind SQL Injection can be used?

There are several uses for the Blind SQL Injection:

  • Testing the vulnerability;
  • Finding the table name;
  • Exporting a value;

Every techniques are based on the ‘guess attack’, because we only have two different input:

TRUE or FALSE. Let me explain better…

Testing vulnerability (MySQL – MSSQL):

Let’s star with an easy example. We have this type of URL:

it will result in this type of query on the database:

Now, we can try some SQL Injection techniques, for example the Blind SQL injection!

SQL query is now:

In this case the query will not return anything (FALSE) because 1 is different from 0; Let’s do the litmus test: try to get the TRUE statement forcing the AND to be TRUE;

In this case 0 is equal to 0… Got it! We should now see the original news page. We now know that is vulnerable to Blind Sql Injection.

Time attack (MySQL)

When you can’t see any kind of results, you must use the time attack. In this example we will try to obtain the password of root user in MySQL (if your have root privileges on MySQL). BENCHMARK function is used to sleep for some seconds.

Syntax: BENCHMARK (how many times,thing to do). When you use it in IF statement, you will be able to make time attack in MySQL;

And so on until you will see the BENCHMARK running (few more seconds delay). Now proceed with the 2nd word of the password…

Time attack (MSSQL)

In this example we will try to obtain the username of the sysusers table. A simple way to generate time delays is to take advantage of one of the biggest database problems, that have made necessary the development of performance-tuning techniques; heavy queries. All you need to generate a time delay is to access a table that has some registers and to build a good query to force the engine to work. In other words, we need to build a query ignoring what the performance best practices recommend. (This technique was made by Chema Alonso, Microsoft Security MVP)

Positive result. The condition is true, and the response has a delay of 14 seconds. We actually know that the ASCII value of the first username’s letter in the sysusers table is lower than 300.

Negative Result. One-second response delay. We actually know than the ASCII value of the first username’s letter in the sysusers table is higher than 0.

And so on for all the possibilities:

Then the result is ASCII(119)=’w‘.

Start with the second letter… and so on!

Regexp attack’s methodology

This is our own creation and it is the faster to extract information from a database. With this you can save a lot of time and bandwidth! The methodology is pretty simple: we define a range of numbers/chars/spacial chars that will be matched with REGEXP (MySQL) or LIKE (MSSQL) functions.

Let’s start with an example because is more simple to understand.

Finding table name with Regexp attack (MySQL)

In this example we will extract the first matched record of information_schema.tables, you must know the name of database!

We tested the blind sql injection attack, and if we see the correct page, everything is ok.

In this case we know that the first matched record start with a char between [a -> z] That example will show you how to extract the complete name of the record:

The first letter of the table is ‘n’. But are there other tables start with ‘n’?

Let’s change the limit to 1,1:

No, there are no more tables that start with ‘n’. From now on we must change the regular expression like this:

‘^n[a-z]’ -> ‘^ne[a-z]’ -> ‘^new[a-z]’ -> ‘^news[a-z]’ -> FALSE

To test if we found the correct table name, we must test something like this:


Finding table name with Regexp attack (MSSQL)

For MSSQL, the syntax is a little bit more complicated. There are two limitations: LIMIT and REGEXP are not present.

To bypass it, we must use TOP and LIKE functions. See that example:

SELECT TOP is used to extract the first x record from information_schema table. In MSSQL, LIKE function is similar to REGEXP function in MySQL, but the syntax is not equal.

For learn more about LIKE functions consult http://msdn.microsoft.com/enus/library/ms179859.aspx

When you need to grab the second table_name, you must use “table_name NOT IN ( SELECT TOP x table_name FROM information_schema.tables)” like in the example below:

The second SELECT TOP is used to exclude X row and extract the X+1.
Like in the MySQL example, we show how to modify LIKE expression, to extract the first row: ‘n[a-z]%’ -> ‘ne[a-z]%’ -> ‘new[a-z]%’ -> ‘news[a-z]%’ -> TRUE Otherwise MySQL ending, we have TRUE because ‘%’ define any string of zero or more characters.

To check the end, we must append “_” and verify if exist another character. ‘news%’ TRUE -> ‘news_’ FALSE.

Exporting a value with Regexp attack (MySQL)

In this example we will extract a MD5 hash from a know table name (in this case ‘users’);

Remember: MD5 can ONLY contain [a-f0-9] values.

We will use the same methodology described in the “Finding table name”.

Our hash start with ‘5’ in just 6 try!

Exporting a value with Regexp attack (MSSQL)

Same thing as MySQL and “Finding Table name”. We now continue the search of second char. An example below:

We have found our second char is ‘f’ in just 5 try! (This is also the worst case for brute-force)

Time considerations

Take for example the MD5 case. We must export an hash of 32 chars using a Blind SQL Injection.

You know that there are only 16 chars to be tested (1234567890abcdef);
In an optimistic case, regexp and normal blind need 32 query to be done;
In a worst-case , regexp need 128 query and normal blind need 512 query;

Let’s take now a password case. We must export a 15 chars password mixalpha-numericspecial14.

You know that there are 76 chars to be tested ([email protected]#$%^&*()-_+=);

In an optimistic case, regexp and normal blind need 15 query to be done;
In a worst-case, regexp need approx 94 query and normal blind need 1140 query;

Bypassing filters

Below are examples of common filters bypass.


Special chars like:
%0c = form feed, new page
%09 = horizontal tab
%0d = carriage return
%0a = line feed, new line


Usually the ‘ AND “ are used to input some kind of string. So you can input the HEX

Where 0x61646d696e is the hex value of ‘admin’ Or also using the CHAR function:


To conclude our paper, we must specify that:

1. Is possible make a “combo” attack using “Time Attack” or other;

2. The regexp that you will use, could also be a list of chars like “[abcdef0123456789]”;

3. Our English is fu**ing bad! 🙂