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.

Chapter 9 n Attacking Data Stores 311<br />

TIP When multiple columns are returned from a target table, <strong>the</strong>se can be<br />

concatenated into a single column. This makes retrieval more straightforward,<br />

because it requires identification of only a single varchar field in <strong>the</strong> original<br />

query:<br />

n Oracle: SELECT table_name||’:’||column_name FROM<br />

all_tab_columns<br />

n MS-SQL: SELECT table_name+’:’+column_name from information_<br />

schema.columns<br />

n MySQL: SELECT CONCAT(table_name,’:’,column_name) from<br />

information_schema.columns<br />

Bypassing Filters<br />

In some situations, an <strong>application</strong> that is vulnerable to SQL injection may implement<br />

various input filters that prevent you from exploiting <strong>the</strong> flaw without<br />

restrictions. For example, <strong>the</strong> <strong>application</strong> may remove or sanitize certain characters<br />

or may block common SQL keywords. Filters of this kind are often vulnerable<br />

to bypasses, so you should try numerous tricks in this situation.<br />

Avoiding Blocked Characters<br />

If <strong>the</strong> <strong>application</strong> removes or encodes some characters that are often used in<br />

SQL injection attacks, you may still be able to perform an attack without <strong>the</strong>se:<br />

n The single quotation mark is not required if you are injecting into a numeric<br />

data field or column name. If you need to introduce a string into your<br />

attack payload, you can do this without needing quotes. You can use<br />

various string functions to dynamically construct a string using <strong>the</strong> ASCII<br />

codes for individual characters. For example, <strong>the</strong> following two queries<br />

for Oracle and MS-SQL, respectively, are <strong>the</strong> equivalent of select ename,<br />

sal from emp where ename=’marcus’:<br />

SELECT ename, sal FROM emp where ename=CHR(109)||CHR(97)||<br />

CHR(114)||CHR(99)||CHR(117)||CHR(115)<br />

SELECT ename, sal FROM emp WHERE ename=CHAR(109)+CHAR(97)<br />

+CHAR(114)+CHAR(99)+CHAR(117)+CHAR(115)<br />

n If <strong>the</strong> comment symbol is blocked, you can often craft your injected data<br />

such that it does not break <strong>the</strong> syntax of <strong>the</strong> surrounding query, even<br />

without using this. For example, instead of injecting:<br />

‘ or 1=1--<br />

you can inject:<br />

‘ or ‘a’=’a

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

Saved successfully!

Ooh no, something went wrong!