Files
metasploit-gs/lib/msf/core/exploit/oracle.rb
T

105 lines
2.2 KiB
Ruby
Raw Normal View History

2009-07-14 03:55:32 +00:00
###
#
# This module provides methods for communicating with a host running oracle.
# Dependencies:
# - Oracle Instant Client
# - ruby-dbi
# - ruby-oci8
#
###
module Msf
module Exploit::ORACLE
def initialize(info = {})
super
register_options(
[
2009-10-16 18:27:18 +00:00
OptString.new('RHOST', [ true, 'The Oracle host.', '']),
OptString.new('RPORT', [ true, 'The TNS port.', '1521']),
OptString.new('SID', [ true, 'The sid to authenticate with.', 'ORCL']),
OptString.new('DBUSER', [ true, 'The username to authenticate with.', 'SCOTT']),
OptString.new('DBPASS', [ true, 'The password to authenticate with.', 'TIGER']),
2009-07-14 03:55:32 +00:00
], Msf::Exploit::ORACLE
)
2009-10-16 18:27:18 +00:00
2009-07-14 03:55:32 +00:00
begin
require 'rubygems'
gem 'dbi'
2009-07-14 03:55:32 +00:00
require 'dbi'
@havedbi = true
rescue ::LoadError
@havedbi = false
end
if(not @havedbi)
2009-07-14 03:55:32 +00:00
begin
require 'dbi'
@havedbi = true
rescue ::LoadError
@havedbi = false
2009-07-14 03:55:32 +00:00
end
end
end
def connect
print_status("Connecting to #{datastore['RHOST']}:#{datastore['RPORT']}/#{datastore['SID']}...")
2009-07-14 03:55:32 +00:00
if ( not @havedbi )
print_error("The dbi module is not available!")
raise RuntimeError, "The dbi module is not available!"
2009-07-14 03:55:32 +00:00
end
2009-07-14 03:55:32 +00:00
begin
handle = DBI.connect(
"DBI:OCI8://#{datastore['RHOST']}:#{datastore['RPORT']}/#{datastore['SID']}",
"#{datastore['DBUSER']}",
"#{datastore['DBPASS']}"
)
rescue ::DBI::DatabaseError => e
print_error("Oracle DB connection failed: #{e.class} #{e.to_s}")
handle.disconnect_all if handle
return
rescue ::Interrupt
raise $!
rescue DBI::InterfaceError
print_error("The Oracle Database Instant Client has not been installed")
raise RuntimeError, "Missing OCI8 DBI driver"
end
2009-07-14 03:55:32 +00:00
end
def disconnect
disconnect_all
end
def prepare_exec(exec)
begin
sploit = connect.prepare(exec)
sploit.execute
rescue DBI::DatabaseError => e
print_status("#{e.to_s}")
return
end
begin
sploit.each do | data |
print_status("#{data.join(",").to_s}")
end
print_status("Done...")
sploit.finish
rescue DBI::DatabaseError => e
#print_error("#{e.to_s}")
if ( e.to_s =~ /ORA-24374: define not done before fetch or execute and fetch/ )
2009-07-14 03:55:32 +00:00
print_status("Done...")
else
return
2009-07-14 03:55:32 +00:00
end
end
end
2009-07-14 03:55:32 +00:00
end
end