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.

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

Introduction<br />

So, you’ve found an <strong>SQL</strong> injection point, but the application gives you only a generic<br />

error page. Or perhaps it gives you the page as normal, but there is a small difference in<br />

what you get back, visible or not. These are examples of blind <strong>SQL</strong> injection, where you<br />

exploit without any of the useful error messages or feedback that you may be used to,<br />

as you saw in Chapter 4. Don’t worry; you can still reliably exploit <strong>SQL</strong> injection even<br />

in these scenarios.<br />

You saw a number of classic <strong>SQL</strong> injection examples in Chapter 4 that relied on verbose<br />

error messages to extract data, <strong>and</strong> this was the first widely used attack technique for data<br />

extraction in these vulnerabilities. Before <strong>SQL</strong> injection was well understood, developers<br />

were advised to disable all verbose error messages in the mistaken belief that without error<br />

messages the attacker’s data retrieval goal was next to impossible to achieve. In some cases<br />

developers would trap errors within the application <strong>and</strong> display generic error messages,<br />

whereas in other cases no errors would be shown to the user. However, attackers soon realized<br />

that even though the error-based channel was no longer available, the root cause still<br />

remained: Attacker-supplied <strong>SQL</strong> was executing within a database query. Figuring out new<br />

channels was left to the ingenuity of the attackers <strong>and</strong> a number of channels were discovered<br />

<strong>and</strong> published. Along the way, the term blind <strong>SQL</strong> injection entered into common usage with<br />

slight differences in the definition used by each author. Chris Anley first introduced a blind<br />

<strong>SQL</strong> injection technique in a 2002 paper that demonstrated how disabling verbose error<br />

messages could still lead to injection attacks, <strong>and</strong> he provided several examples. Ofer Maor<br />

<strong>and</strong> Amichai Shulman’s definition required that verbose errors be disabled but that broken<br />

<strong>SQL</strong> syntax would yield a generic error page, <strong>and</strong> implicitly assumed that the vulnerable<br />

statement was a SELECT query whose result set was ultimately displayed to the user.<br />

The query’s result (either success or failure) was then used to first derive the vulnerable<br />

statement <strong>and</strong> then to extract data through a UNION SELECT. Kevin Spett’s definition was<br />

similar in that verbose error messages were disabled <strong>and</strong> injection occurred in a SELECT<br />

statement; however, instead of relying on generic error pages, his technique altered content<br />

within the page through <strong>SQL</strong> logic manipulations to infer data on a byte-by-byte basis,<br />

which was identical to Cameron Hotchkies’ usage.<br />

It is clear that blind <strong>SQL</strong> injection has received significant attention from attackers, <strong>and</strong><br />

its techniques are a key component in any <strong>SQL</strong> injection arsenal; however, before delving<br />

into the specifics, we need to define blind <strong>SQL</strong> injection <strong>and</strong> explore the scenarios in which<br />

it commonly occurs. Toward that end, in this chapter we will cover techniques for extracting<br />

information from the back-end database through the use inference <strong>and</strong> alternative channels,<br />

including time delays, errors, domain name system (DNS) queries, <strong>and</strong> HTML responses.<br />

This will give you flexible ways to communicate with the database, even in situations where<br />

the application is catching exceptions properly <strong>and</strong> you do not have any feedback from the<br />

Web interface that your exploits are working.

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

Saved successfully!

Ooh no, something went wrong!