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.

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

Figure 2.16 shows an example of a multiline comment attack. Note that the text in the<br />

Password field is disclosed for clarity. It illustrates an attack using multiline comments.<br />

Figure 2.16 Using Multiline Comments<br />

In this attack, we use the Username field to select the user we want <strong>and</strong> start the comment<br />

with the /* sequence. In the Password field we finish the comment ( ∗/ ) <strong>and</strong> we add<br />

the single-quote sequence to end the statement syntactically correct with no effect on the<br />

result. The resultant <strong>SQL</strong> statement is:<br />

SELECT *<br />

FROM administrators<br />

WHERE username = 'admin'/*' AND password = '*/ '';<br />

Removing the commented code helps to better illustrate the example:<br />

SELECT *<br />

FROM administrators<br />

WHERE username = 'admin' '';<br />

As you can see, we needed to finish the statement with a string due to the last single<br />

quote inserted by the application which we cannot control. We chose to concatenate an<br />

empty string, which has no effect on the result of the query.<br />

In the previous example, we concatenated our input with an empty string. String concatenation<br />

is something you will always need when doing <strong>SQL</strong> injection testing. However, because<br />

it is done differently in <strong>SQL</strong> Server, My<strong>SQL</strong>, <strong>and</strong> Oracle, it can therefore be used as a tool to<br />

identify the remote database. Table 2.4 shows the concatenation operators in each database.

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

Saved successfully!

Ooh no, something went wrong!