Skip to content

Commit 1a8eb7b

Browse files
committed
Update nis_ypserv_map after bootparam feedback
Yes, yes, I see the off-by-one "error." It's more accurate this way. Basically, we want to ensure there's actually data to dump.
1 parent c080329 commit 1a8eb7b

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

modules/auxiliary/gather/nis_bootparamd_domain.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ def parse_bootparams(res)
133133
Integer # Router Address: [redacted]
134134
)
135135

136-
host && domain ? bootparams[host] = domain : break
136+
if host && domain
137+
bootparams[host] = domain
138+
else
139+
break
140+
end
137141
rescue Rex::ArgumentError
138142
vprint_status("Finished XDR decoding at #{res.inspect}")
139143
break

modules/auxiliary/gather/nis_ypserv_map.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ def run
5858
2 # Program Version: 2
5959
)
6060
rescue Rex::ConnectionError
61-
print_error('Could not connect to portmapper')
62-
return
61+
fail_with(Failure::Unreachable, 'Could not connect to portmapper')
6362
rescue Rex::Proto::SunRPC::RPCError
64-
print_error('Could not connect to ypserv')
65-
return
63+
fail_with(Failure::Unreachable, 'Could not connect to ypserv')
6664
end
6765

6866
# Flavor: AUTH_NULL (0)
@@ -80,41 +78,39 @@ def run
8078
ypserv_all_call # Yellow Pages Service ALL call
8179
)
8280
rescue Rex::Proto::SunRPC::RPCError
83-
print_error('Could not call ypserv procedure')
84-
return
81+
fail_with(Failure::NotFound, 'Could not call ypserv procedure')
8582
ensure
8683
# Shut it down! Shut it down forever!
8784
sunrpc_destroy
8885
end
8986

90-
if res.nil? || res.length < 8
91-
print_error('Invalid response from server')
87+
unless res && res.length > 8
88+
fail_with(Failure::UnexpectedReply, 'Invalid response from server')
9289
return
9390
end
9491

9592
# XXX: Rex::Encoder::XDR doesn't do signed ints
9693
case res[4, 4].unpack('l>').first
9794
# Status: YP_NOMAP (-1)
9895
when -1
99-
print_error("Invalid map #{map_name} specified")
100-
return
96+
fail_with(Failure::BadConfig, "Invalid map #{map_name} specified")
10197
# Status: YP_NODOM (-2)
10298
when -2
103-
print_error("Invalid domain #{domain} specified")
104-
return
99+
fail_with(Failure::BadConfig, "Invalid domain #{domain} specified")
105100
end
106101

107102
map = begin
108103
Timeout.timeout(datastore['XDRTimeout']) do
109104
parse_map(res)
110105
end
111106
rescue Timeout::Error
112-
print_error('XDR decoding timed out (try increasing XDRTimeout?)')
107+
fail_with(Failure::TimeoutExpired,
108+
'XDR decoding timed out (try increasing XDRTimeout?)')
113109
return
114110
end
115111

116-
if map.nil? || map.empty?
117-
print_error("Could not parse map #{map_name}")
112+
if map.blank?
113+
fail_with(Failure::Unknown, "Could not parse map #{map_name}")
118114
return
119115
end
120116

@@ -140,7 +136,11 @@ def parse_map(res)
140136
String # Key: [redacted]
141137
)
142138

143-
status == 1 ? map[key] = value : break
139+
if status == 1 && key && value
140+
map[key] = value
141+
else
142+
break
143+
end
144144
rescue Rex::ArgumentError
145145
vprint_status("Finished XDR decoding at #{res.inspect}")
146146
break

0 commit comments

Comments
 (0)