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
컨테이너 폴더 내에서는 번들 ID의 이름으로 샌드박스에서 실행되는 각 앱의 폴더를 찾을 수 있습니다:
주의하세요. 심볼릭 링크가 존재하여 샌드박스를 "탈출"하고 다른 폴더에 접근할 수 있더라도, 앱은 여전히 해당 폴더에 접근할 권한이 있어야 합니다. 이러한 권한은 .plist 파일 내에 있습니다.
# Get permissionsplutil-convertxml1.com.apple.containermanagerd.metadata.plist-o-# Binary sandbox profile<key>SandboxProfileData</key><data>AAAhAboBAAAAAAgAAABZAO4B5AHjBMkEQAUPBSsGPwsgASABHgEgASABHwEf...# 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/><key>keychain-access-groups</key><array><string>6N38VWS5BX.ru.keepcoder.Telegram</string><string>6N38VWS5BX.ru.keepcoder.TelegramShare</string></array>[...]# 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><key>RedirectedPaths</key><array/>[...]
모든 샌드박스 애플리케이션에서 생성/수정된 모든 것은 격리 속성을 가집니다. 이는 샌드박스 앱이 **open**을 사용하여 무언가를 실행하려고 할 때 게이트키퍼를 트리거하여 샌드박스 공간을 방지합니다.
샌드박스 프로필
샌드박스 프로필은 해당 샌드박스에서 허용/금지되는 내용을 나타내는 구성 파일입니다. 이는 **샌드박스 프로필 언어 (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"))
앱 스토어 앱은 프로필 **/System/Library/Sandbox/Profiles/application.sb**를 사용합니다. 이 프로필에서 **com.apple.security.network.server**와 같은 권한을 확인할 수 있습니다. 이 권한은 프로세스가 네트워크를 사용할 수 있도록 허용합니다.
SIP는 /System/Library/Sandbox/rootless.conf에 있는 platform_profile이라는 샌드박스 프로필입니다.
(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
Windows에서 실행되는 Apple이 작성한 소프트웨어는 추가적인 보안 조치 (예: 응용 프로그램 샌드박싱)를 가지고 있지 않습니다.
sbtool<pid>mach#Check mac-ports (got from launchd with an api)sbtool<pid>file/tmp#Check file accesssbtool<pid>inspect#Gives you an explaination of the sandbox profilesbtool<pid>all
App Store 앱에서 사용자 정의 SBPL
회사들은 앱을 기본적인 것이 아닌 사용자 정의 Sandbox 프로필로 실행할 수 있습니다. 이를 위해 Apple의 승인이 필요한 com.apple.security.temporary-exception.sbpl 권한을 사용해야 합니다.
이 권한의 정의는 **/System/Library/Sandbox/Profiles/application.sb:**에서 확인할 수 있습니다.