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.

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

Injecting Queries with Side Effects<br />

Stepping toward confirmation of the vulnerability, it is generally possible to submit queries<br />

that have side effects the attacker can observe. The oldest technique uses a timing attack to<br />

confirm that execution of the attacker’s <strong>SQL</strong> has occurred, <strong>and</strong> it is also sometimes possible<br />

to execute operating system comm<strong>and</strong>s whose output is observed by the attacker. For example,<br />

in Microsoft <strong>SQL</strong> Server it is possible to generate a five-second pause with the following<br />

<strong>SQL</strong> snippet:<br />

WAITFOR DELAY '0:0:5'<br />

Likewise, My<strong>SQL</strong> users could use the SLEEP( ) function which performs the same task<br />

in My<strong>SQL</strong> 5.0.12 <strong>and</strong> later.<br />

Finally, the observed output can also be in-channel. For instance, if the injected string<br />

' AND '1'='2<br />

is inserted into a search field <strong>and</strong> produces a different response from<br />

' OR '1'='1<br />

then <strong>SQL</strong> injection appears very likely. The first string introduces an always false clause<br />

into the search query, which will return nothing, <strong>and</strong> the second string ensures that the<br />

search query matches every row.<br />

We covered this in more detail in Chapter 2.<br />

Splitting <strong>and</strong> Balancing<br />

Where generic errors or side effects are not useful, you can also try the “parameter splitting<br />

<strong>and</strong> balancing” technique (as named by David Litchfield), which is a staple of many blind<br />

<strong>SQL</strong> injection exploits. Splitting occurs when the legitimate input is broken up, <strong>and</strong> balancing<br />

ensures that the resultant query does not have trailing single quotes that are unbalanced.<br />

The basic idea is to gather legitimate request parameters <strong>and</strong> then modify them with<br />

<strong>SQL</strong> keywords so that they are different from the original data, although functionally<br />

equivalent when parsed by the database. By way of example, imagine that in the URL<br />

http://www.victim.com/view_review.aspx?id=5 the value of the id parameter is inserted<br />

into an <strong>SQL</strong> statement to form the following query:<br />

SELECT review_content, review_author FROM reviews WHERE id=5<br />

If you substitute 2+3 in place of 5, the input to the application will be different from the<br />

original request, but the <strong>SQL</strong> will be functionally equivalent:<br />

SELECT review_content, review_author FROM reviews WHERE id=2+3<br />

This is not limited to numeric data. Assume that the URL http://www.victim.com/<br />

count_reviews.jsp?author=MadBob returns information relating to a particular

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

Saved successfully!

Ooh no, something went wrong!