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.

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

On the other h<strong>and</strong>, if the only vulnerable parameters at your disposal are used<br />

to modify some data, most of the techniques outlined in this chapter will be useful for<br />

exploiting the vulnerability. However, be extra careful in what you inject <strong>and</strong> how this<br />

might affect the database. If the application you are testing is in production, before<br />

performing the actual attack make sure all the data is backed up <strong>and</strong> that it is possible<br />

to perform a full rollback after the security testing of the application has been<br />

completed.<br />

This is especially true when using an automated tool such as the ones I will introduce<br />

at the end of the chapter. Such tools can easily execute hundreds or thous<strong>and</strong>s<br />

of queries in a very short time to do their job, all with minimal user interaction. Using<br />

such a tool to inject on an UPDATE or a DELETE statement can wreak havoc on a<br />

DBMS, so be careful!<br />

Underst<strong>and</strong>ing<br />

Common Exploit Techniques<br />

Arriving at this point, you have probably found one or more vulnerable parameters on the<br />

Web application you are testing, by either using the techniques for testing the application<br />

outlined in Chapter 2, or reviewing the code outlined in Chapter 3. Perhaps a single quote<br />

inserted in the first GET parameter that you tried was sufficient to make the application<br />

return a database error, or maybe you literally spent days stubbornly going through each<br />

parameter trying entire arrays of different <strong>and</strong> exotic attack vectors. In any case, now is the<br />

time to have some real fun with the actual exploitation.<br />

It is very useful at this stage to have a local installation of the same database system that<br />

sits behind the application you are attacking. Unless you have the Web application source<br />

code, <strong>SQL</strong> injection requires a black-box attack approach, <strong>and</strong> you will have to craft the<br />

queries to inject by observing how your target responds to your requests. Being able to<br />

locally test the queries you are going to inject in order to see how the database responds to<br />

such queries makes this phase a lot easier.<br />

Exploiting an <strong>SQL</strong> injection vulnerability can mean different things in different situations<br />

depending on the conditions in place, such as the privileges of the user performing the queries,<br />

the exact DBMS server that sits on the back end, <strong>and</strong> whether you are more interested in<br />

extracting data, modifying data, or running comm<strong>and</strong>s on the remote host. However, at this<br />

stage what really makes a difference is whether the application presents in the HTML code<br />

the output of your <strong>SQL</strong> queries (even if the DBMS returns only the error message). If you<br />

don’t have any kind of <strong>SQL</strong> output displayed within the application, you will need to perform<br />

a blind <strong>SQL</strong> injection attack, which is more intricate (but a lot more fun). We’ll cover blind<br />

<strong>SQL</strong> injection in Chapter 5. For now, <strong>and</strong> unless specified otherwise, we will assume that the<br />

remote database returns <strong>SQL</strong> output to some extent, <strong>and</strong> we will go through a plethora of<br />

attack techniques that leverage this fact.

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

Saved successfully!

Ooh no, something went wrong!