[macOS翻译]关于 OS X 10.11 El Capitan 的 SIP(系统完整性保护)的更多详情

332 阅读3分钟

本文由 简悦 SimpRead转码, 原文地址 rcmdnk.com

OS X 10.11 El Capitan 采用了名为 SIP(系统完整性保护)的新安全系统。这个新系统......。

OS X 10.11 El Capitan 采用了名为 SIP(系统完整性保护)的新安全系统。

这一新系统会影响某些应用程序,有些应用程序在该系统下无法使用。它还会影响 Homebrew

SIP(系统完整性保护)是 OS X El Capitan 采用的新安全系统。

它有时被称为 无根1,因为它减少了 root 的权限。

在该安全系统下,即使 root 也只能修改有限的文件/目录,某些进程的修改也受到限制。

这是 El Capitan 安全层的概念图。

  • 网守

在最外层,Gatekeeper 2会拒绝安装没有正确开发者 ID 的应用程序。

  • 沙箱

经 Gatakeeper 确认的应用程序将在沙盒OS X - Security - Apple中启动。这可以保护 OS X 的数据不被应用程序意外访问或更改。

  • POSIX

此外,由于 OS X 是 UNIX 系统,它还具有 POSIX 访问控制功能,可限制每个用户访问/更改每个文件/目录的权限。

在 POSIX 控制下,基本上 root 可以访问/更改所有文件/目录。

  • 钥匙串

最底层是钥匙串。Keychain 是一个特殊的数据库,其中包含密码信息,并已加密。它受到严格保护,即使 root 也无法直接访问。

简而言之,OS X 的安全系统可以这样描述。但在 Yosemite 之前(或者说在 Unix 中)存在一个问题,那就是如果有人获得了POSIX的全部权限,他/她就可以更改 Keychain 3 以外的所有内容。

为了解决这个问题,需要建立一个限制 root 权限的新系统。(上图中的Keychain被分隔开来)。

在此系统下,即使用户允许应用程序拥有 root 权限,OS X 中的某些部分也会受到保护。

但是,这种保护变得过于强大,一些应用程序再也无法在此系统下运行......

受保护的文件/目录被写入

/System/Library/Sandbox/rootless.conf

尝试检查

$ cat /System/Library/Sandbox/rootless.conf
                /Applications/App Store.app
                /Applications/Automator.app
                /Applications/Calculator.app
                /Applications/Calendar.app
                /Applications/Chess.app
                /Applications/Contacts.app
                /Applications/Dashboard.app
                /Applications/Dictionary.app
                /Applications/DVD Player.app
                /Applications/FaceTime.app
                /Applications/Font Book.app
                /Applications/Game Center.app
                /Applications/Image Capture.app
                /Applications/Launchpad.app
                /Applications/Mail.app
                /Applications/Maps.app
                /Applications/Messages.app
                /Applications/Mission Control.app
                /Applications/Notes.app
                /Applications/Photo Booth.app
                /Applications/Photos.app
                /Applications/Preview.app
                /Applications/QuickTime Player.app
                /Applications/Reminders.app
                /Applications/Safari.app
                /Applications/Stickies.app
                /Applications/System Preferences.app
                /Applications/TextEdit.app
                /Applications/Time Machine.app
                /Applications/Utilities/Activity Monitor.app
                /Applications/Utilities/AirPort Utility.app
                /Applications/Utilities/Audio MIDI Setup.app
                /Applications/Utilities/Bluetooth File Exchange.app
                /Applications/Utilities/Boot Camp Assistant.app
                /Applications/Utilities/ColorSync Utility.app
                /Applications/Utilities/Console.app
                /Applications/Utilities/Digital Color Meter.app
                /Applications/Utilities/Disk Utility.app
                /Applications/Utilities/Feedback Assistant.app
                /Applications/Utilities/Grab.app
                /Applications/Utilities/Grapher.app
                /Applications/Utilities/Keychain Access.app
                /Applications/Utilities/Migration Assistant.app
                /Applications/Utilities/Script Editor.app
                /Applications/Utilities/System Information.app
                /Applications/Utilities/Terminal.app
                /Applications/Utilities/VoiceOver Utility.app
                /Library/Preferences/SystemConfiguration/com.apple.Boot.plist
                /System
*               /System/Library/Caches
booter          /System/Library/CoreServices
*               /System/Library/CoreServices/Photo Library Migration Utility.app
                /System/Library/CoreServices/RawCamera.bundle
