Skip to content

Commit

Permalink
Update nis_ypserv_map after bootparam feedback
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wvu committed Jan 13, 2018
1 parent c080329 commit 1a8eb7b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
6 changes: 5 additions & 1 deletion modules/auxiliary/gather/nis_bootparamd_domain.rb
Expand Up @@ -133,7 +133,11 @@ def parse_bootparams(res)
Integer # Router Address: [redacted]
)

host && domain ? bootparams[host] = domain : break
if host && domain
bootparams[host] = domain
else
break
end
rescue Rex::ArgumentError
vprint_status("Finished XDR decoding at #{res.inspect}")
break
Expand Down
32 changes: 16 additions & 16 deletions modules/auxiliary/gather/nis_ypserv_map.rb
Expand Up @@ -58,11 +58,9 @@ def run
2 # Program Version: 2
)
rescue Rex::ConnectionError
print_error('Could not connect to portmapper')
return
fail_with(Failure::Unreachable, 'Could not connect to portmapper')
rescue Rex::Proto::SunRPC::RPCError
print_error('Could not connect to ypserv')
return
fail_with(Failure::Unreachable, 'Could not connect to ypserv')
end

# Flavor: AUTH_NULL (0)
Expand All @@ -80,41 +78,39 @@ def run
ypserv_all_call # Yellow Pages Service ALL call
)
rescue Rex::Proto::SunRPC::RPCError
print_error('Could not call ypserv procedure')
return
fail_with(Failure::NotFound, 'Could not call ypserv procedure')
ensure
# Shut it down! Shut it down forever!
sunrpc_destroy
end

if res.nil? || res.length < 8
print_error('Invalid response from server')
unless res && res.length > 8
fail_with(Failure::UnexpectedReply, 'Invalid response from server')
return
end

# XXX: Rex::Encoder::XDR doesn't do signed ints
case res[4, 4].unpack('l>').first
# Status: YP_NOMAP (-1)
when -1
print_error("Invalid map #{map_name} specified")
return
fail_with(Failure::BadConfig, "Invalid map #{map_name} specified")
# Status: YP_NODOM (-2)
when -2
print_error("Invalid domain #{domain} specified")
return
fail_with(Failure::BadConfig, "Invalid domain #{domain} specified")
end

map = begin
Timeout.timeout(datastore['XDRTimeout']) do
parse_map(res)
end
rescue Timeout::Error
print_error('XDR decoding timed out (try increasing XDRTimeout?)')
fail_with(Failure::TimeoutExpired,
'XDR decoding timed out (try increasing XDRTimeout?)')
return
end

if map.nil? || map.empty?
print_error("Could not parse map #{map_name}")
if map.blank?
fail_with(Failure::Unknown, "Could not parse map #{map_name}")
return
end

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

status == 1 ? map[key] = value : break
if status == 1 && key && value
map[key] = value
else
break
end
rescue Rex::ArgumentError
vprint_status("Finished XDR decoding at #{res.inspect}")
break
Expand Down

0 comments on commit 1a8eb7b

Please sign in to comment.