hacktricks/macos-hardening/macos-security-and-privilege-escalation/macos-security-protections/macos-sandbox
2023-08-03 19:12:22 +00:00
..
macos-sandbox-debug-and-bypass Translated to Chinese 2023-08-03 19:12:22 +00:00
README.md Translated to Chinese 2023-08-03 19:12:22 +00:00

macOS沙盒

☁️ HackTricks云 ☁️ -🐦 推特 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥

基本信息

MacOS沙盒最初称为Seatbelt限制在沙盒内运行的应用程序只能执行沙盒配置文件中指定的允许操作。这有助于确保应用程序只能访问预期的资源

任何具有**com.apple.security.app-sandbox权限的应用程序都将在沙盒内执行。Apple二进制文件通常在沙盒内执行,并且为了在App Store**中发布,此权限是强制性的。因此,大多数应用程序将在沙盒内执行。

为了控制进程可以执行的操作,沙盒在内核中的所有系统调用中都有钩子。根据应用程序的权限,沙盒将允许特定的操作。

沙盒的一些重要组件包括:

  • 内核扩展/System/Library/Extensions/Sandbox.kext
  • 私有框架/System/Library/PrivateFrameworks/AppSandbox.framework
  • 在用户空间运行的守护进程/usr/libexec/sandboxd
  • 容器~/Library/Containers

在容器文件夹中,你可以找到每个在沙盒中执行的应用程序的文件夹文件夹的名称是bundle id

ls -l ~/Library/Containers
total 0
drwx------@ 4 username  staff  128 May 23 20:20 com.apple.AMPArtworkAgent
drwx------@ 4 username  staff  128 May 23 20:13 com.apple.AMPDeviceDiscoveryAgent
drwx------@ 4 username  staff  128 Mar 24 18:03 com.apple.AVConference.Diagnostic
drwx------@ 4 username  staff  128 Mar 25 14:14 com.apple.Accessibility-Settings.extension
drwx------@ 4 username  staff  128 Mar 25 14:10 com.apple.ActionKit.BundledIntentHandler
[...]

在每个bundle id文件夹中您可以找到应用程序的plistData目录

cd /Users/username/Library/Containers/com.apple.Safari
ls -la
total 104
drwx------@   4 username  staff    128 Mar 24 18:08 .
drwx------  348 username  staff  11136 May 23 20:57 ..
-rw-r--r--    1 username  staff  50214 Mar 24 18:08 .com.apple.containermanagerd.metadata.plist
drwx------   13 username  staff    416 Mar 24 18:05 Data

ls -l Data
total 0
drwxr-xr-x@  8 username  staff   256 Mar 24 18:08 CloudKit
lrwxr-xr-x   1 username  staff    19 Mar 24 18:02 Desktop -> ../../../../Desktop
drwx------   2 username  staff    64 Mar 24 18:02 Documents
lrwxr-xr-x   1 username  staff    21 Mar 24 18:02 Downloads -> ../../../../Downloads
drwx------  35 username  staff  1120 Mar 24 18:08 Library
lrwxr-xr-x   1 username  staff    18 Mar 24 18:02 Movies -> ../../../../Movies
lrwxr-xr-x   1 username  staff    17 Mar 24 18:02 Music -> ../../../../Music
lrwxr-xr-x   1 username  staff    20 Mar 24 18:02 Pictures -> ../../../../Pictures
drwx------   2 username  staff    64 Mar 24 18:02 SystemData
drwx------   2 username  staff    64 Mar 24 18:02 tmp

{% hint style="danger" %} 请注意,即使符号链接存在以便从沙盒中"逃脱"并访问其他文件夹,应用程序仍然需要具有权限来访问它们。这些权限在**.plist**文件中。 {% endhint %}

# Get permissions
plutil -convert xml1 .com.apple.containermanagerd.metadata.plist -o -

# In this file you can find the entitlements:
<key>Entitlements</key>
<dict>
<key>com.apple.MobileAsset.PhishingImageClassifier2</key>
<true/>
<key>com.apple.accounts.appleaccount.fullaccess</key>
<true/>
<key>com.apple.appattest.spi</key>
<true/>
[...]

