Skip to content

Commit a9f9a8b

Browse files
committed
Introduce new ::Rex::Proto::SunRPC::RPCError, making run_host cleaner
1 parent c7794a7 commit a9f9a8b

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

lib/msf/core/exploit/sunrpc.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,26 +68,23 @@ def sunrpc_create(protocol, program, version)
6868
end
6969

7070
ret = rpcobj.create
71-
return print_error("#{rhost}:#{rport} - SunRPC - No response to Portmap request") unless ret
71+
raise ::Rex::Proto::SunRPC::RPCError, "#{rhost}:#{rport} - SunRPC - No response to Portmap request" unless ret
7272

7373
arr = XDR.decode!(ret, Integer, Integer, Integer, String, Integer, Integer)
7474
if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS || arr[5] == 0
7575
err = "#{rhost}:#{rport} - SunRPC - Portmap request failed: "
7676
err << 'Message not accepted' if arr[1] != MSG_ACCEPTED
7777
err << 'RPC did not execute' if arr[4] != SUCCESS
7878
err << 'Program not available' if arr[5] == 0
79-
print_error(err)
80-
return nil
79+
raise ::Rex::Proto::SunRPC::RPCError, err
8180
end
8281

8382
rpcobj.pport = arr[5]
84-
#progname = progresolv(rpcobj.program)
85-
#print_status("#{rhost} - SunRPC Found #{progname} on #{protocol} port #{rpcobj.pport}")
8683
end
8784

8885
def sunrpc_call(proc, buf, timeout=20)
8986
ret = rpcobj.call(proc, buf, timeout)
90-
return print_error("#{rhost}:#{rport} - SunRPC - No response to SunRPC call for procedure: #{proc}") unless ret
87+
raise ::Rex::Proto::SunRPC::RPCError, "#{rhost}:#{rport} - SunRPC - No response to SunRPC call for procedure: #{proc}" unless ret
9188

9289
arr = Rex::Encoder::XDR.decode!(ret, Integer, Integer, Integer, String, Integer)
9390
if arr[1] != MSG_ACCEPTED || arr[4] != SUCCESS
@@ -105,8 +102,7 @@ def sunrpc_call(proc, buf, timeout=20)
105102
else err << "Unknown Error"
106103
end
107104
end
108-
print_error("#{rhost}:#{rport} - SunRPC - #{err}")
109-
return nil
105+
raise ::Rex::Proto::SunRPC::RPCError, "#{rhost}:#{rport} - SunRPC - #{err}"
110106
end
111107
return ret
112108
end
@@ -142,8 +138,7 @@ def portmap_qry()
142138
when GARBAGE_ARGS then err << "Garbage Arguments"
143139
else err << "Unknown Error"
144140
end
145-
print_error("#{rhost}:#{rport} - SunRPC - #{err}")
146-
return nil
141+
raise ::Rex::Proto::SunRPC::RPCError, "#{rhost}:#{rport} - SunRPC - #{err}"
147142
end
148143

149144
return ret

lib/rex/proto/sunrpc/client.rb

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@ module Rex
66
module Proto
77
module SunRPC
88

9+
class RPCError < ::StandardError
10+
def initialize(msg = 'RPC operation failed')
11+
super
12+
@msg = msg
13+
end
14+
15+
def to_s
16+
@msg
17+
end
18+
end
19+
920
class RPCTimeout < ::Interrupt
10-
def initialize(msg = 'Operation timed out.')
11-
@msg = msg
12-
end
21+
def initialize(msg = 'Operation timed out.')
22+
@msg = msg
23+
end
1324

1425
def to_s
1526
@msg

modules/auxiliary/scanner/misc/sunrpc_portmapper.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def run_host(ip)
3535
progver = 2
3636
procedure = 4
3737

38-
sunrpc_create('udp', program, progver)
38+
return unless sunrpc_create('udp', program, progver)
3939
sunrpc_authnull
4040
resp = sunrpc_call(procedure, "")
4141

@@ -80,7 +80,8 @@ def run_host(ip)
8080
end
8181

8282
print_good(table.to_s)
83-
rescue ::Rex::Proto::SunRPC::RPCTimeout
83+
rescue ::Rex::Proto::SunRPC::RPCTimeout, ::Rex::Proto::SunRPC::RPCError => e
84+
vprint_error(e.to_s)
8485
end
8586
end
8687
end

0 commit comments

Comments
 (0)