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.

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

Using Response-Based Techniques<br />

Just as we used request timing to infer information about a particular byte, we can also infer<br />

state by carefully examining all data in the response, including content <strong>and</strong> headers. You can<br />

infer state either by the text contained in the response or by forcing errors when particular<br />

values are under examination. For example, the inference exploit could contain logic that<br />

alters the query such that query results are returned when the examined bit is 1 <strong>and</strong> no<br />

results if the bit is 0, or again, an error could be forced if a bit is 1 <strong>and</strong> no error generated<br />

when the bit is 0.<br />

Although we will delve into error-generating techniques shortly, it is worth mentioning<br />

here that the types of errors we strive to generate are runtime errors rather than query<br />

compilation errors. If the syntax in the query is wrong, it will always produce an error,<br />

regardless of the inference question; the error should be generated only when the inference<br />

question is either TRUE or FALSE, but never both.<br />

Most blind <strong>SQL</strong> injection tools use response-based techniques for inferring information,<br />

as the results are not influenced by uncontrolled variables such as load <strong>and</strong> line congestion;<br />

however, this approach does rely on the injection point returning some modifiable response<br />

to the attacker. You can use either the binary search approach or the bit-by-bit approach<br />

when inferring information by poring over the response.<br />

My<strong>SQL</strong> Response Techniques<br />

Consider the case where the following <strong>SQL</strong> query is executed through a Web application<br />

with input data MadBob, <strong>and</strong> returns one row from the reviews table that is contained in the<br />

page response. The query is:<br />

SELECT COUNT(*) FROM reviews WHERE review_author='MadBob'<br />

The result of execution is a single row containing the number of reviews written by<br />

MadBob, <strong>and</strong> this is displayed on the Web page in Figure 5.6.<br />

Figure 5.6 Query for “MadBob” Returning a<br />

Count of Two Reviews, Used As TRUE Inference

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

Saved successfully!

Ooh no, something went wrong!