Android Anti-Instrumentation & SSL Pinning Bypass (Frida/Objection)
Reading time: 13 minutes
tip
AWSハッキングを学び、実践する:
HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:
HackTricks Training GCP Red Team Expert (GRTE)
Azureハッキングを学び、実践する:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricksをサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリにPRを提出してハッキングトリックを共有してください。
このページは、instrumentation を検知/root‑block する、または TLS pinning を強制する Android アプリに対して dynamic analysis を再確立するための実践的なワークフローを提供します。高速なトリアージ、一般的な検知項目、および可能な限りリパッキングせずに回避するためのコピペ可能な hooks/tactics に焦点を当てています。
Detection Surface (what apps check)
- Root checks: su binary, Magisk paths, getprop values, common root packages
- Frida/debugger checks (Java): Debug.isDebuggerConnected(), ActivityManager.getRunningAppProcesses(), getRunningServices(), scanning /proc, classpath, loaded libs
- Native anti‑debug: ptrace(), syscalls, anti‑attach, breakpoints, inline hooks
- Early init checks: Application.onCreate() or process start hooks that crash if instrumentation is present
- TLS pinning: custom TrustManager/HostnameVerifier, OkHttp CertificatePinner, Conscrypt pinning, native pins
Step 1 — Quick win: hide root with Magisk DenyList
- Enable Zygisk in Magisk
- Enable DenyList, add the target package
- Reboot and retest
多くのアプリは明白な指標(su/Magisk paths/getprop)しか見ていないことが多く、DenyList は単純なチェックを無効化することがよくあります。
References:
- Magisk (Zygisk & DenyList): https://github.com/topjohnwu/Magisk
Step 2 — 30‑second Frida Codeshare tests
深掘りする前に、よくあるドロップインスクリプトを試してください:
- anti-root-bypass.js
- anti-frida-detection.js
- hide_frida_gum.js
Example:
frida -U -f com.example.app -l anti-frida-detection.js
これらは通常、Javaのroot/debug checks、process/service scans、およびnative ptrace()をスタブ化します。軽度に保護されたアプリでは有用ですが、ハード化されたターゲットではカスタムのhooksが必要になる場合があります。
- Codeshare: https://codeshare.frida.re/
Medusa (Frida framework) で自動化
Medusaは、SSL unpinning、root/emulator detection bypass、HTTP comms logging、crypto key interceptionなどのために90+の既成モジュールを提供します。
git clone https://github.com/Ch0pin/medusa
cd medusa
pip install -r requirements.txt
python medusa.py
# Example interactive workflow
show categories
use http_communications/multiple_unpinner
use root_detection/universal_root_detection_bypass
run com.target.app
Tip: Medusa は custom hooks を書く前に素早く成果を上げるのに最適です。モジュールを cherry‑pick して自分のスクリプトと組み合わせることもできます。
ステップ3 — 遅れて attach して init-time detectors を bypass する
多くの検出は process spawn/onCreate() の実行時にのみ動作します。Spawn‑time injection (-f) や gadgets は検出されやすく、UI がロードされた後に attach すると回避できる場合があります。
# Launch the app normally (launcher/adb), wait for UI, then attach
frida -U -n com.example.app
# Or with Objection to attach to running process
aobjection --gadget com.example.app explore # if using gadget
これが機能する場合、セッションを安定させたまま、マッピングとスタブのチェックに進みます。
ステップ4 — Jadxと文字列探索による検出ロジックのマッピング
Static triage keywords in Jadx:
- "frida", "gum", "root", "magisk", "ptrace", "su", "getprop", "debugger"
典型的なJavaパターン:
public boolean isFridaDetected() {
return getRunningServices().contains("frida");
}
確認・フックする一般的な API:
- android.os.Debug.isDebuggerConnected
- android.app.ActivityManager.getRunningAppProcesses / getRunningServices
- java.lang.System.loadLibrary / System.load (native bridge)
- java.lang.Runtime.exec / ProcessBuilder (probing commands)
- android.os.SystemProperties.get (root/emulator heuristics)
ステップ5 — Frida (Java) を使ったランタイムスタブ
再パッケージ化せずに安全な値を返すようカスタムガードをオーバーライドする:
Java.perform(() => {
const Checks = Java.use('com.example.security.Checks');
Checks.isFridaDetected.implementation = function () { return false; };
// Neutralize debugger checks
const Debug = Java.use('android.os.Debug');
Debug.isDebuggerConnected.implementation = function () { return false; };
// Example: kill ActivityManager scans
const AM = Java.use('android.app.ActivityManager');
AM.getRunningAppProcesses.implementation = function () { return java.util.Collections.emptyList(); };
});
早期クラッシュをトリアージしていますか?クラッシュ直前にクラスをダンプして、検出されやすい名前空間を特定します:
Java.perform(() => {
Java.enumerateLoadedClasses({
onMatch: n => console.log(n),
onComplete: () => console.log('Done')
});
});
// Quick root detection stub example (adapt to target package/class names)
Java.perform(() => {
try {
const RootChecker = Java.use('com.target.security.RootCheck');
RootChecker.isDeviceRooted.implementation = function () { return false; };
} catch (e) {}
});
疑わしいメソッドをログに記録し、無効化して実行フローを確認する:
Java.perform(() => {
const Det = Java.use('com.example.security.DetectionManager');
Det.checkFrida.implementation = function () {
console.log('checkFrida() called');
return false;
};
});
Bypass emulator/VM detection (Java stubs)
一般的な判定条件: Build.FINGERPRINT/MODEL/MANUFACTURER/HARDWARE に generic/goldfish/ranchu/sdk が含まれる; QEMU の痕跡(/dev/qemu_pipe, /dev/socket/qemud); デフォルトの MAC 02:00:00:00:00:00; 10.0.2.x の NAT; telephony/sensors が存在しない。
Build フィールドの簡易偽装例:
Java.perform(function(){
var Build = Java.use('android.os.Build');
Build.MODEL.value = 'Pixel 7 Pro';
Build.MANUFACTURER.value = 'Google';
Build.BRAND.value = 'google';
Build.FINGERPRINT.value = 'google/panther/panther:14/UP1A.231105.003/1234567:user/release-keys';
});
ファイルの存在チェックや識別子(TelephonyManager.getDeviceId/SubscriberId、WifiInfo.getMacAddress、SensorManager.getSensorList)に対するスタブを追加して、現実的な値を返すようにしてください。
SSL pinning bypass quick hook (Java)
カスタム TrustManagers を無効化し、許容的な SSL contexts を強制します:
Java.perform(function(){
var X509TrustManager = Java.use('javax.net.ssl.X509TrustManager');
var SSLContext = Java.use('javax.net.ssl.SSLContext');
// No-op validations
X509TrustManager.checkClientTrusted.implementation = function(){ };
X509TrustManager.checkServerTrusted.implementation = function(){ };
// Force permissive TrustManagers
var TrustManagers = [ X509TrustManager.$new() ];
var SSLContextInit = SSLContext.init.overload('[Ljavax.net.ssl.KeyManager;','[Ljavax.net.ssl.TrustManager;','java.security.SecureRandom');
SSLContextInit.implementation = function(km, tm, sr){
return SSLContextInit.call(this, km, TrustManagers, sr);
};
});
注意
- OkHttp 用に拡張: 必要に応じて okhttp3.CertificatePinner と HostnameVerifier を hook するか、CodeShare の汎用 unpinning スクリプトを使用してください。
- 実行例:
frida -U -f com.target.app -l ssl-bypass.js --no-pause
Step 6 — Java hooks が失敗したときは JNI/native の追跡を行う
JNI のエントリポイントをトレースして native loaders と detection init を特定する:
frida-trace -n com.example.app -i "JNI_OnLoad"
バンドルされた .so ファイルの簡易ネイティブトリアージ:
# List exported symbols & JNI
nm -D libfoo.so | head
objdump -T libfoo.so | grep Java_
strings -n 6 libfoo.so | egrep -i 'frida|ptrace|gum|magisk|su|root'
インタラクティブ/ネイティブ reversing:
- Ghidra: https://ghidra-sre.org/
- r2frida: https://github.com/nowsecure/r2frida
例: ptrace を無効化して libc の単純な anti‑debug を回避する:
const ptrace = Module.findExportByName(null, 'ptrace');
if (ptrace) {
Interceptor.replace(ptrace, new NativeCallback(function () {
return -1; // pretend failure
}, 'int', ['int', 'int', 'pointer', 'pointer']));
}
参照: Reversing Native Libraries
ステップ7 — Objection のパッチ適用 (embed gadget / strip basics)
repacking を runtime hooks より好む場合は、次を試してください:
objection patchapk --source app.apk
Notes:
- apktool が必要です。ビルドの問題を避けるため、公式ガイドから最新バージョンを入手してください: https://apktool.org/docs/install
- Gadget injection により root なしで instrumentation が可能になりますが、より強力な init‑time checks によって検出される場合があります。
Optionally, add LSPosed modules and Shamiko for stronger root hiding in Zygisk environments, and curate DenyList to cover 子プロセス。
For a complete workflow including script-mode Gadget configuration and bundling your Frida 17+ agent into the APK, see:
Frida Tutorial — Self-contained agent + Gadget embedding
References:
- Objection: https://github.com/sensepost/objection
ステップ8 — フォールバック: TLS pinning をパッチしてネットワークの可視化
If instrumentation is blocked, you can still inspect traffic by removing pinning statically:
apk-mitm app.apk
# Then install the patched APK and proxy via Burp/mitmproxy
- ツール: https://github.com/shroudedcode/apk-mitm
- ネットワーク設定の CA‑trust トリック(および Android 7+ user CA trust)については、参照:
Make APK Accept CA Certificate
便利なコマンド チートシート
# List processes and attach
frida-ps -Uai
frida -U -n com.example.app
# Spawn with a script (may trigger detectors)
frida -U -f com.example.app -l anti-frida-detection.js
# Trace native init
frida-trace -n com.example.app -i "JNI_OnLoad"
# Objection runtime
objection --gadget com.example.app explore
# Static TLS pinning removal
apk-mitm app.apk
汎用 proxy 強制 + TLS unpinning (HTTP Toolkit Frida hooks)
近年のアプリはシステムプロキシを無視し、(Java とネイティブの)複数レイヤーのピンニングを強制することが多いため、user/system CAs をインストールしていても通信のキャプチャが困難になります。実務的な対処法は、汎用の TLS unpinning と proxy forcing を既製の Frida hooks で組み合わせ、すべてを mitmproxy/Burp 経由でルーティングすることです。
ワークフロー
- ホストで mitmproxy(または Burp)を起動し、デバイスがホストの IP/ポートに到達できることを確認します。
- HTTP Toolkit の統合済み Frida hooks を読み込み、OkHttp/OkHttp3、HttpsURLConnection、Conscrypt、WebView などの一般的なスタック全体で TLS の unpinning と proxy の強制を行います。これにより CertificatePinner/TrustManager のチェックをバイパスし、proxy selectors を上書きするため、アプリが明示的に proxy を無効化していても通信は常にあなたの proxy 経由で送信されます。
- 対象アプリを Frida とフックスクリプトで起動し、mitmproxy でリクエストをキャプチャします。
例
# Device connected via ADB or over network (-U)
# See the repo for the exact script names & options
frida -U -f com.vendor.app \
-l ./android-unpinning-with-proxy.js \
--no-pause
# mitmproxy listening locally
mitmproxy -p 8080
注意
- 可能な場合はシステム全体のプロキシ(
adb shell settings put global http_proxy <host>:<port>)と組み合わせて使用してください。Frida hooks は、アプリがグローバル設定を回避してもプロキシの使用を強制します。 - pinning や proxy 回避が一般的な、モバイル→IoT のオンボーディングフローをMITMする必要がある場合に、この手法は理想的です。
- Hooks: https://github.com/httptoolkit/frida-interception-and-unpinning
References
- Reversing Android Apps: Bypassing Detection Like a Pro
- Frida Codeshare
- Objection
- apk-mitm
- Jadx
- Ghidra
- r2frida
- Apktool install guide
- Magisk
- Medusa (Android Frida framework)
- Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa
tip
AWSハッキングを学び、実践する:
HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:
HackTricks Training GCP Red Team Expert (GRTE)
Azureハッキングを学び、実践する:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricksをサポートする
- サブスクリプションプランを確認してください!
- **💬 Discordグループまたはテレグラムグループに参加するか、Twitter 🐦 @hacktricks_liveをフォローしてください。
- HackTricksおよびHackTricks CloudのGitHubリポジトリにPRを提出してハッキングトリックを共有してください。
HackTricks