19.09.2017 Views

the-web-application-hackers-handbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 9 n Attacking Data Stores 299<br />

2. If an error or o<strong>the</strong>r divergent behavior was observed, submit two single<br />

quotation marks toge<strong>the</strong>r. Databases use two single quotation marks as<br />

an escape sequence to represent a literal single quote, so <strong>the</strong> sequence is<br />

interpreted as data within <strong>the</strong> quoted string ra<strong>the</strong>r than <strong>the</strong> closing string<br />

terminator. If this input causes <strong>the</strong> error or anomalous behavior to disappear,<br />

<strong>the</strong> <strong>application</strong> is probably vulnerable to SQL injection.<br />

3. As a fur<strong>the</strong>r verification that a bug is present, you can use SQL concatenator<br />

characters to construct a string that is equivalent to some benign<br />

input. If <strong>the</strong> <strong>application</strong> handles your crafted input in <strong>the</strong> same way as it<br />

does <strong>the</strong> corresponding benign input, it is likely to be vulnerable. Each<br />

type of database uses different methods for string concatenation. The<br />

following examples can be injected to construct input that is equivalent to<br />

FOO in a vulnerable <strong>application</strong>:<br />

n Oracle: ‘||’FOO<br />

n MS-SQL: ‘+’FOO<br />

n MySQL: ‘ ‘FOO (note <strong>the</strong> space between <strong>the</strong> two quotes)<br />

TIP One way of confirming that <strong>the</strong> <strong>application</strong> is interacting with a backend<br />

database is to submit <strong>the</strong> SQL wildcard character % in a given parameter.<br />

For example, submitting this in a search field often returns a large number of<br />

results, indicating that <strong>the</strong> input is being passed into a SQL query. Of course,<br />

this does not necessarily indicate that <strong>the</strong> <strong>application</strong> is vulnerable — only that<br />

you should probe fur<strong>the</strong>r to identify any actual flaws.<br />

TIP While looking for SQL injection using a single quote, keep an eye<br />

out for any JavaScript errors occurring when your browser processes <strong>the</strong><br />

returned page. It is fairly common for user-supplied input to be returned<br />

within JavaScript, and an unsanitized single quote will cause an error in <strong>the</strong><br />

JavaScript interpreter, just as it does in <strong>the</strong> SQL interpreter. The ability to<br />

inject arbitrary JavaScript into responses allows cross-site scripting attacks, as<br />

described in Chapter 12.<br />

Injecting into Numeric Data<br />

When user-supplied numeric data is incorporated into a SQL query, <strong>the</strong> <strong>application</strong><br />

may still handle this as string data by encapsulating it within single quotation<br />

marks. Therefore, you should always follow <strong>the</strong> steps described previously for string<br />

data. In most cases, however, numeric data is passed directly to <strong>the</strong> database in<br />

numeric form and <strong>the</strong>refore is not placed within single quotation marks. If none<br />

of <strong>the</strong> previous tests points toward <strong>the</strong> presence of a vulnerability, you can take<br />

some o<strong>the</strong>r specific steps in relation to numeric data.

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

Saved successfully!

Ooh no, something went wrong!