Skip to content

Commit 9fdf2ca

Browse files
author
Brent Cook
committed
Land rapid7#8830, Cleanup auxiliary/scanner/msf/msf_rpc_login
2 parents 59086af + fa4fae3 commit 9fdf2ca

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

modules/auxiliary/scanner/msf/msf_rpc_login.rb

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,25 @@
33
# Current source: https://github.com/rapid7/metasploit-framework
44
##
55

6+
require 'msf/core/rpc/v10/client'
7+
68
class MetasploitModule < Msf::Auxiliary
9+
include Msf::Exploit::Remote::Tcp
710
include Msf::Auxiliary::Report
811
include Msf::Auxiliary::AuthBrute
912
include Msf::Auxiliary::Scanner
1013

11-
def initialize
12-
super(
14+
def initialize(info = {})
15+
super(update_info(info,
1316
'Name' => 'Metasploit RPC Interface Login Utility',
1417
'Description' => %q{
1518
This module simply attempts to login to a
1619
Metasploit RPC interface using a specific
1720
user/pass.
1821
},
19-
'Author' => [ 'Vlatko Kosturjak <kost[at]linux.hr>' ],
20-
'License' => MSF_LICENSE
21-
)
22+
'Author' => [ 'Vlatko Kosturjak <kost[at]linux.hr>' ],
23+
'License' => MSF_LICENSE
24+
))
2225

2326
register_options(
2427
[
@@ -27,34 +30,21 @@ def initialize
2730
OptBool.new('BLANK_PASSWORDS', [false, "Try blank passwords for all users", false]),
2831
OptBool.new('SSL', [ true, "Negotiate SSL for outgoing connections", true])
2932
])
30-
register_autofilter_ports([3790])
3133

32-
end
33-
34-
@@loaded_msfrpc = false
35-
begin
36-
require 'msf/core/rpc/v10/client'
37-
@@loaded_msfrpc = true
38-
rescue LoadError
34+
register_autofilter_ports([3790])
3935
end
4036

4137
def run_host(ip)
42-
43-
unless @@loaded_msfrpc
44-
print_error("You don't have 'msgpack', please install that gem manually.")
45-
return
46-
end
47-
4838
begin
4939
@rpc = Msf::RPC::Client.new(
50-
:host => datastore['RHOST'],
51-
:port => datastore['RPORT'],
52-
:ssl => datastore['SSL']
40+
:host => rhost,
41+
:port => rport,
42+
:ssl => ssl
5343
)
5444
rescue ::Interrupt
5545
raise $!
56-
rescue ::Exception => e
57-
vprint_error("#{datastore['SSL'].to_s} Cannot create RPC client : #{e.to_s}")
46+
rescue => e
47+
vprint_error("Cannot create RPC client : #{e}")
5848
return
5949
end
6050

@@ -90,27 +80,29 @@ def report_cred(opts)
9080
create_credential_login(login_data)
9181
end
9282

93-
def do_login(user='msf', pass='msf')
83+
def do_login(user = 'msf', pass = 'msf')
9484
vprint_status("Trying username:'#{user}' with password:'#{pass}'")
9585
begin
9686
res = @rpc.login(user, pass)
9787
if res
9888
print_good("SUCCESSFUL LOGIN. '#{user}' : '#{pass}'")
9989
report_cred(
100-
ip: datastore['RHOST'],
101-
port: datastore['RPORT'],
90+
ip: rhost,
91+
port: rport,
10292
service_name: 'msf-rpc',
10393
user: user,
104-
password: pass,
105-
proof: res.body
94+
password: pass
10695
)
107-
@rpc.close
10896
return :next_user
10997
end
110-
rescue => e
111-
vprint_status("#{datastore['SSL'].to_s} - Bad login")
112-
@rpc.close
98+
rescue Rex::ConnectionRefused => e
99+
print_error("Connection refused : #{e}")
100+
return :abort
101+
rescue => e
102+
vprint_status("#{peer} - Bad login")
113103
return :skip_pass
114104
end
105+
ensure
106+
@rpc.close
115107
end
116108
end

0 commit comments

Comments
 (0)