Introduce new ::Rex::Proto::SunRPC::RPCError, making run_host cleaner

bug/bundler_fix
Jon Hart 2014-10-21 10:54:52 -07:00
parent c7794a7ed9
commit a9f9a8b116
3 changed files with 22 additions and 15 deletions

View File

@ -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

View File

@ -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

View File

@ -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