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.

70 Chapter 2 • Testing for <strong>SQL</strong> <strong>Injection</strong><br />

Tip<br />

A defense technique consists of detecting <strong>and</strong> removing all spaces or truncating<br />

the value to the first space from the user entry. Multiline comments can<br />

be used to bypass such restrictions. Say you are exploiting an application<br />

using the following attack:<br />

http://www.victim.com/messages/list.aspx?uid=45 or 1=1<br />

However, the application removes the spaces <strong>and</strong> the <strong>SQL</strong> statement<br />

becomes:<br />

SELECT *<br />

FROM messages<br />

WHERE uid=45or1=1<br />

This will not return the results you want, but you can add multiline<br />

comments with no content to avoid using spaces:<br />

http://www.victim.com/messages/list.aspx?uid=45/**/or/**/1=1<br />

The new query will not have spaces in the user input, but it will be valid,<br />

returning all of the rows in the messages table.<br />

The “Evading Input Filters” section in Chapter 7 explains in detail this<br />

technique <strong>and</strong> many others used for signature evasion.<br />

The following technique to confirm the existence of a vulnerability makes use of<br />

<strong>SQL</strong> comments. Have a look at the following request:<br />

http://www.victim.com/messages/list.aspx?uid=45/*hello yes*/<br />

If vulnerable, the application will send the value of the uid followed by a comment.<br />

If there are no problems processing the request <strong>and</strong> we get the same result we would get<br />

with uid=45, this means the database ignored the content of the comment. This might be<br />

due to an <strong>SQL</strong> injection vulnerability.<br />

Using Comments<br />

Let’s see how we can use comments to terminate <strong>SQL</strong> statements.<br />

We are going to use the authentication mechanism in the Victim Inc. administration<br />

Web site. Figure 2.15 represents the concept of terminating the <strong>SQL</strong> statement.

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

Saved successfully!

Ooh no, something went wrong!