Skip to content

Commit 319bb06

Browse files
author
HackTricks News Bot
committed
Add content from: phantom-frida
1 parent 897d411 commit 319bb06

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,31 @@ This page provides a practical workflow to regain dynamic analysis against Andro
1212
- Early init checks: Application.onCreate() or process start hooks that crash if instrumentation is present
1313
- TLS pinning: custom TrustManager/HostnameVerifier, OkHttp CertificatePinner, Conscrypt pinning, native pins
1414

15+
## Bypassing Anti-Frida Detection / Stealth Frida Servers
16+
17+
**phantom-frida** rebuilds Frida from source and applies ~90 patches so common Frida fingerprints disappear while the stock Frida protocol remains compatible (`frida-tools` can still connect). Target: apps that grep `/proc` (cmdline, maps, task comm, fd readlink), D-Bus service names, default ports, or exported symbols.
18+
19+
Phases:
20+
- **Source patches:** global rename of `frida` identifiers (server/agent/helper) and rebuilt helper DEX with a renamed Java package.
21+
- **Targeted build/runtime patches:** meson tweaks, memfd label changed to `jit-cache`, SELinux labels (e.g., `frida_file`) renamed, libc hooks on `exit`/`signal` disabled to avoid hook-detectors.
22+
- **Post-build rename:** exported symbol `frida_agent_main` renamed after the first compile (Vala emits it), requiring a second incremental build.
23+
- **Binary hex patches:** thread names (`gmain`, `gdbus`, `pool-spawner`) replaced; optional sweep removes leftover `frida`/`Frida` strings.
24+
25+
Detection vectors covered:
26+
- **Base (1–8):** process name `frida-server`, mapped `libfrida-agent.so`, thread names, memfd label, exported `frida_agent_main`, SELinux labels, libc hook side-effects, and D-Bus service `re.frida.server` are renamed/neutralized.
27+
- **Extended (9–16):** change listening port (`--port`), rename D-Bus interfaces/internal C symbols/GType names, temp paths like `.frida`/`frida-`, sweep binary strings, rename build-time defines and asset paths (`libdir/frida`). D-Bus interface names that are part of the wire protocol stay unchanged in base mode to avoid breaking stock clients.
28+
29+
Build/usage (Android arm64 example):
30+
```bash
31+
python3 build.py --version 17.7.2 --name myserver --port 27142 --extended --verify
32+
adb push output/myserver-server-17.7.2-android-arm64 /data/local/tmp/myserver-server
33+
adb shell chmod 755 /data/local/tmp/myserver-server
34+
adb shell /data/local/tmp/myserver-server -D &
35+
adb forward tcp:27142 tcp:27142
36+
frida -H 127.0.0.1:27142 -f com.example.app
37+
```
38+
Flags: `--skip-build` (patch only), `--skip-clone`, `--arch`, `--ndk-path`, `--temp-fixes`; WSL helper: `wsl -d Ubuntu bash build-wsl.sh`.
39+
1540
## Step 1 — Quick win: hide root with Magisk DenyList
1641

1742
- Enable Zygisk in Magisk
@@ -123,13 +148,16 @@ Java.perform(() => {
123148
});
124149
```
125150

126-
// Quick root detection stub example (adapt to target package/class names)
151+
Quick root detection stub example (adapt to target package/class names):
152+
153+
```js
127154
Java.perform(() => {
128155
try {
129156
const RootChecker = Java.use('com.target.security.RootCheck');
130157
RootChecker.isDeviceRooted.implementation = function () { return false; };
131158
} catch (e) {}
132159
});
160+
```
133161

134162
Log and neuter suspicious methods to confirm execution flow:
135163

@@ -322,5 +350,6 @@ Notes
322350
- [Magisk](https://github.com/topjohnwu/Magisk)
323351
- [Medusa (Android Frida framework)](https://github.com/Ch0pin/medusa)
324352
- [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)
353+
- [phantom-frida (stealth Frida server builder)](https://github.com/TheQmaks/phantom-frida)
325354

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

0 commit comments

Comments
 (0)