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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

156 Chapter 4 • Exploiting <strong>SQL</strong> <strong>Injection</strong><br />

This query will remove the original row (the one containing the product details) with<br />

the <strong>and</strong> 1 =0 clause, <strong>and</strong> return the first row containing a client with a userid value of more<br />

than 1. This will result in the response shown in Figure 4.7.<br />

Figure 4.7 Looping through the Rows of a Table with UNION SELECT<br />

Further increasing the value of the userid parameter will allow you to loop through the<br />

whole table, extracting the full list of the customers of victim.com.<br />

Using Conditional Statements<br />

Using UNION to inject arbitrary queries is a fast <strong>and</strong> efficient method of extracting data.<br />

However, this is not always possible; Web applications, even when they are vulnerable, are not<br />

always willing to give their data away so easily. Fortunately, several other techniques work<br />

equally well, albeit not always as quickly <strong>and</strong> easily. And even the most successful <strong>and</strong> spectacular<br />

“jackpot” of an <strong>SQL</strong> injection attack, usually consisting of dumping entire databases or<br />

obtaining interactive access to the database server, often begins by extracting pieces of data<br />

that are far smaller than what a UNION statement can achieve. In several cases, these pieces of<br />

data comprise just one bit of information, because they are the outcome of queries that have<br />

only two possible answers: “Yes” or “No”. Even if such queries allow such a minimal amount<br />

of data extraction, they are extremely powerful <strong>and</strong> are one of the deadliest exploitation<br />

vectors available. Such queries can always be expressed in the following form:<br />

IF condition THEN do_something ELSE do_something_else

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

Saved successfully!

Ooh no, something went wrong!