The Mobile Hacking CheatSheet
The Mobile Hacking CheatSheet is an attempt to summarise a few interesting basics info regarding tools and commands needed to assess the security of Android and iOS mobile applications.
PDF versions:
Main Steps
- Review the codebase
- Run the app
- Dynamic instrumentation
- Analyze network communications
OWASP Mobile Security Testing Project
Mobile Security Testing Guide
https://github.com/OWASP/owasp-mstg
Mobile Application Security Verification Standard
https://github.com/OWASP/owasp-masvs
Mobile Security Checklist
https://github.com/OWASP/owasp-mstg/tree/master/Checklists
Android CheatSheet
APK Structure
- META-INF: Files related to the signature scheme (v1 scheme only)
- lib: Folder containing native libraries (ARM, MIPS, x86, x64)
- assets: Folder containing application specific files
- res: Folder containing all the resources files (layouts, strings, etc.) of the application
- classes.dex [classes2.dex] ...: Dalvik bytecode of the application
- AndroidManifest.xml: Manifest file describing essential information about the app (permissions, components, etc.)
Package Name
The package name represents the app's unique identifier (e.g. for YouTube):
com.google.android.youtube
Data Storage
User applications
Shared Preferences Files
SQLite Databases
Internal Storage
adb
Connect throug USB
Connect through TCP/IP
Get a shell or execute the specified command
List processes
List Android devices connected to your machine
Dump the log messages from Android system
Copy local file to Android device
Copy file from the Android device
Install APK file on the Android device
Install an App Bundle
Set-up port forwarding using TCP protocol from host to Android device
List all packages on the device
Find the path where the APK is stored for the selected package name
List only installed apps (not system apps) and the associated path
List packages names matching the specified pattern
Application Signing
For signing your APK file, you have 2 options
-
jarsigner: Only supports v1 signature scheme (JAR signature)
jarsigner -verbose -keystore-storepass -
apksigner: Official tool from Android SDK (since version 24.0.3), which supports all the signature schemes (from v1 to v4)
apksigner sign --ks--ks-pass pass:
To create your own keystore, the following one-liner can be used:
-keystore <keystore_name> -storepass <keystore_password> -validity <days> -keyalg RSA -keysize 2048 -sigalg SHA1withRSA
Code Tampering
To tamper an APK file, the foolowing steps should be performed:
-
Disassemble the app with
apktooland save the smali code into output directoryapktool d <APK_file> -o <directory_output> -
Modify the smali code of your app (or the resource files if needed)
-
Build the modified APK with
apktoolapktool b <directory_output> -o <new_APK_file> -
Sign the APK (see Application Signing)
-
(Optional) Use
zipalignto provide optimization to the APK filezipalign -fv 4 <input_APK> <output_APK>
Frida
Installation
Install Frida and Python bindings on your system using pip
Download the Frida server binary matching the targeted architecture and your Frida version
ABI=`adb shell getprop ro.product.cpu.abi`
wget https://github.com/frida/frida/releases/download/$VER/frida-server-$VER-android-$ABI.xz
xz -d frida-server-$VER-android-$ABI.xz
Upload and execute the Frida server binary on your Android device (root privileges are needed)
ABI=`adb shell getprop ro.product.cpu.abi`
adb root
adb push frida-server-$VER-android-$ABI /data/local/tmp/frida
adb shell "chmod 755 /data/local/tmp/frida"
adb shell "/data/local/tmp/frida"
Tools
List running processes (emulators or devices connected through USB)
List only installed applications
Attach Frida client to the specified application (emulator or device connected through USB)
Spawn the specified application (emulator or device connected through USB)
Spawn the specified application without any pause at the beginning (emulator or device connected through USB)
Load a Frida script when attaching to the specified application
Objection
Inject Frida Gadget library inside an APK file by specifying the targeted architecture (if emulator not running or device not connected)
Inject Frida Gadget library inside an APK file using lastest Frida version available on Github (if emulator running or device connected to the device)
SSL/TLS Interception with BurpSuite
Before Android 7
- Launch
BurpSuiteand modify Proxy settings in order to listen on "All interfaces" (or a specific interface) - Edit the Wireless network settings in your device or the emulator proxy settings (Android Studio)
- Export the CA certificate from Burp and save it with ".cer" extension
- Push the exported certificate on the device with adb (into the SD card)
- Go to "Settings->Security" and select "Install from device storage"
- Select for "Credentials use" select "VPN and apps"
References:
- Configuring an Android device to work with Burp
- Installing BurpSuite's CA certificate in an Android device
After Android 7
From Android 7, the Android system no longer trusts the user supplied CA certificates. To be able to intercept SSL/TLS communication, you have 3 options:
- Use an older version of Android
- Use a rooted device and install the BurpSuite CA certificate inside the sytem store certificate
- Tamper the targeted application in order to re-enable the user store certificate
In order to tamper the targeted Android application, we are going to add or modify the network security configuration file. This file on recent Android versions allows to force the application to trust the user supplied CA certificates. The following steps should be performed:
-
Install the Burpsuite's CA certificate on your Android device (see Before Android 7)
-
Disassemble the targeted app (APK file) with
apktool -
Add or modify the
network_security_config.xmlfile (usually onres/xml/folder). The content of the file should be:xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config>
<trust-anchors>
<certificates src="system" />
<certificates src="user" />
trust-anchors>
base-config>
network-security-config> -
If the
network_security_config.xmlfile is not present on your app, theAndroidManifest.xmlalso need to be modified by adding thenetworkSecurityConfigtag as follow:<application android:name="AppName" android:networkSecurityConfig="@xml/network_security_config"> -
Build the modified app with
apktooland then sign the newly created APK file (see Application Signing)
Content Provider
Query a Content Provider
Insert an element on a Content Provider
--bind <param_name>:<param_type>:<param_value>
Delete a row on a Content Provider
--where "
Activity Manager
Start an Activity with the specified Intent
Start an Activity with the specified Intent and extra parameters
iOS CheatSheet
Filesystem
App list database
Binary directory: include all the static resources of the app
Path of the binary (executable)
App metadata: configuration of the app (icon to display, supported document types, etc.)
Data directory
UUID (Universally Unique Identifier): random 36 alphanumeric characters string unique to the app Data-UUID: random 36 alphanumeric characters string unique to the app
Default password
By default the root password on your jailbroken iOS device is alpine
If you've changed it and want to reset it:
- Open
/etc/passwdor/private/etc/master.passwdwith a file manager app (e.g. iFile/Fileza) - Change the hash to:
/smx7MYTQIi2M - root password will be
alpine
Bundle ID
The bundle ID (aka package name) represents the app's unique identifier (e.g. for YouTube)
com.google.ios.youtube
How to find the data and binary directories
Grep is the not-so-quick 'n dirty way to find where are the data and binary directories of your app
How to find the data and binary directories and the Bundle ID
By launching Frida with the ios-app-info script
And then
Or manually by opening the app list database
And displaying the key_tab table to get the binary directories
Or displaying the application_identifier_tab table to get the bundle IDs
App decryption
- Add https://level3tjg.xyz/repo/ src to Cydia and install bfdecrypt tool
- Go to bfdecrypt pref pane in Settings and set the app to decrypt
- Launch the app to decrypt: decrypted IPA is stored in the Documents folder of the app
Dynamic analysis with Frida
List running processes
Analyse the calls to a method by launching Frida with the objc-method-observer script
And then using the command observeSomething
Hook the calls to the method
Then open the JavaScript handler file to edit the onEnter or onLeave functions to manipulate the behavior of the app
Dynamic analysis with Objection
Inject objection
List the classes (output will contain thousands of lines)
List the methods of a class
Search for classes|methods names containing
Analyse the calls to the method
Hook the
Get the NSLog (syslog)
Impactor (http://www.cydiaimpactor.com) let you display the NSLog (syslog) on command line
SSL Interception with BurpSuite
- Launch Burp and modify proxy settings in order to listen on "All interfaces"
- Browse to the IP/port of your Burp proxy using Safari
- Tap on the "CA Certificate" at the top right of the screen
- Tap on "Allow" on the pop-up asking to download a configuration profile
- Go to "Settings->Profile Downloaded" and select the "PortSwigger CA" profile
- Tap on "Install" then "Install" again and then "Install" one last time
- Edit the wireless network settings on your device to set a proxy ("Settings->Wi-Fi" then tap on the blue "i", slide to the bottom of the screen and tap on "Configure Proxy")
- Tap on "Manual", set the IP/port of your Burp proxy, tap on "Save"
- Go to "Settings->General->About->Certificate Trust Settings" & toggle on the PortSwiggerCA
Bypass SSL Pinning using SSL Kill Switch 2
Download and install SSL Kill Switch 2 tweak
dpkg -i com.nablac0d3.sslkillswitch2_0.14.deb
killall -HUP SpringBoard
Go to "Settings->SSL Kill Switch 2" to "Disable Certificate Validation"
UDID (Unique Device Identifier)
UDID is a string that is used to identify a device. Needed for some operations like signature, app installation, network monitoring.
- Get the UDID with MacOS
or
or by launching Impactor without parameters
- Get the UDID with Linux
or
or by launching Impactor without parameters
Network capture (works also on non jailbroken devices)
- With MacOS (install Xcode and additional tools and connect the device with USB)
tcpdump or tshark or wireshark -i rvi0
- With Linux or Windows (get https://github.com/gh2o/rvi_capture and connect the device with USB)
Sideloading an app
Sideloading an app including an instrumentation library like Frida let you interact with the app even if it's installed on a non jailbroken device.
With IPAPatch
Here's the process to do it with IPAPatch: Clone the IPAPatch project
Move the IPA of the app you want to sideload to the Assets directory
Download the FridaGadget library (in Assets/Dylibs/FridaGadget.dylib)
Select the identity to sign the app
Sign FridaGadget library
Then open IPAPatch Xcode project, Build and Run.
With Objection
Here's the process to do it with Objection (detailed steps on https://github.com/sensepost/objection/wiki/Patching-iOS-Applications)
objection patchipa --source <IPAfile> --codesign-signature <IDENTITY>
unzip <patchedIPAfile>
ios-deploy --bundle Payload/my-app.app -W -d
objection explore
Data Protection Class
Four levels are provided by iOS to encrypt automatically files on the device:
NSProtectionComplete: file is only accessible when device is unlocked (files are encrypted with a key derived from the user PIN code & an AES key generated by the device)NSProtectionCompleteUntilFirstUserAuthentication: (defaut class) same except as before, but the decryption key is not deleted when the device is lockedProtectedUnlessOpen: file is accessible until openNoProtection: file is accessible even if device is locked
Get Data Protection Class
By launching Frida with the ios-dataprotection script
License
The Mobile Hacking CheatSheet is an open source project released under the CC-BY-SA 4.0 licence.