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.

358 Chapter 8 • Code-Level <strong>Defense</strong>s<br />

You can use the preceding functions as shown in the following examples. The first<br />

code snippet is an insecure query without dbms_assert (<strong>SQL</strong> injection in FIELD, OWNER,<br />

<strong>and</strong> TABLE):<br />

execute immediate 'select '|| FIELD ||'<br />

from'|| OWNER ||'.'|| TABLE;<br />

Here is the same query, with input validation using dbms_assert:<br />

execute immediate 'select '||sys.dbms_assert.SIMPLE_<strong>SQL</strong>_NAME(FIELD) ||'<br />

from'||sys.dbms_assert.ENQUOTE_NAME<br />

(sys.dbms_assert.SCHEMA_NAME(OWNER),FALSE)<br />

||'.'||sys.dbms_assert.QUALIFIED_<strong>SQL</strong>_NAME(TABLE);<br />

Table 8.3 lists the various functions supported by dbms_assert.<br />

Table 8.3 dbms_assert Functions<br />

Function<br />

DBMS_ASSERT.SCHEMA_NAME<br />

DBMS_ASSERT.SIMPLE_<strong>SQL</strong>_NAME<br />

DBMS_ASSERT.<strong>SQL</strong>_OBJECT_NAME<br />

DBMS_ASSERT.SIMPLE_<strong>SQL</strong>_NAME<br />

DBMS_ASSERT.QUALIFIED_<strong>SQL</strong>_NAME<br />

DBMS_ASSERT.ENQUOTE_LITERAL<br />

DBMS_ASSERT.ENQUOTE_NAME<br />

Description<br />

This function checks to see whether the passed<br />

string is an existing object in the database<br />

This function checks that characters in an <strong>SQL</strong><br />

element consist only of A–Z, a–z, 0–9, $, #, <strong>and</strong> _.<br />

If the parameter is quoted with double quotes,<br />

everything with the exception of double quotes<br />

is allowed<br />

This function checks to see whether the passed<br />

string is an existing object in the database<br />

This function checks that characters in an <strong>SQL</strong><br />

element consist only of A–Z, a–z, 0–9, $, #, <strong>and</strong> _.<br />

If the parameter is quoted with double quotes,<br />

everything with the exception of double quotes<br />

is allowed<br />

This function is very similar to the SIMPLE_<strong>SQL</strong>_<br />

NAME function but also allows database links<br />

This function quotes the passed argument in<br />

double quotes. If the argument was already<br />

quoted, nothing will be done<br />

This function encloses the user-supplied string in<br />

single quotes if it has not already been done

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

Saved successfully!

Ooh no, something went wrong!