在 iOSGuard 侧产出可集成产物与接入文档,不修改 readoor 代码。 - defender/: anti_hook/anti_frida/anti_debug/anti_jailbreak 探针 + syscall 直发、 policy 分级层、poison 数据依赖毒化、dispatch/resolve/call_bridge 等子模块 - poison: 三副本冗余、无分支掩码;健康恒等、毒化破坏 key(替代 if-exit 处置) - policy: STRONG/MEDIUM/WEAK 分级,守误报底线,仅 DETECTED 参与、组合命中才毒化 - anti_jailbreak: IGSyscall 直发 svc 检测越狱文件(400)/沙盒逃逸(401),绕 libc hook - tools/build_defender_lib.sh: 一键交叉编译打包 libIGDefender.a(arm64) + umbrella 头 - docs/18_READOOR_DEFENDER_INTEGRATION.md: 精确到文件/bridging/替换点/代码片段 - docs/05-17 + evidence + tests + macho_guard/static_sdk_redirect 工具链 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
89 lines
3.3 KiB
C
89 lines
3.3 KiB
C
/*
|
||
* IGAntiJailbreak.c — 越狱检测探针实现。见 .h 的定位与边界。
|
||
*
|
||
* 全部文件探测经 IGSyscall 直发(access/open/close/unlink),不经 libc——规避 Shadow/Liberty
|
||
* 等对 stat/access 的 hook。证据经 sink 上报,不做处置。
|
||
*/
|
||
#include "IGAntiJailbreak.h"
|
||
#include "syscall/IGSyscall.h"
|
||
|
||
#include <stdio.h>
|
||
|
||
/* access 的 amode:F_OK=0(仅测存在/可访问)。open 标志(BSD/Darwin 值)。 */
|
||
#define IG_F_OK 0
|
||
#define IG_O_RDWR 0x0002
|
||
#define IG_O_CREAT 0x0200
|
||
#define IG_O_EXCL 0x0800
|
||
|
||
/*
|
||
* 内置 iOS 越狱特征(强信号)。沙盒内正常 App 对这些路径 access 应得 -ENOENT/-EPERM;
|
||
* 能访问即越狱。rootless 越狱重点在 /var/jb。TODO:改为 IG_ENC XOR 混淆,勿明文驻留。
|
||
*/
|
||
static const char *const kIGJailbreakPaths[] = {
|
||
"/var/jb", /* rootless 越狱根 */
|
||
"/Applications/Cydia.app",
|
||
"/Applications/Sileo.app",
|
||
"/Applications/Zebra.app",
|
||
"/usr/sbin/sshd",
|
||
"/usr/bin/ssh",
|
||
"/bin/bash",
|
||
"/bin/sh",
|
||
"/etc/apt",
|
||
"/private/var/lib/apt",
|
||
"/usr/lib/substrate",
|
||
"/Library/MobileSubstrate/MobileSubstrate.dylib",
|
||
"/usr/lib/TweakInject",
|
||
};
|
||
|
||
static void ig_jb_emit(IGFindingSink sink, void *ctx, int *hits,
|
||
IGStatus st, int reason, const char *subject, const char *evidence) {
|
||
IGFinding f;
|
||
__builtin_memset(&f, 0, sizeof(f));
|
||
f.status = st;
|
||
f.reason = reason;
|
||
if (subject) snprintf(f.subject, sizeof(f.subject), "%s", subject);
|
||
if (evidence) snprintf(f.evidence, sizeof(f.evidence), "%s", evidence);
|
||
if (st == IG_DETECTED) (*hits)++;
|
||
if (sink) sink(&f, ctx);
|
||
}
|
||
|
||
int ig_anti_jb_check_paths(const char *const *paths, size_t count,
|
||
const char *sandbox_probe_path,
|
||
IGFindingSink sink, void *ctx) {
|
||
int hits = 0;
|
||
|
||
/* 1) 越狱特征文件:直发 access(path, F_OK)==0 即可访问。 */
|
||
for (size_t i = 0; i < count; ++i) {
|
||
if (!paths[i]) continue;
|
||
if (ig_sys_access(paths[i], IG_F_OK) == 0) {
|
||
char ev[256];
|
||
snprintf(ev, sizeof(ev), "直发 access 可访问越狱特征:%s", paths[i]);
|
||
ig_jb_emit(sink, ctx, &hits, IG_DETECTED, IG_REASON_JAILBREAK_FILE, paths[i], ev);
|
||
}
|
||
}
|
||
|
||
/* 2) 沙盒逃逸:在沙盒外路径直发 open(O_CREAT|O_EXCL) 创建文件,成功=越狱强信号。 */
|
||
if (sandbox_probe_path) {
|
||
ig_sys_unlink(sandbox_probe_path); /* 清理上次残留(忽略错误) */
|
||
int fd = ig_sys_open(sandbox_probe_path, IG_O_RDWR | IG_O_CREAT | IG_O_EXCL, 0600);
|
||
if (fd >= 0) {
|
||
ig_sys_close(fd);
|
||
ig_sys_unlink(sandbox_probe_path); /* 立即清理,不留痕 */
|
||
char ev[256];
|
||
snprintf(ev, sizeof(ev), "能在沙盒外创建文件:%s", sandbox_probe_path);
|
||
ig_jb_emit(sink, ctx, &hits, IG_DETECTED, IG_REASON_JAILBREAK_SANDBOX,
|
||
sandbox_probe_path, ev);
|
||
}
|
||
}
|
||
|
||
return hits;
|
||
}
|
||
|
||
int ig_anti_jb_check(IGFindingSink sink, void *ctx) {
|
||
return ig_anti_jb_check_paths(
|
||
kIGJailbreakPaths,
|
||
sizeof(kIGJailbreakPaths) / sizeof(kIGJailbreakPaths[0]),
|
||
"/private/.ig_jb_probe", /* 沙盒外路径:正常 App 不可写 */
|
||
sink, ctx);
|
||
}
|