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.

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

Note that injecting a number doesn’t require terminating <strong>and</strong> commencing the<br />

single-quote delimiters. In this example, we can directly inject after the uid parameter<br />

in the URL.<br />

In this scenario, we have control over the messages returned from the database.<br />

The application doesn’t perform any sanitization in the uid parameter, <strong>and</strong> therefore we can<br />

interfere in the rows selected from the messages table. The method of exploitation in this<br />

scenario is to add an always true (or 1=1) statement, so instead of returning only the messages<br />

for our user, all of them are displayed. The URL would be:<br />

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

The result of the request would return messages to every user, as shown in Figure 2.13.<br />

Figure 2.13 Exploitation of a Numeric <strong>Injection</strong><br />

The result of the exploitation generated the following <strong>SQL</strong> statement:<br />

SELECT *<br />

FROM messages<br />

WHERE uid=45 or 1=1 /* Always true condition*/<br />

ORDER BY received;<br />

Due to the always true condition injected (or 1=1) the database returns all rows in the<br />

messages table <strong>and</strong> not just the ones sent to our user. In Chapter 4, you will learn how to<br />

exploit this further to read arbitrary data from any table of the database <strong>and</strong> even from<br />

other databases.<br />

Table 2.2 shows a collection of signatures for testing numeric values.

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

Saved successfully!

Ooh no, something went wrong!