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:
Vendored
+92
-2
@@ -10,6 +10,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
static int early_ok;
|
||||
__attribute__((constructor)) static void early(void) {
|
||||
@@ -64,8 +66,75 @@ int main(int argc,char **argv) {
|
||||
} else if (!strcmp(argv[1],"init-failure")) {
|
||||
assert(IG_dispatch_write(-1,"x",1)==-1 && errno==ENOSYS);
|
||||
assert(IG_dispatch_close(-1)==-1 && errno==ENOSYS);
|
||||
assert(ig_dispatch_check(collect,NULL)==0 && unavailable==2);
|
||||
assert(reasons[IG_REASON_DISPATCH_UNAVAILABLE]==2);
|
||||
char b;
|
||||
assert(IG_dispatch_read(-1,&b,1)==-1 && errno==ENOSYS);
|
||||
assert(IG_dispatch_open("/dev/null",O_RDONLY)==-1 && errno==ENOSYS);
|
||||
assert(IG_dispatch_unlink("/tmp/ig-must-not-remove")==-1 && errno==ENOSYS);
|
||||
assert(IG_dispatch_getpid()==-1 && errno==ENOSYS);
|
||||
assert(IG_dispatch_fork()==-1 && errno==ENOSYS);
|
||||
assert(IG_dispatch_dlopen(NULL,RTLD_LAZY)==NULL && errno==ENOSYS);
|
||||
assert(IG_dispatch_dlsym(RTLD_DEFAULT,"getpid")==NULL && errno==ENOSYS);
|
||||
assert(ig_dispatch_check(collect,NULL)==0 && unavailable==11);
|
||||
assert(reasons[IG_REASON_DISPATCH_UNAVAILABLE]==11);
|
||||
} else if (!strcmp(argv[1],"extended")) {
|
||||
char path[]="/tmp/ig-dispatch-XXXXXX";
|
||||
int fd=mkstemp(path); assert(fd>=0); close(fd); unlink(path);
|
||||
mode_t mask=umask(0);
|
||||
errno=EDOM; fd=IG_dispatch_open(path,O_CREAT|O_EXCL|O_RDWR,0600);
|
||||
umask(mask);
|
||||
assert(fd>=0 && errno==EDOM);
|
||||
struct stat st; assert(fstat(fd,&st)==0 && (st.st_mode & 0777)==0600);
|
||||
assert(IG_dispatch_write(fd,"abc",3)==3); assert(lseek(fd,0,SEEK_SET)==0);
|
||||
char bytes[16]={0}; errno=ERANGE;
|
||||
assert(IG_dispatch_read(fd,bytes,sizeof(bytes))==3 && !memcmp(bytes,"abc",3) && errno==ERANGE);
|
||||
assert(IG_dispatch_read(fd,bytes,sizeof(bytes))==0);
|
||||
assert(IG_dispatch_close(fd)==0);
|
||||
fd=IG_dispatch_open(path,O_RDONLY); assert(fd>=0); assert(IG_dispatch_close(fd)==0);
|
||||
assert(IG_dispatch_open(path,O_CREAT|O_EXCL|O_RDWR,0600)==-1 && errno==EEXIST);
|
||||
FILE *stream=IG_dispatch_fopen(path,"r");
|
||||
assert(stream && fgetc(stream)=='a' && fclose(stream)==0);
|
||||
assert(IG_dispatch_unlink(path)==0);
|
||||
assert(IG_dispatch_fopen(path,"r")==NULL && errno==ENOENT);
|
||||
assert(IG_dispatch_open(path,O_RDONLY)==-1 && errno==ENOENT);
|
||||
assert(IG_dispatch_unlink(path)==-1 && errno==ENOENT);
|
||||
assert(IG_dispatch_read(-1,bytes,1)==-1 && errno==EBADF);
|
||||
errno=EDOM; assert(IG_dispatch_getpid()==getpid() && errno==EDOM);
|
||||
void *self_handle=IG_dispatch_dlopen(NULL,RTLD_LAZY);
|
||||
assert(self_handle!=NULL);
|
||||
assert(IG_dispatch_dlsym(RTLD_DEFAULT,"getpid")==dlsym(RTLD_DEFAULT,"getpid"));
|
||||
pid_t child=IG_dispatch_fork();
|
||||
assert(child>=0);
|
||||
if (child==0) IG_dispatch_exit(42);
|
||||
int wstatus=0;
|
||||
assert(waitpid(child,&wstatus,0)==child && WIFEXITED(wstatus) && WEXITSTATUS(wstatus)==42);
|
||||
} else if (!strcmp(argv[1],"extended-tamper")) {
|
||||
pid_t child=fork();
|
||||
assert(child>=0);
|
||||
if (child==0) {
|
||||
ig_dispatch_test_override(7,(void *)fake_close);
|
||||
IG_dispatch_exit(37);
|
||||
}
|
||||
int wstatus=0;
|
||||
assert(waitpid(child,&wstatus,0)==child && WIFEXITED(wstatus) && WEXITSTATUS(wstatus)==37);
|
||||
for (unsigned i=2;i<11;i++) ig_dispatch_test_override(i,(void *)fake_close);
|
||||
char bytes[1];
|
||||
assert(IG_dispatch_read(-1,bytes,1)==-1 && errno==EACCES);
|
||||
assert(IG_dispatch_open("/dev/null",O_RDONLY)==-1 && errno==EACCES);
|
||||
assert(IG_dispatch_unlink("/tmp/ig-must-not-remove")==-1 && errno==EACCES);
|
||||
assert(IG_dispatch_getpid()==-1 && errno==EACCES);
|
||||
assert(IG_dispatch_fopen("/dev/null","r")==NULL && errno==EACCES);
|
||||
assert(IG_dispatch_fork()==-1 && errno==EACCES);
|
||||
assert(IG_dispatch_dlopen(NULL,RTLD_LAZY)==NULL && errno==EACCES);
|
||||
assert(IG_dispatch_dlsym(RTLD_DEFAULT,"getpid")==NULL && errno==EACCES);
|
||||
assert(ig_dispatch_check(collect,NULL)==9 && reasons[IG_REASON_DISPATCH_TAMPER]==9);
|
||||
} else if (!strcmp(argv[1],"read-eintr")) {
|
||||
int p[2]; assert(pipe(p)==0);
|
||||
struct sigaction action={0};action.sa_handler=signal_handler;sigemptyset(&action.sa_mask);
|
||||
assert(sigaction(SIGUSR1,&action,NULL)==0);
|
||||
main_thread=pthread_self();pthread_t thread;
|
||||
assert(pthread_create(&thread,NULL,interruptor,NULL)==0);
|
||||
char b; assert(IG_dispatch_read(p[0],&b,1)==-1 && errno==EINTR);
|
||||
pthread_join(thread,NULL);IG_dispatch_close(p[1]);IG_dispatch_close(p[0]);
|
||||
} else if (!strcmp(argv[1],"semantics")) {
|
||||
assert(ig_dispatch_check(collect,NULL)==0 && unavailable==0);
|
||||
errno=0; assert(IG_dispatch_write(-1,"x",1)==-1 && errno==EBADF);
|
||||
@@ -123,9 +192,30 @@ int main(int argc,char **argv) {
|
||||
} else if (!strcmp(argv[1],"prologue")) {
|
||||
assert(ig_arm64_suspicious_prologue(0x14000001,0));
|
||||
assert(ig_arm64_suspicious_prologue(0x58000050,0xd61f0200));
|
||||
assert(ig_arm64_suspicious_prologue(0x58000049,0xd61f0120)); /* ldr x9; br x9 */
|
||||
assert(!ig_arm64_suspicious_prologue(0x58000050,0xd61f0220));
|
||||
assert(!ig_arm64_suspicious_prologue(0x18000050,0xd61f0200));
|
||||
assert(!ig_arm64_suspicious_prologue(0xd503245f,0xd65f03c0));
|
||||
const uint32_t clean_win[8] = {
|
||||
0xd503237fu, 0xa9bf7bfdu, 0x910003fdu, 0xaa0003f3u,
|
||||
0xf100001fu, 0x54000080u, 0xd503201fu, 0xd65f03c0u
|
||||
};
|
||||
assert(!ig_arm64_suspicious_window(clean_win, 8));
|
||||
const uint32_t adrp_win[8] = {
|
||||
0xd503237fu, 0x9000000au, 0x9100414au, 0xd61f0140u,
|
||||
0xd503201fu, 0xd503201fu, 0xd503201fu, 0xd503201fu
|
||||
};
|
||||
assert(ig_arm64_suspicious_window(adrp_win, 8));
|
||||
const uint32_t movk_win[8] = {
|
||||
0xd280000bu, 0xf2c2468bu, 0xd61f0160u, 0xd503201fu,
|
||||
0xd503201fu, 0xd503201fu, 0xd503201fu, 0xd503201fu
|
||||
};
|
||||
assert(ig_arm64_suspicious_window(movk_win, 8));
|
||||
const uint32_t mid_ldr_win[8] = {
|
||||
0xd503237fu, 0xa9bf7bfdu, 0x910003fdu, 0x58000050u,
|
||||
0xd61f0200u, 0xd503201fu, 0xd503201fu, 0xd503201fu
|
||||
};
|
||||
assert(ig_arm64_suspicious_window(mid_ldr_win, 8));
|
||||
} else return 2;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user