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.

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

Introduction<br />

Once you have found <strong>and</strong> confirmed that you have an <strong>SQL</strong> injection point, what do you do<br />

with it? You may know you can interact with the database, but you don’t know what the<br />

back-end database is, or anything about the query you are injecting into, or the table(s) it is<br />

accessing. Again, using inference techniques <strong>and</strong> the useful error the application gives you,<br />

you can determine all of this, <strong>and</strong> more.<br />

In this chapter, we will discuss how deep the rabbit hole goes (you did take the red pill,<br />

didn’t you?). We’ll explore a number of the building blocks you’ll need for later chapters, as<br />

well as exploit techniques for reading or returning data to the browser, for enumerating the<br />

database schema from the database, <strong>and</strong> for returning information out of b<strong>and</strong> (i.e., not<br />

through the browser). Some of the attacks will be targeted to extract the data that the remote<br />

database stores <strong>and</strong> others will be focused on the database management system (DBMS) itself,<br />

such as trying to steal the database users’ password hashes. Because some of these attacks need<br />

administrative privileges to be carried out successfully, <strong>and</strong> because the queries that many<br />

Web applications run are performed with the privileges of a normal user, we will also illustrate<br />

some strategies for obtaining administrative privileges. And finally, so that you don’t have<br />

to do it all manually, we’ll also look at techniques <strong>and</strong> tools (many written by the authors of<br />

this book) for automating a lot of these steps for efficiency.<br />

Tools & Traps...<br />

The Big Danger: Modifying Live Data<br />

Although the examples in the following sections will deal primarily with injections<br />

into SELECT statements, never forget that your vulnerable parameter could be used in<br />

far more dangerous queries that use comm<strong>and</strong>s such as INSERT, UPDATE, or DELETE<br />

instead. Although a SELECT comm<strong>and</strong> only retrieves data from the database <strong>and</strong><br />

strictly follows a “look but don’t touch” approach, other comm<strong>and</strong>s can (<strong>and</strong> will)<br />

change the actual data in the database that you are testing, which might cause major<br />

problems in the case of a live application. As a general approach, when performing an<br />

<strong>SQL</strong> injection attack on an application where more than one parameter is vulnerable,<br />

always try to give priority to parameters that are used in queries that do not modify<br />

any data. This will allow you to operate far more effectively, freely using your favorite<br />

techniques without the risk of tainting the data or even disrupting application<br />

functionality.<br />

Continued

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

Saved successfully!

Ooh no, something went wrong!