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.

Using Hybrid <strong>Attacks</strong><br />

Advanced Topics • Chapter 7 335<br />

Hybrid attacks combine two or more exploits to attack an application, often resulting in a<br />

compromise that is greater than the sum of its parts. You can combine <strong>SQL</strong> injection with<br />

other techniques in numerous ways to achieve your objectives in attacking an application.<br />

Leveraging Captured Data<br />

First, of course, you can use <strong>SQL</strong> injection to retrieve sensitive data that you can use to<br />

escalate your privileges within the application. For example, you may be able to read the<br />

passwords for other users, <strong>and</strong> log in as them. If the passwords are hashed <strong>and</strong> you know the<br />

algorithm, you can try to crack the captured hashes offline. Similarly, you may be able to<br />

read tables of sensitive logging data, containing usernames, session tokens, or even the<br />

parameters submitted in the requests of other users.<br />

More elaborately, if the application contains an account recovery function which e-mails<br />

a one-time recovery URL to users who have forgotten their password, you may be able to<br />

read the values of the account recovery tokens issued to other users, <strong>and</strong> so initiate account<br />

recovery for arbitrary users <strong>and</strong> thereby compromise their accounts.<br />

Creating Cross-Site Scripting<br />

<strong>SQL</strong> injection is a great bug to find in a Web application, but sometimes you may really<br />

want a different bug, such as cross-site scripting (XSS). Often, you can use <strong>SQL</strong> injection<br />

vulnerabilities to introduce different kinds of XSS into the application.<br />

If the input which you supply to the application is not itself being echoed back, but<br />

instead the application returns the output from an <strong>SQL</strong> query which you control, you can<br />

usually exploit the vulnerability to achieve the same effects as a reflected XSS attack. For<br />

example, if the application returns the results of the query as shown here:<br />

SELECT orderNum, orderDesc, orderAmount FROM tblOrders WHERE orderType = 123<br />

<strong>and</strong> the orderType field is vulnerable to <strong>SQL</strong> injection, you may be able to create a proofof-concept<br />

XSS attack with a URL such as the following:<br />

https://www.example.org/MyOrders.php?orderType=123+UNION+SELECT+1,'<br />

alert(1)',1<br />

Unlike conventional XSS, the application does not simply echo your attack payload in<br />

its response. Rather, you modify the <strong>SQL</strong> query to append your payload to the query<br />

results, which the application copies into its response. Provided that the application does<br />

not perform any output encoding on the query results (if it assumes that the query results<br />

are trustworthy), your attack will be successful.<br />

In other situations, you may be able to leverage <strong>SQL</strong> injection vulnerabilities to perform<br />

a persistent XSS attack within the application. This possibility usually arises when data that

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

Saved successfully!

Ooh no, something went wrong!