diff --git a/lib/msf/core/exploit/sunrpc.rb b/lib/msf/core/exploit/sunrpc.rb index e315742419..741d1b1a29 100644 --- a/lib/msf/core/exploit/sunrpc.rb +++ b/lib/msf/core/exploit/sunrpc.rb @@ -68,7 +68,7 @@ module Exploit::Remote::SunRPC end ret = rpcobj.create - return print_error("#{rhost}:#{rport} - SunRPC - No response to Portmap request") unless ret + raise ::Rex::Proto::SunRPC::RPCError, "#{rhost}:#{rport} - SunRPC - No response to Portmap request" unless ret arr = XDR.decode!(ret, Integer, Integer, Integer, String, Integer, Integer) if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS || arr[5] == 0 @@ -76,18 +76,15 @@ module Exploit::Remote::SunRPC err << 'Message not accepted' if arr[1] != MSG_ACCEPTED err << 'RPC did not execute' if arr[4] != SUCCESS err << 'Program not available' if arr[5] == 0 - print_error(err) - return nil + raise ::Rex::Proto::SunRPC::RPCError, err end rpcobj.pport = arr[5] - #progname = progresolv(rpcobj.program) - #print_status("#{rhost} - SunRPC Found #{progname} on #{protocol} port #{rpcobj.pport}") end def sunrpc_call(proc, buf, timeout=20) ret = rpcobj.call(proc, buf, timeout) - return print_error("#{rhost}:#{rport} - SunRPC - No response to SunRPC call for procedure: #{proc}") unless ret + raise ::Rex::Proto::SunRPC::RPCError, "#{rhost}:#{rport} - SunRPC - No response to SunRPC call for procedure: #{proc}" unless ret arr = Rex::Encoder::XDR.decode!(ret, Integer, Integer, Integer, String, Integer) if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS @@ -105,8 +102,7 @@ module Exploit::Remote::SunRPC else err << "Unknown Error" end end - print_error("#{rhost}:#{rport} - SunRPC - #{err}") - return nil + raise ::Rex::Proto::SunRPC::RPCError, "#{rhost}:#{rport} - SunRPC - #{err}" end return ret end @@ -142,8 +138,7 @@ module Exploit::Remote::SunRPC when GARBAGE_ARGS then err << "Garbage Arguments" else err << "Unknown Error" end - print_error("#{rhost}:#{rport} - SunRPC - #{err}") - return nil + raise ::Rex::Proto::SunRPC::RPCError, "#{rhost}:#{rport} - SunRPC - #{err}" end return ret diff --git a/lib/rex/proto/sunrpc/client.rb b/lib/rex/proto/sunrpc/client.rb index b96e9c6f46..25847a81c0 100644 --- a/lib/rex/proto/sunrpc/client.rb +++ b/lib/rex/proto/sunrpc/client.rb @@ -6,10 +6,21 @@ module Rex module Proto module SunRPC +class RPCError < ::StandardError + def initialize(msg = 'RPC operation failed') + super + @msg = msg + end + + def to_s + @msg + end +end + class RPCTimeout < ::Interrupt - def initialize(msg = 'Operation timed out.') - @msg = msg - end + def initialize(msg = 'Operation timed out.') + @msg = msg + end def to_s @msg diff --git a/modules/auxiliary/scanner/misc/sunrpc_portmapper.rb b/modules/auxiliary/scanner/misc/sunrpc_portmapper.rb index 8d90d62190..79e0140fbf 100644 --- a/modules/auxiliary/scanner/misc/sunrpc_portmapper.rb +++ b/modules/auxiliary/scanner/misc/sunrpc_portmapper.rb @@ -35,7 +35,7 @@ class Metasploit3 < Msf::Auxiliary progver = 2 procedure = 4 - sunrpc_create('udp', program, progver) + return unless sunrpc_create('udp', program, progver) sunrpc_authnull resp = sunrpc_call(procedure, "") @@ -80,7 +80,8 @@ class Metasploit3 < Msf::Auxiliary end print_good(table.to_s) - rescue ::Rex::Proto::SunRPC::RPCTimeout + rescue ::Rex::Proto::SunRPC::RPCTimeout, ::Rex::Proto::SunRPC::RPCError => e + vprint_error(e.to_s) end end end