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.

50 Chapter 2 • Testing for <strong>SQL</strong> <strong>Injection</strong><br />

ORA-01756: quoted string not properly terminated<br />

System.Web.HttpUnh<strong>and</strong>ledException: Exception of type<br />

'System.Web.HttpUnh<strong>and</strong>ledException' was thrown. ---><br />

System.Data.OleDb.OleDbException: ORA-01756: quoted string not properly<br />

terminated<br />

The PHP function ociparse( ) is used to prepare an Oracle statement for execution. Here<br />

is an example of the error generated by the PHP engine when the function fails:<br />

Warning: ociparse() [function.ociparse]: ORA-01756: quoted string not<br />

properly terminated in /var/www/victim.com/ocitest.php on line 31<br />

If the ociparse( ) function fails <strong>and</strong> the error is not h<strong>and</strong>led, the application may show<br />

some other errors as a consequence of the first failure. This is an example:<br />

Warning: ociexecute(): supplied argument is not a valid OCI8-Statement<br />

resource in c:\www\victim.com\oracle\index.php on line 31<br />

As you read this book, you will see that sometimes the success of an attack depends on<br />

the information disclosed by the database server. Let’s examine the following error:<br />

java.sql.<strong>SQL</strong>Exception: ORA-00907: missing right parenthesis<br />

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at<br />

oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289) at<br />

oracle.jdbc.ttc7.Oall7.receive(Oall7.java:582) at<br />

oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1986)<br />

The database reports that there is a missing right parenthesis in the <strong>SQL</strong> statement.<br />

This error can be returned for a number of reasons. A very typical situation of this is<br />

presented when an attacker has some kind of control in a nested <strong>SQL</strong> statement.<br />

For example:<br />

SELECT field1, field2,<br />

/* Select the first <strong>and</strong> second fields*/<br />

(SELECT field1 /* Start subquery */<br />

FROM table2<br />

WHERE something = [attacker controlled variable]) /* End subquery */<br />

as field3 /* result from subquery */<br />

FROM table1<br />

The preceding example shows a nested subquery. The main SELECT executes another<br />

SELECT enclosed in parentheses. If the attacker injects something in the second query <strong>and</strong><br />

comments out the rest of the <strong>SQL</strong> statement, Oracle will return a missing right parenthesis error.

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

Saved successfully!

Ooh no, something went wrong!