从沙盒应用启动的应用程序未被沙盒化。

3

我有一个在macOS上不被信任的应用程序,我想运行它,但不允许它连接到互联网。

有什么最好的方法可以实现这一点吗?

我的最佳想法是在Xcode中构建一个简单的Swift启动应用程序,并对此启动器进行沙箱处理。从我所了解的情况来看,从沙盒应用程序启动的应用程序本身应该是沙盒化的。

因此,我的启动器应用程序如下:

@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {

    @IBOutlet weak var window: NSWindow!


    func applicationDidFinishLaunching(_ aNotification: Notification) {
        NSWorkspace.shared.open("/path/inside/bundle/to/untrustedApp.app")
        print ("after")

    }

    func applicationWillTerminate(_ aNotification: Notification) {

    }


}

(注意,我使用了 NSWorkspace.shared.open,因为 NSWorkspace.shared.openApp 没有做任何事情,甚至没有调用完成处理程序。)
我在 Xcode 中添加了沙盒能力,并确保所有框都未被选中。我做错了什么吗?或者我的理解不正确吗?
1个回答

1
一种方法是使用NSTask直接启动不受信任应用程序中的Mach-O可执行文件:
  • NSTask继承父应用程序的沙箱(请参见此处
  • NSTask允许您指定Mach-O可执行文件,这是必要的,因为untrusted.app具有其自己的代码签名、plist文件和授权(或缺乏授权)
例如,以下简单应用程序将从中获取Mach-O可执行文件的名称:
/path/to/your/ParentApp.app/relative/path/to/Restricted.app
例如,对于 firefox

/path/to/your/ParentApp.app/relative/path/to/Restricted.app/Contents/MacOS/firefox

Swift:

func applicationDidFinishLaunching(_ aNotification: Notification) {

    let theMainAppBundle = Bundle.main.bundlePath
    let theChildAppBundle = theMainAppBundle + ("/relative/path/to/RestrictedApp.app")
    let childBundleExecutable = Bundle(path: theChildAppBundle)?.executablePath
    Process.launchedProcess(launchPath: childBundleExecutable ?? "", arguments: [""])
    NSApp.terminate(self)

}

Objective C:

(void)applicationDidFinishLaunching:(NSNotification *)aNotification {

    NSString *theMainAppBundle = [[NSBundle mainBundle] bundlePath];
    NSString *theChildAppBundle = [theMainAppBundle stringByAppendingString:@"/relative/path/to/RestrictedApp.app"];
    NSString *childBundleExecutable = [NSBundle bundleWithPath:theChildAppBundle].executablePath;
    [NSTask launchedTaskWithLaunchPath:childBundleExecutable arguments:[NSArray arrayWithObjects:@"", nil]];
    [NSApp terminate:self];

}

@DevShark 无论如何,肯定有100种方法可以实现你想要的,但是你的限制是什么?你说这个不受信任的应用程序已经被沙盒化了,但没有继承的授权。我听说辅助应用程序需要这两个授权,但我可能是做错了辅助应用程序,因为这从来不是我的问题。 - hmedia1
@DevShark,你试过我发布的启动器了吗?我已经尝试过使用沙盒和非沙盒应用程序,它们都没有继承权限,并且所有这些应用程序都有比那两个显式权限更多的权限。既然至少我知道你控制着父应用程序,那么为什么需要将其沙盒化呢?抱歉,我忘记提到了,我发布的代码可以在没有网络访问权限的情况下运行应用程序,只要在“父”应用程序中关闭了出站连接权限-这就是我认为你想要的...能够控制子应用程序的沙盒属性。 - hmedia1
即使您无法控制子应用程序 - 您仍然可以随意再次codesign它,甚至没有开发人员证书。 - hmedia1
沙盒执行失败。顺便说一下,我正在尝试在macOS 10.15上运行,如果您使用的是旧版本,那可能就可以解释为什么它对您有效但对我无效。 - DevShark
辅助应用程序是第三方应用程序,例如/Applications/Safari.app。 - DevShark
显示剩余8条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接