macOS Default Sandbox Debug

macOS默认沙箱调试

从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS红队专家)

支持HackTricks的其他方式:

在本页面中,您可以找到如何创建一个应用程序,从默认的macOS沙箱中启动任意命令:

  1. 编译应用程序:

main.m
#include <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
while (true) {
char input[512];

printf("Enter command to run (or 'exit' to quit): ");
if (fgets(input, sizeof(input), stdin) == NULL) {
break;
}

// Remove newline character
size_t len = strlen(input);
if (len > 0 && input[len - 1] == '\n') {
input[len - 1] = '\0';
}

if (strcmp(input, "exit") == 0) {
break;
}

system(input);
}
}
return 0;
}

运行以下命令进行编译:clang -framework Foundation -o SandboxedShellApp main.m

  1. 构建 .app bundle

  1. 定义授权

```bash cat << EOF > entitlements.plist com.apple.security.app-sandbox com.apple.security.files.downloads.read-write EOF ``` 4. 对应用程序进行签名(您需要在钥匙串中创建一个证书) ```bash codesign --entitlements entitlements.plist -s "YourIdentity" SandboxedShellApp.app ./SandboxedShellApp.app/Contents/MacOS/SandboxedShellApp

An d in case you need this in the future

codesign --remove-signature SandboxedShellApp.app

最后更新于