Skip to content

Commit 60bb4b1

Browse files
authored
Merge pull request #1388 from HackTricks-wiki/update_Build_a_Repeatable_Android_Bug_Bounty_Lab__Emulato_20250905_123731
Build a Repeatable Android Bug Bounty Lab Emulator vs Magisk...
2 parents 25bf097 + fbaf46c commit 60bb4b1

5 files changed

Lines changed: 224 additions & 8 deletions

File tree

src/mobile-pentesting/android-app-pentesting/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,14 @@ You need to activate the **debugging** options and it will be cool if you can **
291291
> Once you have installed the application, the first thing you should do is to try it and investigate what does it do, how does it work and get comfortable with it.\
292292
> I will suggest to **perform this initial dynamic analysis using MobSF dynamic analysis + pidcat**, so we will be able to **learn how the application works** while MobSF **captures** a lot of **interesting** **data** you can review later on.
293293
294+
Magisk/Zygisk quick notes (recommended on Pixel devices)
295+
- Patch boot.img with the Magisk app and flash via fastboot to get systemless root
296+
- Enable Zygisk + DenyList for root hiding; consider LSPosed/Shamiko when stronger hiding is required
297+
- Keep original boot.img to recover from OTA updates; re-patch after each OTA
298+
- For screen mirroring, use scrcpy on the host
299+
300+
301+
294302
### Unintended Data Leakage
295303

