macOS逆向-Interface Inspector

1,044 阅读1分钟

Interface Inspector简介

Interface Inspector允许我们研究任何Mac App运行时候的UI结构和属性。

环境

逆向前的分析

打开Interface Inspector后,出现一个License窗口: image.png 看到这个窗口,大胆猜测代码里会出现很多License相关的命名。

使用Hopper Disassembler进行逆向

Hopper Disassembler打开Interface Inspector

Interface Inspector拖拽进Hopper Disassembler,然后点击OKimage.png image.png

查找并修改License逻辑

搜索 License ,果然有重大发现:

-[SMLicenseManager isLicensed]

果断修改返回值为YES,Modify -> Assemble Instruction...(⌥A)

                     -[SMLicenseManager isLicensed]:
000000010010fe70         mov        rax, 0x1
000000010010fe77         ret

如图: image.png

修改完后,我们保存试一下: File -> Produce New Executable...(⌘⇧E),选择Remove SignatureSaveInterface Inspector.app/Contents/MacOS/Interface Inspector,选择Replaceimage.png image.png

尝试运行修改后的Interface Inspector,发现有验证签名: image.png

查找并修改验证签名的逻辑

同样大胆猜想代码里有Sign相关的命名,搜索 Sign ,发现 aCodeSignStateimage.png Navigate -> References To Highlighted Word...(X)查看引用,发现在applicationWillFinishLaunching中调用了这个方法:

void -[SMAppDelegate applicationWillFinishLaunching:](void * self, void * _cmd, void * arg2) {
    rdx = arg2;
    rbx = self;
    var_30 = *___stack_chk_guard;
    rax = [NSBundle mainBundle];
    rax = [rax retain];
    var_128 = rax;
    if ([rax codeSignState] != 0x2) goto loc_100024851;
......
loc_100024851:
    r14 = [[NSAlert alloc] init];
    var_F8 = r14;
    r13 = [[NSBundle mainBundle] retain];
    rbx = [[r13 localizedStringForKey:@"Signature of the Interface Inspector is broken" value:@"" table:0x0] retain];

需要把codeSignState的值修改为0x2。 在SMFoundation.framework找到这个方法,直接修改:

                     -[NSBundle codeSignState]:
000000000003b298         mov        rax, 0x2
000000000003b29f         ret

替换SMFoundation后再次运行,成功了!但是Attach的时候弹窗Could not attach to application

解决Could not attach to application

面对这个问题,没啥头绪,我们还是先看看日志吧,说不定能多些线索。打开Console,点击Start streamingimage.png 筛选InspectorInterface Inspector再次使用Attach功能,之后查看日志: image.png

Error loading /Library/Frameworks/mach_inject_bundle.framework/Resources/mach_inject_bundle_stub.bundle/Contents/MacOS/mach_inject_bundle_stub:  dlopen(/Library/Frameworks/mach_inject_bundle.framework/Resources/mach_inject_bundle_stub.bundle/Contents/MacOS/mach_inject_bundle_stub, 262): Symbol not found: ___pthread_set_self
  Referenced from: /Library/Frameworks/mach_inject_bundle.framework/Resources/mach_inject_bundle_stub.bundle/Contents/MacOS/mach_inject_bundle_stub
  Expected in: /usr/lib/libSystem.B.dylib
 in /Library/Frameworks/mach_inject_bundle.framework/Resources/mach_inject_bundle_stub.bundle/Contents/MacOS/mach_inject_bundle_stub

查阅资料,mach_inject_bundle.framework过期导致:
Fix Bug for Interface Inspector on macOS Serria
去github下载最新源码: github.com/rentzsch/ma…
编译出mach_inject_bundle.framework文件,放在:

/Library/Frameworks/mach_inject_bundle.framework