Skip to content

Commit

Permalink
Modify Post read_file to check if file is readable
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles committed Feb 1, 2019
1 parent 7633c28 commit 47a13ea
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/msf/core/post/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ def writable?(path)
cmd_exec("test -w '#{path}' && echo true").to_s.include? 'true'
end

#
# See if +path+ on the remote system exists and is readable
#
# @param path [String] Remote path to check
#
# @return [Boolean] true if +path+ exists and is readable
#
def readable?(path)
raise "`readable?' method does not support Windows systems" if session.platform == 'windows'

cmd_exec("test -r '#{path}' && echo true").to_s.include? 'true'
end

#
# Check for existence of +path+ on the remote file system
#
Expand Down Expand Up @@ -318,6 +331,8 @@ def read_file(file_name)
return session.shell_command_token("type \"#{file_name}\"")
end

return nil unless readable?(file_name)

if command_exists?('cat')
return session.shell_command_token("cat \"#{file_name}\"")
end
Expand Down

0 comments on commit 47a13ea

Please sign in to comment.