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.

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

Inline <strong>SQL</strong> <strong>Injection</strong><br />

In this section, I will show you some examples of inline <strong>SQL</strong> injection. Inline injection<br />

happens when you inject some <strong>SQL</strong> code in such a way that all parts of the original query<br />

are executed.<br />

Figure 2.10 shows a representation of an inline <strong>SQL</strong> injection.<br />

Figure 2.10 Injecting <strong>SQL</strong> Code Inline<br />

Injecting Strings Inline<br />

Let’s see an example that illustrates this kind of attack so that you can fully underst<strong>and</strong> how<br />

it works.<br />

Victim Inc. has an authentication form for accessing the administration part of its Web<br />

site. The authentication requires the user to enter a valid username <strong>and</strong> password. After sending<br />

a username <strong>and</strong> password, the application sends a query to the database to validate the<br />

user. The query has the following format:<br />

SELECT *<br />

FROM administrators<br />

WHERE username = '[USER ENTRY]' AND password = '[USER ENTRY]'<br />

The application doesn’t perform any sanitization of the received data, <strong>and</strong> therefore we<br />

have full control over what we send to the server.<br />

Be aware that the data entry for both the username <strong>and</strong> the password is enclosed in two<br />

single quotes which you cannot control. You will have to keep that in mind when crafting a<br />

valid <strong>SQL</strong> statement. Figure 2.11 shows the creation of the <strong>SQL</strong> statement from the user entry.

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

Saved successfully!

Ooh no, something went wrong!