19.09.2017 Views

the-web-application-hackers-handbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

302 Chapter 9 n Attacking Data Stores<br />

path traversal string, single quote, double quote, or any o<strong>the</strong>r arbitrary string.<br />

Therefore, common techniques for both automated fuzzing and manual testing<br />

are liable to overlook <strong>the</strong> vulnerability. The standard test strings for numerous<br />

kinds of vulnerabilities will all cause <strong>the</strong> same response, which may not itself<br />

disclose <strong>the</strong> nature of <strong>the</strong> error.<br />

NOTE Some conventional SQL injection defenses described later in this<br />

chapter cannot be implemented for user-specified column names. Using<br />

prepared statements or escaping single quotes will not prevent this type of<br />

SQL injection. As a result, this vector is a key one to look out for in modern<br />

<strong>application</strong>s.<br />

HACK STEPS<br />

1. Make a note of any parameters that appear to control <strong>the</strong> order or field<br />

types within <strong>the</strong> results that <strong>the</strong> <strong>application</strong> returns.<br />

2. Make a series of requests supplying a numeric value in <strong>the</strong> parameter<br />

value, starting with <strong>the</strong> number 1 and incrementing it with each subsequent<br />

request:<br />

n If changing <strong>the</strong> number in <strong>the</strong> input affects <strong>the</strong> ordering of <strong>the</strong> results,<br />

<strong>the</strong> input is probably being inserted into an ORDER BY clause. In SQL,<br />

ORDER BY 1 orders by <strong>the</strong> first column. Increasing this number to 2<br />

should <strong>the</strong>n change <strong>the</strong> display order of data to order by <strong>the</strong> second<br />

column. If <strong>the</strong> number supplied is greater than <strong>the</strong> number of columns<br />

in <strong>the</strong> result set, <strong>the</strong> query should fail. In this situation, you can confirm<br />

that fur<strong>the</strong>r SQL can be injected by checking whe<strong>the</strong>r <strong>the</strong> results order<br />

can be reversed, using <strong>the</strong> following:<br />

1 ASC --<br />

1 DESC --<br />

n If supplying <strong>the</strong> number 1 causes a set of results with a column containing<br />

a 1 in every row, <strong>the</strong> input is probably being inserted into <strong>the</strong> name<br />

of a column being returned by <strong>the</strong> query. For example:<br />

SELECT 1,title,year FROM books WHERE publisher=’Wiley’<br />

NOTE Exploiting SQL injection in an ORDER BY clause is significantly different<br />

from most o<strong>the</strong>r cases. A database will not accept a UNION, WHERE, OR, or<br />

AND keyword at this point in <strong>the</strong> query. Generally exploitation requires <strong>the</strong><br />

attacker to specify a nested query in place of <strong>the</strong> parameter, such as replacing<br />

<strong>the</strong> column name with (select 1 where or 1/0=0),<br />

<strong>the</strong>reby leveraging <strong>the</strong> inference techniques described later in this chapter.<br />

For databases that support batched queries such as MS-SQL, this can be <strong>the</strong><br />

most efficient option.

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

Saved successfully!

Ooh no, something went wrong!