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.

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

simply a ‘500 Internal Server Error’ returned by the Web server, or it might contain the full<br />

<strong>SQL</strong> Server error message, which will look like the screenshot in Figure 4.8.<br />

Figure 4.8 Error Message As a Result of a Divide-by-Zero<br />

It might also be a generic HTML page that is used to make the application fail<br />

gracefully, but the bottom line is the same: Depending on the value of a specific bit, you can<br />

trigger different responses, <strong>and</strong> therefore extract the value of the bit itself.<br />

You can easily extend this principle to other types of queries, <strong>and</strong> for this purpose the<br />

CASE statement is introduced, which is supported by the majority of DBMSs <strong>and</strong> can be<br />

injected inside an existing query, making it also available when stacked queries cannot be<br />

used. The CASE statement has the following syntax:<br />

CASE WHEN condition THEN action1 ELSE action2 END<br />

As an example, let’s see how we can use a CASE statement to check, in our e-commerce<br />

application, whether the current user is sa:<br />

http://www.victim.com/products.asp?id=12/(case+when+(system_user='sa')+then+<br />

1+else+0+end)

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

Saved successfully!

Ooh no, something went wrong!