feat(defender): 可集成静态库 + readoor 接入方案(检测→分级→数据毒化闭环)
在 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>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
ff0aee7f47
commit
599e1da5ce
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* IGAntiJailbreak.h — 越狱检测探针(走 IGSyscall 直发 svc,绕过 libc 层 hook)。
|
||||
*
|
||||
* 定位:Shadow / Liberty / A-Bypass 这类反越狱检测插件主要 hook 在 libc/ObjC 层
|
||||
* (stat/access/fopen/NSFileManager)。本探针用 IGSyscall 的 svc #0x80 直发
|
||||
* access(2)/open(2),那条可被 hook 的 libSystem 入口在此路径上不存在——检测点下沉到
|
||||
* bypass 够不到的层。这是纯客户端对抗里"抬高绕过成本"的关键一环(非根治)。
|
||||
*
|
||||
* 只采集证据、不处置:命中经 sink 上报,是否毒化/降级由策略层([[iosguard-disposition-strategy]]
|
||||
* 的 ig_poison_mark)按强信号组合决定。本探针绝不自行 exit。
|
||||
*
|
||||
* 边界:
|
||||
* - 路径特征可被 rootless 越狱改位;未命中不等于干净(组合判定原则不变)。
|
||||
* - 当前骨架路径字符串为明文,静态可见、bypass 可针对——TODO 用 IGResolve 的 XOR 混淆
|
||||
* (IG_ENC),与 svc 号混淆同理。svc 直发本身已是主要价值,字符串混淆是第二层。
|
||||
* - 仅 arm64 直发;非 arm64(宿主 x86_64)syscall 退化 unavailable。
|
||||
*/
|
||||
#ifndef IG_ANTI_JAILBREAK_H
|
||||
#define IG_ANTI_JAILBREAK_H
|
||||
|
||||
#include "IGDefender.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* 默认检测:内置 iOS 越狱特征表 + 沙盒逃逸探测。返回 DETECTED 条数。 */
|
||||
int ig_anti_jb_check(IGFindingSink sink, void *ctx);
|
||||
|
||||
/*
|
||||
* 可注入版本(供自测/定制)。
|
||||
* paths/count:要探测可访问性的路径表(access F_OK);命中记 reason=400。
|
||||
* sandbox_probe_path:非 NULL 时尝试在该(应在沙盒外的)路径创建文件,成功=沙盒逃逸,记 401
|
||||
* 并立即清理;NULL 跳过逃逸探测。
|
||||
*/
|
||||
int ig_anti_jb_check_paths(const char *const *paths, size_t count,
|
||||
const char *sandbox_probe_path,
|
||||
IGFindingSink sink, void *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* IG_ANTI_JAILBREAK_H */
|
||||
Reference in New Issue
Block a user