Skip to content

Commit

Permalink
Land rapid7#8987, Fix opening non-existant files on unix
Browse files Browse the repository at this point in the history
  • Loading branch information
pbarry-r7 committed Sep 22, 2017
2 parents 68fa3d4 + 36fc01d commit 8853193
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions lib/msf/core/post/unix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ def get_users
#
def get_groups
groups = []
cmd_out = read_file("/etc/group").split("\n")
cmd_out.each do |l|
entry = {}
user_field = l.split(":")
entry[:name] = user_field[0]
entry[:gid] = user_field[2]
entry[:users] = user_field[3]
groups << entry
group = '/etc/group'
if file_exist?(group)
cmd_out = read_file(group).split("\n")
cmd_out.each do |l|
entry = {}
user_field = l.split(":")
entry[:name] = user_field[0]
entry[:gid] = user_field[2]
entry[:users] = user_field[3]
groups << entry
end
end
return groups
end
Expand All @@ -59,8 +62,11 @@ def enum_user_directories
user_dirs = []

# get all user directories from /etc/passwd
read_file("/etc/passwd").each_line do |passwd_line|
user_dirs << passwd_line.split(/:/)[5]
passwd = '/etc/passwd'
if file_exist?(passwd)
read_file(passwd).each_line do |passwd_line|
user_dirs << passwd_line.split(/:/)[5]
end
end

# also list other common places for home directories in the event that
Expand Down

0 comments on commit 8853193

Please sign in to comment.