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.

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

Are You Owned?<br />

Counting Eggs <strong>and</strong> Requests<br />

If it is not already clear, the inference techniques described in this chapter are noisy<br />

<strong>and</strong> resource-intensive; extracting one bit per request means that an attacker will<br />

have to send thous<strong>and</strong>s of requests at a minimum, running into the millions where<br />

megabytes of data is retrieved. This helps in spotting such attacks using basic metrics:<br />

Requests per minute, database queries per minute, tracking database connection pool<br />

errors, <strong>and</strong> b<strong>and</strong>width utilization are all possible data points that you can monitor to<br />

evaluate whether an inference attack is ongoing.<br />

For large sites, many of these metrics could fall under the radar, as the attack may<br />

not sufficiently spike the numbers; it may also help to track requests per page as the<br />

inference attack will in all likelihood use a single injection point to complete the<br />

attack.<br />

Increasing the Complexity of Inference Techniques<br />

It may have occurred to you that testing each character in the username against the entire<br />

alphabet (plus digits <strong>and</strong> possibly non-alphanumeric characters) is a pretty inefficient method<br />

for extracting data. To retrieve the username we had to request the page 112 times (five<br />

times for the length <strong>and</strong> 19, 17, 12, 27, <strong>and</strong> 32 times for the characters s, q, l, 0, <strong>and</strong> 5,<br />

respectively). A further consequence of this approach is that when retrieving binary data we<br />

could potentially have an alphabet of 256 characters, which sharply increases the number of<br />

requests <strong>and</strong> in any case is often not binary-safe. Two methods can improve the efficiency of<br />

retrieval through inference: a bit-by-bit method <strong>and</strong> a binary search method. Both methods<br />

are binary-safe.<br />

The binary search method is mostly used to infer the value of single bytes without<br />

having to search through an entire alphabet. It successively halves the search space until the<br />

value of the byte is identified, by playing a game of eight questions. (Because a byte can have<br />

one of 256 values, the value will always be determined in eight requests. This is intuitively<br />

demonstrated by counting the number of times you can successively divide 256 in half<br />

before you get a non-integer quotient.) Assume that the byte we are interested in has the<br />

value 14. We ask questions <strong>and</strong> infer the answers through a convenient inference mechanism,<br />

which will return Yes if the answer is true <strong>and</strong> No if the answer is false. The game then<br />

proceeds like this:

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

Saved successfully!

Ooh no, something went wrong!