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.

294 Chapter 9 n Attacking Data Stores<br />

TIP In some situations, an alternative way to handle <strong>the</strong> trailing quotation<br />

mark without using <strong>the</strong> comment symbol is to “balance <strong>the</strong> quotes.” You finish<br />

<strong>the</strong> injected input with an item of string data that requires a trailing quote<br />

to encapsulate it. For example, entering <strong>the</strong> search term:<br />

Wiley’ OR ‘a’ = ‘a<br />

results in <strong>the</strong> query:<br />

SELECT author,title,year FROM books WHERE publisher = ‘Wiley’ OR<br />

‘a’=’a’ and published=1<br />

This is perfectly valid and achieves <strong>the</strong> same result as <strong>the</strong> 1 = 1 attack to<br />

return all books published by Wiley, regardless of whe<strong>the</strong>r <strong>the</strong>y have been<br />

published.<br />

This example shows how <strong>application</strong> logic can be bypassed, allowing an access<br />

control flaw in which <strong>the</strong> attacker can view all books, not just books matching<br />

<strong>the</strong> allowed filter (showing published books). However, we will describe<br />

shortly how SQL injection flaws like this can be used to extract arbitrary data<br />

from different database tables and to escalate privileges within <strong>the</strong> database<br />

and <strong>the</strong> database server. For this reason, any SQL injection vulnerability should<br />

be regarded as extremely serious, regardless of its precise context within <strong>the</strong><br />

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

Injecting into Different Statement Types<br />

The SQL language contains a number of verbs that may appear at <strong>the</strong> beginning<br />

of statements. Because it is <strong>the</strong> most commonly used verb, <strong>the</strong> majority of SQL<br />

injection vulnerabilities arise within SELECT statements. Indeed, discussions<br />

about SQL injection often give <strong>the</strong> impression that <strong>the</strong> vulnerability occurs only<br />

in connection with SELECT statements, because <strong>the</strong> examples used are all of this<br />

type. However, SQL injection flaws can exist within any type of statement. You<br />

need to be aware of some important considerations in relation to each.<br />

Of course, when you are interacting with a remote <strong>application</strong>, it usually is<br />

not possible to know in advance what type of statement a given item of user<br />

input will be processed by. However, you can usually make an educated guess<br />

based on <strong>the</strong> type of <strong>application</strong> function you are dealing with. The most common<br />

types of SQL statements and <strong>the</strong>ir uses are described here.<br />

SELECT Statements<br />

SELECT statements are used to retrieve information from <strong>the</strong> database. They are<br />

frequently employed in functions where <strong>the</strong> <strong>application</strong> returns information in<br />

response to user actions, such as browsing a product catalog, viewing a user’s

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

Saved successfully!

Ooh no, something went wrong!