苹果脚本注入方法的POC

逆向工程 操作系统 注射
2021-07-07 06:02:53

我正在尝试使用 GitHub 项目中使用的 applescript 注入技术制作代码注入的 POC EasySIMBL

此处也介绍该方法(这基本上是一篇大文章,只需在 bundle injection 中搜索 AppleScript,就可以到达那里)

我所做的步骤:

  1. 我制作了一个包后缀osax文件,它在/tmp/test.txt. 该捆绑包包含以下项目:

1.1 信息.plist:

<?xml version=“1.0” encoding=“UTF-8"?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd“>
<plist version=“1.0”>
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>English</string>
    <key>CFBundleExecutable</key>
    <string>OsaxLoaded</string>
    <key>CFBundleIdentifier</key>
    <string>com.yourcompany.OsaxLoaded</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>OsaxLoaded</string>
    <key>CFBundlePackageType</key>
    <string>osax</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>ascr</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>OSAScriptingDefinition</key>
    <string>app.sdef</string>
    <key>OSAXHandlers</key>
    <dict>
        <key>Events</key>
        <dict>
            <key>OPNeopen</key>
            <dict>
                <key>Context</key>
                <string>Process</string>
                <key>Handler</key>
                <string>InjectEventHandler</string>
                <key>ThreadSafe</key>
                <true/>
            </dict>
        </dict>
    </dict>
</dict>
</plist>

1.2 需要注入的代码(osaxbundle):

//  main.m
//  OsaxLoaded
//
//

#import <Foundation/Foundation.h>

__attribute__((visibility(“default”)))
OSErr InjectEventHandler(const AppleEvent *ev, AppleEvent *reply, long refcon)
{
    OSErr resultCode = noErr;
    [[NSFileManager defaultManager] createFileAtPath:@“/tmp/test.txt” contents:nil attributes:nil];
    return resultCode;
}

这是我的osax的结构

sh-3.2# ls /Library/ScriptingAdditions/OsaxLoaded.osax/Contents/
Info.plist    MacOS        _CodeSignature

现在我把这个osax包放在 /Library/ScriptingAdditions/

然后我写了一个模板化的 Cocoa App(注入目标),什么都不做(没有添加任何额外的代码)

此外,我编写了一个 Mach-o,它应该使我之前编写的应用程序加载脚本添加(osax 包)。之后,它发送与 info.plist 中的事件相对应的事件,并应该执行我在 osax 包 Mach-o 中编写的处理程序。

喷油器代码:

//  main.m
//  OsaxInjector
//
//

#import <Foundation/Foundation.h>
#import <Carbon/Carbon.h>
#import <ScriptingBridge/ScriptingBridge.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        if (argc != 2)
        {
            printf(“USAGE: injector pid\n”);
            return 1;
        }
        TEST *test = [[TEST alloc] init];
        pid_t pid = atoi(argv[1]);
        SBApplication* sbApp = [SBApplication applicationWithProcessIdentifier:pid];
        [sbApp setSendMode:kAENoReply | kAENeverInteract | kAEDontRecord];
        [sbApp sendEvent:kASAppleScriptSuite id:kGetAEUT parameters:0];

        // Inject!
        [sbApp setSendMode:kAENoReply | kAENeverInteract | kAEDontRecord];
        id injectReply = [sbApp sendEvent:‘OPNe’ id:‘open’ parameters:0];
        if (injectReply != nil) {
            NSLog(@“unexpected injectReply: %@“, injectReply);
        }
        [[NSProcessInfo processInfo]disableSuddenTermination];
    }
    return 0;
}

使用 提供的 pid 进行测试时lsappinfo info “ToInjectApp”,似乎没有注入/tmp/test.txt也没有创建代码

知道我做错了什么吗?

操作系统版本:Sierra

0个回答
没有发现任何回复~