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,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 枚举进程已加载模块、枚举指定 SO 导入/导出表,以及打印 Native 调用栈工具函数
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -F -l scripts/04-native-hook/enum-modules-imports.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function listModules() {
|
|
8
|
+
for (const mod of Process.enumerateModules()) {
|
|
9
|
+
console.log(`${mod.name} | base=${mod.base} | size=0x${mod.size.toString(16)} | path=${mod.path}`);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function listModuleImports(soPathOrName) {
|
|
14
|
+
const mod = Process.findModuleByName(soPathOrName) || Module.load(soPathOrName);
|
|
15
|
+
for (const imp of mod.enumerateImports()) {
|
|
16
|
+
console.log(`[import] type=${imp.type} name=${imp.name} module=${imp.module} addr=${imp.address}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function listModuleExports(soName) {
|
|
21
|
+
const mod = Process.getModuleByName(soName);
|
|
22
|
+
for (const exp of mod.enumerateExports()) {
|
|
23
|
+
console.log(`[export] type=${exp.type} name=${exp.name} addr=${exp.address}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// 在 Interceptor 回调内调用:printNativeBacktrace(this.context)
|
|
28
|
+
function printNativeBacktrace(cpuContext, accurate = false) {
|
|
29
|
+
const mode = accurate ? Backtracer.ACCURATE : Backtracer.FUZZY;
|
|
30
|
+
console.log(
|
|
31
|
+
'Native backtrace:\n' +
|
|
32
|
+
Thread.backtrace(cpuContext, mode).map(DebugSymbol.fromAddress).join('\n') +
|
|
33
|
+
'\n'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
listModules();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook dlopen 与 android_dlopen_ext,监控 SO 加载并在目标 SO 加载完成后触发回调
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/04-native-hook/hook-dlopen.js
|
|
5
|
+
* @customize 修改 TARGET_SO 并在 onTargetLoaded 中挂载目标 SO 的 Hook
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const TARGET_SO = 'libxxx.so';
|
|
9
|
+
|
|
10
|
+
function onTargetLoaded(soName) {
|
|
11
|
+
const mod = Process.findModuleByName(soName);
|
|
12
|
+
console.log(`[+] ${soName} loaded, base=${mod ? mod.base : 'unknown'}`);
|
|
13
|
+
// 在这里挂载目标 SO 内部函数 Hook
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function hookDlopen(targetSoName) {
|
|
17
|
+
const dlopenAddr = Module.findGlobalExportByName('dlopen');
|
|
18
|
+
if (dlopenAddr) {
|
|
19
|
+
Interceptor.attach(dlopenAddr, {
|
|
20
|
+
onEnter(args) {
|
|
21
|
+
this.matched = false;
|
|
22
|
+
if (!args[0].isNull()) {
|
|
23
|
+
const path = args[0].readCString();
|
|
24
|
+
if (path && path.includes(targetSoName)) {
|
|
25
|
+
console.log('[dlopen]', path);
|
|
26
|
+
this.matched = true;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
onLeave() {
|
|
31
|
+
if (this.matched) {
|
|
32
|
+
onTargetLoaded(targetSoName);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const extAddr = Module.findGlobalExportByName('android_dlopen_ext');
|
|
39
|
+
if (extAddr) {
|
|
40
|
+
Interceptor.attach(extAddr, {
|
|
41
|
+
onEnter(args) {
|
|
42
|
+
this.matched = false;
|
|
43
|
+
if (!args[0].isNull()) {
|
|
44
|
+
const path = args[0].readCString();
|
|
45
|
+
console.log('[android_dlopen_ext]', path);
|
|
46
|
+
if (path && path.includes(targetSoName)) {
|
|
47
|
+
this.matched = true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
onLeave() {
|
|
52
|
+
if (this.matched) {
|
|
53
|
+
onTargetLoaded(targetSoName);
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
hookDlopen(TARGET_SO);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook libdl.so 的 dlsym,追踪符号解析与静态注册 JNI 函数定位
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/04-native-hook/hook-dlsym.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function hookDlsym() {
|
|
8
|
+
const dlsymAddr = Process.getModuleByName('libdl.so').findExportByName('dlsym');
|
|
9
|
+
console.log('[+] dlsym:', dlsymAddr);
|
|
10
|
+
if (!dlsymAddr) return;
|
|
11
|
+
|
|
12
|
+
Interceptor.attach(dlsymAddr, {
|
|
13
|
+
onEnter(args) {
|
|
14
|
+
this.symNamePtr = args[1];
|
|
15
|
+
},
|
|
16
|
+
onLeave(retval) {
|
|
17
|
+
const md = Process.findModuleByAddress(retval);
|
|
18
|
+
if (md === null) return;
|
|
19
|
+
const symName = this.symNamePtr.isNull() ? '<null>' : this.symNamePtr.readCString();
|
|
20
|
+
console.log(`dlsym: ${symName} | mod=${md.name} | addr=${retval} | offset=${retval.sub(md.base)}`);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
hookDlsym();
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook linker/linker64 的 soinfo::call_constructors 拦截 .init_array 执行时机(附 open 早期触发示例)
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/04-native-hook/hook-init-array.js
|
|
5
|
+
* @customize 修改 TARGET_SO 并在 onEnter(初始化前)或 onLeave(初始化后)挂载 Hook / Patch
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const TARGET_SO = 'libDexHelper.so';
|
|
9
|
+
|
|
10
|
+
function hookInitArray(targetSoName) {
|
|
11
|
+
const linkerName = Process.pointerSize === 4 ? 'linker' : 'linker64';
|
|
12
|
+
const linker = Process.getModuleByName(linkerName);
|
|
13
|
+
|
|
14
|
+
let callConstructorsAddr = null;
|
|
15
|
+
let getSoname = null;
|
|
16
|
+
for (const symbol of linker.enumerateSymbols()) {
|
|
17
|
+
if (symbol.name === '__dl__ZN6soinfo17call_constructorsEv') {
|
|
18
|
+
callConstructorsAddr = symbol.address;
|
|
19
|
+
} else if (symbol.name === '__dl__ZNK6soinfo10get_sonameEv') {
|
|
20
|
+
getSoname = new NativeFunction(symbol.address, 'pointer', ['pointer']);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
console.log('[+] call_constructors:', callConstructorsAddr);
|
|
25
|
+
if (!callConstructorsAddr || !getSoname) return;
|
|
26
|
+
|
|
27
|
+
Interceptor.attach(callConstructorsAddr, {
|
|
28
|
+
onEnter(args) {
|
|
29
|
+
this.matched = false;
|
|
30
|
+
const sonamePtr = getSoname(args[0]);
|
|
31
|
+
const soname = sonamePtr.isNull() ? '' : sonamePtr.readCString();
|
|
32
|
+
if (soname && soname.includes(targetSoName)) {
|
|
33
|
+
this.matched = true;
|
|
34
|
+
console.log(`[init_array] before constructors: ${soname}`);
|
|
35
|
+
// 此时 SO 已映射但尚未执行 .init_array,可在此处提前 Patch / NOP
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
onLeave() {
|
|
39
|
+
if (this.matched) {
|
|
40
|
+
const mod = Process.findModuleByName(targetSoName);
|
|
41
|
+
console.log(`[init_array] after constructors: ${targetSoName}, base=${mod ? mod.base : 'null'}`);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 备选:利用早期系统调用 open 拦截 .init_array 期间读取 /proc/self/maps 的行为
|
|
48
|
+
function hookEarlyOpenForMaps() {
|
|
49
|
+
const openAddr = Module.findGlobalExportByName('open');
|
|
50
|
+
if (!openAddr) return;
|
|
51
|
+
|
|
52
|
+
Interceptor.attach(openAddr, {
|
|
53
|
+
onEnter(args) {
|
|
54
|
+
this.isMaps = false;
|
|
55
|
+
if (!args[0].isNull()) {
|
|
56
|
+
const filename = args[0].readCString();
|
|
57
|
+
if (filename && filename.includes('maps')) {
|
|
58
|
+
console.log('[early open maps]', filename);
|
|
59
|
+
console.log(
|
|
60
|
+
Thread.backtrace(this.context, Backtracer.FUZZY)
|
|
61
|
+
.map(DebugSymbol.fromAddress)
|
|
62
|
+
.join('\n')
|
|
63
|
+
);
|
|
64
|
+
this.isMaps = true;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
onLeave(retval) {
|
|
69
|
+
if (this.isMaps) {
|
|
70
|
+
retval.replace(ptr(-1));
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
hookInitArray(TARGET_SO);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook libart.so 中的 JNI NewStringUTF,打印 Native 层构造的字符串及调用栈
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/04-native-hook/hook-jni-newstringutf.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function hookNewStringUTF() {
|
|
8
|
+
const artModule = Process.getModuleByName('libart.so');
|
|
9
|
+
let newStringUTF = null;
|
|
10
|
+
for (const symbol of artModule.enumerateSymbols()) {
|
|
11
|
+
if (symbol.name.includes('NewStringUTF') && !symbol.name.includes('CheckJNI')) {
|
|
12
|
+
console.log('[+] symbol:', symbol.name, symbol.address);
|
|
13
|
+
newStringUTF = symbol.address;
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (!newStringUTF) {
|
|
19
|
+
console.log('[!] NewStringUTF symbol not found');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
Interceptor.attach(newStringUTF, {
|
|
24
|
+
onEnter(args) {
|
|
25
|
+
const str = args[1].isNull() ? '<null>' : args[1].readCString();
|
|
26
|
+
console.log('[NewStringUTF]:', str);
|
|
27
|
+
console.log(
|
|
28
|
+
'[Backtrace]:\n' +
|
|
29
|
+
Thread.backtrace(this.context, Backtracer.FUZZY)
|
|
30
|
+
.map(DebugSymbol.fromAddress)
|
|
31
|
+
.join('\n') +
|
|
32
|
+
'\n'
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
hookNewStringUTF();
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook libart.so 的 RegisterNatives,自动打印动态注册 JNI 方法的类名、方法名、签名、模块与偏移
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+;需在 Java 运行时可用环境中运行)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/04-native-hook/hook-jni-registernatives.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function hookRegisterNatives() {
|
|
8
|
+
let registerNativesAddr = null;
|
|
9
|
+
for (const symbol of Process.getModuleByName('libart.so').enumerateSymbols()) {
|
|
10
|
+
if (!symbol.name.includes('CheckJNI') && symbol.name.includes('JNI') && symbol.name.includes('RegisterNatives')) {
|
|
11
|
+
registerNativesAddr = symbol.address;
|
|
12
|
+
console.log('[+] RegisterNatives:', symbol.name, registerNativesAddr);
|
|
13
|
+
break;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!registerNativesAddr) {
|
|
18
|
+
console.log('[!] RegisterNatives symbol not found');
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
Interceptor.attach(registerNativesAddr, {
|
|
23
|
+
onEnter(args) {
|
|
24
|
+
const jclass = args[1];
|
|
25
|
+
const className = Java.vm.tryGetEnv().getClassName(jclass);
|
|
26
|
+
const methodsPtr = ptr(args[2]);
|
|
27
|
+
const methodCount = args[3].toInt32();
|
|
28
|
+
console.log(`[RegisterNatives] ${className} (count=${methodCount})`);
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < methodCount; i++) {
|
|
31
|
+
const entry = methodsPtr.add(i * Process.pointerSize * 3);
|
|
32
|
+
const name = entry.readPointer().readCString();
|
|
33
|
+
const sig = entry.add(Process.pointerSize).readPointer().readCString();
|
|
34
|
+
const fnPtr = entry.add(Process.pointerSize * 2).readPointer();
|
|
35
|
+
const mod = Process.findModuleByAddress(fnPtr);
|
|
36
|
+
const modInfo = mod ? `${mod.name}+${fnPtr.sub(mod.base)}` : 'unknown';
|
|
37
|
+
console.log(` -> ${name}${sig} @ ${fnPtr} (${modInfo})`);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
hookRegisterNatives();
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook libc 常用文件与进程控制函数(open / exit / kill)
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/04-native-hook/hook-libc-io-proc.js
|
|
5
|
+
* @customize 在文件末尾按需启用 hookOpen / hookExit / hookKill
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function hookOpen() {
|
|
9
|
+
const openAddr = Module.findGlobalExportByName('open');
|
|
10
|
+
if (!openAddr) return;
|
|
11
|
+
Interceptor.attach(openAddr, {
|
|
12
|
+
onEnter(args) {
|
|
13
|
+
const filename = args[0].isNull() ? '<null>' : args[0].readCString();
|
|
14
|
+
console.log('[open]', filename);
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function hookExit() {
|
|
20
|
+
const exitAddr = Module.findGlobalExportByName('exit');
|
|
21
|
+
console.log('[+] exit:', exitAddr);
|
|
22
|
+
if (!exitAddr) return;
|
|
23
|
+
Interceptor.attach(exitAddr, {
|
|
24
|
+
onEnter(args) {
|
|
25
|
+
const status = args[0].toInt32();
|
|
26
|
+
console.log('[exit] status =', status);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function hookKill() {
|
|
32
|
+
const killAddr = Module.findGlobalExportByName('kill');
|
|
33
|
+
console.log('[+] kill:', killAddr);
|
|
34
|
+
if (!killAddr) return;
|
|
35
|
+
Interceptor.attach(killAddr, {
|
|
36
|
+
onEnter(args) {
|
|
37
|
+
console.log(`[kill] pid=${args[0].toInt32()}, signal=${args[1].toInt32()}`);
|
|
38
|
+
},
|
|
39
|
+
onLeave(retval) {
|
|
40
|
+
console.log(`[kill] returned=${retval.toInt32()}`);
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 按需启用(注意部分反调试会直接走 svc 0 系统调用绕过 libc)
|
|
46
|
+
hookExit();
|
|
47
|
+
hookKill();
|
|
48
|
+
// hookOpen();
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook libc 内存与字符串函数(memcpy / memcmp / strstr / strcmp)
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/04-native-hook/hook-mem-str.js
|
|
5
|
+
* @customize 这些函数调用极频繁,请仅在底部按需启用单个函数并添加过滤条件
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// 监控从代码段复制 4 字节(疑似 ARM64 指令完整性校验)的 memcpy
|
|
9
|
+
function hookMemcpyCodeCheck(targetModuleName) {
|
|
10
|
+
const mod = Process.findModuleByName(targetModuleName);
|
|
11
|
+
const textRange = mod ? mod.enumerateRanges('r-x')[0] : null;
|
|
12
|
+
const memcpyAddr = Process.getModuleByName('libc.so').findExportByName('memcpy');
|
|
13
|
+
if (!memcpyAddr || !textRange) return;
|
|
14
|
+
|
|
15
|
+
Interceptor.attach(memcpyAddr, {
|
|
16
|
+
onEnter(args) {
|
|
17
|
+
this.dst = args[0];
|
|
18
|
+
this.src = args[1];
|
|
19
|
+
this.size = args[2].toInt32();
|
|
20
|
+
},
|
|
21
|
+
onLeave() {
|
|
22
|
+
if (
|
|
23
|
+
this.size === 4 &&
|
|
24
|
+
this.src.compare(textRange.base) >= 0 &&
|
|
25
|
+
this.src.compare(textRange.base.add(textRange.size)) < 0
|
|
26
|
+
) {
|
|
27
|
+
console.log('[memcpy ARM64 insn]', 'dst=' + this.dst, 'src=' + this.src);
|
|
28
|
+
console.log(hexdump(this.dst, { offset: 0, length: this.size }));
|
|
29
|
+
console.log('Instruction (hex):', this.dst.readU32().toString(16));
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 示例:拦截对 libc pthread_create 头部字节的 memcmp 完整性检测并强制返回 0
|
|
36
|
+
function hookMemcmpPthreadCheck() {
|
|
37
|
+
const libc = Process.getModuleByName('libc.so');
|
|
38
|
+
const target = libc.getExportByName('pthread_create').and(-2);
|
|
39
|
+
const listener = Interceptor.attach(libc.getExportByName('memcmp'), {
|
|
40
|
+
onEnter(args) {
|
|
41
|
+
this.match = args[0].compare(target) === 0 || args[1].compare(target) === 0;
|
|
42
|
+
},
|
|
43
|
+
onLeave(retval) {
|
|
44
|
+
if (this.match) {
|
|
45
|
+
retval.replace(ptr(0));
|
|
46
|
+
listener.detach();
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function hookStrstr(keyword) {
|
|
53
|
+
const strstrAddr = Module.findGlobalExportByName('strstr');
|
|
54
|
+
if (!strstrAddr) return;
|
|
55
|
+
Interceptor.attach(strstrAddr, {
|
|
56
|
+
onEnter(args) {
|
|
57
|
+
const haystack = args[0].isNull() ? '' : args[0].readCString();
|
|
58
|
+
const needle = args[1].isNull() ? '' : args[1].readCString();
|
|
59
|
+
if (!keyword || (haystack && haystack.includes(keyword)) || (needle && needle.includes(keyword))) {
|
|
60
|
+
console.log(`[strstr] haystack="${haystack}" needle="${needle}"`);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function hookStrcmp(keyword) {
|
|
67
|
+
const strcmpAddr = Module.findGlobalExportByName('strcmp');
|
|
68
|
+
if (!strcmpAddr) return;
|
|
69
|
+
Interceptor.attach(strcmpAddr, {
|
|
70
|
+
onEnter(args) {
|
|
71
|
+
this.s1 = args[0].isNull() ? '' : args[0].readUtf8String();
|
|
72
|
+
this.s2 = args[1].isNull() ? '' : args[1].readUtf8String();
|
|
73
|
+
this.shouldLog = !keyword || (this.s1 && this.s1.includes(keyword)) || (this.s2 && this.s2.includes(keyword));
|
|
74
|
+
},
|
|
75
|
+
onLeave(retval) {
|
|
76
|
+
if (this.shouldLog) {
|
|
77
|
+
console.log(`[strcmp] "${this.s1}" vs "${this.s2}" => ${retval.toInt32()}`);
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 按需取消注释启用
|
|
84
|
+
// hookStrstr('frida');
|
|
85
|
+
// hookStrcmp('test');
|
|
86
|
+
// hookMemcmpPthreadCheck();
|
|
87
|
+
// hookMemcpyCodeCheck('libtarget.so');
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 监控或替换线程创建(pthread_create attach / replace 及 __pthread_start)
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/04-native-hook/hook-pthread.js
|
|
5
|
+
* @customize 默认启用 hookPthreadCreate();如需改为函数替换或追踪 __pthread_start,请调整底部入口
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function hookPthreadCreate() {
|
|
9
|
+
const addr = Module.findGlobalExportByName('pthread_create');
|
|
10
|
+
if (!addr) return;
|
|
11
|
+
Interceptor.attach(addr, {
|
|
12
|
+
onEnter(args) {
|
|
13
|
+
const startRoutine = args[2];
|
|
14
|
+
const arg = args[3];
|
|
15
|
+
const mod = Process.findModuleByAddress(startRoutine);
|
|
16
|
+
if (!mod) return;
|
|
17
|
+
console.log(
|
|
18
|
+
'[pthread_create]',
|
|
19
|
+
mod.name,
|
|
20
|
+
'arg=0x' + arg.toString(16),
|
|
21
|
+
'offset=0x' + startRoutine.sub(mod.base).toString(16)
|
|
22
|
+
);
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function replacePthreadCreate() {
|
|
28
|
+
const pthreadCreateAddr = Module.findGlobalExportByName('pthread_create');
|
|
29
|
+
if (!pthreadCreateAddr) return;
|
|
30
|
+
const origPthreadCreate = new NativeFunction(pthreadCreateAddr, 'int', ['pointer', 'pointer', 'pointer', 'pointer']);
|
|
31
|
+
|
|
32
|
+
const replacement = new NativeCallback(
|
|
33
|
+
(parg0, parg1, parg2, parg3) => {
|
|
34
|
+
const mod = Process.findModuleByAddress(parg2);
|
|
35
|
+
if (mod) {
|
|
36
|
+
console.log(
|
|
37
|
+
'[pthread_create replace]',
|
|
38
|
+
mod.name,
|
|
39
|
+
'offset=0x' + parg2.sub(mod.base).toString(16),
|
|
40
|
+
'arg=0x' + parg3.toString(16)
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
// 如需阻止特定检测线程启动,可在此直接 return 0;
|
|
44
|
+
return origPthreadCreate(parg0, parg1, parg2, parg3);
|
|
45
|
+
},
|
|
46
|
+
'int',
|
|
47
|
+
['pointer', 'pointer', 'pointer', 'pointer']
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
Interceptor.replace(pthreadCreateAddr, replacement);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function hookPthreadStart() {
|
|
54
|
+
const startAddr = DebugSymbol.fromName('_ZL15__pthread_startPv').address;
|
|
55
|
+
console.log('[+] __pthread_start:', startAddr);
|
|
56
|
+
if (!startAddr || startAddr.isNull()) return;
|
|
57
|
+
Interceptor.attach(startAddr, {
|
|
58
|
+
onEnter(args) {
|
|
59
|
+
const routine = args[0].add(12 * 8).readPointer();
|
|
60
|
+
const mod = Process.findModuleByAddress(routine);
|
|
61
|
+
if (!mod) return;
|
|
62
|
+
console.log('[__pthread_start]', mod.name, mod.base, routine.sub(mod.base));
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
hookPthreadCreate();
|
|
68
|
+
// replacePthreadCreate();
|
|
69
|
+
// hookPthreadStart();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 轮询等待动态加载的 SO 模块出现,返回模块基址
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/04-native-hook/wait-for-module.js
|
|
5
|
+
* @customize 修改 TARGET_SO 及回调逻辑
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const TARGET_SO = 'libxxx.so';
|
|
9
|
+
|
|
10
|
+
function waitForModule(moduleName, intervalMs = 1000) {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
const timer = setInterval(() => {
|
|
13
|
+
const module = Process.findModuleByName(moduleName);
|
|
14
|
+
if (module !== null) {
|
|
15
|
+
clearInterval(timer);
|
|
16
|
+
resolve(module);
|
|
17
|
+
}
|
|
18
|
+
}, intervalMs);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
waitForModule(TARGET_SO).then((mod) => {
|
|
23
|
+
console.log(`[+] Module ready: ${mod.name}, base=${mod.base}, size=${mod.size}`);
|
|
24
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose Hook libc strstr 屏蔽常见 Frida 关键字(frida / gum-js-loop / gmain / linjector)字符串检测
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -f <package> -l scripts/05-anti-frida/bypass-strstr-anti-frida.js
|
|
5
|
+
* @customize 可在 KEYWORDS 中增删检测特征串(注意无法拦截直接内联手写比较或走 svc 的检测)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const KEYWORDS = ['frida', 'gum-js-loop', 'gmain', 'linjector'];
|
|
9
|
+
|
|
10
|
+
function bypassStrstrAntiFrida() {
|
|
11
|
+
const strstrAddr = Module.findGlobalExportByName('strstr');
|
|
12
|
+
console.log('[+] strstr:', strstrAddr);
|
|
13
|
+
if (!strstrAddr) return;
|
|
14
|
+
|
|
15
|
+
Interceptor.attach(strstrAddr, {
|
|
16
|
+
onEnter(args) {
|
|
17
|
+
this.block = false;
|
|
18
|
+
if (args[0].isNull() || args[1].isNull()) return;
|
|
19
|
+
const haystack = args[0].readCString();
|
|
20
|
+
const needle = args[1].readCString();
|
|
21
|
+
if (haystack === null || needle === null) return;
|
|
22
|
+
|
|
23
|
+
for (const kw of KEYWORDS) {
|
|
24
|
+
if (haystack.includes(kw) || needle.includes(kw)) {
|
|
25
|
+
this.block = true;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
onLeave(retval) {
|
|
31
|
+
if (this.block) {
|
|
32
|
+
retval.replace(ptr(0));
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
bypassStrstrAntiFrida();
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 读取 /proc/self/maps 定位 /memfd 映射并内存扫描替换 "libfrida-agent" 字符串特征
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -F -l scripts/05-anti-frida/patch-memfd-frida-str.js
|
|
5
|
+
* @customize 注意 REPLACEMENT 与 SEARCH_HEX 字节长度需一致
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const SEARCH_HEX = '6c 69 62 66 72 69 64 61 2d 61 67 65 6e 74'; // "libfrida-agent"
|
|
9
|
+
const REPLACEMENT_HEX = '6c 69 62 77 7a 64 6e 62 2d 61 67 65 6e 74'; // "libwzdnb-agent"
|
|
10
|
+
|
|
11
|
+
function readTextFileJava(fileName) {
|
|
12
|
+
const JString = Java.use('java.lang.String');
|
|
13
|
+
const Files = Java.use('java.nio.file.Files');
|
|
14
|
+
const Paths = Java.use('java.nio.file.Paths');
|
|
15
|
+
const URI = Java.use('java.net.URI');
|
|
16
|
+
const path = Paths.get(URI.create('file://' + fileName));
|
|
17
|
+
return JString.$new(Files.readAllBytes(path)).toString();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function patchRange(startAddress, endAddress) {
|
|
21
|
+
const matchedAddresses = [];
|
|
22
|
+
const patchBytes = REPLACEMENT_HEX.split(' ').map((b) => parseInt(b, 16));
|
|
23
|
+
const size = patchBytes.length;
|
|
24
|
+
|
|
25
|
+
Memory.scan(startAddress, endAddress.sub(startAddress).toInt32(), SEARCH_HEX, {
|
|
26
|
+
onMatch(address) {
|
|
27
|
+
console.log('[+] Matched at:', address);
|
|
28
|
+
matchedAddresses.push(address);
|
|
29
|
+
},
|
|
30
|
+
onComplete() {
|
|
31
|
+
console.log(`[+] Scan complete, matches=${matchedAddresses.length}`);
|
|
32
|
+
for (const address of matchedAddresses) {
|
|
33
|
+
try {
|
|
34
|
+
Memory.protect(address, size, 'rwx');
|
|
35
|
+
address.writeByteArray(patchBytes);
|
|
36
|
+
Memory.protect(address, size, 'r--');
|
|
37
|
+
console.log('[+] Patched:', address);
|
|
38
|
+
} catch (err) {
|
|
39
|
+
console.log('[!] Patch failed at', address, err);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
Java.perform(function () {
|
|
47
|
+
const data = readTextFileJava('/proc/self/maps');
|
|
48
|
+
Interceptor.detachAll();
|
|
49
|
+
|
|
50
|
+
let startAddress = null;
|
|
51
|
+
let endAddress = null;
|
|
52
|
+
for (const line of data.split('\n')) {
|
|
53
|
+
if (line.includes('/memfd')) {
|
|
54
|
+
console.log('[memfd]', line);
|
|
55
|
+
const match = line.match(/^([0-9a-f]+)-([0-9a-f]+)/);
|
|
56
|
+
if (match && !startAddress) {
|
|
57
|
+
startAddress = ptr('0x' + match[1]);
|
|
58
|
+
endAddress = ptr('0x' + match[2]);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (startAddress && endAddress) {
|
|
64
|
+
patchRange(startAddress, endAddress);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @purpose 读取 /proc/self/maps 的两种实现(Java NIO 版 + SO 原生 open/read/close 版)
|
|
3
|
+
* @frida >= 17(同时兼容 Frida 16.7+)
|
|
4
|
+
* @usage frida -U -F -l scripts/05-anti-frida/read-proc-maps.js
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
function readFileJava(fileName) {
|
|
8
|
+
const JString = Java.use('java.lang.String');
|
|
9
|
+
const Files = Java.use('java.nio.file.Files');
|
|
10
|
+
const Paths = Java.use('java.nio.file.Paths');
|
|
11
|
+
const URI = Java.use('java.net.URI');
|
|
12
|
+
const path = Paths.get(URI.create('file://' + fileName));
|
|
13
|
+
return JString.$new(Files.readAllBytes(path)).toString();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function readMapsNative() {
|
|
17
|
+
const libc = Process.getModuleByName('libc.so');
|
|
18
|
+
const open = new NativeFunction(libc.getExportByName('open'), 'int', ['pointer', 'int']);
|
|
19
|
+
const read = new NativeFunction(libc.getExportByName('read'), 'ssize_t', ['int', 'pointer', 'size_t']);
|
|
20
|
+
const close = new NativeFunction(libc.getExportByName('close'), 'int', ['int']);
|
|
21
|
+
|
|
22
|
+
const O_RDONLY = 0;
|
|
23
|
+
const BUFFER_SIZE = 1024;
|
|
24
|
+
const pathPtr = Memory.allocUtf8String('/proc/self/maps');
|
|
25
|
+
const fd = open(pathPtr, O_RDONLY);
|
|
26
|
+
if (fd < 0) {
|
|
27
|
+
console.log('[!] Failed to open /proc/self/maps');
|
|
28
|
+
return '';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let content = '';
|
|
32
|
+
const buffer = Memory.alloc(BUFFER_SIZE);
|
|
33
|
+
let bytesRead;
|
|
34
|
+
do {
|
|
35
|
+
bytesRead = read(fd, buffer, BUFFER_SIZE);
|
|
36
|
+
if (bytesRead > 0) {
|
|
37
|
+
content += buffer.readUtf8String(bytesRead);
|
|
38
|
+
}
|
|
39
|
+
} while (bytesRead > 0);
|
|
40
|
+
close(fd);
|
|
41
|
+
return content;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.log(readMapsNative());
|