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.

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

Tip<br />

As always with <strong>SQL</strong> injection, asking where in the original query your input ends<br />

up is an important step toward underst<strong>and</strong>ing the effect of your exploit. For<br />

example, the timing-based inference attacks on My<strong>SQL</strong> almost always introduce<br />

a delay in the WHERE clause of the query. However, because the WHERE clause<br />

is evaluated against each row, any delay is multiplied by the number of rows<br />

against which the clause is compared. For example, using the exploit snippet<br />

+ IF(ASCII(SUBSTRING((…),i,1))>k,SLEEP(5),1) on a table of 100 rows produces a<br />

delay of 500 seconds. At first glance, this may seem contrary to what you would<br />

like, but it does allow you to estimate the size of tables; moreover, since SLEEP( )<br />

can pause for microseconds, you can still have the overall delay for the query<br />

take just a few seconds even if the table has thous<strong>and</strong>s or millions of rows.<br />

<strong>SQL</strong> Server Delays<br />

<strong>SQL</strong> Server provides an explicit facility for pausing the execution of any query. Using the<br />

WAITFOR keyword it is possible to cause <strong>SQL</strong> Server to halt execution of a query until<br />

some time period has passed, which can be either relative to the time at which the keyword<br />

was encountered or an absolute time when execution should resume (such as 21:15).<br />

You most often will use the relative option, which makes use of the DELAY keyword.<br />

Thus, to pause execution for 1 minute, 53 seconds you would use WAITFOR DELAY<br />

‘00:01:53’. The result is a query that indeed executes for 1 minute, 53 seconds, as Figure 5.5<br />

shows—the time the query took to execute is shown in the status bar along the bottom<br />

of the window. Note that this does not impose a maximum bound on the execution time;<br />

you are not telling the database to only execute for 1:53; rather, you are adding 1:53 to the<br />

query’s normal execution time, so the delay is a minimum bound.<br />

Notes from the Underground…<br />

Simulating BENCHMARK( ) on<br />

Microsoft <strong>SQL</strong> Server <strong>and</strong> Other Databases<br />

In mid-2007, Chema Alonso published a technique for duplicating My<strong>SQL</strong>’s<br />

BENCHMARK( ) effect of prolonging queries through an extra processing load in <strong>SQL</strong><br />

Server, <strong>and</strong> this provided another mechanism for inferring data without the need for<br />

Continued

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

Saved successfully!

Ooh no, something went wrong!