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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

) c<br />

/<br />

)<br />

)<br />

),<br />

bfilename('GETPWDIR', 'data-sources.xml'),<br />

nls_charset_id('WE8ISO8859P1')<br />

'/data-sources/connection-pool/connection-factory'<br />

Exploiting the Operating System • Chapter 6 291<br />

Instead of using the utl_ file_dir/Oracle directory concept, it is also possible to read <strong>and</strong><br />

write files using Java. You can find sample code for this approach on Marco Ivaldis’s Web site,<br />

at www.0xdeadbeef.info/exploits/raptor_oraexec.sql.<br />

A widely unknown technique for reading files <strong>and</strong> URIs is Oracle Text. This feature<br />

does not require Java or utl_ file_dir/Oracle directories. Just insert the file or URL you want<br />

to read into a table, <strong>and</strong> create a full text index or wait until the full text index is created.<br />

The index contains the contents of the entire file.<br />

The following sample code shows how to read the boot.ini file by inserting it into<br />

a table:<br />

CREATE TABLE files (<br />

id NUMBER PRIMARY KEY,<br />

path VARCHAR(255) UNIQUE,<br />

ot_format VARCHAR(6)<br />

);<br />

INSERT INTO files VALUES (1, 'c:\boot.ini', NULL);<br />

CREATE INDEX file_index ON files(path) INDEXTYPE IS ctxsys.context<br />

PARAMETERS ('datastore ctxsys.file_datastore format column ot_format');<br />

-- retrieve data from the fulltext index<br />

Select token_text from dr$file_index$i;<br />

Writing Files<br />

Writing files to the remote server is sometimes a bit of a throwback to the old days when<br />

an attacker would drop a text file on the remote host to prove that he “captured his flag.”<br />

Indeed, when so much value resides in the database itself, it sometimes seems strange to see<br />

people obsess about breaking out of the database. Writing files does, however, have its uses,<br />

<strong>and</strong> often it serves as the springboard toward compromising the host itself (which in turn<br />

serves as the beachhead for attacking the internal network).<br />

All of the common RDBMSs have built-in functionality for writing files to the server<br />

file system. These can be abused within <strong>SQL</strong> injection attacks to a lesser or greater degree<br />

depending on the family type of the underlying system.

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

Saved successfully!

Ooh no, something went wrong!