Path: blob/master/modules/auxiliary/scanner/msf/msf_rpc_login.rb
19593 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::Tcp7include Msf::Auxiliary::Report8include Msf::Auxiliary::AuthBrute9include Msf::Auxiliary::Scanner1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Metasploit RPC Interface Login Utility',16'Description' => %q{17This module simply attempts to login to a18Metasploit RPC interface using a specific19user/pass.20},21'Author' => [ 'Vlatko Kosturjak <kost[at]linux.hr>' ],22'License' => MSF_LICENSE,23'Notes' => {24'Reliability' => UNKNOWN_RELIABILITY,25'Stability' => UNKNOWN_STABILITY,26'SideEffects' => UNKNOWN_SIDE_EFFECTS27}28)29)3031register_options(32[33Opt::RPORT(55553),34OptString.new('USERNAME', [true, "A specific username to authenticate as. Default is msf", "msf"]),35OptBool.new('BLANK_PASSWORDS', [false, "Try blank passwords for all users", false]),36OptBool.new('SSL', [ true, "Negotiate SSL for outgoing connections", true])37]38)3940register_autofilter_ports([3790])41end4243def run_host(ip)44begin45@rpc = Msf::RPC::Client.new(46:host => rhost,47:port => rport,48:ssl => ssl49)50rescue ::Interrupt51raise $!52rescue => e53vprint_error("Cannot create RPC client : #{e}")54return55end5657each_user_pass do |user, pass|58do_login(user, pass)59end60end6162def report_cred(opts)63service_data = {64address: opts[:ip],65port: opts[:port],66service_name: opts[:service_name],67protocol: 'tcp',68workspace_id: myworkspace_id69}7071credential_data = {72origin_type: :service,73module_fullname: fullname,74username: opts[:user],75private_data: opts[:password],76private_type: :password77}.merge(service_data)7879login_data = {80last_attempted_at: Time.now,81core: create_credential(credential_data),82status: Metasploit::Model::Login::Status::SUCCESSFUL,83proof: opts[:proof]84}.merge(service_data)8586create_credential_login(login_data)87end8889def do_login(user = 'msf', pass = 'msf')90vprint_status("Trying username:'#{user}' with password:'#{pass}'")91begin92res = @rpc.login(user, pass)93if res94print_good("SUCCESSFUL LOGIN. '#{user}' : '#{pass}'")95report_cred(96ip: rhost,97port: rport,98service_name: 'msf-rpc',99user: user,100password: pass101)102return :next_user103end104rescue Rex::ConnectionRefused => e105print_error("Connection refused : #{e}")106return :abort107rescue => e108vprint_status("#{peer} - Bad login")109return :skip_pass110end111ensure112@rpc.close113end114end115116117