feat: 集成 LLVM IR 混淆体系、Route 2 全量合规与系统调用调度加固

- defender: 扩展 IGDispatch/IGArchiveGuard/IGAntiHook/IGObjCBaseline/IGResolve,支持 Route 2 静态库桥接 (IGThreadID.c) 与防重签名检测
- llvm_passes: 新增 IGObfuscator LLVM IR 插件源码(控制流平坦化、字符串加密、间接跳转/调用、不透明常量/字段、MBA、函数外提、基本块拆分、反 Hook 序言)
- tools & config: 新增 Xcode 归档编译/链接包装器、LLVM 自愈工具链 (ig_toolchain_resolver)、IPA 审计门禁、崩溃符号还原及最新 ig_llvm_policy.json(文件级匹配 + 3.0 全业务 Handler 平坦化)
- tests & docs: 补齐 M0~M3、Pass 单测及系统调用调度/Route 2/LLVM 方案文档;.gitignore 忽略 *.bc 与 .obfuscate_extraction_cache.json
This commit is contained in:
shenlei
2026-11-24 15:00:07 +09:00
parent 1094cc2760
commit 704ee66834
106 changed files with 27487 additions and 286 deletions
+46 -6
View File
@@ -11,9 +11,12 @@
*/
#include "IGAntiInject.h"
#include "IGInline.h" /* ig_strstr/ig_strcmp/ig_strncmp/ig_strlen:抹除探针自身对 libc 匹配函数的依赖 */
#include "../dispatch/IGDispatch.h"
#include <string.h>
#include <stdio.h>
#if IG_DIAGNOSTIC_STRINGS
# include <stdio.h>
#endif
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
@@ -68,6 +71,12 @@ static size_t ig_inj_decode(const unsigned char *enc, size_t n, int idx,
return n;
}
/* "DYLD_INSERT_LIBRARIES" ^ 0x5A(避免明文驻留 __cstring)。 */
static const unsigned char kIGDyldEnvEnc[21] = {
0x1eu, 0x03u, 0x16u, 0x1eu, 0x05u, 0x13u, 0x14u, 0x09u, 0x1fu, 0x08u, 0x0eu,
0x05u, 0x16u, 0x13u, 0x18u, 0x08u, 0x1bu, 0x08u, 0x13u, 0x1fu, 0x09u
};
static void ig_emit2(IGFindingSink sink, void *ctx, int *stop, int *hits,
IGStatus st, int reason, const char *subject, const char *evidence) {
if (*stop) return;
@@ -75,8 +84,13 @@ static void ig_emit2(IGFindingSink sink, void *ctx, int *stop, int *hits,
memset(&f, 0, sizeof(f));
f.status = st;
f.reason = reason;
#if IG_DIAGNOSTIC_STRINGS
if (subject) strncpy(f.subject, subject, sizeof(f.subject)-1);
if (evidence) strncpy(f.evidence, evidence, sizeof(f.evidence)-1);
#else
(void)subject;
(void)evidence;
#endif
if (st == IG_DETECTED) (*hits)++;
if (sink && sink(&f, ctx) != 0) *stop = 1;
}
@@ -124,9 +138,13 @@ int ig_anti_inject_check(const char *bundle_path, IGFindingSink sink, void *ctx)
int matched = 0;
for (int s = 0; s < IG_INJ_ENC_COUNT; ++s) {
if (ig_strstr(low, injsig[s])) {
#if IG_DIAGNOSTIC_STRINGS
char ev[256];
snprintf(ev, sizeof(ev), "镜像=%s 命中特征=%s", name, injsig[s]);
ig_emit2(sink, ctx, &stop, &hits, IG_DETECTED, IG_REASON_INJECTED_IMAGE, name, ev);
#else
ig_emit2(sink, ctx, &stop, &hits, IG_DETECTED, IG_REASON_INJECTED_IMAGE, NULL, NULL);
#endif
matched = 1;
break;
}
@@ -136,12 +154,21 @@ int ig_anti_inject_check(const char *bundle_path, IGFindingSink sink, void *ctx)
/* 非系统、非特征命中:若在 Bundle 外则作为弱信号上报。 */
if (bundle_path && ig_strncmp(name, bundle_path, ig_strlen(bundle_path)) != 0) {
ig_emit2(sink, ctx, &stop, &hits, IG_DETECTED, IG_REASON_FOREIGN_IMAGE, name,
"Bundle 外非系统镜像(弱信号,需结合其它证据)");
IG_DIAG_STR("Bundle 外非系统镜像(弱信号,需结合其它证据)"));
}
}
/* 3. DYLD_INSERT_LIBRARIES 逐条解析。 */
const char *dyld = ig_local_getenv("DYLD_INSERT_LIBRARIES");
/* 3. DYLD_INSERT_LIBRARIES 逐条解析(运行期解码环境变量名)。 */
char env_name[24];
{
volatile unsigned char emask = 0x5Au;
for (size_t ei = 0; ei < sizeof(kIGDyldEnvEnc); ++ei) {
env_name[ei] = (char)(kIGDyldEnvEnc[ei] ^ emask);
}
env_name[sizeof(kIGDyldEnvEnc)] = '\0';
}
const char *dyld = ig_local_getenv(env_name);
__builtin_memset(env_name, 0, sizeof(env_name));
if (dyld && dyld[0] && !stop) {
char buf[4096];
strncpy(buf, dyld, sizeof(buf)-1); buf[sizeof(buf)-1] = '\0';
@@ -153,9 +180,13 @@ int ig_anti_inject_check(const char *bundle_path, IGFindingSink sink, void *ctx)
* /usr/lib/libViewDebuggerSupport.dylib、/System/.../GPUToolsCapture 等,非恶意注入。
* 越狱 frida/substrate 的插入库位于 Bundle 内或非系统路径,仍会命中。 */
if (!in_bundle && !ig_is_system_path2(tok)) {
#if IG_DIAGNOSTIC_STRINGS
char ev[256];
snprintf(ev, sizeof(ev), "DYLD_INSERT_LIBRARIES 条目=%s(Bundle 外)", tok);
ig_emit2(sink, ctx, &stop, &hits, IG_DETECTED, IG_REASON_DYLD_INSERT, tok, ev);
#else
ig_emit2(sink, ctx, &stop, &hits, IG_DETECTED, IG_REASON_DYLD_INSERT, NULL, NULL);
#endif
}
}
}
@@ -169,7 +200,7 @@ static void ig_scan_threads(IGFindingSink sink, void *ctx, int *stop, int *hits)
mach_msg_type_number_t count = 0;
if (task_threads(mach_task_self(), &threads, &count) != KERN_SUCCESS) {
ig_emit2(sink, ctx, stop, hits, IG_UNAVAILABLE, IG_REASON_FRIDA_THREAD,
"task_threads", "无法枚举线程");
IG_DIAG_STR("task_threads"), IG_DIAG_STR("无法枚举线程"));
return;
}
/* §7.1:frida 线程名运行期解码进栈,比对后擦除。 */
@@ -185,10 +216,15 @@ static void ig_scan_threads(IGFindingSink sink, void *ctx, int *stop, int *hits)
if (info.pth_name[0] == '\0') continue;
for (int t = 0; t < IG_THR_ENC_COUNT; ++t) {
if (ig_strcmp(info.pth_name, thr[t]) == 0) {
#if IG_DIAGNOSTIC_STRINGS
char ev[256];
snprintf(ev, sizeof(ev), "线程名=%s 命中注入运行时特征", info.pth_name);
ig_emit2(sink, ctx, stop, hits, IG_DETECTED, IG_REASON_FRIDA_THREAD,
info.pth_name, ev);
#else
ig_emit2(sink, ctx, stop, hits, IG_DETECTED, IG_REASON_FRIDA_THREAD,
NULL, NULL);
#endif
break;
}
}
@@ -225,7 +261,7 @@ static int ig_port_open(int port) {
open = (err == 0);
}
}
close(fd);
IG_dispatch_close(fd);
return open;
}
@@ -234,10 +270,14 @@ int ig_anti_frida_check(int probe_port, IGFindingSink sink, void *ctx) {
ig_scan_threads(sink, ctx, &stop, &hits);
if (probe_port && !stop) {
if (ig_port_open(probe_port)) {
#if IG_DIAGNOSTIC_STRINGS
char ev[128];
snprintf(ev, sizeof(ev), "127.0.0.1:%d 可连接(弱信号)", probe_port);
char sub[32]; snprintf(sub, sizeof(sub), "port:%d", probe_port);
ig_emit2(sink, ctx, &stop, &hits, IG_DETECTED, IG_REASON_FRIDA_PORT, sub, ev);
#else
ig_emit2(sink, ctx, &stop, &hits, IG_DETECTED, IG_REASON_FRIDA_PORT, NULL, NULL);
#endif
}
}
return hits;