| name | android-pentest-environment-setup |
| description | Complete Android app penetration testing environment setup with Android Studio, rooted emulator, Magisk, and reverse engineering tools |
| triggers | ["how do I set up an Android pentesting environment","configure Android emulator for app security testing","root Android Studio emulator with Magisk","install frida on rooted Android emulator","setup Android app reverse engineering environment","configure proxy for Android app traffic interception","bypass Android SSL pinning with Magisk modules","setup ADB for Android security testing"] |
Android Penetration Testing Environment Setup
Skill by ara.so — Security Skills collection.
This skill covers setting up a complete Android application penetration testing environment using Android Studio emulators, including rooting with Magisk, installing security testing frameworks (Frida, LSPosed), and configuring traffic interception tools.
What This Project Provides
A comprehensive guide to building a modern (2026) Android app penetration testing lab environment on Android Studio, including:
- Android Studio AVD (Android Virtual Device) configuration optimized for security testing
- Root access via Magisk framework
- Frida dynamic instrumentation framework
- LSPosed/Xposed module framework for runtime hooking
- SSL/TLS certificate pinning bypass capabilities
- Traffic interception setup with Burp Suite/mitmproxy
- Anti-emulator detection bypass techniques
Key Advantages:
- Reproducible environment using snapshots
- No need for physical devices
- Full system access for deep analysis
- Support for Android 16 (API 36)
Limitations:
- Some apps detect emulators and refuse to run
- Performance may be slower than physical devices
Prerequisites
- macOS, Linux, or Windows
- 16GB+ RAM recommended
- Android Studio installed
- Proxy tool (Burp Suite, mitmproxy, Charles) for traffic analysis
Installation
1. Install Android Studio and SDK
cat >> ~/.bash_profile << 'EOF'
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/emulator
EOF
source ~/.bash_profile
cat >> ~/.zshrc << 'EOF'
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/platform-tools
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/emulator
EOF
source ~/.zshrc
adb version
Windows PowerShell:
# Add to System Environment Variables
[Environment]::SetEnvironmentVariable("ANDROID_HOME", "$env:LOCALAPPDATA\Android\Sdk", "User")
$path = [Environment]::GetEnvironmentVariable("Path", "User")
[Environment]::SetEnvironmentVariable("Path", "$path;$env:ANDROID_HOME\platform-tools;$env:ANDROID_HOME\tools", "User")
2. Create Android Virtual Device (AVD)
sdkmanager --list | grep system-images
sdkmanager "system-images;android-36;google_apis;arm64-v8a"
avdmanager create avd \
-n pentest_pixel9 \
-k "system-images;android-36;google_apis;arm64-v8a" \
-d "pixel_9_pro"
Important: Choose Google APIs (NOT Google Play) to allow root access.
3. Root with Magisk (Method A: rootAVD - Recommended)
git clone https://gitlab.com/newbit/rootAVD.git
cd rootAVD
curl -L -o Magisk.zip https://github.com/topjohnwu/Magisk/releases/download/v28.1/Magisk-v28.1.apk
./rootAVD.sh ListAllAVDs
./rootAVD.sh system-images/android-36/google_apis/arm64-v8a/ramdisk.img
emulator -avd pentest_pixel9 -writable-system
adb shell su -c "id"
4. Root with Magisk (Method B: Manual Patch - If rootAVD Fails)
emulator -avd pentest_pixel9 -writable-system &
sleep 30
adb root
adb remount
adb install Magisk-v28.1.apk
RAMDISK="$ANDROID_HOME/system-images/android-36/google_apis/arm64-v8a/ramdisk.img"
adb push "$RAMDISK" /sdcard/Download/ramdisk.img
adb pull /sdcard/Download/magisk_patched_*.img ./
cp magisk_patched_*.img "$ANDROID_HOME/system-images/android-36/google_apis/arm64-v8a/ramdisk.img"
adb reboot
Key Commands
ADB (Android Debug Bridge)
adb devices
adb -s emulator-5554 shell
adb install app.apk
adb install -r app.apk
adb pull /data/data/com.example.app/databases/app.db ./
adb push burp-cert.der /sdcard/
adb forward tcp:8080 tcp:8080
adb root
adb shell
adb remount
adb logcat | grep -i "com.example.app"
adb logcat -c
adb shell screencap /sdcard/screen.png
adb pull /sdcard/screen.png
adb shell am start -n com.example.app/.MainActivity
adb shell am force-stop com.example.app
Magisk Module Management
adb push module.zip /sdcard/Download/
adb shell su -c "magisk --install-module /sdcard/Download/module.zip"
adb shell su -c "ls /data/adb/modules"
adb shell su -c "magisk --sqlite 'UPDATE settings SET value=1 WHERE key=\"zygisk\"'"
adb reboot
adb shell su -c "magisk -v"
Installing Security Testing Frameworks
1. Install Frida
adb shell getprop ro.product.cpu.abi
FRIDA_VERSION=$(pip3 show frida | grep Version | cut -d' ' -f2)
wget "https://github.com/frida/frida/releases/download/${FRIDA_VERSION}/frida-server-${FRIDA_VERSION}-android-arm64.xz"
unxz frida-server-*-android-arm64.xz
adb root
adb push frida-server-*-android-arm64 /data/local/tmp/frida-server
adb shell chmod 755 /data/local/tmp/frida-server
adb shell "/data/local/tmp/frida-server &"
pip3 install frida-tools
frida-ps -U
Persistent Frida with Magisk Module:
mkdir -p frida-module/system/bin
cp frida-server-*-android-arm64 frida-module/system/bin/frida-server
cat > frida-module/module.prop << 'EOF'
id=frida_server
name=Frida Server
version=16.5.0
versionCode=16050
author=Frida
description=Frida dynamic instrumentation toolkit
EOF
cat > frida-module/service.sh << 'EOF'
/system/bin/frida-server &
EOF
cd frida-module
zip -r ../frida-module.zip .
adb push ../frida-module.zip /sdcard/
adb shell su -c "magisk --install-module /sdcard/frida-module.zip"
adb reboot
2. Install LSPosed (Xposed Framework)
wget https://github.com/LSPosed/LSPosed/releases/download/v1.9.2/LSPosed-v1.9.2-7024-zygisk-release.zip
adb push LSPosed-v1.9.2-7024-zygisk-release.zip /sdcard/
adb shell su -c "magisk --install-module /sdcard/LSPosed-v1.9.2-7024-zygisk-release.zip"
adb reboot
adb shell am start -n org.lsposed.manager/.ui.activity.MainActivity
Common LSPosed Modules for Pentesting:
3. Install ZygiskNext (Improved Zygisk)
wget https://github.com/Dr-TSNG/ZygiskNext/releases/download/v4.0.1/Zygisk-Next-4.0.1-release.zip
adb shell su -c "magisk --sqlite 'UPDATE settings SET value=0 WHERE key=\"zygisk\"'"
adb push Zygisk-Next-4.0.1-release.zip /sdcard/
adb shell su -c "magisk --install-module /sdcard/Zygisk-Next-4.0.1-release.zip"
adb reboot
SSL/TLS Certificate Pinning Bypass
Method 1: System Certificate Installation
openssl x509 -inform PEM -subject_hash_old -in burp-cert.pem | head -1
cp burp-cert.pem 9a5ba575.0
adb root
adb remount
adb push 9a5ba575.0 /system/etc/security/cacerts/
adb shell chmod 644 /system/etc/security/cacerts/9a5ba575.0
adb reboot
Method 2: Using Magisk Modules
Install TrustMeAlready:
adb push TrustMeAlready.apk /sdcard/
adb install /sdcard/TrustMeAlready.apk
Install Shamiko (Hide root from apps):
wget https://github.com/LSPosed/LSPosed.github.io/releases/download/shamiko-354/Shamiko-v0.7.4-354-release.zip
adb push Shamiko-v0.7.4-354-release.zip /sdcard/
adb shell su -c "magisk --install-module /sdcard/Shamiko-v0.7.4-354-release.zip"
adb reboot
Traffic Interception Setup
Configure Proxy on Emulator
adb shell settings put global http_proxy <HOST_IP>:8080
adb shell settings put global http_proxy :0
adb shell settings get global http_proxy
Burp Suite Configuration
adb push burp-cert.der /sdcard/
openssl x509 -inform DER -in burp-cert.der -out burp-cert.pem
openssl x509 -inform PEM -subject_hash_old -in burp-cert.pem | head -1
cp burp-cert.pem 9a5ba575.0
adb root
adb remount
adb push 9a5ba575.0 /system/etc/security/cacerts/
adb shell chmod 644 /system/etc/security/cacerts/9a5ba575.0
adb reboot
Frida Scripts for Common Tasks
Bypass SSL Pinning (Universal Script)
Java.perform(function() {
console.log("[*] Bypassing SSL Pinning...");
try {
var CertificatePinner = Java.use('okhttp3.CertificatePinner');
CertificatePinner.check.overload('java.lang.String', 'java.util.List').implementation = function() {
console.log('[+] OkHttp3 pinning bypassed');
return;
};
} catch(err) {
console.log('[-] OkHttp3 not found');
}
var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');
var SSLContext = Java.use('javax.net.ssl.SSLContext');
var TrustManager = Java.registerClass({
name: 'dev.asd.test.TrustManager',
implements: [X509TrustManager],
methods: {
checkClientTrusted: function(chain, authType) {},
checkServerTrusted: function(chain, authType) {},
getAcceptedIssuers: function() { return []; }
}
});
var TrustManagers = [TrustManager.$new()];
var SSLContext_init = SSLContext.init.overload(
'[Ljavax.net.ssl.KeyManager;', '[Ljavax.net.ssl.TrustManager;', 'java.security.SecureRandom'
);
SSLContext_init.implementation = function(keyManager, trustManager, secureRandom) {
console.log('[+] TrustManager bypassed');
SSLContext_init.call(this, keyManager, TrustManagers, secureRandom);
};
});
Run the script:
frida -U -f com.example.app -l ssl-pinning-bypass.js --no-pause
Extract Shared Preferences
Java.perform(function() {
var context = Java.use('android.app.ActivityThread')
.currentApplication()
.getApplicationContext();
var prefsDir = context.getFilesDir().getParent() + '/shared_prefs';
console.log('[*] Shared Preferences location:', prefsDir);
var File = Java.use('java.io.File');
var dir = File.$new(prefsDir);
var files = dir.listFiles();
for (var i = 0; i < files.length; i++) {
console.log('[+] Found:', files[i].getName());
}
});
Hook Crypto Functions
Java.perform(function() {
var Cipher = Java.use('javax.crypto.Cipher');
Cipher.doFinal.overload('[B').implementation = function(byteArr) {
console.log('[*] Cipher.doFinal called');
console.log('[*] Algorithm:', this.getAlgorithm());
console.log('[*] Input:', Java.use('android.util.Base64')
.encodeToString(byteArr, 0));
var result = this.doFinal(byteArr);
console.log('[*] Output:', Java.use('android.util.Base64')
.encodeToString(result, 0));
return result;
};
});
Troubleshooting
Emulator Won't Start
emulator -list-avds
emulator -avd pentest_pixel9 -verbose
emulator -avd pentest_pixel9 -no-snapshot-load
emulator -avd pentest_pixel9 -wipe-data
ADB Can't Connect
adb kill-server
adb start-server
adb devices
adb connect localhost:5554
Magisk Not Working After Reboot
cd rootAVD
./rootAVD.sh system-images/android-36/google_apis/arm64-v8a/ramdisk.img
Frida Connection Issues
adb shell "ps | grep frida-server"
adb shell "pkill frida-server"
adb shell "/data/local/tmp/frida-server &"
adb forward tcp:27042 tcp:27042
frida --version
adb shell /data/local/tmp/frida-server --version
LSPosed Not Appearing
adb shell su -c "magisk --sqlite 'SELECT * FROM settings WHERE key=\"zygisk\"'"
adb shell su -c "ls -la /data/adb/modules/zygisk_lsposed"
adb logcat | grep -i lsposed
App Detects Emulator
Use Shamiko + DenyList:
adb shell su -c "magisk --denylist add com.example.app"
adb shell su -c "magisk --denylist enable"
Modify build.prop:
adb root
adb remount
adb pull /system/build.prop
adb push build.prop /system/build.prop
adb reboot
SSL Pinning Still Active
frida -U -f com.example.app \
-l ssl-pinning-bypass.js \
-l universal-ssl-bypass.js \
--no-pause
Advanced Configuration
Create Snapshot After Setup
adb shell "sync; echo 3 > /proc/sys/vm/drop_caches"
Automated Environment Setup Script
#!/bin/bash
AVD_NAME="pentest_pixel9"
ANDROID_API="android-36"
ARCH="arm64-v8a"
echo "[*] Setting up Android Pentest Environment..."
sdkmanager "system-images;${ANDROID_API};google_apis;${ARCH}"
avdmanager create avd -n ${AVD_NAME} \
-k "system-images;${ANDROID_API};google_apis;${ARCH}" \
-d "pixel_9_pro" --force
cd rootAVD
./rootAVD.sh system-images/${ANDROID_API}/google_apis/${ARCH}/ramdisk.img
emulator -avd ${AVD_NAME} -writable-system &
sleep 60
FRIDA_VERSION=$(pip3 show frida | grep Version | awk '{print $2}')
wget -q "https://github.com/frida/frida/releases/download/${FRIDA_VERSION}/frida-server-${FRIDA_VERSION}-android-${ARCH}.xz"
unxz frida-server-*.xz
adb root
adb push frida-server-* /data/local/tmp/frida-server
adb shell chmod 755 /data/local/tmp/frida-server
adb shell "/data/local/tmp/frida-server &"
echo "[+] Setup complete. Connect via: adb -s emulator-5554 shell"
References