Android Anti-Instrumentation & SSL Pinning Bypass (Frida/Objection)
Reading time: 9 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 を検出/ブロックしたり TLS pinning を強制する Android アプリに対して、動的解析を取り戻すための実践的なワークフローを提供します。高速なトリアージ、一般的な検出方法、可能な限り再パッケージ不要で回避するためのコピペ可能なフック/戦術に焦点を当てています。
Detection Surface (what apps check)
- Root チェック: su binary、Magisk paths、getprop values、一般的な root パッケージ
- Frida/debugger チェック (Java): Debug.isDebuggerConnected(), ActivityManager.getRunningAppProcesses(), getRunningServices(), /proc のスキャン、classpath、読み込まれた libs
- Native anti‑debug: ptrace(), syscalls、anti‑attach、ブレークポイント、インラインフック
- Early init チェック: Application.onCreate() やプロセス開始時のフックで、instrumentation が存在するとクラッシュさせるもの
- TLS pinning: custom TrustManager/HostnameVerifier、OkHttp CertificatePinner、Conscrypt pinning、ネイティブのピン
Step 1 — Quick win: hide root with Magisk DenyList
- Magisk で Zygisk を有効にする
- DenyList を有効にし、対象パッケージを追加する
- 再起動して再テストする
多くのアプリは明白な指標(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
例:
frida -U -f com.example.app -l anti-frida-detection.js
これらは通常、Java の root/debug チェック、process/service スキャン、およびネイティブ ptrace() をスタブ化します。軽度に保護されたアプリには有用ですが、ハード化されたターゲットでは専用のフックが必要になる場合があります。
- Codeshare: https://codeshare.frida.re/
ステップ3 — init-time detectors を遅れてアタッチして回避する
多くの検出は process spawn/onCreate() の実行時のみ走ります。Spawn‑time injection (-f) や gadgets は検出されやすいですが、UI がロードされた後にアタッチすれば回避できることがあります。
# 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
If this works, keep the session stable and proceed to map and stub checks.
Step 4 — Jadx と文字列探索で検出ロジックをマッピング
Static triage keywords in Jadx:
- "frida", "gum", "root", "magisk", "ptrace", "su", "getprop", "debugger"
Typical Java patterns:
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(); };
});
初期の crashes をトリアージしていますか?終了直前に Dump classes を行い、検出に使われそうな namespaces を特定しましょう:
Java.perform(() => {
Java.enumerateLoadedClasses({
onMatch: n => console.log(n),
onComplete: () => console.log('Done')
});
});
実行フローを確認するために、疑わしいメソッドをログ出力して無効化する:
Java.perform(() => {
const Det = Java.use('com.example.security.DetectionManager');
Det.checkFrida.implementation = function () {
console.log('checkFrida() called');
return false;
};
});
ステップ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'
Interactive/native 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 patching (embed gadget / strip basics)
repackingをruntime hooksの代わりに好む場合は、次を試してください:
objection patchapk --source app.apk
注記:
- Requires apktool; ensure a current version from the official guide to avoid build issues: https://apktool.org/docs/install
- Gadget injection enables instrumentation without root but can still be caught by stronger init‑time checks.
参考:
- Objection: https://github.com/sensepost/objection
Step 8 — フォールバック: ネットワーク可視化のために TLS pinning をパッチする
もし instrumentation がブロックされている場合、pinning を静的に除去することでトラフィックを確認できます:
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
ヒントと注意点
- アプリが起動時にクラッシュする場合は、spawnより遅くattachすることを優先する
- いくつかの検知は重要なフロー(例: payment、auth)で再実行されることがある — ナビゲーション中はhooksを有効に保つ
- 静的解析と動的解析を組み合わせる: Jadxで文字列を探索してクラスを絞り、ランタイムで確認するためにメソッドをhookする
- 強化されたアプリはpackersやnative TLS pinningを使用する可能性がある — ネイティブコードの逆解析を想定する
参考
- Reversing Android Apps: Bypassing Detection Like a Pro
- Frida Codeshare
- Objection
- apk-mitm
- Jadx
- Ghidra
- r2frida
- Apktool install guide
- Magisk
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を提出してハッキングトリックを共有してください。