dsh-reverse-plugin 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -0
- package/package.json +3 -3
- package/preset/reverse.patch.yml +10 -5
- package/skills/android/adb-install/SKILL.md +50 -0
- package/skills/android/adb-install/agents/openai.yaml +4 -0
- package/skills/android/adb-install/references/linux.md +35 -0
- package/skills/android/adb-install/references/macos.md +67 -0
- package/skills/android/adb-install/references/sources.md +73 -0
- package/skills/android/adb-install/references/windows.md +73 -0
- package/skills/android/adb-install/scripts/list_downloads.py +105 -0
- package/skills/android/android-hook/SKILL.md +69 -0
- package/skills/android/android-hook/agents/openai.yaml +4 -0
- package/skills/android/android-hook/references/cli-and-frida-trace.md +59 -0
- package/skills/android/android-hook/references/frida-16-to-17.md +39 -0
- package/skills/android/android-hook/references/native-and-cmodule-api.md +85 -0
- package/skills/android/android-hook/references/process-and-memory-api.md +135 -0
- package/skills/android/android-hook/references/script-index.md +86 -0
- package/skills/android/android-hook/scripts/01-crypto/crypto-auto-dump.js +181 -0
- package/skills/android/android-hook/scripts/01-crypto/hook-base64.js +15 -0
- package/skills/android/android-hook/scripts/01-crypto/hook-cipher.js +37 -0
- package/skills/android/android-hook/scripts/02-network-ssl/bypass-conscrypt-pinning.js +26 -0
- package/skills/android/android-hook/scripts/02-network-ssl/bypass-ssl-pinning.js +54 -0
- package/skills/android/android-hook/scripts/02-network-ssl/bypass-vpn-proxy.js +39 -0
- package/skills/android/android-hook/scripts/02-network-ssl/dump-client-cert-p12.js +55 -0
- package/skills/android/android-hook/scripts/02-network-ssl/hook-url-okhttp.js +29 -0
- package/skills/android/android-hook/scripts/02-network-ssl/hook-webview.js +35 -0
- package/skills/android/android-hook/scripts/03-java-trace/activity-control.js +36 -0
- package/skills/android/android-hook/scripts/03-java-trace/art-method-spec.js +110 -0
- package/skills/android/android-hook/scripts/03-java-trace/hook-json.js +37 -0
- package/skills/android/android-hook/scripts/03-java-trace/hook-map.js +39 -0
- package/skills/android/android-hook/scripts/03-java-trace/hook-packed-classloader.js +29 -0
- package/skills/android/android-hook/scripts/03-java-trace/hook-storage.js +66 -0
- package/skills/android/android-hook/scripts/03-java-trace/hook-string.js +57 -0
- package/skills/android/android-hook/scripts/03-java-trace/hook-ui-log.js +19 -0
- package/skills/android/android-hook/scripts/03-java-trace/java-inspect-utils.js +81 -0
- package/skills/android/android-hook/scripts/03-java-trace/register-java-class.js +31 -0
- package/skills/android/android-hook/scripts/04-native-hook/enum-modules-imports.js +37 -0
- package/skills/android/android-hook/scripts/04-native-hook/hook-dlopen.js +60 -0
- package/skills/android/android-hook/scripts/04-native-hook/hook-dlsym.js +25 -0
- package/skills/android/android-hook/scripts/04-native-hook/hook-init-array.js +76 -0
- package/skills/android/android-hook/scripts/04-native-hook/hook-jni-newstringutf.js +38 -0
- package/skills/android/android-hook/scripts/04-native-hook/hook-jni-registernatives.js +43 -0
- package/skills/android/android-hook/scripts/04-native-hook/hook-libc-io-proc.js +48 -0
- package/skills/android/android-hook/scripts/04-native-hook/hook-mem-str.js +87 -0
- package/skills/android/android-hook/scripts/04-native-hook/hook-pthread.js +69 -0
- package/skills/android/android-hook/scripts/04-native-hook/wait-for-module.js +24 -0
- package/skills/android/android-hook/scripts/05-anti-frida/bypass-strstr-anti-frida.js +38 -0
- package/skills/android/android-hook/scripts/05-anti-frida/patch-memfd-frida-str.js +66 -0
- package/skills/android/android-hook/scripts/05-anti-frida/read-proc-maps.js +44 -0
- package/skills/android/android-hook/scripts/05-anti-frida/strip-rwxp.js +43 -0
- package/skills/android/android-hook/scripts/06-unpack-dump/dump-dex-defineclass.js +104 -0
- package/skills/android/android-hook/scripts/06-unpack-dump/load-dex.js +19 -0
- package/skills/android/android-hook/scripts/07-lowlevel-trace/arm64-patch-code.js +40 -0
- package/skills/android/android-hook/scripts/07-lowlevel-trace/got-hook.js +213 -0
- package/skills/android/android-hook/scripts/07-lowlevel-trace/stalker-cmodule-events.js +69 -0
- package/skills/android/android-hook/scripts/07-lowlevel-trace/stalker-trace.js +107 -0
- package/skills/android/android-hook/scripts/07-lowlevel-trace/yahfa-loader.mjs +292 -0
- package/skills/android/android-reverse/SKILL.md +63 -0
- package/skills/android/android-reverse/agents/openai.yaml +4 -0
- package/skills/android/android-reverse/references/developer-options.md +29 -0
- package/skills/android/android-root/SKILL.md +65 -0
- package/skills/android/android-root/agents/openai.yaml +4 -0
- package/skills/android/android-root/references/apatch.md +128 -0
- package/skills/android/android-root/references/kernelsu.md +134 -0
- package/skills/android/android-root/references/post-root-apps.md +31 -0
- package/skills/android/android-root/references/preflight-and-fastboot.md +208 -0
- package/skills/android/frida-install/SKILL.md +54 -0
- package/skills/android/frida-install/agents/openai.yaml +4 -0
- package/skills/android/frida-install/references/install-and-verify.md +126 -0
- package/skills/android/frida-install/references/rusda-releases.md +55 -0
- package/skills/ios/ios-device-bridge/SKILL.md +49 -0
- package/skills/ios/ios-device-bridge/references/pymobiledevice3-cheatsheet.md +81 -0
- package/skills/ios/ios-device-bridge/scripts/check_device.sh +35 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 绕过常见 VPN 与系统 HTTP/HTTPS 代理检测
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/02-network-ssl/bypass-vpn-proxy.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
Java.perform(function () {
|
|
8
|
+
const ConnectivityManager = Java.use('android.net.ConnectivityManager');
|
|
9
|
+
ConnectivityManager.getNetworkInfo.overload('int').implementation = function (networkType) {
|
|
10
|
+
const result = this.getNetworkInfo(networkType);
|
|
11
|
+
if (networkType === ConnectivityManager.TYPE_VPN.value) {
|
|
12
|
+
console.log('[+] Bypassing VPN detection (TYPE_VPN)');
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return result;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const System = Java.use('java.lang.System');
|
|
19
|
+
System.getProperty.overload('java.lang.String').implementation = function (key) {
|
|
20
|
+
if (key === 'http.proxyHost' || key === 'https.proxyHost') {
|
|
21
|
+
console.log('[+] Bypassing proxy property detection:', key);
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
return this.getProperty(key);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const Proxy = Java.use('android.net.Proxy');
|
|
28
|
+
Proxy.getDefaultHost.implementation = function () {
|
|
29
|
+
console.log('[+] Bypassing Proxy.getDefaultHost');
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
Proxy.getDefaultPort.implementation = function () {
|
|
34
|
+
console.log('[+] Bypassing Proxy.getDefaultPort');
|
|
35
|
+
return -1;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
console.log('[+] VPN and Proxy detection hooks installed');
|
|
39
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 客户端双向证书校验场景下 Dump 客户端私钥与证书并导出为 .p12(源自 r0capture)
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/02-network-ssl/dump-client-cert-p12.js
|
|
5
|
+
* @customize 导出路径为 /data/data/<package>/files/base.p12,默认密码 r0ysue
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const P12_PASSWORD = 'r0ysue';
|
|
9
|
+
|
|
10
|
+
if (Java.available) {
|
|
11
|
+
Java.perform(function () {
|
|
12
|
+
function storeP12(pri, p7, p12Path, p12Password) {
|
|
13
|
+
const X509Certificate = Java.use('java.security.cert.X509Certificate');
|
|
14
|
+
const JString = Java.use('java.lang.String');
|
|
15
|
+
const p7X509 = Java.cast(p7, X509Certificate);
|
|
16
|
+
const chain = Java.array('java.security.cert.X509Certificate', [p7X509]);
|
|
17
|
+
const ks = Java.use('java.security.KeyStore').getInstance('PKCS12', 'BC');
|
|
18
|
+
ks.load(null, null);
|
|
19
|
+
const pwdChars = JString.$new(p12Password).toCharArray();
|
|
20
|
+
ks.setKeyEntry('client', pri, pwdChars, chain);
|
|
21
|
+
try {
|
|
22
|
+
const out = Java.use('java.io.FileOutputStream').$new(p12Path);
|
|
23
|
+
ks.store(out, pwdChars);
|
|
24
|
+
out.close();
|
|
25
|
+
} catch (exp) {
|
|
26
|
+
console.log('[!] storeP12 failed:', exp);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function dumpFromEntry(entry) {
|
|
31
|
+
const packageName = Java.use('android.app.ActivityThread')
|
|
32
|
+
.currentApplication()
|
|
33
|
+
.getApplicationContext()
|
|
34
|
+
.getPackageName();
|
|
35
|
+
const outPath = '/data/data/' + packageName + '/files/base.p12';
|
|
36
|
+
storeP12(entry.getPrivateKey(), entry.getCertificate(), outPath, P12_PASSWORD);
|
|
37
|
+
console.log('dumpClientCertificate => ' + outPath + ' pwd: ' + P12_PASSWORD);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const PrivateKeyEntry = Java.use('java.security.KeyStore$PrivateKeyEntry');
|
|
41
|
+
PrivateKeyEntry.getPrivateKey.implementation = function () {
|
|
42
|
+
const result = this.getPrivateKey();
|
|
43
|
+
dumpFromEntry(this);
|
|
44
|
+
return result;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
PrivateKeyEntry.getCertificateChain.implementation = function () {
|
|
48
|
+
const result = this.getCertificateChain();
|
|
49
|
+
dumpFromEntry(this);
|
|
50
|
+
return result;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
console.log('[+] Client certificate dump hooks installed');
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook java.net.URL 构造及 OkHttp3 Request$Builder 的 url / addHeader
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/02-network-ssl/hook-url-okhttp.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
Java.perform(function () {
|
|
8
|
+
const URL = Java.use('java.net.URL');
|
|
9
|
+
URL.$init.overload('java.lang.String').implementation = function (urlStr) {
|
|
10
|
+
console.log('java.net.URL:', urlStr);
|
|
11
|
+
return this.$init(urlStr);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const Builder = Java.use('okhttp3.Request$Builder');
|
|
16
|
+
Builder.url.overload('okhttp3.HttpUrl').implementation = function (httpUrl) {
|
|
17
|
+
const res = this.url(httpUrl);
|
|
18
|
+
console.log('okhttp3.Request$Builder.url:', httpUrl);
|
|
19
|
+
return res;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
Builder.addHeader.implementation = function (key, val) {
|
|
23
|
+
console.log(`okhttp3.Request$Builder.addHeader: ${key} = ${val}`);
|
|
24
|
+
return this.addHeader(key, val);
|
|
25
|
+
};
|
|
26
|
+
} catch (e) {
|
|
27
|
+
console.log('[!] okhttp3.Request$Builder not found (may be obfuscated):', e);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook android.webkit.WebView 的 postUrl / loadUrl(含 HTTPS 堆栈打印)
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/02-network-ssl/hook-webview.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function printJavaStack() {
|
|
8
|
+
console.log(
|
|
9
|
+
Java.use('android.util.Log').getStackTraceString(Java.use('java.lang.Throwable').$new())
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
Java.perform(function () {
|
|
14
|
+
const WebView = Java.use('android.webkit.WebView');
|
|
15
|
+
const JString = Java.use('java.lang.String');
|
|
16
|
+
|
|
17
|
+
WebView.postUrl.implementation = function (url, postData) {
|
|
18
|
+
const body = JString.$new(postData);
|
|
19
|
+
console.log(`WebView.postUrl: url=${url}, body=${body}`);
|
|
20
|
+
return this.postUrl(url, postData);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
WebView.loadUrl.overload('java.lang.String').implementation = function (url) {
|
|
24
|
+
console.log(`WebView.loadUrl: url=${url}`);
|
|
25
|
+
if (url && String(url).includes('https')) {
|
|
26
|
+
printJavaStack();
|
|
27
|
+
}
|
|
28
|
+
return this.loadUrl(url);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
WebView.loadUrl.overload('java.lang.String', 'java.util.Map').implementation = function (url, headers) {
|
|
32
|
+
console.log(`WebView.loadUrl(headers): url=${url}, headers=${headers}`);
|
|
33
|
+
return this.loadUrl(url, headers);
|
|
34
|
+
};
|
|
35
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 查看当前进程存活的 Activity 列表,以及通过 Intent 直接拉起目标 Activity
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -F -l scripts/03-java-trace/activity-control.js
|
|
5
|
+
* @customize 在 REPL 中调用 listActivities() 或 gotoActivity('com.example.TargetActivity')
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function listActivities() {
|
|
9
|
+
Java.perform(function () {
|
|
10
|
+
const ActivityThread = Java.use('android.app.ActivityThread');
|
|
11
|
+
const currentActivityThread = ActivityThread.currentActivityThread();
|
|
12
|
+
const activities = currentActivityThread.mActivities.value;
|
|
13
|
+
const iterator = activities.entrySet().iterator();
|
|
14
|
+
while (iterator.hasNext()) {
|
|
15
|
+
const entry = iterator.next();
|
|
16
|
+
console.log(entry.getClass(), '=>', entry.getValue());
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function gotoActivity(targetClassName) {
|
|
22
|
+
Java.perform(function () {
|
|
23
|
+
const Intent = Java.use('android.content.Intent');
|
|
24
|
+
const ActivityThread = Java.use('android.app.ActivityThread');
|
|
25
|
+
const context = ActivityThread.currentApplication().getApplicationContext();
|
|
26
|
+
const targetClass = Java.use(targetClassName);
|
|
27
|
+
|
|
28
|
+
const intent = Intent.$new(context, targetClass.class);
|
|
29
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK.value);
|
|
30
|
+
console.log('Starting activity:', targetClassName);
|
|
31
|
+
context.startActivity(intent);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 默认仅列出当前 Activity;如需跳转可在 REPL 调用 gotoActivity('完整类名')
|
|
36
|
+
setImmediate(listActivities);
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 自动探测当前 Android/ART 的 ArtMethod 结构体偏移(jniCode / quickCode / accessFlags)并解析指定 Java 方法的 ArtMethod
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -F -l scripts/03-java-trace/art-method-spec.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function getArtMethodSpec(vm) {
|
|
8
|
+
const nativeFunctionOptions = { exceptions: 'propagate' };
|
|
9
|
+
const systemPropertyGet = new NativeFunction(
|
|
10
|
+
Process.getModuleByName('libc.so').getExportByName('__system_property_get'),
|
|
11
|
+
'int',
|
|
12
|
+
['pointer', 'pointer'],
|
|
13
|
+
nativeFunctionOptions
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
function getAndroidSystemProperty(name) {
|
|
17
|
+
const PROP_VALUE_MAX = 92;
|
|
18
|
+
const buf = Memory.alloc(PROP_VALUE_MAX);
|
|
19
|
+
systemPropertyGet(Memory.allocUtf8String(name), buf);
|
|
20
|
+
return buf.readUtf8String();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const pointerSize = Process.pointerSize;
|
|
24
|
+
const kAccPublic = 0x0001;
|
|
25
|
+
const kAccStatic = 0x0008;
|
|
26
|
+
const kAccFinal = 0x0010;
|
|
27
|
+
const kAccNative = 0x0100;
|
|
28
|
+
const kAccFastInterpreterToInterpreterInvoke = 0x40000000;
|
|
29
|
+
const kAccNterpInvokeFastPathFlag = 0x00200000;
|
|
30
|
+
const kAccPublicApi = 0x10000000;
|
|
31
|
+
let spec;
|
|
32
|
+
|
|
33
|
+
vm.perform(function (env) {
|
|
34
|
+
const process = env.findClass('android/os/Process');
|
|
35
|
+
const getElapsedCpuTime = env.getStaticMethodId(process, 'getElapsedCpuTime', '()J');
|
|
36
|
+
env.deleteLocalRef(process);
|
|
37
|
+
|
|
38
|
+
const runtimeModule = Process.getModuleByName('libandroid_runtime.so');
|
|
39
|
+
const runtimeStart = runtimeModule.base;
|
|
40
|
+
const runtimeEnd = runtimeStart.add(runtimeModule.size);
|
|
41
|
+
|
|
42
|
+
const apiLevel = parseInt(getAndroidSystemProperty('ro.build.version.sdk'), 10);
|
|
43
|
+
const entrypointFieldSize = apiLevel <= 21 ? 8 : pointerSize;
|
|
44
|
+
|
|
45
|
+
const expectedAccessFlags = kAccPublic | kAccStatic | kAccFinal | kAccNative;
|
|
46
|
+
const relevantAccessFlagsMask =
|
|
47
|
+
~(kAccFastInterpreterToInterpreterInvoke | kAccPublicApi | kAccNterpInvokeFastPathFlag) >>> 0;
|
|
48
|
+
|
|
49
|
+
let jniCodeOffset = null;
|
|
50
|
+
let accessFlagsOffset = null;
|
|
51
|
+
let remaining = 2;
|
|
52
|
+
for (let offset = 0; offset !== 64 && remaining !== 0; offset += 4) {
|
|
53
|
+
const field = getElapsedCpuTime.add(offset);
|
|
54
|
+
|
|
55
|
+
if (jniCodeOffset === null) {
|
|
56
|
+
const address = field.readPointer();
|
|
57
|
+
if (address.compare(runtimeStart) >= 0 && address.compare(runtimeEnd) < 0) {
|
|
58
|
+
jniCodeOffset = offset;
|
|
59
|
+
remaining--;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (accessFlagsOffset === null) {
|
|
64
|
+
const flags = field.readU32();
|
|
65
|
+
if ((flags & relevantAccessFlagsMask) === expectedAccessFlags) {
|
|
66
|
+
accessFlagsOffset = offset;
|
|
67
|
+
remaining--;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (remaining !== 0) {
|
|
73
|
+
throw new Error('Unable to determine ArtMethod field offsets');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const quickCodeOffset = jniCodeOffset + entrypointFieldSize;
|
|
77
|
+
const size = apiLevel <= 21 ? quickCodeOffset + 32 : quickCodeOffset + pointerSize;
|
|
78
|
+
|
|
79
|
+
spec = {
|
|
80
|
+
size,
|
|
81
|
+
offset: {
|
|
82
|
+
jniCode: jniCodeOffset,
|
|
83
|
+
quickCode: quickCodeOffset,
|
|
84
|
+
accessFlags: accessFlagsOffset,
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
return spec;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function inspectArtMethod(className, methodName) {
|
|
93
|
+
Java.perform(function () {
|
|
94
|
+
const spec = getArtMethodSpec(Java.vm);
|
|
95
|
+
console.log('[+] ArtMethod spec:', JSON.stringify(spec));
|
|
96
|
+
|
|
97
|
+
const Clazz = Java.use(className);
|
|
98
|
+
Clazz[methodName].overloads.forEach(function (method) {
|
|
99
|
+
const artMethodPtr = method._p[3];
|
|
100
|
+
console.log('--- ArtMethod*:', artMethodPtr);
|
|
101
|
+
console.log(' [jniCode] ', artMethodPtr.add(spec.offset.jniCode).readPointer());
|
|
102
|
+
console.log(' [quickCode] ', artMethodPtr.add(spec.offset.quickCode).readPointer());
|
|
103
|
+
console.log(' [accessFlags] 0x' + artMethodPtr.add(spec.offset.accessFlags).readU32().toString(16));
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
setImmediate(function () {
|
|
109
|
+
inspectArtMethod('android.util.Log', 'w');
|
|
110
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook org.json.JSONObject 的 put / getString / optString(命中目标键时打印堆栈)
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/03-java-trace/hook-json.js
|
|
5
|
+
* @customize 修改 STACK_TARGET_KEY 指定需要打印调用栈的 JSON 字段名
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const STACK_TARGET_KEY = 'data';
|
|
9
|
+
|
|
10
|
+
function printJavaStack() {
|
|
11
|
+
console.log(
|
|
12
|
+
Java.use('android.util.Log').getStackTraceString(Java.use('java.lang.Throwable').$new())
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
Java.perform(function () {
|
|
17
|
+
const JSONObject = Java.use('org.json.JSONObject');
|
|
18
|
+
|
|
19
|
+
JSONObject.put.overload('java.lang.String', 'java.lang.Object').implementation = function (key, value) {
|
|
20
|
+
console.log('JSONObject.put:', key, '=>', value);
|
|
21
|
+
return this.put(key, value);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
JSONObject.getString.implementation = function (key) {
|
|
25
|
+
const result = this.getString(key);
|
|
26
|
+
console.log('JSONObject.getString:', key, '=>', result);
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
JSONObject.optString.overload('java.lang.String').implementation = function (key) {
|
|
31
|
+
if (key === STACK_TARGET_KEY) {
|
|
32
|
+
console.log('JSONObject.optString hit:', key);
|
|
33
|
+
printJavaStack();
|
|
34
|
+
}
|
|
35
|
+
return this.optString(key);
|
|
36
|
+
};
|
|
37
|
+
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook HashMap / ConcurrentHashMap / LinkedHashMap 的 put 方法,追踪键值对组装(常用于请求头、签名参数定位)
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/03-java-trace/hook-map.js
|
|
5
|
+
* @customize 建议按需过滤目标 key,否则日志量极大
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const KEY_FILTER = null; // 例如改为 'sign' 只打印包含 sign 的 key
|
|
9
|
+
|
|
10
|
+
function shouldLog(key) {
|
|
11
|
+
if (!KEY_FILTER) return true;
|
|
12
|
+
return key !== null && String(key).includes(KEY_FILTER);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
Java.perform(function () {
|
|
16
|
+
const HashMap = Java.use('java.util.HashMap');
|
|
17
|
+
HashMap.put.implementation = function (key, value) {
|
|
18
|
+
if (shouldLog(key)) {
|
|
19
|
+
console.log('HashMap.put:', key, '=>', value);
|
|
20
|
+
}
|
|
21
|
+
return this.put(key, value);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const ConcurrentHashMap = Java.use('java.util.concurrent.ConcurrentHashMap');
|
|
25
|
+
ConcurrentHashMap.put.implementation = function (key, value) {
|
|
26
|
+
if (shouldLog(key)) {
|
|
27
|
+
console.log('ConcurrentHashMap.put:', key, '=>', value);
|
|
28
|
+
}
|
|
29
|
+
return this.put(key, value);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const LinkedHashMap = Java.use('java.util.LinkedHashMap');
|
|
33
|
+
LinkedHashMap.put.implementation = function (key, value) {
|
|
34
|
+
if (shouldLog(key)) {
|
|
35
|
+
console.log('LinkedHashMap.put:', key, '=>', value);
|
|
36
|
+
}
|
|
37
|
+
return this.put(key, value);
|
|
38
|
+
};
|
|
39
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 加壳/多 DEX 场景下遍历全部 ClassLoader 定位目标类并切换 Java.classFactory.loader 进行 Hook
|
|
3
|
+
* @frida >= 17(纯 Java 层;Java.enumerateClassLoadersSync 在 frida-java-bridge 中持续保留)
|
|
4
|
+
* @usage frida -U -F -l scripts/03-java-trace/hook-packed-classloader.js
|
|
5
|
+
* @customize 修改 TARGET_CLASS 与 TARGET_METHOD 为目标类名与方法名
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const TARGET_CLASS = 'ot2.b';
|
|
9
|
+
const TARGET_METHOD = 'getBdOz';
|
|
10
|
+
|
|
11
|
+
Java.perform(function () {
|
|
12
|
+
Java.enumerateClassLoadersSync().forEach(function (classLoader) {
|
|
13
|
+
try {
|
|
14
|
+
if (classLoader.loadClass(TARGET_CLASS)) {
|
|
15
|
+
Java.classFactory.loader = classLoader;
|
|
16
|
+
console.log('[+] Found class in loader:', classLoader);
|
|
17
|
+
const Target = Java.use(TARGET_CLASS);
|
|
18
|
+
Target[TARGET_METHOD].implementation = function () {
|
|
19
|
+
console.log(`[+] ${TARGET_CLASS}.${TARGET_METHOD} called:`, ...arguments);
|
|
20
|
+
const result = this[TARGET_METHOD](...arguments);
|
|
21
|
+
console.log(`[+] ${TARGET_CLASS}.${TARGET_METHOD} result:`, result);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
} catch (e) {
|
|
26
|
+
// ClassNotFoundException,继续尝试下一个 ClassLoader
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook 本地存储 SharedPreferences 写入与跨进程 ContentResolver 增删改查
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/03-java-trace/hook-storage.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
Java.perform(function () {
|
|
8
|
+
const sp = Java.use('android.app.SharedPreferencesImpl$EditorImpl');
|
|
9
|
+
|
|
10
|
+
sp.putBoolean.overload('java.lang.String', 'boolean').implementation = function (k, v) {
|
|
11
|
+
console.log(`[SharedPreferences] putBoolean -> ${k} = ${v}`);
|
|
12
|
+
return this.putBoolean(k, v);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
sp.putString.overload('java.lang.String', 'java.lang.String').implementation = function (k, v) {
|
|
16
|
+
console.log(`[SharedPreferences] putString -> ${k} = ${v}`);
|
|
17
|
+
return this.putString(k, v);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
sp.putInt.overload('java.lang.String', 'int').implementation = function (k, v) {
|
|
21
|
+
console.log(`[SharedPreferences] putInt -> ${k} = ${v}`);
|
|
22
|
+
return this.putInt(k, v);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
sp.putFloat.overload('java.lang.String', 'float').implementation = function (k, v) {
|
|
26
|
+
console.log(`[SharedPreferences] putFloat -> ${k} = ${v}`);
|
|
27
|
+
return this.putFloat(k, v);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
sp.putLong.overload('java.lang.String', 'long').implementation = function (k, v) {
|
|
31
|
+
console.log(`[SharedPreferences] putLong -> ${k} = ${v}`);
|
|
32
|
+
return this.putLong(k, v);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const content = Java.use('android.content.ContentResolver');
|
|
36
|
+
|
|
37
|
+
content.insert.overload('android.net.Uri', 'android.content.ContentValues').implementation = function (uri, values) {
|
|
38
|
+
console.log(`[ContentResolver] insert -> Uri: ${uri} Values: ${values}`);
|
|
39
|
+
return this.insert(uri, values);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
content.delete.overload('android.net.Uri', 'java.lang.String', '[Ljava.lang.String;').implementation = function (uri, where, args) {
|
|
43
|
+
console.log(`[ContentResolver] delete -> Uri: ${uri}\n where: ${where}\n args: ${args}`);
|
|
44
|
+
return this.delete(uri, where, args);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
content.update.overload('android.net.Uri', 'android.content.ContentValues', 'java.lang.String', '[Ljava.lang.String;').implementation = function (uri, values, where, args) {
|
|
48
|
+
console.log(`[ContentResolver] update -> Uri: ${uri}\n values: ${values}\n where: ${where}\n args: ${args}`);
|
|
49
|
+
return this.update(uri, values, where, args);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
content.query.overload('android.net.Uri', '[Ljava.lang.String;', 'android.os.Bundle', 'android.os.CancellationSignal').implementation = function (a1, a2, a3, a4) {
|
|
53
|
+
console.log(`[ContentResolver] query(Bundle) -> Uri: ${a1}\n proj: ${a2}\n args: ${a3}`);
|
|
54
|
+
return this.query(a1, a2, a3, a4);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
content.query.overload('android.net.Uri', '[Ljava.lang.String;', 'java.lang.String', '[Ljava.lang.String;', 'java.lang.String').implementation = function (a1, a2, a3, a4, a5) {
|
|
58
|
+
console.log(`[ContentResolver] query -> Uri: ${a1}\n proj: ${a2}\n sel: ${a3}\n args: ${a4}\n sort: ${a5}`);
|
|
59
|
+
return this.query(a1, a2, a3, a4, a5);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
content.query.overload('android.net.Uri', '[Ljava.lang.String;', 'java.lang.String', '[Ljava.lang.String;', 'java.lang.String', 'android.os.CancellationSignal').implementation = function (a1, a2, a3, a4, a5, a6) {
|
|
63
|
+
console.log(`[ContentResolver] query(Cancel) -> Uri: ${a1}\n proj: ${a2}\n sel: ${a3}\n args: ${a4}\n sort: ${a5}`);
|
|
64
|
+
return this.query(a1, a2, a3, a4, a5, a6);
|
|
65
|
+
};
|
|
66
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook 字符串构造与拼接(StringFactory / StringBuilder / StringBuffer)
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/03-java-trace/hook-string.js
|
|
5
|
+
* @customize 强烈建议设置 KEYWORD_FILTER 过滤输出,否则进程会因海量字符串输出卡顿
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const KEYWORD_FILTER = null; // 例如改为 'token'
|
|
9
|
+
|
|
10
|
+
function matchFilter(str) {
|
|
11
|
+
if (!KEYWORD_FILTER) return true;
|
|
12
|
+
return str !== null && String(str).includes(KEYWORD_FILTER);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function hookStringFactory() {
|
|
16
|
+
const StringFactory = Java.use('java.lang.StringFactory');
|
|
17
|
+
StringFactory.newStringFromString.implementation = function (a) {
|
|
18
|
+
const retval = this.newStringFromString(a);
|
|
19
|
+
if (matchFilter(retval)) {
|
|
20
|
+
console.log('StringFactory.newStringFromString:', retval);
|
|
21
|
+
}
|
|
22
|
+
return retval;
|
|
23
|
+
};
|
|
24
|
+
StringFactory.newStringFromChars.overload('[C').implementation = function (a) {
|
|
25
|
+
const retval = this.newStringFromChars(a);
|
|
26
|
+
if (matchFilter(retval)) {
|
|
27
|
+
console.log('StringFactory.newStringFromChars:', retval);
|
|
28
|
+
}
|
|
29
|
+
return retval;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function hookStringBuilders() {
|
|
34
|
+
const StringBuilder = Java.use('java.lang.StringBuilder');
|
|
35
|
+
StringBuilder.toString.implementation = function () {
|
|
36
|
+
const retval = this.toString();
|
|
37
|
+
if (matchFilter(retval)) {
|
|
38
|
+
console.log('StringBuilder.toString:', retval);
|
|
39
|
+
}
|
|
40
|
+
return retval;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const StringBuffer = Java.use('java.lang.StringBuffer');
|
|
44
|
+
StringBuffer.toString.implementation = function () {
|
|
45
|
+
const retval = this.toString();
|
|
46
|
+
if (matchFilter(retval)) {
|
|
47
|
+
console.log('StringBuffer.toString:', retval);
|
|
48
|
+
}
|
|
49
|
+
return retval;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Java.perform(function () {
|
|
54
|
+
hookStringBuilders();
|
|
55
|
+
// 如需更底层拦截 new String,取消下方注释(注意输出极多)
|
|
56
|
+
// hookStringFactory();
|
|
57
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook android.util.Log.w 与 android.widget.Toast.show
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/03-java-trace/hook-ui-log.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
Java.perform(function () {
|
|
8
|
+
const Log = Java.use('android.util.Log');
|
|
9
|
+
Log.w.overload('java.lang.String', 'java.lang.String').implementation = function (tag, message) {
|
|
10
|
+
console.log('Log.w:', tag, message);
|
|
11
|
+
return this.w(tag, message);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const Toast = Java.use('android.widget.Toast');
|
|
15
|
+
Toast.show.implementation = function () {
|
|
16
|
+
console.log('Toast.show called');
|
|
17
|
+
return this.show();
|
|
18
|
+
};
|
|
19
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Java 层常用诊断与反射辅助函数集合(字段 dump、UTF-8 字节转换、Map 转 JSON、堆栈打印、方法签名枚举、JNI handle/元数据读取)
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -F -l scripts/03-java-trace/java-inspect-utils.js 后在 REPL 调用对应工具函数
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function dumpAllFieldValue(obj) {
|
|
8
|
+
if (obj === null) return;
|
|
9
|
+
console.log('Dump all fields for ' + obj.getClass() + ':');
|
|
10
|
+
let cls = obj.getClass();
|
|
11
|
+
const ObjectClass = Java.use('java.lang.Object').class;
|
|
12
|
+
while (cls !== null && !cls.equals(ObjectClass)) {
|
|
13
|
+
const fields = cls.getDeclaredFields();
|
|
14
|
+
if (fields === null || fields.length === 0) {
|
|
15
|
+
cls = cls.getSuperclass();
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (!cls.equals(obj.getClass())) {
|
|
19
|
+
console.log('Dump super class ' + cls.getName() + ' fields:');
|
|
20
|
+
}
|
|
21
|
+
for (let i = 0; i < fields.length; i++) {
|
|
22
|
+
const field = fields[i];
|
|
23
|
+
field.setAccessible(true);
|
|
24
|
+
console.log(field.getType() + ' ' + field.getName() + '=' + field.get(obj));
|
|
25
|
+
}
|
|
26
|
+
cls = cls.getSuperclass();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function utf8Bytes(byteArray) {
|
|
31
|
+
const StringClass = Java.use('java.lang.String');
|
|
32
|
+
const CharsetClass = Java.use('java.nio.charset.Charset');
|
|
33
|
+
const utf8Charset = CharsetClass.forName('UTF-8');
|
|
34
|
+
return StringClass.$new(byteArray, utf8Charset);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function mapToJson(map) {
|
|
38
|
+
const Gson = Java.use('com.google.gson.Gson').$new();
|
|
39
|
+
return Gson.toJsonTree(map).getAsJsonObject();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getStackTraceString() {
|
|
43
|
+
console.log(
|
|
44
|
+
Java.use('android.util.Log').getStackTraceString(Java.use('java.lang.Throwable').$new())
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function dumpDeclaredMethods(className) {
|
|
49
|
+
Java.perform(function () {
|
|
50
|
+
const clazz = Java.use(className);
|
|
51
|
+
const methods = clazz.class.getDeclaredMethods();
|
|
52
|
+
for (let i = 0; i < methods.length; i++) {
|
|
53
|
+
console.log('Method:', methods[i].getName(), '| Signature:', methods[i].toString());
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// 示例:创建 Java Class 数组、获取底层 jclass/jobject ($h)、查看 Frida 内部类元信息 ($l / _p)
|
|
59
|
+
function inspectJavaInternalsExample() {
|
|
60
|
+
Java.perform(function () {
|
|
61
|
+
const StringClass = Java.use('java.lang.String');
|
|
62
|
+
const Log = Java.use('android.util.Log');
|
|
63
|
+
|
|
64
|
+
// 1. 构建 Java 数组
|
|
65
|
+
const classArray = Java.array('Ljava.lang.Class;', [StringClass.class, StringClass.class]);
|
|
66
|
+
console.log('classArray length:', classArray.length);
|
|
67
|
+
|
|
68
|
+
// 2. 获取 jclass / jobject 原始 JNI handle ($h) 与 JNIEnv 指针
|
|
69
|
+
const logClassPtr = Log.class.$h;
|
|
70
|
+
const methodName = StringClass.$new('w');
|
|
71
|
+
const methodSig = StringClass.$new('(Ljava/lang/String;Ljava/lang/String;)I');
|
|
72
|
+
const envPtr = Java.vm.getEnv().handle;
|
|
73
|
+
console.log('jclass:', logClassPtr, 'namePtr:', methodName.$h, 'sigPtr:', methodSig.$h, 'env:', envPtr);
|
|
74
|
+
|
|
75
|
+
// 3. 查看 Frida 内部 class-model ($l) 与 overload 底层信息 (_p,其中 _p[3] 通常为 ArtMethod*)
|
|
76
|
+
console.log('Log.$l.find("w"):', Log.$l.find('w'));
|
|
77
|
+
Log.w.overloads.forEach(function (method) {
|
|
78
|
+
console.log('overload._p:', method._p, 'ArtMethod*:', method._p[3]);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 使用 Java.registerClass 在运行时动态创建自定义 Java 类(常用于构造接口实现或配合 YAHFA)
|
|
3
|
+
* @frida >= 17(纯 Java 层)
|
|
4
|
+
* @usage frida -U -F -l scripts/03-java-trace/register-java-class.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
Java.perform(function () {
|
|
8
|
+
const Hook_Log_e = Java.registerClass({
|
|
9
|
+
name: 'lab.galaxy.yahfa.demoApp.Hook_Log_e',
|
|
10
|
+
methods: {
|
|
11
|
+
hook: {
|
|
12
|
+
returnType: 'int',
|
|
13
|
+
argumentTypes: ['java.lang.String', 'java.lang.String'],
|
|
14
|
+
implementation: function (tag, msg) {
|
|
15
|
+
Java.use('android.util.Log').w('HookTest', 'in Log.e(): ' + tag + ', ' + msg);
|
|
16
|
+
return 1;
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
backup: {
|
|
20
|
+
returnType: 'int',
|
|
21
|
+
argumentTypes: ['java.lang.String', 'java.lang.String'],
|
|
22
|
+
implementation: function (tag, msg) {
|
|
23
|
+
Java.use('android.util.Log').w('HookTest', 'Log.e() should not be here');
|
|
24
|
+
return 1;
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
console.log('[+] Registered class:', Hook_Log_e);
|
|
31
|
+
});
|