`を使用してルートに昇格すると、`~/.zshenv`ファイルがトリガーされ、実質的にルートに昇格します。
#### [**CVE-2022-22583**](https://perception-point.io/blog/technical-analysis-cve-2022-22583/)
[**CVE-2022-22583**](https://perception-point.io/blog/technical-analysis-cve-2022-22583/)では、同じ**`system_installd`**プロセスが依然として悪用される可能性があることが発見されました。なぜなら、**post-installスクリプトがSIPによって保護されたランダムに名付けられたフォルダー内に配置されていたからです**。問題は、**`/tmp`自体はSIPによって保護されていないため**、**仮想イメージをマウント**し、その後**インストーラー**が**post-installスクリプト**をそこに配置し、**仮想イメージをアンマウント**し、すべての**フォルダーを再作成**し、**ペイロード**を実行する**post installation**スクリプトを追加することが可能だったことです。
#### [fsck_csユーティリティ](https://www.theregister.com/2016/03/30/apple_os_x_rootless/)
**`fsck_cs`**が重要なファイルを破損させるように誤導される脆弱性が特定されました。これは、**シンボリックリンク**をたどる能力によるものでした。具体的には、攻撃者は`/dev/diskX`から`/System/Library/Extensions/AppleKextExcludeList.kext/Contents/Info.plist`へのリンクを作成しました。**`fsck_cs`**を`/dev/diskX`で実行すると、`Info.plist`が破損しました。このファイルの整合性は、カーネル拡張の読み込みを制御するオペレーティングシステムのSIP(システム整合性保護)にとって重要です。一度破損すると、SIPのカーネル除外を管理する能力が損なわれます。
この脆弱性を悪用するためのコマンドは:
```bash
ln -s /System/Library/Extensions/AppleKextExcludeList.kext/Contents/Info.plist /dev/diskX
fsck_cs /dev/diskX 1>&-
touch /Library/Extensions/
reboot
```
この脆弱性の悪用は深刻な影響を及ぼします。通常、カーネル拡張の権限を管理する役割を持つ`Info.plist`ファイルが無効になります。これには、`AppleHWAccess.kext`のような特定の拡張をブラックリストに登録できないことが含まれます。その結果、SIPの制御メカニズムが機能しなくなると、この拡張が読み込み可能になり、システムのRAMへの不正な読み書きアクセスが許可されます。
#### [SIP保護フォルダ上にマウント](https://www.slideshare.net/i0n1c/syscan360-stefan-esser-os-x-el-capitan-sinking-the-ship)
**保護を回避するためにSIP保護フォルダ上に新しいファイルシステムをマウントする**ことが可能でした。
```bash
mkdir evil
# Add contento to the folder
hdiutil create -srcfolder evil evil.dmg
hdiutil attach -mountpoint /System/Library/Snadbox/ evil.dmg
```
#### [Upgrader bypass (2016)](https://objective-see.org/blog/blog_0x14.html)
システムは、OSをアップグレードするために`Install macOS Sierra.app`内の埋め込みインストーラーディスクイメージからブートするように設定されており、`bless`ユーティリティを利用しています。使用されるコマンドは次のとおりです:
```bash
/usr/sbin/bless -setBoot -folder /Volumes/Macintosh HD/macOS Install Data -bootefi /Volumes/Macintosh HD/macOS Install Data/boot.efi -options config="\macOS Install Data\com.apple.Boot" -label macOS Installer
```
このプロセスのセキュリティは、攻撃者がブート前にアップグレードイメージ(`InstallESD.dmg`)を変更すると危険にさらされる可能性があります。この戦略は、動的ローダー(dyld)を悪意のあるバージョン(`libBaseIA.dylib`)に置き換えることを含みます。この置き換えにより、インストーラーが開始されると攻撃者のコードが実行されます。
攻撃者のコードは、アップグレードプロセス中に制御を取得し、インストーラーに対するシステムの信頼を利用します。攻撃は、`InstallESD.dmg`イメージをメソッドスウィズリングを通じて変更し、特に`extractBootBits`メソッドをターゲットにします。これにより、ディスクイメージが使用される前に悪意のあるコードを注入することが可能になります。
さらに、`InstallESD.dmg`内には、アップグレードコードのルートファイルシステムとして機能する`BaseSystem.dmg`があります。ここに動的ライブラリを注入することで、悪意のあるコードがOSレベルのファイルを変更できるプロセス内で動作することができ、システムの危険性が大幅に増加します。
#### [systemmigrationd (2023)](https://www.youtube.com/watch?v=zxZesAN-TEk)
この[**DEF CON 31**](https://www.youtube.com/watch?v=zxZesAN-TEk)の講演では、**`systemmigrationd`**(SIPをバイパスできる)が**bash**と**perl**スクリプトを実行し、これが環境変数**`BASH_ENV`**と**`PERL5OPT`**を介して悪用される可能性があることが示されています。
#### CVE-2023-42860
[**このブログ記事で詳述されているように**](https://blog.kandji.io/apple-mitigates-vulnerabilities-installer-scripts)、`InstallAssistant.pkg`パッケージの`postinstall`スクリプトが実行されていました:
```bash
/usr/bin/chflags -h norestricted "${SHARED_SUPPORT_PATH}/SharedSupport.dmg"
```
and it was possible to create a symlink in `${SHARED_SUPPORT_PATH}/SharedSupport.dmg` that would allow a user to **unrestrict any file, bypassing SIP protection**.
### **com.apple.rootless.install**
> [!CAUTION]
> The entitlement **`com.apple.rootless.install`** allows to bypass SIP
The entitlement `com.apple.rootless.install` is known to bypass System Integrity Protection (SIP) on macOS. This was notably mentioned in relation to [**CVE-2022-26712**](https://jhftss.github.io/CVE-2022-26712-The-POC-For-SIP-Bypass-Is-Even-Tweetable/).
In this specific case, the system XPC service located at `/System/Library/PrivateFrameworks/ShoveService.framework/Versions/A/XPCServices/SystemShoveService.xpc` possesses this entitlement. This allows the related process to circumvent SIP constraints. Furthermore, this service notably presents a method that permits the movement of files without enforcing any security measures.
## Sealed System Snapshots
Sealed System Snapshotsは、Appleが**macOS Big Sur (macOS 11)**で導入した機能で、**System Integrity Protection (SIP)**メカニズムの一部として、追加のセキュリティとシステムの安定性を提供します。これらは本質的にシステムボリュームの読み取り専用バージョンです。
以下は詳細な説明です:
1. **不変のシステム**: Sealed System SnapshotsはmacOSシステムボリュームを「不変」にし、変更できないようにします。これにより、セキュリティやシステムの安定性を損なう可能性のある不正または偶発的な変更を防ぎます。
2. **システムソフトウェアの更新**: macOSの更新やアップグレードをインストールすると、macOSは新しいシステムスナップショットを作成します。macOSの起動ボリュームはその後、**APFS (Apple File System)**を使用してこの新しいスナップショットに切り替えます。更新を適用するプロセス全体が安全で信頼性が高くなり、更新中に何か問題が発生した場合でも、システムは常に前のスナップショットに戻ることができます。
3. **データの分離**: macOS Catalinaで導入されたデータとシステムボリュームの分離の概念と組み合わせて、Sealed System Snapshot機能は、すべてのデータと設定が別の「**Data**」ボリュームに保存されることを保証します。この分離により、データがシステムから独立し、システムの更新プロセスが簡素化され、システムのセキュリティが向上します。
これらのスナップショットはmacOSによって自動的に管理され、APFSのスペース共有機能のおかげでディスク上に追加のスペースを占有しません。また、これらのスナップショットは、ユーザーがアクセス可能なシステム全体のバックアップである**Time Machineスナップショット**とは異なることに注意することが重要です。
### Check Snapshots
The command **`diskutil apfs list`** lists the **details of the APFS volumes** and their layout:
+-- Container disk3 966B902E-EDBA-4775-B743-CF97A0556A13
| ====================================================
| APFS Container Reference: disk3
| Size (Capacity Ceiling): 494384795648 B (494.4 GB)
| Capacity In Use By Volumes: 219214536704 B (219.2 GB) (44.3% used)
| Capacity Not Allocated: 275170258944 B (275.2 GB) (55.7% free)
| |
| +-< Physical Store disk0s2 86D4B7EC-6FA5-4042-93A7-D3766A222EBE
| | -----------------------------------------------------------
| | APFS Physical Store Disk: disk0s2
| | Size: 494384795648 B (494.4 GB)
| |
| +-> Volume disk3s1 7A27E734-880F-4D91-A703-FB55861D49B7
| | ---------------------------------------------------
| | APFS Volume Disk (Role): disk3s1 (System)
| | Name: Macintosh HD (Case-insensitive)
| | Mount Point: /System/Volumes/Update/mnt1
| | Capacity Consumed: 12819210240 B (12.8 GB)
| | Sealed: Broken
| | FileVault: Yes (Unlocked)
| | Encrypted: No
| | |
| | Snapshot: FAA23E0C-791C-43FF-B0E7-0E1C0810AC61
| | Snapshot Disk: disk3s1s1
| | Snapshot Mount Point: /
| | Snapshot Sealed: Yes
[...]
+-> Volume disk3s5 281959B7-07A1-4940-BDDF-6419360F3327
| ---------------------------------------------------
| APFS Volume Disk (Role): disk3s5 (Data)
| Name: Macintosh HD - Data (Case-insensitive)
| Mount Point: /System/Volumes/Data
| Capacity Consumed: 412071784448 B (412.1 GB)
| Sealed: No
| FileVault: Yes (Unlocked)
In the previous output it's possible to see that **user-accessible locations** are mounted under `/System/Volumes/Data`.
Moreover, **macOS System volume snapshot** is mounted in `/` and it's **sealed** (cryptographically signed by the OS). So, if SIP is bypassed and modifies it, the **OS won't boot anymore**.
It's also possible to **verify that seal is enabled** by running:
```bash
csrutil authenticated-root status
Authenticated Root status: enabled
```
さらに、スナップショットディスクは**読み取り専用**としてマウントされます:
```bash
mount
/dev/disk3s1s1 on / (apfs, sealed, local, read-only, journaled)
```
{{#include ../../../banners/hacktricks-training.md}}