Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/documentation/modules/payload/android/meterpreter/reverse_tcp.md
Views: 11788
Vulnerable Application
The android/meterpreter/reverse_tcp payload is a Java-based Meterpreter that can be used on an Android device. It is still at an early stage of development, but there are so many things you can do with it already.
Android Meterpreter allows you to do things like take remote control the file system, listen to phone calls, retrieve or send SMS messages, geo-locate the user, run post-exploitation modules, etc.
You can test android/meterpreter/reverse_tcp
on these devices:
Android Emulator
An emulator is the most convenient way to test Android Meterpreter. You can try:
Android SDK - Creates and manages your emulators from a command prompt or terminal.
Android Studio - Allows you to manage emulators more easily than the SDK.
GenyMotion - Requires an account.
AndroidAVDRepo - Contains a collection of pre-configured emulators.
Bluestacks - Very easy to install Android Emulator on Windows.
A real Android device
Having a real Android device allows you to test features or vulnerabilities you don't necessarily have from an emulator, which might be specific to a manufacturer, carrier, or hardware. You also get to test it over a real network.
Verification Steps
To create the APK with msfconsole
Currently, the most common way to use Android Meterpreter is to create it as an APK, and then execute it on a victim device.
To create the APK with msfconsole
:
To create the APK with msfvenom:
To inject Meterpreter into an existing APK with msfvenom:
You can also add Android Meterpreter to any existing APK. This will make it harder for Anti-virus software to detect the payload, and allow you read internal files and take screenshots of the Android app that you are backdooring:
Please see here for more documentation on Android injection.
Next, start an Android device. Upload the APK, and execute it. There are different ways to do this, so please refer to the Scenarios section for more information.
Important Basic Commands
pwd
The pwd
command allows you to see the current directory you're in.
cd
The cd
command allows you to change directory. For example:
cat
The cat
command allows you to see the contents of a file.
ls
The ls
command displays items in a directory. For example:
upload
The upload
command allows you to upload a file to the remote target. The -r
option allows you to do so recursively.
download
The download
command allows you to download a file from the remote target. The -r
option allows you to do so recursively.
search
The search
command allows you to find files on the remote target. For example:
ifconfig
The ifconfig
command displays the network interfaces on the remote machine.
getuid
The getuid
command shows the current user that the payload is running as:
ps
The ps
command shows a list of processes the Android device is running. For example:
shell
The shell
command allows you to interact with a shell:
To get back to the Meterpreter prompt, you can do: [CTRL]+[Z]
sysinfo
The sysinfo
command shows you basic information about the Android device.
webcam_list
The webcam_list
command shows a list of webcams you could use for the webcam_snap
command. Example:
webcam_snap
The webcam_snap
command takes a picture from the device. You will have to use the webcam_list
command to figure out which camera to use. Example:
record_mic
The record_mic
command records audio. Good for listening to a phone conversation, as well as other uses. Example:
activity_start
The activity_start
command is an execute command by starting an Android activity from a URI string.
check_root
The check_root
command detects whether your payload is running as root or not. Example:
dump_calllog
The dump_calllog
command retrieves the call log from the Android device.
dump_contacts
geolocate
The geolocate
commands allows you to locate the phone by retrieving the current lat-long using geolocation.
wlan_geolocate
The wlan_geolocation
command allows you to locate the phone by retrieving the current lat-long using WLAN information. Example:
send_sms
The send_sms
command allows you to send an SMS message. Keep in mind the phone will keep a copy of it, too.
sms_dump
The sms_dump
command allows you to retrieve SMS messages. And save them as a text file. For example:
run
The run
command allows you to run a post module against the remote machine at the Meterpreter prompt. For example:
Scenarios
Uploading APK to an Emulator using install_msf_apk.sh
The Metasploit Framework comes with a script that allows you to automatically upload your APK to an active emulator and execute it. It requires the Android SDK platform-tools to run, as well as Java.
To use this, follow these steps:
Start the Android Emulator
Generate the Android payload as an APK.
In
msfconsole
, start a handler forandroid/meterpreter/reverse_tcp
Run the installer script like this from a terminal:
The script will do something like this:
Back in msfconsole
, you should receive a session:
Uploading APK to a real Android device using install_msf_apk.sh
On the Android device, make sure to enable Developer Options. To do this:
Go to Settings -> About -> Software Information
Tap on the Build Number section a couple of times. It should unlock Developer Options.
Go back to the Settings page, you should see Developer Options.
Under Developer Options, make sure to:
Enable USB debugging
Disable Verify apps via USB
Open a terminal, and type:
adb devices
. On your Android device, you should see a prompt asking you to allow the computer for debugging, click OK on that.Do:
adb devices
again, adb should now have access.
Run the installer script like this from a terminal:
And you should get a session.
Uploading APK from a Web Server
One way to upload an APK to Android without adb is by hosting it from a web server. To do this, you must make sure to allow to trust "Unknown sources". The way to do this varies, but normally it's something like this: Settings -> Security -> Check "Unknown Sources"
Once you have that changed, you'll need to:
Generate the APK payload.
Start a web server from the directory where the payload is:
ruby -run -e httpd . -p 8181
On your Android device, open a browser, and download the APK.
You should be able to find the APK from the Downloads folder, install it.
After installation, you will have to manually execute it.
Reconnect Android Meterpreter from the Browser Remotely
When you have the APK payload installed on your Android device, another trick to reconnect it is to launch an intent from a browser. An intent is simply a term in Android development that means "an operation to be performed."
Here's how you do this:
In
msfconsole
, start amulti/handler
forandroid/meterpreter/reverse_tcp
as a background job.Do:
auxiliary/server/android_browsable_msf_launch
.Set the URIPATH if needed.
Do:
run
. At this point, the web server should be up.On your Android device, open the native web browser, and go the URL generated by the auxiliary module.
The Android handler should get a session like the following demo: