Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

guard Rex::Version.new against crashes on local modules #19813

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions modules/exploits/example_linux_priv_esc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,24 @@ def base_dir

def check
# Check the kernel version to see if its in a vulnerable range
# we guard this because some distros have funky kernel versions /~https://github.com/rapid7/metasploit-framework/issues/19812
release = kernel_release
if Rex::Version.new(release.split('-').first) > Rex::Version.new('4.14.11') ||
Rex::Version.new(release.split('-').first) < Rex::Version.new('4.0')
return CheckCode::Safe("Kernel version #{release} is not vulnerable")
begin
if Rex::Version.new(release.split('-').first) > Rex::Version.new('4.14.11') ||
Rex::Version.new(release.split('-').first) < Rex::Version.new('4.0')
return CheckCode::Safe("Kernel version #{release} is not vulnerable")
end
rescue ArgumentError => e
return CheckCode::Safe("Error determining or processing kernel release (#{release}) into known format: #{e}")
end
vprint_good "Kernel version #{release} appears to be vulnerable"

# Check the app is installed and the version, debian based example
package = cmd_exec('dpkg -l example | grep \'^ii\'')
if package&.include?('1:2015.3.14AR.1-1build1')
CheckCode::Appears("Vulnerable app version #{package} detected")
return CheckCode::Appears("Vulnerable app version #{package} detected")
end

CheckCode::Safe("app #{package} is not vulnerable")
end

Expand Down
18 changes: 11 additions & 7 deletions modules/exploits/linux/local/docker_cgroup_escape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,17 @@ def check
print_status('Unable to determine host OS, this check method is unlikely to be accurate if the host isn\'t Ubuntu')
release = kernel_release
# https://people.canonical.com/~ubuntu-security/cve/2022/CVE-2022-0492
release_short = Rex::Version.new(release.split('-').first)
release_long = Rex::Version.new(release.split('-')[0..1].join('-'))
if release_short >= Rex::Version.new('5.13.0') && release_long < Rex::Version.new('5.13.0-37.42') || # Ubuntu 21.10
release_short >= Rex::Version.new('5.4.0') && release_long < Rex::Version.new('5.4.0-105.119') || # Ubuntu 20.04 LTS
release_short >= Rex::Version.new('4.15.0') && release_long < Rex::Version.new('4.15.0-173.182') || # Ubuntu 18.04 LTS
release_short >= Rex::Version.new('4.4.0') && release_long < Rex::Version.new('4.4.0-222.255') # Ubuntu 16.04 ESM
return CheckCode::Vulnerable("IF host OS is Ubuntu, kernel version #{release} is vulnerable")
begin
release_short = Rex::Version.new(release.split('-').first)
release_long = Rex::Version.new(release.split('-')[0..1].join('-'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we re-join with '-' (which works on ubuntu where I tested it), this will fail on amazon linux.

if release_short >= Rex::Version.new('5.13.0') && release_long < Rex::Version.new('5.13.0-37.42') || # Ubuntu 21.10
release_short >= Rex::Version.new('5.4.0') && release_long < Rex::Version.new('5.4.0-105.119') || # Ubuntu 20.04 LTS
release_short >= Rex::Version.new('4.15.0') && release_long < Rex::Version.new('4.15.0-173.182') || # Ubuntu 18.04 LTS
release_short >= Rex::Version.new('4.4.0') && release_long < Rex::Version.new('4.4.0-222.255') # Ubuntu 16.04 ESM
return CheckCode::Vulnerable("IF host OS is Ubuntu, kernel version #{release} is vulnerable")
end
rescue ArgumentError => e
return CheckCode::Safe("Error determining or processing kernel release (#{release}) into known format: #{e}")
end

CheckCode::Safe("Kernel version #{release} may not be vulnerable depending on the host OS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def check
# 0 is ii for installed
# 1 is tomcat# for package name
# 2 is version number
package = Rex::Version.new(package[2])
begin
package = Rex::Version.new(package[2])
rescue ArgumentError => e
return CheckCode::Safe("Error processing Tomcat version (#{package[2]}) into known format: #{e}")
end

if (package.to_s.start_with?('8') && package < Rex::Version.new('8.0.32-1ubuntu1.2')) ||
(package.to_s.start_with?('7') && package < Rex::Version.new('7.0.52-1ubuntu0.7')) ||
Expand Down
10 changes: 7 additions & 3 deletions modules/exploits/linux/local/vmwgfx_fd_priv_esc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ def base_dir
def check
# Check the kernel version to see if its in a vulnerable range
release = kernel_release
unless Rex::Version.new(release) > Rex::Version.new('4.14-rc1') &&
Rex::Version.new(release) < Rex::Version.new('5.17-rc1')
return CheckCode::Safe("Kernel version #{release} is not vulnerable")
begin
unless Rex::Version.new(release) > Rex::Version.new('4.14-rc1') &&
Rex::Version.new(release) < Rex::Version.new('5.17-rc1')
return CheckCode::Safe("Kernel version #{release} is not vulnerable")
end
rescue ArgumentError => e
return CheckCode::Safe("Error determining or processing kernel release (#{release}) into known format: #{e}")
end

vprint_good "Kernel version #{release} appears to be vulnerable"
Expand Down
Loading