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.

300 Chapter 9 n Attacking Data Stores<br />

HACK STEPS<br />

1. Try supplying a simple ma<strong>the</strong>matical expression that is equivalent to <strong>the</strong><br />

original numeric value. For example, if <strong>the</strong> original value is 2, try submitting<br />

1+1 or 3-1. If <strong>the</strong> <strong>application</strong> responds in <strong>the</strong> same way, it may be<br />

vulnerable.<br />

2. The preceding test is most reliable in cases where you have confirmed<br />

that <strong>the</strong> item being modified has a noticeable effect on <strong>the</strong> <strong>application</strong>’s<br />

behavior. For example, if <strong>the</strong> <strong>application</strong> uses a numeric PageID<br />

parameter to specify which content should be returned, substituting 1+1<br />

for 2 with equivalent results is a good sign that SQL injection is present.<br />

However, if you can place arbitrary input into a numeric parameter without<br />

changing <strong>the</strong> <strong>application</strong>’s behavior, <strong>the</strong> preceding test provides no<br />

evidence of a vulnerability.<br />

3. If <strong>the</strong> first test is successful, you can obtain fur<strong>the</strong>r evidence of <strong>the</strong> vulnerability<br />

by using more complicated expressions that use SQL-specific keywords<br />

and syntax. A good example of this is <strong>the</strong> ASCII command, which returns<br />

<strong>the</strong> numeric ASCII code of <strong>the</strong> supplied character. For example, because <strong>the</strong><br />

ASCII value of A is 65, <strong>the</strong> following expression is equivalent to 2 in SQL:<br />

67-ASCII(‘A’)<br />

4. The preceding test will not work if single quotes are being filtered.<br />

However, in this situation you can exploit <strong>the</strong> fact that databases implicitly<br />

convert numeric data to string data where required. Hence, because<br />

<strong>the</strong> ASCII value of <strong>the</strong> character 1 is 49, <strong>the</strong> following expression is equivalent<br />

to 2 in SQL:<br />

51-ASCII(1)<br />

TIP A common mistake when probing an <strong>application</strong> for defects such as SQL<br />

injection is to forget that certain characters have special meaning within HTTP<br />

requests. If you want to include <strong>the</strong>se characters within your attack payloads,<br />

you must be careful to URL-encode <strong>the</strong>m to ensure that <strong>the</strong>y are interpreted in<br />

<strong>the</strong> way you intend. In particular:<br />

n & and = are used to join name/value pairs to create <strong>the</strong> query string and<br />

<strong>the</strong> block of POST data. You should encode <strong>the</strong>m using %26 and %3d,<br />

respectively.<br />

n Literal spaces are not allowed in <strong>the</strong> query string. If <strong>the</strong>y are submitted,<br />

<strong>the</strong>y will effectively terminate <strong>the</strong> entire string. You should encode <strong>the</strong>m<br />

using + or %20.<br />

n Because + is used to encode spaces, if you want to include an actual +<br />

in your string, you must encode it using %2b. In <strong>the</strong> previous numeric<br />

example, <strong>the</strong>refore, 1+1 should be submitted as 1%2b1.

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

Saved successfully!

Ooh no, something went wrong!