28.10.2014 Views

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1. Is the byte greater than 127? No, because 14 < 127.<br />

2. Is the byte greater than 63? No, because 14 < 63.<br />

3. Is the byte greater than 31? No, because 14 < 31.<br />

4. Is the byte greater than 15? No, because 14 < 15.<br />

5. Is the byte greater than 7? Yes, because 14 > 7.<br />

6. Is the byte greater than 11? Yes, because 14 > 11.<br />

7. Is the byte greater than 13? Yes, because 14 > 13.<br />

8. Is the byte greater than 14? No, because 14 = 14.<br />

Blind <strong>SQL</strong> <strong>Injection</strong> Exploitation • Chapter 5 231<br />

Since the byte is greater than 13 but not greater than 14, we can infer that the byte has<br />

the value 14. This technique relies on a database function to provide the integer value of any<br />

byte; under Microsoft <strong>SQL</strong> Server, My<strong>SQL</strong>, <strong>and</strong> Oracle, this is provided by the ASCII( )<br />

function.<br />

If we return to the original problem of finding the database username, but now we use<br />

the binary search technique to find the first character of the username, we would like to<br />

execute the following <strong>SQL</strong> statement:<br />

SELECT COUNT(chick_id) FROM chickens WHERE status='Incubating' AND<br />

ASCII(SUBSTRING(system_user,1,1))>127--'<br />

We need to issue eight <strong>SQL</strong> statements to absolutely determine the character’s value.<br />

Converting all these queries into a page requests produces the following:<br />

status=Incubating' <strong>and</strong> ASCII(SUBSTRING(SYSTEM_USER,1,1))>127-- (False)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1))>63-- (True)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1))>95-- (True)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1))>111-- (True)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1))>119-- (False)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1))>115-- (False)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1))>113-- (True)<br />

status=Incubating' AND ASCII(SUBSTRING(SYSTEM_USER,1,1))>114-- (True)<br />

From this series of requests, we can infer that the byte value of the first character of<br />

the username is 115, which, when converted to its ASCII table equivalent, is s. Using this<br />

technique it is possible to extract a byte in exactly eight requests, which is a vast improvement<br />

over comparing the full byte against an alphabet. If we add a third state to the request<br />

(Error), it is possible to test for equality in our binary search, thereby reducing the best-case<br />

number of requests to one request, with eight requests being a worst case.<br />

This is great. We have a method by which we can efficiently extract the value of a given<br />

byte in a fixed time in as many requests as there are bits. Unless we use compression or an<br />

injection string that h<strong>and</strong>les more than two states this is as good as it gets from an information

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!