*               /System/Library/Extensions
                /System/Library/Extensions/*
UpdateSettings  /System/Library/LaunchDaemons/com.apple.UpdateSettings.plist
*               /System/Library/Speech
*               /System/Library/User Template
                /bin
dyld            /private/var/db/dyld
                /sbin
                /usr
*               /usr/libexec/cups
*               /usr/local
*               /usr/share/man
# symlinks
                /etc
                /tmp
                /var

就像这样

你可以看到这样的 /System/user/bin/sbin

此外,还包括一些预装的应用程序。

在列表中,以 "*"开头的行表示这些文件/目录即使位于受保护目录下也不受保护。

因此,/user 受保护,但 /usr/local 不受保护,用户可以修改。

Disabling SIP

如上所述,/usr/local 可以修改,但不能在 /usr 下创建新目录,因此如果 /usr/local 不存在,/usr/local 也不能创建。

此外,还列出了一些应用程序,这意味着你不能修改它们的图标。

要修改它们,需要禁用 SIP。

要禁用 SIP,首先在恢复模式下启动 OS X,按 ⌘-R 键启动 OS X。

在恢复模式下,你可以在菜单栏中找到实用工具,还有终端

启动终端并执行命令:

-bash-3.2 # csrutil disable
Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.
-bash-3.2 #

重启并正常启动 OS X 后,SIP 已禁用。

要检查它,请启动终端并执行命令:

$ csrutil status
System Integrity Protection status: enabled (Custom Configuration).

Configuration:
        Apple Internal: disabled
        Kext Signing: enabled
        Filesystem Protections: disabled
        Debugging Restrictions: disabled
        DTrace Restrictions: disabled
        NVRAM Protections: disabled

This is an unsupported configuration, likely to break in the future and leave your machine in an unknown state.
$

应该像这样4

这里说的 "已启用 "是这样的:

System Integrity Protection status: enabled (Custom Configuration).

但你可以看到它下面的每个组件都已禁用。

要修改图标或创建 /usr/local,需要暂时禁用 SIP,因此最好在修改后重新启用 SIP。

要启用 SIP,请在恢复模式下再次启动 OS X,并在终端中执行以下命令:

-bash-3.2 # csrutil enable
Successfully enabled System Integrity Protection. Please restart the machine for the changes to take effect.
-bash-3.2 #

然后重新启动。

使用 csrutil status 检查 SIP:

$ csrutil status
System Integrity Protection status: enabled.
$

现在 SIP 已完全启用。

另一方面,如果你想使用 XtraFinderTotalFinder 等应用程序,则需要始终禁用 SIP。

这些应用程序似乎与 El Capitan 不兼容,但如果禁用 SIP,则可以使用它们。

但如果禁用所有 SIP 功能,就有点不安全了。如果你看到上面的 "csrutil status "结果,就会发现 SIP 被分成了几组。

对于这样的 XtraFinder,你可以通过 csrutil enable -without debug 命令只禁用一部分:

-bash-3.2 # csrutil enable --without debug
csrutil: requesting an unsupported configuration. This is likely break in the future and leave your machine in an unknown state.
Successfully enabled System Integrity Protection. Please restart the machine for the changes to take effect.
-bash-3.2 #

这将启用所有 SIP 功能,但 "debug "部分除外。即使启用了所有 SIP 功能,也可以使用该命令。(它只禁用 debug 部分)。

执行此命令后,可以看到如下状态:

$ csrutil status
System Integrity Protection status: enabled (Custom Configuration).

Configuration:
        Apple Internal: disabled
        Kext Signing: enabled
        Filesystem Protections: enabled
        Debugging Restrictions: disabled
        DTrace Restrictions: enabled
        NVRAM Protections: enabled

This is an unsupported configuration, likely to break in the future and leave your machine in an unknown state.
$

因此,只有苹果内部调试限制: 被禁用。

这种文件系统保护是启用的,因此在这种情况下,即使你是root用户也无法修改**/usr**。

在这种情况下,可以使用 XtraFinder 或 TotalFinder。如果要使用它们,最好禁用最小部分("调试 "部分)。

如果只想禁用文件系统保护,可以使用--without fs

-bash-3.2 # csrutil enable --without fs

我发现一些文档显示,在不进入恢复模式的情况下可以禁用 SIP,例如

Rootless and boot-args - Cryptomonkeys Consulting: www.cryptomonkeys.com/2015/07/osx…

在这里,你可以使用命令禁用 SIP:

$ sudo nvram boot-args="rootless=0"

在正常模式下禁用 SIP,然后重新启动,但我无法重现。

此外,据说命令

$ sudo nvram boot-args="-x"

会使下一次启动成为安全模式。但我也做不到。

NVRAM 是一个小内存,里面有 OS X 的一些设置5

在 SIP 的状态列表中,可以找到 NVRAM Protections,因此它也受到 SIP 的保护。

因此,如果启用了 SIP,就无法修改 NVRAM。

此外,我还找到了以下文章:

SIP/Rootless Internal in El Capitan Delta's Lair: www.idelta.info/archives/si…

它解释了 csrutil 更改了什么。这是启动属性数据,其中包含 SIP 信息。

例如,"--without debug "只会更改某些位。

但上面说 El Capitan 会删除 "rootless=0"。

似乎这些与 SIP 相关的内容从 Beta 版开始就发生了很大变化,以至于出现了 GUI 应用程序。因此,你需要谨慎对待这些信息,因为这是操作系统中非常深层次的设置。