# Some parameters
<key>Parameters</key>
<dict>
<key>_HOME</key>
<string>/Users/username</string>
<key>_UID</key>
<string>501</string>
<key>_USER</key>
<string>username</string>
[...]

# The paths it can access
<key>RedirectablePaths</key>
<array>
<string>/Users/username/Downloads</string>
<string>/Users/username/Documents</string>
<string>/Users/username/Library/Calendars</string>
<string>/Users/username/Desktop</string>
[...]

沙盒配置文件

沙盒配置文件是指示在该沙盒中允许/禁止的配置文件。它使用沙盒配置语言SBPL该语言使用Scheme编程语言。

这里是一个示例:

(version 1) ; First you get the version

(deny default) ; Then you shuold indicate the default action when no rule applies

(allow network*) ; You can use wildcards and allow everything

(allow file-read* ; You can specify where to apply the rule
(subpath "/Users/username/")
(literal "/tmp/afile")
(regex #"^/private/etc/.*")
)

(allow mach-lookup
(global-name "com.apple.analyticsd")
)

{% hint style="success" %} 查看这个研究 以了解更多可能被允许或拒绝的操作。 {% endhint %}

重要的系统服务也在它们自己的自定义沙盒中运行,例如mdnsresponder服务。您可以在以下位置查看这些自定义沙盒配置文件

App Store应用程序使用配置文件 /System/Library/Sandbox/Profiles/application.sb。您可以在此配置文件中查看诸如**com.apple.security.network.server**的权限如何允许进程使用网络。

SIP是一个名为platform_profile的沙盒配置文件位于/System/Library/Sandbox/rootless.conf

沙盒配置文件示例

要使用特定的沙盒配置文件启动应用程序,可以使用:

sandbox-exec -f example.sb /Path/To/The/Application

{% code title="touch.sb" %}

(version 1)
(deny default)
(allow file-read-metadata)
(allow file-write-metadata)
(allow file-read-data (literal "/private/var/tmp/"))
(allow file-write-data (literal "/private/var/tmp/"))
(allow file-read-data (regex #"^/private/var/folders/[^/]+/[^/]+/[C,T]/"))
(allow file-write-data (regex #"^/private/var/folders/[^/]+/[^/]+/[C,T]/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/C/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/C/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/C/T/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/C/T/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/C/C/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/C/C/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/T/T/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/T/T/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/C/C/T/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/C/T/T/T/"))
(allow file-write-data (literal "/private/var/folders/[^/]+/[^/]+/[^/]+/T/C/T/C/T/T/T/"))
(allow file-read-data (literal "/private/var/folders/[^/]+/[^/]+/
```scheme
(version 1)
(deny default)
(allow file* (literal "/tmp/hacktricks.txt"))

{% endcode %}

# This will fail because default is denied, so it cannot execute touch
sandbox-exec -f touch.sb touch /tmp/hacktricks.txt
# Check logs
log show --style syslog --predicate 'eventMessage contains[c] "sandbox"' --last 30s
[...]
2023-05-26 13:42:44.136082+0200  localhost kernel[0]: (Sandbox) Sandbox: sandbox-exec(41398) deny(1) process-exec* /usr/bin/touch
2023-05-26 13:42:44.136100+0200  localhost kernel[0]: (Sandbox) Sandbox: sandbox-exec(41398) deny(1) file-read-metadata /usr/bin/touch
2023-05-26 13:42:44.136321+0200  localhost kernel[0]: (Sandbox) Sandbox: sandbox-exec(41398) deny(1) file-read-metadata /var
2023-05-26 13:42:52.701382+0200  localhost kernel[0]: (Sandbox) 5 duplicate reports for Sandbox: sandbox-exec(41398) deny(1) file-read-metadata /var
[...]

{% code title="touch2.sb" %}

;; touch2.sb
;; Sandbox profile for the touch2 command

(version 1)
(deny default)

(allow file-write*
    (literal "/tmp/evilfile.txt"))

(allow file-read-data
    (literal "/etc/passwd"))

(allow file-read-metadata
    (literal "/usr/share/misc/magic"))

(allow file-read-metadata
    (regex #"^/usr/share/locale/[^/]+/LC_.*"))

(allow file-read-metadata
    (regex #"^/usr/share/terminfo/[^/]+/[^/]+$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/[^/]+/[^/]+$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/zone.tab$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/iso3166.tab$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/leap-seconds.list$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/leapseconds$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zoneinfo/tzdata.zi$"))

(allow file-read-metadata
    (regex #"^/usr/share/zone
```scheme
(version 1)
(deny default)
(allow file* (literal "/tmp/hacktricks.txt"))
(allow process* (literal "/usr/bin/touch"))
; This will also fail because:
; 2023-05-26 13:44:59.840002+0200  localhost kernel[0]: (Sandbox) Sandbox: touch(41575) deny(1) file-read-metadata /usr/bin/touch
; 2023-05-26 13:44:59.840016+0200  localhost kernel[0]: (Sandbox) Sandbox: touch(41575) deny(1) file-read-data /usr/bin/touch
; 2023-05-26 13:44:59.840028+0200  localhost kernel[0]: (Sandbox) Sandbox: touch(41575) deny(1) file-read-data /usr/bin
; 2023-05-26 13:44:59.840034+0200  localhost kernel[0]: (Sandbox) Sandbox: touch(41575) deny(1) file-read-metadata /usr/lib/dyld
; 2023-05-26 13:44:59.840050+0200  localhost kernel[0]: (Sandbox) Sandbox: touch(41575) deny(1) sysctl-read kern.bootargs
; 2023-05-26 13:44:59.840061+0200  localhost kernel[0]: (Sandbox) Sandbox: touch(41575) deny(1) file-read-data /

{% code title="touch3.sb" %}

(version 1)
(deny default)
(allow file* (literal "/private/tmp/hacktricks.txt"))
(allow process* (literal "/usr/bin/touch"))
(allow file-read-data (literal "/"))
; This one will work

{% endcode %} {% endtab %} {% endtabs %}

{% hint style="info" %} 请注意,运行在Windows上的由Apple编写的软件没有额外的安全预防措施,比如应用程序沙箱。 {% endhint %}

绕过示例:

调试和绕过沙箱

在macOS上进程不会自动进入沙箱与iOS不同在iOS上沙箱是在程序的第一条指令执行之前由内核应用的而在macOS上进程必须选择将自己置于沙箱中

如果进程具有com.apple.security.app-sandbox权限,则在启动时,进程会自动从用户空间进入沙箱。有关此过程的详细说明,请参见:

{% content-ref url="macos-sandbox-debug-and-bypass/" %} macos-sandbox-debug-and-bypass {% endcontent-ref %}

检查PID权限

根据这个视频sandbox_check(它是一个__mac_syscall可以检查特定PID中的沙箱是否允许执行某个操作。

工具sbtool可以检查PID是否可以执行某个操作

sbtool <pid> mach #Check mac-ports (got from launchd with an api)
sbtool <pid> file /tmp #Check file access
sbtool <pid> inspect #Gives you an explaination of the sandbox profile
sbtool <pid> all

在App Store应用中使用自定义SBPL

公司有可能使他们的应用程序运行在自定义沙盒配置文件下(而不是默认配置文件)。他们需要使用授权的权限**com.apple.security.temporary-exception.sbpl**,该权限需要经过苹果授权。

可以在**/System/Library/Sandbox/Profiles/application.sb:**中检查此权限的定义。

(sandbox-array-entitlement
"com.apple.security.temporary-exception.sbpl"
(lambda (string)
(let* ((port (open-input-string string)) (sbpl (read port)))
(with-transparent-redirection (eval sbpl)))))

这将在此权限之后评估字符串作为沙盒配置文件。

☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