296304
**Logging**
@@ -858,6 +866,7 @@ AndroL4b is an Android security virtual machine based on ubuntu-mate includes th
858866
- [SSLPinDetect: Advanced SSL Pinning Detection for Android Security Analysis](https://petruknisme.medium.com/sslpindetect-advanced-ssl-pinning-detection-for-android-security-analysis-1390e9eca097)
859867
- [SSLPinDetect GitHub](https://github.com/aancw/SSLPinDetect)
860868
- [smali-sslpin-patterns](https://github.com/aancw/smali-sslpin-patterns)
869+
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
861870

862871
## Yet to try
863872

src/mobile-pentesting/android-app-pentesting/android-anti-instrumentation-and-ssl-pinning-bypass.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ These typically stub Java root/debug checks, process/service scans, and native p
4141

4242
- Codeshare: https://codeshare.frida.re/
4343

44+
## Automate with Medusa (Frida framework)
45+
46+
Medusa provides 90+ ready-made modules for SSL unpinning, root/emulator detection bypass, HTTP comms logging, crypto key interception, and more.
47+
48+
```bash
49+
git clone https://github.com/Ch0pin/medusa
50+
cd medusa
51+
pip install -r requirements.txt
52+
python medusa.py
53+
54+
# Example interactive workflow
55+
show categories
56+
use http_communications/multiple_unpinner
57+
use root_detection/universal_root_detection_bypass
58+
run com.target.app
59+
```
60+
61+
Tip: Medusa is great for quick wins before writing custom hooks. You can also cherry-pick modules and combine them with your own scripts.
62+
4463
## Step 3 — Bypass init-time detectors by attaching late
4564

4665
Many detections only run during process spawn/onCreate(). Spawn‑time injection (-f) or gadgets get caught; attaching after UI loads can slip past.
@@ -104,6 +123,14 @@ Java.perform(() => {
104123
});
105124
```
106125

126+
// Quick root detection stub example (adapt to target package/class names)
127+
Java.perform(() => {
128+
try {
129+
const RootChecker = Java.use('com.target.security.RootCheck');
130+
RootChecker.isDeviceRooted.implementation = function () { return false; };
131+
} catch (e) {}
132+
});
133+
107134
Log and neuter suspicious methods to confirm execution flow:
108135

109136
```js
@@ -116,6 +143,48 @@ Java.perform(() => {
116143
});
117144
```
118145

146+
## Bypass emulator/VM detection (Java stubs)
147+
148+
Common heuristics: Build.FINGERPRINT/MODEL/MANUFACTURER/HARDWARE containing generic/goldfish/ranchu/sdk; QEMU artifacts like /dev/qemu_pipe, /dev/socket/qemud; default MAC 02:00:00:00:00:00; 10.0.2.x NAT; missing telephony/sensors.
149+
150+
Quick spoof of Build fields:
151+
```js
152+
Java.perform(function(){
153+
var Build = Java.use('android.os.Build');
154+
Build.MODEL.value = 'Pixel 7 Pro';
155+
Build.MANUFACTURER.value = 'Google';
156+
Build.BRAND.value = 'google';
157+
Build.FINGERPRINT.value = 'google/panther/panther:14/UP1A.231105.003/1234567:user/release-keys';
158+
});
159+
```
160+
161+
Complement with stubs for file existence checks and identifiers (TelephonyManager.getDeviceId/SubscriberId, WifiInfo.getMacAddress, SensorManager.getSensorList) to return realistic values.
162+
163+
## SSL pinning bypass quick hook (Java)
164+
165+
Neutralize custom TrustManagers and force permissive SSL contexts:
166+
```js
167+
Java.perform(function(){
168+
var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');
169+
var SSLContext = Java.use('javax.net.ssl.SSLContext');
170+
171+
// No-op validations
172+
X509TrustManager.checkClientTrusted.implementation = function(){ };
173+
X509TrustManager.checkServerTrusted.implementation = function(){ };
174+
175+
// Force permissive TrustManagers
176+
var TrustManagers = [ X509TrustManager.$new() ];
177+
var SSLContextInit = SSLContext.init.overload('[Ljavax.net.ssl.KeyManager;','[Ljavax.net.ssl.TrustManager;','java.security.SecureRandom');
178+
SSLContextInit.implementation = function(km, tm, sr){
179+
return SSLContextInit.call(this, km, TrustManagers, sr);
180+
};
181+
});
182+
```
183+
184+
Notes
185+
- Extend for OkHttp: hook okhttp3.CertificatePinner and HostnameVerifier as needed, or use a universal unpinning script from CodeShare.
186+
- Run example: `frida -U -f com.target.app -l ssl-bypass.js --no-pause`
187+
119188
## Step 6 — Follow the JNI/native trail when Java hooks fail
120189

121190
Trace JNI entry points to locate native loaders and detection init:
@@ -165,6 +234,8 @@ Notes:
165234
- Requires apktool; ensure a current version from the official guide to avoid build issues: https://apktool.org/docs/install
166235
- Gadget injection enables instrumentation without root but can still be caught by stronger init‑time checks.
167236

237+
Optionally, add LSPosed modules and Shamiko for stronger root hiding in Zygisk environments, and curate DenyList to cover child processes.
238+
168239
References:
169240
- Objection: https://github.com/sensepost/objection
170241

@@ -226,5 +297,7 @@ apk-mitm app.apk
226297
- [r2frida](https://github.com/nowsecure/r2frida)
227298
- [Apktool install guide](https://apktool.org/docs/install)
228299
- [Magisk](https://github.com/topjohnwu/Magisk)
300+
- [Medusa (Android Frida framework)](https://github.com/Ch0pin/medusa)
301+
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
229302

230303
{{#include ../../banners/hacktricks-training.md}}

src/mobile-pentesting/android-app-pentesting/avd-android-virtual-device.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,59 @@ However there are **a lot of different command line useful options** that you ca
208208
- `-screen {touch(default)|multi-touch|o-touch}` : Set emulated touch screen mode.
209209
- **`-writable-system`** : Use this option to have a writable system image during your emulation session. You will need also to run `adb root; adb remount`. This is very useful to install a new certificate in the system.
210210

211+
## Linux CLI setup (SDK/AVD quickstart)
212+
213+
The official CLI tools make it easy to create fast, debuggable emulators without Android Studio.
214+
215+
```bash
216+
# Directory layout
217+
mkdir -p ~/Android/cmdline-tools/latest
218+
219+
# Download commandline tools (Linux)
220+
wget https://dl.google.com/android/repository/commandlinetools-linux-13114758_latest.zip -O /tmp/cmdline-tools.zip
221+
unzip /tmp/cmdline-tools.zip -d ~/Android/cmdline-tools/latest
222+
rm /tmp/cmdline-tools.zip
223+
224+
# Env vars (add to ~/.bashrc or ~/.zshrc)
225+
export ANDROID_HOME=$HOME/Android
226+
export PATH=$ANDROID_HOME/cmdline-tools/latest/bin:$ANDROID_HOME/platform-tools:$ANDROID_HOME/emulator:$PATH
227+
228+
# Install core SDK components
229+
sdkmanager --install "platform-tools" "emulator"
230+
231+
# Install a debuggable x86_64 system image (Android 11 / API 30)
232+
sdkmanager --install "system-images;android-30;google_apis;x86_64"
233+
234+
# Create an AVD and run it with a writable /system & snapshot name
235+
avdmanager create avd -n PixelRootX86 -k "system-images;android-30;google_apis;x86_64" -d "pixel"
236+
emulator -avd PixelRootX86 -writable-system -snapshot PixelRootX86_snap
237+
238+
# Verify root (debuggable images allow `adb root`)
239+
adb root
240+
adb shell whoami # expect: root
241+
```
242+
243+
Notes
244+
- System image flavors: google_apis (debuggable, allows adb root), google_apis_playstore (not rootable), aosp/default (lightweight).
245+
- Build types: userdebug often allows `adb root` on debug-capable images. Play Store images are production builds and block root.
246+
- On x86_64 hosts, full-system ARM64 emulation is unsupported from API 28+. For Android 11+ use Google APIs/Play images that include per-app ARM-to-x86 translation to run many ARM-only apps quickly.
247+
248+
### Snapshots from CLI
249+
250+
```bash
251+
# Save a clean snapshot from the running emulator
252+
adb -s emulator-5554 emu avd snapshot save my_clean_setup
253+
254+
# Boot from a named snapshot (if it exists)
255+
emulator -avd PixelRootX86 -writable-system -snapshot my_clean_setup
256+
```
257+
258+
## ARM→x86 binary translation (Android 11+)
259+
260+
Google APIs and Play Store images on Android 11+ can translate ARM app binaries per process while keeping the rest of the system native x86/x86_64. This is often fast enough to test many ARM-only apps on desktop.
261+
262+
> Tip: Prefer Google APIs x86/x86_64 images during pentests. Play images are convenient but block `adb root`; use them only when you specifically require Play services and accept the lack of root.
263+
211264
## Rooting a Play Store device
212265

213266
If you downloaded a device with Play Store you are not going to be able to get root directly, and you will get this error message
@@ -236,6 +289,12 @@ You can **use the GUI** to take a snapshot of the VM at any time:
236289

237290
![](<../../images/image (234).png>)
238291

292+
## References
293+
294+
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
295+
- [Android Emulator command line](https://developer.android.com/studio/run/emulator-commandline)
296+
- [Run ARM apps on the Android Emulator (x86 translation)](https://android-developers.googleblog.com/2020/03/run-arm-apps-on-android-emulator.html)
297+
239298
{{#include ../../banners/hacktricks-training.md}}
240299

241300

src/mobile-pentesting/android-app-pentesting/frida-tutorial/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,64 @@ frida-ps -U #List packages and processes
2626
frida-ps -U | grep -i <part_of_the_package_name> #Get all the package name
2727
```
2828

29+
## Frida server vs. Gadget (root vs. no-root)
30+
31+
Two common ways to instrument Android apps with Frida:
32+
33+
- Frida server (rooted devices): Push and run a native daemon that lets you attach to any process.
34+
- Frida Gadget (no root): Bundle Frida as a shared library inside the APK and auto-load it within the target process.
35+
36+
Frida server (rooted)
37+
38+
```bash
39+
# Download the matching frida-server binary for your device's arch
40+
# https://github.com/frida/frida/releases
41+
adb root
42+
adb push frida-server-<ver>-android-<arch> /data/local/tmp/frida-server
43+
adb shell chmod 755 /data/local/tmp/frida-server
44+
adb shell /data/local/tmp/frida-server & # run at boot via init/magisk if desired
45+
46+
# From host, list processes and attach
47+
frida-ps -Uai
48+
frida -U -n com.example.app
49+
```
50+
51+
Frida Gadget (no-root)
52+
53+
1) Unpack the APK, add the gadget .so and config:
54+
- Place libfrida-gadget.so into lib/<abi>/ (e.g., lib/arm64-v8a/)
55+
- Create assets/frida-gadget.config with your script loading settings
56+
57+
Example frida-gadget.config
58+
```json
59+
{
60+
"interaction": { "type": "script", "path": "/sdcard/ssl-bypass.js" },
61+
"runtime": { "logFile": "/sdcard/frida-gadget.log" }
62+
}
63+
```
64+
65+
2) Reference/load the gadget so it’s initialized early:
66+
- Easiest: Add a small Java stub to System.loadLibrary("frida-gadget") in Application.onCreate(), or use native lib loading already present.
67+
68+
3) Repack and sign the APK, then install:
69+
```bash
70+
apktool d app.apk -o app_m
71+
# ... add gadget .so and config ...
72+
apktool b app_m -o app_gadget.apk
73+
uber-apk-signer -a app_gadget.apk -o out_signed
74+
adb install -r out_signed/app_gadget-aligned-debugSigned.apk
75+
```
76+
77+
4) Attach from host to the gadget process:
78+
```bash
79+
frida-ps -Uai
80+
frida -U -n com.example.app
81+
```
82+
83+
Notes
84+
- Gadget is detected by some protections; keep names/paths stealthy and load late/conditionally if needed.
85+
- On hardened apps, prefer rooted testing with server + late attach, or combine with Magisk/Zygisk hiding.
86+
2987
## Tutorials
3088

