đ These study notes serve as a concise reference, capturing the essential insights, guidelines, and best practices for securing mobile applications, based on the OWASP MASTG (Mobile Application Security Testing) Standard - Techniques.
# USB
adb devices -l
adb shell
adb -s <device_ID> shell
su
# WiFi (same network)
# Set a listener on the device (via USB)
adb tcpip 5555
# Disconnect USB and run from host pc (same network)
adb connect <device_IP>
adb devices
adb shell
# SSH
# On device > Setup Termux (default port 8022)
sshd
# On Host pc
ssh -p 8022 <device_IP>
# "SSH for Magisk" Module can be used too
objection - runtime mobile exploration toolkit for security testing on non-rooted devices. Injects the Frida gadget into an application by repackaging it, disable SSL pinning methods, access app storage, execute custom Frida scripts, list activities/services/broadcast receivers, start activities, ecc
On rooted device with frida-server configured, Objection can connect directly to it without app repackage.
Interact with it via Objection REPL
The ability to perform advanced dynamic analysis on non-jailbroken devices is one of the features that makes Objection incredibly useful.
# Connect to a patched APK
objection explore
# Connect to a specific app
frida-ps -Ua | grep -i telegram
objection --gadget="org.telegram.messenger" explore
cd ..
ls
file download <file_name>
adb shell pm list packages
adb shell pm list packages -3 -f
adb shell pm path <app_package_id>
# Get all installed apps on USB device & # List running apps
frida-ps -Uai
adb shell ps
Export cert from BurpSuite in DER format (or download the cert from the http://burpsuite page after setting the Proxy on the device)
openssl x509 -inform DER -in burp-ad -out burp.pem
adb push burp.pem /sdcard/
# Install burp.pem in the user certificate store
# Move User Certificates to rot store / System CAs (using Magisk module Movecert)
Set Proxy on device WiFi Network
Host with BurpSuite must be on the same WiFi network
This module will automatically add all user-installed CA certificates to the list of the system trusted CAs (reboot is necessary)
Manual
Not always working
adb shell
mount -o rw,remount /system
# mount -o rw,remount -t ext4 /system
openssl x509 -inform DER -in cacert.der -out cacert.pem
openssl x509 -inform PEM -subject_hash_old -in cacert.pem | head -1
mv cacert.pem <hash>.0
mv <hash>.0 /system/etc/security/cacerts
chmod 644 <hash>.0
đ Starting with Android 7.0 (API level 24), the Android OS will no longer trust user CA certificates by default, unless specified in the application
Obstacles
Security controls such as root detection, certificate pinning
# Intercept traffic in WiFis with Client Isolation
# Configure Android device proxy to point to 127.0.0.1:8080
# Connect device via USB to host PC
# Make a reverse port forwarding
adb reverse tcp:8080 tcp:8080
Non-proxy-aware apps: e.g. Xamarin, or the app verifies if proxy is set and doesn't allow any traffic if it is set
# Enable "Support invisible proxying" in Burp Proxy request handling options
# iptables - redirect Android traffic to interception proxy
iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to-destination <Your-Proxy-IP>:8080
iptables -t nat -L
# Reset iptables
iptables -t nat -F
# bettercap - target and host on same network
sudo bettercap -eval "set arp.spoof.targets <ANDROID-IP>; arp.spoof on; set arp.spoof.internal true; set arp.spoof.fullduplex true;"
keytool -importcert -v -trustcacerts -file proxy.cer -alias aliascert -keystore "res/raw/truststore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "providerpath/bcprov-jdk15on-164.jar" -storetype BKS -storepass password
# proxy.cer - proxy's certificate
# aliascert - alias for proxy's cert
# BouncyCastle Provider jar file
# password - keystore pw, from decompiled app code
# List BKS truststore certs
keytool -list -keystore "res/raw/truststore.bks" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath "providerpath/bcprov-jdk15on-164.jar" -storetype BKS -storepass password
# Repackage the app and install it on device
Dynamic
More convenient and faster to perform.
Find the correct method to hook by searching for strings and licences files, identifying the used library. Examine the source code (SMALI code) to find methods suited for dynamic instrumentation.
# Search for all methods that take a string and a variable list of strings as args and return a complex object
grep -ri java/lang/String;\[Ljava/lang/String;)L ./
Hook each method with Frida and print the arguments. Find the one that prints out a domain name and a cert hash. Modify the arguments to circumvent the implemented pinning.