Android-Dynamic-Analysis
Android-Dynamic-Analysis
SSL Pinning
What is SSL Pinning?
SSL (Secure Sockets Layer) Pinning is a security mechanism used in applications to
prevent Man-in-the-Middle (MITM) attacks by ensuring that the app communicates
only with a server possessing a specific SSL certificate or public key. Instead of
relying solely on the operating system’s trusted Certificate Authorities (CAs), SSL
pinning pins a certificate or public key to the application.
Emulator Setup
Installing Android Studio
To access an Android Emulator, you need to install Android Studio. You can download
and install it from Android Studio’s official page.
Key Points:
The Emulator is an actual CPU emulator, reproducing the device architecture.
Google Play emulator images do not have root by default, but have the Google
Play Store installed like a real phone.
You can choose different Android versions depending on the API level you want to
test.
./rootAVD.sh ListAllAVDs
This script (and associated tools) can help you root various Android emulator versions
(e.g., Android 14).
ADB
ADB Setup
1. Create an emulator of your choice (preferably one for each major version).
2. Root it (using the rootAvd script) if you need deeper system-level testing.
3. Add Burp certificate to the emulator:
Drag and drop the certificate into the emulator.
Go to Settings > Certificate Management > Install Certificate and choose it.
For Android 14, you may need a script (see below) that copies the user
certificates to the system store.
# Copy the existing certs back into the tmpfs, so we keep trusting them
mv /data/local/tmp/tmp-ca-copy/* /system/etc/security/cacerts/
APP_PIDS=$(
echo "$ZYGOTE_PID $ZYGOTE64_PID" | \
xargs -n1 ps -o 'PID' -P | \
grep -v PID
)
APK Patching
Generating a Keystore
keytool -genkey -v -keystore research.keystore -alias research_key \
-keyalg RSA -keysize 2048 -validity 10000
<application
android:extractNativeLibs="true"
...
/>
# Sign it
apksigner sign --ks ./research.keystore ./aligned.apk
Frida Setup
Installing Frida
pip3 install frida-tools
frida --version
Objection Setup
pip3 install objection
This extracts, patches, repacks, aligns, and signs the APK automatically.
3. Start the application with Frida:
frida -U FridaTarget
3. Connect with:
frida -U FridaTarget
Tracing Activities
Java.perform(() => {
let ActivityClass = Java.use("android.app.Activity");
ActivityClass.onResume.implementation = function() {
console.log("Activity resumed:", this.getClass().getName());
// Call original onResume method
this.onResume();
}
})
Tracing Fragments
Java.perform(() => { let FragmentClass =
Java.use("androidx.fragment.app.Fragment");
FragmentClass.onResume.implementation = function() { console.log("Fragment
resumed:", this.getClass().getName()); // Call original onResume method
this.onResume(); } })
Frida Tracing
frida-trace -U -j 'classname!methodname'
frida-trace -U -j 'packagename.*!*' FridaTarget
Java.perform(() => {
var PlatformClass = Java.use("com.android.org.conscrypt.Platform");
PlatformClass.checkServerTrusted.overload('javax.net.ssl.X509TrustManager',
'[Ljava.security.cert.X509Certificate;', 'java.lang.String',
'com.android.org.conscrypt.AbstractConscryptSocket').implementation =
function() {
console.log("Check server trusted");
}
})
For OKHTTP3-based pinning we need to combine the script of the previous section,
and a small new one that prevents the SSLPinner from being added to the
OkHttpClient:
Java.perform(() => {
var BuilderClass = Java.use("okhttp3.OkHttpClient$Builder");
BuilderClass.certificatePinner.implementation = function() {
console.log("Certificate pinner called");
return this;
}
})
Intent Redirect
An attacker can supply (or control) an Intent used by a vulnerable app to start another
Activity or component. For example, a developer might let the user pass an Intent to
an exported Activity that then forwards that Intent to a privileged Activity.
Pending Intents
PendingIntents allow one app to pass an Intent to another app (e.g., for notifications)
that retains the original app’s permissions. If an attacker obtains this PendingIntent ,
they can exploit its privileged context.
Deep Links
A deep link is a special URL that opens a specific screen within an app. For instance,
a link in a browser could open myapp://open?param=value in your app.
These links can be hijacked like any other implicit Intent if you have an <intent-
filter> specifying you can handle the link.
Developers must carefully design deep link handling to avoid accidentally
exposing sensitive activities.
Launch Modes
Android defines four launch modes for activities that determine how new instances of
activities are created and how they interact with the back stack (task). Here is a
summary of each.
1. Standard (default)
Behavior: A new instance is created every time the activity is launched.
Usage: Default for most activities.
Example: An Activity A starts itself multiple times: stack looks like A -> A -> A .
<activity android:name=".YourActivity"
android:launchMode="standard" />
2. SingleTop
Behavior: If the activity is already at the top of the stack, no new instance is
created; onNewIntent() is called instead.
Usage: Good for activities that handle updates or new data via Intents.
Example: A notification repeatedly opens the same detail screen if it’s already on
top.
<activity android:name=".YourActivity"
android:launchMode="singleTop" />
3. SingleTask
Behavior: Only one instance of the activity in a task. If it exists in a background
task, that task is brought to the foreground and onNewIntent() is called.
Usage: Common for a main “Home” activity.
Example: Launching the main activity from multiple places reuses the same
instance in the same task.
<activity android:name=".YourActivity"
android:launchMode="singleTask" />
4. SingleInstance
Behavior: Similar to SingleTask but no other activities can be in the same task.
Usage: Used for standalone activities like a fullscreen media player or a kiosk
mode.
Example: A media player that must run separately.
<activity android:name=".YourActivity"
android:launchMode="singleInstance" />
Use Cases
Standard: General-purpose activities.
SingleTop: Activities opened repeatedly via notifications/intents (e.g., detail
pages).
SingleTask: Main or entry-point activities (e.g., dashboards, home screens).
SingleInstance: Activities requiring complete isolation (e.g., special media
players, kiosks).