diff --git a/lib/msf/core/post/file.rb b/lib/msf/core/post/file.rb index e25616931be1..06a1452aa911 100644 --- a/lib/msf/core/post/file.rb +++ b/lib/msf/core/post/file.rb @@ -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 # @@ -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