Mac OS X El Capitan系统完整性保护System Integrity Protection (SIP)

引言:前段时间经历了XCode编译器代码被注入的事件后,这次 Mac OS X El Capitan系统的升级,启用了更高的安全性保护机制:系统完整性保护System Integrity Protection (SIP),是By Design?还是巧合呢?

关于 系统完整性保护System Integrity Protection (SIP),可以从Apple官网下载下来学习,从第29页到54页 http://devstreaming.apple.com/vi ... y_and_your_apps.pdf

关键点:
1、Security policy applying to every process, including privileged code running unsandboxed
2、Extends additional protections to system components on disk and at runtime
3、System binaries can only be modified by Apple Installer and Software Update, and no longer permit runtime attachment or code injection

实际上从Mac AppStore下载的应用是不受影响的;如果不是则可能会受影响,比如:
修改系统文件,安装文件到系统目录中,观察系统进程内存,注入代码到系统进程中等
内核会直接中断这些破坏性的工作,哈哈哈。
所以对于像 /System /bin /usr /sbin 仅仅供系统使用,开发者或者应用程序则无法直接使用,而使用 ~/Library /usr/local /Applications,升级之后,那些文件将被移出去。

注入代码到系统进程中等同于修改硬盘上的可执行文件,所以会进行各种安全检查确保安全可信,比如签名检查

整个机制主要从三方面入手:
1、文件系统保护(Filesystem protections)
2、运行时保护(Runtime protections)
3、内核扩展签名(Kernel extensions)

总结:
1、新的安全策略机制适用于每一个进程
2、默认下系统启用SIP系统完整性保护机制,无论是对于硬盘还是运行时的进程
     限制对系统目录的写操作
     阻止在运行时附加或注入代码到系统进程中
3、第三方安装的内容必须移入系统目录
4、SIP系统完整性保护机制可以在Recovery OS状态下进行更改,也就是留有余地啊哈哈


如何禁用SIP系统完整性保护机制?
1、重新启动操作系统;
2、按住Command + R键;
3、菜单“实用工具” ==>> "终端" ==>> 输入 csrutil disable 回车
    执行成功后,返回信息如下:
Successfully disabled System Integrity Protection. Please restart the machine for the changes to take effect.
4、这样,更改的配置保存到NVRAM中,对整台机器生效,重新启动即可

如何查看SIP系统完整性保护机制?
命令行终端
$ csrutil status
System Integrity Protection status: enabled.

$ csrutil clear / enable / disable 只能在 恢复模式下使用

在禁用掉SIP后,查看状态信息如下
$ csrutil status
System Integrity Protection status: enabled (Custom Configuration).

Configuration:
        Apple Internal: disabled
        Kext Signing: disabled
        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.

那么将之前升级而被移走的文件从 /Library/SystemMigration/History 对应移回到原来的目录下,应用程序就可以使用了。

如何对被移出的应用程序进行恢复?
比如Mobility Client,进入终端,并切换到 root 用户下,然后

su -
cd /Library/SystemMigration/History/Migration-*/QuarantineRoot/usr/libexec
mv MobilityClient/ /usr/libexec/

再启动 Mobility Client 就可以了,不需要重新安装,就这么简单!
上一篇:中介者模式与解释器模式(2)


下一篇:冬季实战营第二期:Linux操作系统实战入门