3189
### [Tutorial 1](frida-tutorial-1.md)
@@ -202,6 +260,12 @@ Java.choose("com.example.a11x256.frida_test.my_activity", {
202260
- [Part 1 of Advanced Frida Usage blog series: IOS Encryption Libraries](https://8ksec.io/advanced-frida-usage-part-1-ios-encryption-libraries-8ksec-blogs/)
203261
204262
263+
## References
264+
265+
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
266+
- [Frida Gadget documentation](https://frida.re/docs/gadget/)
267+
- [Frida releases (server binaries)](https://github.com/frida/frida/releases)
268+
205269
{{#include ../../../banners/hacktricks-training.md}}
206270
207271

src/mobile-pentesting/android-app-pentesting/install-burp-certificate.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,20 @@
33
{{#include ../../banners/hacktricks-training.md}}
44

55

6+
## System-wide proxy via ADB
7+
8+
Configure a global HTTP proxy so all apps route traffic through your interceptor (Burp/mitmproxy):
9+
10+
```bash
11+
# Set proxy (device/emulator must reach your host IP)
12+
adb shell settings put global http_proxy 192.168.1.2:8080
13+
14+
# Clear proxy
15+
adb shell settings put global http_proxy :0
16+
```
17+
18+
Tip: In Burp, bind your listener to 0.0.0.0 so devices on the LAN can connect (Proxy -> Options -> Proxy Listeners).
19+
620
## On a Virtual Machine
721

822
First of all you need to download the Der certificate from Burp. You can do this in _**Proxy**_ --> _**Options**_ --> _**Import / Export CA certificate**_
@@ -37,15 +51,15 @@ If you **rooted your device with Magisc** (maybe an emulator), and you **can't f
3751

3852
Explained in [**this video**](https://www.youtube.com/watch?v=qQicUW0svB8) you need to:
3953

40-
1. **Install a CA certificate**: Just **drag\&drop** the DER Burp certificate **changing the extension** to `.crt` in the mobile so it's stored in the Downloads folder and go to `Install a certificate` -> `CA certificate`
54+
1. **Install a CA certificate**: Just **drag&drop** the DER Burp certificate **changing the extension** to `.crt` in the mobile so it's stored in the Downloads folder and go to `Install a certificate` -> `CA certificate`
4155

4256
<figure><img src="../../images/image (53).png" alt="" width="164"><figcaption></figcaption></figure>
4357

4458
- Check that the certificate was correctly stored going to `Trusted credentials` -> `USER`
4559

4660
<figure><img src="../../images/image (54).png" alt="" width="334"><figcaption></figcaption></figure>
4761

48-
2. **Make it System trusted**: Download the Magisc module [MagiskTrustUserCerts](https://github.com/NVISOsecurity/MagiskTrustUserCerts) (a .zip file), **drag\&drop it** in the phone, go to the **Magics app** in the phone to the **`Modules`** section, click on **`Install from storage`**, select the `.zip` module and once installed **reboot** the phone:
62+
2. **Make it System trusted**: Download the Magisc module [MagiskTrustUserCerts](https://github.com/NVISOsecurity/MagiskTrustUserCerts) (a .zip file), **drag&drop it** in the phone, go to the **Magics app** in the phone to the **`Modules`** section, click on **`Install from storage`**, select the `.zip` module and once installed **reboot** the phone:
4963

5064
<figure><img src="../../images/image (55).png" alt="" width="345"><figcaption></figcaption></figure>
5165

@@ -152,10 +166,7 @@ nsenter --mount=/proc/$APP_PID/ns/mnt -- /bin/mount --bind /system/etc/security/
152166

153167
## References
154168

155-
- [https://httptoolkit.com/blog/android-14-install-system-ca-certificate/](https://httptoolkit.com/blog/android-14-install-system-ca-certificate/)
156-
157-
158-
{{#include ../../banners/hacktricks-training.md}}
159-
160-
169+
- [Android 14: Install a system CA certificate on a rooted device](https://httptoolkit.com/blog/android-14-install-system-ca-certificate/)
170+
- [Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa](https://www.yeswehack.com/learn-bug-bounty/android-lab-mobile-hacking-tools)
161171

172+
{{#include ../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)