From 5f725e09db0df800af582fb06fec3eac05cf2f92 Mon Sep 17 00:00:00 2001 From: cbrnrd Date: Thu, 12 Apr 2018 09:15:44 -0400 Subject: [PATCH] Make nosuid? and noexec? take a filepath as param --- lib/msf/core/post/linux/system.rb | 34 +++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/msf/core/post/linux/system.rb b/lib/msf/core/post/linux/system.rb index a30a542df8..f7301de143 100644 --- a/lib/msf/core/post/linux/system.rb +++ b/lib/msf/core/post/linux/system.rb @@ -243,11 +243,12 @@ module System end # - # Checks if `mount_path` is mounted with noexec + # Checks if `file_path` is mounted on a noexec mount point # @return [Boolean] # - def noexec?(mount_path) + def noexec?(file_path) mount = cmd_exec('cat /proc/mounts').to_s + mount_path = get_mount_path(file_path) mount.lines.each do |l| return true if l =~ Regexp.new("#{mount_path} (.*)noexec(.*)") end @@ -257,11 +258,12 @@ module System end # - # Checks if `mount_path` is mounted with nosuid + # Checks if `file_path` is mounted on a nosuid mount point # @return [Boolean] # - def nosuid?(mount_path) + def nosuid?(file_path) mount = cmd_exec('cat /proc/mounts').to_s + mount_path = get_mount_path(file_path) mount.lines.each do |l| return true if l =~ Regexp.new("#{mount_path} (.*)nosuid(.*)") end @@ -290,6 +292,30 @@ module System raise 'Could not determine protected_symlinks status' end + # + # Gets the version of glibc + # @return [String] + # + def glibc_version + if !command_exists? 'ldd' + raise 'glibc is not installed' + end + cmd_exec('ldd --version').scan(/^ldd\s+\(.*\)\s+([\d.]+)/).flatten.first + rescue + raise 'Could not determine glibc version' + end + + # + # Gets the mount point of `filepath` + # @param [String] filepath The filepath to get the mount point + # @return [String] + # + def get_mount_path_of(filepath) + cmd_exec("df \"#{filepath}\" | tail -1").split(' ')[5] + rescue + raise "Unable to get mount path of #{filepath}" + end + end # System end # Linux