在 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>
82 lines
3.5 KiB
C
82 lines
3.5 KiB
C
#include <assert.h>
|
|
#include <dlfcn.h>
|
|
#include <errno.h>
|
|
#include <mach/mach.h>
|
|
#include <mach-o/dyld.h>
|
|
#include <mach-o/loader.h>
|
|
#include <mach-o/nlist.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
int main(int argc, char **argv) {
|
|
assert(argc == 3);
|
|
void *sdk = dlopen(argv[1], RTLD_NOW); if (!sdk) { puts(dlerror()); return 1; }
|
|
int (*io)(const char *,const char *,size_t) = dlsym(sdk,"archive_fixture_io");
|
|
int (*check)(void) = dlsym(sdk,"ig_archive_check");
|
|
uint64_t (*counter)(unsigned) = dlsym(sdk,"ig_archive_counter");
|
|
assert(io && check && counter && check() == 0);
|
|
assert(!io(argv[2],"abcdef",6));
|
|
for (unsigned i=0;i<4;i++) assert(counter(i*3)>0 && counter(i*3)==counter(i*3+1) && !counter(i*3+2));
|
|
const struct mach_header_64 *header = NULL;
|
|
intptr_t slide = 0;
|
|
for (uint32_t i=0;i<_dyld_image_count();i++) {
|
|
const char *name = _dyld_get_image_name(i);
|
|
if (name && strstr(name,"/SSZipArchive.framework/SSZipArchive")) {
|
|
header=(const void *)_dyld_get_image_header(i); slide=_dyld_get_image_vmaddr_slide(i); break;
|
|
}
|
|
}
|
|
assert(header);
|
|
const struct symtab_command *symtab=NULL;
|
|
const struct dysymtab_command *dysymtab=NULL;
|
|
uintptr_t base=0;
|
|
const uint8_t *command=(const void *)(header+1);
|
|
for (uint32_t i=0;i<header->ncmds;i++) {
|
|
const struct load_command *lc=(const void *)command;
|
|
if (lc->cmd==LC_SYMTAB) symtab=(const void *)lc;
|
|
if (lc->cmd==LC_DYSYMTAB) dysymtab=(const void *)lc;
|
|
if (lc->cmd==LC_SEGMENT_64) {
|
|
const struct segment_command_64 *seg=(const void *)lc;
|
|
if (!strcmp(seg->segname,SEG_LINKEDIT)) base=slide+seg->vmaddr-seg->fileoff;
|
|
}
|
|
command+=lc->cmdsize;
|
|
}
|
|
assert(base && symtab && dysymtab);
|
|
const struct nlist_64 *symbols=(const void *)(base+symtab->symoff);
|
|
const char *strings=(const void *)(base+symtab->stroff);
|
|
const uint32_t *indirect=(const void *)(base+dysymtab->indirectsymoff);
|
|
uintptr_t *slot=NULL;
|
|
command=(const void *)(header+1);
|
|
for (uint32_t i=0;i<header->ncmds;i++) {
|
|
const struct load_command *lc=(const void *)command;
|
|
if (lc->cmd==LC_SEGMENT_64) {
|
|
const struct segment_command_64 *seg=(const void *)lc;
|
|
const struct section_64 *sections=(const void *)(seg+1);
|
|
for (uint32_t j=0;j<seg->nsects;j++) {
|
|
const struct section_64 *s=sections+j;
|
|
if ((s->flags&SECTION_TYPE)!=S_NON_LAZY_SYMBOL_POINTERS) continue;
|
|
for (uint64_t k=0;k<s->size/8;k++) {
|
|
uint32_t n=indirect[s->reserved1+k];
|
|
if (n&(INDIRECT_SYMBOL_LOCAL|INDIRECT_SYMBOL_ABS)) continue;
|
|
if (!strcmp(strings+symbols[n].n_un.n_strx,"_ig_a0")) slot=(void *)(slide+s->addr+k*8);
|
|
}
|
|
}
|
|
}
|
|
command+=lc->cmdsize;
|
|
}
|
|
assert(slot);
|
|
uintptr_t original=*slot;
|
|
vm_address_t page=(uintptr_t)slot & ~((uintptr_t)vm_page_size-1);
|
|
assert(vm_protect(mach_task_self(),page,vm_page_size,0,VM_PROT_READ|VM_PROT_WRITE|VM_PROT_COPY)==KERN_SUCCESS);
|
|
*slot=(uintptr_t)dlsym(RTLD_DEFAULT,"fopen");
|
|
assert(check()==1);
|
|
FILE *(*close_entry)(const char *,const char *) = dlsym(sdk,"ig_a0");
|
|
assert(close_entry && !close_entry("unused","rb") && errno==EACCES);
|
|
*slot=original;
|
|
assert(check()==0);
|
|
assert(!io(argv[2],"ghijkl",6)); unlink(argv[2]);
|
|
puts("真实 chained binding 转发、GOT 篡改检测及拒绝、恢复均通过");
|
|
return 0;
|
|
}
|