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

Conversation

h00die
Copy link
Contributor

@h00die h00die commented Jan 17, 2025

fixes #19812

Fixes some bugs and potential bugs where Rex::Version.new is fed data which may cause a crash. Guard these to prevent crashes on Amazon 2 Linux, and other systems (tomcat one should break on non dpkg based systems like fedora)

@h00die h00die added the bug label Jan 17, 2025
@bcoles
Copy link
Contributor

bcoles commented Jan 18, 2025

All of the existing kernel_release code looks fine to me for the example "funky" version string 5.4.129-72.229.amzn2int.x86_64. Was there another version string causing issues?

This code splits at the first -. Rex::Version receives 5.4.129 which is valid and will not raise.

Edit: modules/exploits/linux/local/vmwgfx_fd_priv_esc.rb does no prior parsing of kernel_release and will raise.

The package parsing code does no prior parsing of the version before passing to Rex::Version and will likely raise.

@h00die
Copy link
Contributor Author

h00die commented Jan 18, 2025

The kernel_release code is good, it returns as expected. That test string won't load well into Rex::Version, so we either need to guard on getting something from kernel_release that won't cleanly load into a Rex::Version, or do some post filtering (typically done with software package versions, less so kernel releases) to make it load correctly.

This is just want I was seeing in an engagement and wanted to fix some crashes that exploit_suggester was seeing

@h00die
Copy link
Contributor Author

h00die commented Jan 18, 2025

I'll be testing these changes on target to make sure its handling better, and get some more test data.

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.

@h00die
Copy link
Contributor Author

h00die commented Jan 22, 2025

@bcoles

Fedora 31 target (vm) I'm getting the following:

[msf](Jobs:2 Agents:1) exploit(linux/local/netfilter_xtables_heap_oob_write_priv_esc) > check
[-] Exploit failed: RuntimeError Could not determine grsecurity status
[-] Check failed: The state could not be determined.

This is caused by /~https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/core/post/linux/kernel.rb#L262 . Which looks like its checking on the LOCAL (metasploit) system, not the remote (exploited) system. Just wanted to confirm if that was right and if that was the expected behavior.

@bcoles
Copy link
Contributor

bcoles commented Jan 22, 2025

@bcoles

Fedora 31 target (vm) I'm getting the following:

[msf](Jobs:2 Agents:1) exploit(linux/local/netfilter_xtables_heap_oob_write_priv_esc) > check
[-] Exploit failed: RuntimeError Could not determine grsecurity status
[-] Check failed: The state could not be determined.

This is caused by /~https://github.com/rapid7/metasploit-framework/blob/master/lib/msf/core/post/linux/kernel.rb#L262 . Which looks like its checking on the LOCAL (metasploit) system, not the remote (exploited) system. Just wanted to confirm if that was right and if that was the expected behavior.

That is definitely checking the local file which is definitely wrong.

The grsec_installed? method was added in d87fef5 and checks the remote file.

The breaking change was introduced in f5145de (#19405).

@h00die
Copy link
Contributor Author

h00die commented Jan 22, 2025

@jvoisin any background on that change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

Rex::Version crashes in some local modules with Amazon Linux 2 kernel versions
2 participants