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.

324 Chapter 9 n Attacking Data Stores<br />

connect to a nonexistent server, causing a timeout. This causes <strong>the</strong> database<br />

to attempt to connect to <strong>the</strong> specified server and eventually time out. For<br />

example:<br />

SELECT ‘a’||Utl_Http.request(‘http://madeupserver.com’) from dual<br />

...delay...<br />

ORA-29273: HTTP request failed<br />

ORA-06512: at “SYS.UTL_HTTP”, line 1556<br />

ORA-12545: Connect failed because target host or object does not exist<br />

You can leverage this behavior to cause a time delay contingent on some<br />

condition that you specify. For example, <strong>the</strong> following query causes a timeout<br />

if <strong>the</strong> default Oracle account DBSNMP exists:<br />

SELECT ‘a’||Utl_Http.request(‘http://madeupserver.com’) FROM dual WHERE<br />

(SELECT username FROM all_users WHERE username = ‘DBSNMP’) = ‘DBSNMP’<br />

In both Oracle and MySQL databases, you can use <strong>the</strong> SUBSTR(ING)and ASCII<br />

functions to retrieve arbitrary information one byte at a time, as described<br />

previously.<br />

TIP We have described <strong>the</strong> use of time delays as a means of extracting<br />

interesting information. However, <strong>the</strong> time-delay technique can also be<br />

immensely useful when performing initial probing of an <strong>application</strong> to<br />

detect SQL injection vulnerabilities. In some cases of completely blind<br />

SQL injection, where no results are returned to <strong>the</strong> browser and all errors<br />

are handled invisibly, <strong>the</strong> vulnerability itself may be hard to detect using<br />

standard techniques based on supplying crafted input. In this situation,<br />

using time delays is often <strong>the</strong> most reliable way to detect <strong>the</strong> presence of a<br />

vulnerability during initial probing. For example, if <strong>the</strong> back-end database<br />

is MS-SQL, you can inject each of <strong>the</strong> following strings into each request<br />

parameter in turn and monitor how long <strong>the</strong> <strong>application</strong> takes to identify<br />

any vulnerabilities:<br />

‘; waitfor delay ‘0:30:0’--<br />

1; waitfor delay ‘0:30:0’--<br />

TRY IT!<br />

This lab example contains a SQL injection vulnerability with no error feedback.<br />

You can use it to practice various advanced techniques, including <strong>the</strong><br />

use of conditional responses and time delays.<br />

http://mdsec.net/addressbook/44/

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

Saved successfully!

Ooh no, something went wrong!