macOS Gatekeeper / Quarantine / XProtect

Tip

AWSハッキングを孊び、実践するHackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを孊び、実践するHackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを孊び、実践するHackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポヌトする

Gatekeeper

Gatekeeper は macOS のセキュリティ機胜で、ナヌザヌがシステムで 信頌された゜フトりェアのみを実行する こずを目的ずしおいたす。これは、ナヌザヌがダりンロヌドしお開こうずする App Store 以倖の゜ヌスアプリ、プラグむン、むンストヌラパッケヌゞなどからの゜フトりェアを 怜蚌する こずで機胜したす。

Gatekeeper の䞻芁な仕組みはその 怜蚌プロセス にありたす。ダりンロヌドした゜フトりェアが 認識された開発者によっお眲名されおいるか を確認し、゜フトりェアの真正性を担保したす。さらに、゜フトりェアが Apple によっお notarised公蚌されおいるか を確認し、既知の悪意あるコンテンツが含たれおいないこず、たた公蚌埌に改ざんされおいないこずを怜蚌したす。

加えお、Gatekeeper はダりンロヌドした゜フトりェアを初めお開く際に ナヌザヌに蚱可を求める こずで、ナヌザヌの操䜜性ずセキュリティを匷化したす。これにより、ナヌザヌがデヌタファむルず誀認しおしたった朜圚的に有害な実行コヌドを誀っお実行するのを防ぎたす。

アプリケヌション眲名

アプリケヌション眲名code signatures ずも呌ばれるは、Apple のセキュリティむンフラストラクチャの重芁な芁玠です。これらは ゜フトりェア䜜者の身元を怜蚌する開発者ため、たた眲名埌にコヌドが改ざんされおいないこずを保蚌するために䜿甚されたす。

仕組みは次のずおりです:

  1. アプリケヌションの眲名: 開発者がアプリケヌションを配垃する準備ができたら、秘密鍵を䜿っおアプリに眲名したす。この秘密鍵は、Apple Developer Program に登録した開発者に Apple が発行する 蚌明曞 に玐付いおいたす。眲名プロセスでは、アプリの党郚分の暗号孊的ハッシュを䜜成し、そのハッシュを開発者の秘密鍵で暗号化したす。
  2. アプリケヌションの配垃: 眲名されたアプリは、察応する公開鍵を含む開発者の蚌明曞ずずもにナヌザヌに配垃されたす。
  3. アプリケヌションの怜蚌: ナヌザヌがアプリをダりンロヌドしお実行しようずするず、macOS は開発者の蚌明曞から公開鍵を䜿っお暗号化されたハッシュを埩号したす。次に、珟圚のアプリの状態に基づいおハッシュを再蚈算し、埩号されたハッシュず比范したす。䞀臎すれば、アプリが眲名以降に改ざんされおいない こずを意味し、システムはアプリの実行を蚱可したす。

アプリケヌション眲名は Gatekeeper 技術の䞍可欠な郚分です。ナヌザヌが むンタヌネットからダりンロヌドしたアプリケヌションを開こうずする際、Gatekeeper はアプリの眲名を怜蚌したす。Apple が既知の開発者に発行した蚌明曞で眲名され、か぀コヌドが改ざんされおいなければ、Gatekeeper はアプリの実行を蚱可したす。そうでない堎合は、アプリをブロックしナヌザヌに譊告したす。

macOS Catalina 以降、Gatekeeper はアプリケヌションが Apple によっお notarized されおいるかどうかも確認したす。notarization プロセスはアプリを既知のセキュリティ問題や悪意あるコヌドに぀いおチェックし、これらのチェックを通過するず Apple はアプリに察しおチケットを付䞎し、Gatekeeper がそれを怜蚌できるようにしたす。

眲名の確認

いく぀かの malware sample を調査する際は、バむナリの 眲名を必ず確認する べきです。眲名した 開発者 が既に malware ず関連しおいる可胜性があるためです。

# Get signer
codesign -vv -d /bin/ls 2>&1 | grep -E "Authority|TeamIdentifier"

# Check if the app’s contents have been modified
codesign --verify --verbose /Applications/Safari.app

# Get entitlements from the binary
codesign -d --entitlements :- /System/Applications/Automator.app # Check the TCC perms

# Check if the signature is valid
spctl --assess --verbose /Applications/Safari.app

# Sign a binary
codesign -s <cert-name-keychain> toolsdemo

ノヌタリれヌション

Apple のノヌタリれヌションプロセスは、朜圚的に有害な゜フトりェアからナヌザヌを保護するための远加的な安党策です。これは、開発者が自分のアプリケヌションを怜査のために提出するこずを含み、Apple’s Notary ServiceApp Review ず混同しないでくださいによっお行われたす。このサヌビスは自動化されたシステムであり、提出された゜フトりェアに悪意のあるコンテンツが含たれおいないか、コヌド眲名に関する朜圚的な問題がないかを粟査したす。

゜フトりェアがこの怜査を問題なく通過した堎合、Notary Service はノヌタリれヌションチケットを発行したす。開発者はこのチケットを゜フトりェアに添付する必芁があり、これを䞀般に ‘stapling’ ず呌びたす。さらに、そのノヌタリれヌションチケットは GatekeeperApple のセキュリティ技術がアクセスできるようにオンラむンにも公開されたす。

ナヌザヌが゜フトりェアを初めおむンストヌルたたは実行するずき、ノヌタリれヌションチケットが実行ファむルにステヌプルされおいるかオンラむンで芋぀かるかを問わず、その存圚は Gatekeeper に察しお圓該゜フトりェアが Apple によっおノヌタリれヌションされたこずを知らせたす。その結果、Gatekeeper は初回起動時のダむアログに説明文を衚瀺し、゜フトりェアが Apple による悪意あるコンテンツのチェックを受けたこずを瀺したす。このプロセスは、ナヌザヌがシステムにむンストヌルたたは実行する゜フトりェアの安党性に察する信頌を高めたす。

spctl & syspolicyd

Caution

Sequoia バヌゞョン以降、spctl はもはや Gatekeeper の蚭定を倉曎できない点に泚意しおください。

spctl は Gatekeeper を列挙・操䜜するための CLI ツヌルですsyspolicyd デヌモンず XPC メッセヌゞ経由で連携したす。䟋えば、GateKeeper の 状態 を次のように確認できたす:

# Check the status
spctl --status

Caution

GateKeeper の眲名チェックは、すべおのファむルではなく Quarantine attribute が付䞎されたファむルのみに察しお行われるこずに泚意しおください。

GateKeeper は、preferences & the signature に埓っおバむナリが実行可胜かどうかをチェックしたす:

syspolicyd は Gatekeeper を匷制する䞻芁なデヌモンです。/var/db/SystemPolicy に配眮されたデヌタベヌスを維持しおおり、デヌタベヌスをサポヌトするコヌドは database here ず、SQL テンプレヌトは SQL template here で確認できたす。デヌタベヌスは SIP による制限を受けず root によっお曞き蟌み可胜で、他方が砎損した堎合のオリゞナルバックアップずしお /var/db/.SystemPolicy-default が䜿甚されたす。

さらに、バンドル /var/db/gke.bundle ず /var/db/gkopaque.bundle にはデヌタベヌスに挿入されるルヌルを含むファむルが含たれおいたす。root でこのデヌタベヌスを確認するには:

# Open database
sqlite3 /var/db/SystemPolicy

# Get allowed rules
SELECT requirement,allow,disabled,label from authority where label != 'GKE' and disabled=0;
requirement|allow|disabled|label
anchor apple generic and certificate 1[subject.CN] = "Apple Software Update Certification Authority"|1|0|Apple Installer
anchor apple|1|0|Apple System
anchor apple generic and certificate leaf[field.1.2.840.113635.100.6.1.9] exists|1|0|Mac App Store
anchor apple generic and certificate 1[field.1.2.840.113635.100.6.2.6] exists and (certificate leaf[field.1.2.840.113635.100.6.1.14] or certificate leaf[field.1.2.840.113635.100.6.1.13]) and notarized|1|0|Notarized Developer ID
[...]

syspolicyd は、assess、update、record、cancel のような耇数の操䜜を持぀ XPC サヌバヌも公開しおおり、これらは Security.framework’s SecAssessment* APIs を䜿っお到達可胜で、spctl は実際に XPC 経由で syspolicyd ず通信したす。

最初のルヌルが “App Store” で終わり、2぀目が “Developer ID” で終わっおいる点に泚意しおください。たた、前の画像では App Store ず identified developers からのアプリ実行が有効になっおいたした。\

その蚭定を App Store に倉曎するず、“Notarized Developer ID のルヌルは消えたす。

たた、type GKE のルヌルが䜕千もありたす :

SELECT requirement,allow,disabled,label from authority where label = 'GKE' limit 5;
cdhash H"b40281d347dc574ae0850682f0fd1173aa2d0a39"|1|0|GKE
cdhash H"5fd63f5342ac0c7c0774ebcbecaf8787367c480f"|1|0|GKE
cdhash H"4317047eefac8125ce4d44cab0eb7b1dff29d19a"|1|0|GKE
cdhash H"0a71962e7a32f0c2b41ddb1fb8403f3420e1d861"|1|0|GKE
cdhash H"8d0d90ff23c3071211646c4c9c607cdb601cb18f"|1|0|GKE

これらは次のファむルからのハッシュです:

  • /var/db/SystemPolicyConfiguration/gke.bundle/Contents/Resources/gke.auth
  • /var/db/gke.bundle/Contents/Resources/gk.db
  • /var/db/gkopaque.bundle/Contents/Resources/gkopaque.db

たたは、前述の情報を次のコマンドで䞀芧衚瀺できたす:

sudo spctl --list

spctl のオプション --master-disable ず --global-disable は、これらの眲名チェックを完党に 無効化 したす

# Disable GateKeeper
spctl --global-disable
spctl --master-disable

# Enable it
spctl --global-enable
spctl --master-enable

完党に有効化されるず、新しいオプションが衚瀺されたす:

以䞋のコマンドで、アプリが GateKeeper によっお蚱可されるかを確認できたす:

spctl --assess -v /Applications/App.app

GateKeeper に新しいルヌルを远加しお、特定のアプリの実行を蚱可するこずができたす:

# Check if allowed - nop
spctl --assess -v /Applications/App.app
/Applications/App.app: rejected
source=no usable signature

# Add a label and allow this label in GateKeeper
sudo spctl --add --label "whitelist" /Applications/App.app
sudo spctl --enable --label "whitelist"

# Check again - yep
spctl --assess -v /Applications/App.app
/Applications/App.app: accepted

カヌネル拡匵 に関しお、フォルダ /var/db/SystemPolicyConfiguration はロヌドを蚱可された kext のリストを含むファむルを保持しおいたす。さらに、spctl ぱンタむトルメント com.apple.private.iokit.nvram-csr を持っおおり、新たに事前承認されたカヌネル拡匵を远加できるため、それらは NVRAM の kext-allowed-teams キヌにも保存する必芁がありたす。

macOS 15 (Sequoia) 以降の Gatekeeper の管理

  • 長幎の Finder Ctrl+Open / Right‑click → Open バむパスは削陀されたした。ナヌザヌは最初のブロックダむアログの埌、System Settings → Privacy & Security → Open Anyway からブロックされたアプリを明瀺的に蚱可する必芁がありたす。
  • spctl --master-disable/--global-disable はもはや受け付けられたせん。spctl は評䟡ずラベル管理に関しお実質的に読み取り専甚ずなり、ポリシヌの匷制は UI たたは MDM を通じお構成されたす。

macOS 15 Sequoia 以降、゚ンドナヌザヌは spctl から Gatekeeper ポリシヌを切り替えるこずができなくなりたした。管理は System Settings で行うか、com.apple.systempolicy.control ペむロヌドを含む MDM 構成プロファむルを展開しお行いたす。App Store ず identified developers を蚱可するただし “Anywhere” は蚱可しないためのプロファむルの䟋スニペット

App Store ず identified developers を蚱可する MDM プロファむル ```xml PayloadContent PayloadType com.apple.systempolicy.control PayloadVersion 1 PayloadIdentifier com.example.gatekeeper EnableAssessment AllowIdentifiedDevelopers PayloadType Configuration PayloadIdentifier com.example.profile.gatekeeper PayloadUUID 00000000-0000-0000-0000-000000000000 PayloadVersion 1 PayloadDisplayName Gatekeeper ```

隔離ファむル

アプリやファむルをダりンロヌドするず、webブラりザやメヌルクラむアントなどの特定の macOS アプリケヌションは、ダりンロヌドされたファむルに䞀般に「隔離フラグ」ずしお知られる拡匵ファむル属性を付加したす。この属性は、ファむルが信頌できない゜ヌスむンタヌネットから来たこずを瀺すセキュリティ察策であり、朜圚的なリスクを含んでいる可胜性がありたす。ただし、すべおのアプリがこの属性を付䞎するわけではなく、䟋えば䞀般的な BitTorrent クラむアント゜フトは通垞この凊理をバむパスしたす。

隔離フラグの存圚は、ナヌザヌがファむルを実行しようずした際に macOS の Gatekeeper セキュリティ機胜に通知したす。

もし隔離フラグが存圚しない堎合いく぀かの BitTorrent クラむアントでダりンロヌドされたファむルのように、Gatekeeper のチェックが行われない堎合がありたす。したがっお、安党性の䜎い、たたは䞍明な゜ヌスからダりンロヌドしたファむルを開く際には泚意が必芁です。

[!NOTE] > コヌド眲名の有効性を確認するこずは、コヌドずそのバンドルされたリ゜ヌス党䜓の暗号孊的ハッシュを生成するなどのリ゜ヌス集玄型の凊理です。さらに、蚌明曞の有効性を確認するには、発行埌に取り消されおいないかを確かめるために Apple のサヌバヌぞのオンラむンチェックが必芁です。これらの理由から、完党なコヌド眲名および公蚌のチェックをアプリ起動時に毎回実行するのは珟実的ではありたせん。

したがっお、これらのチェックは隔離属性が付䞎されたアプリを実行する堎合にのみ行われたす。

Warning

この属性はファむルを䜜成/ダりンロヌドするアプリケヌションによっお蚭定される必芁がありたす。

ただし、サンドボックス化されたアプリが䜜成するファむルには垞にこの属性が蚭定されたす。サンドボックス化されおいないアプリは自分で蚭定するこずもでき、たたは Info.plist の LSFileQuarantineEnabled キヌを指定するず、システムが䜜成されたファむルに com.apple.quarantine 拡匵属性を蚭定したす、

さらに、qtn_proc_apply_to_self を呌び出すプロセスによっお䜜成されたすべおのファむルは隔離されたす。あるいは、API qtn_file_apply_to_path が指定したファむルパスに隔離属性を远加したす。

次の方法でroot 暩限が必芁そのステヌタスを確認し、有効/無効を切り替えるこずができたす:

spctl --status
assessments enabled

spctl --enable
spctl --disable
#You can also allow nee identifies to execute code using the binary "spctl"

次のコマンドでファむルに quarantine 拡匵属性があるかどうか を確認できたす:

xattr file.png
com.apple.macl
com.apple.quarantine

extended attributes の value を確認し、どのアプリが quarantine attr を曞き蟌んだかを次のコマンドで調べる:

xattr -l portada.png
com.apple.macl:
00000000  03 00 53 DA 55 1B AE 4C 4E 88 9D CA B7 5C 50 F3  |..S.U..LN.....P.|
00000010  16 94 03 00 27 63 64 97 98 FB 4F 02 84 F3 D0 DB  |....'cd...O.....|
00000020  89 53 C3 FC 03 00 27 63 64 97 98 FB 4F 02 84 F3  |.S....'cd...O...|
00000030  D0 DB 89 53 C3 FC 00 00 00 00 00 00 00 00 00 00  |...S............|
00000040  00 00 00 00 00 00 00 00                          |........|
00000048
com.apple.quarantine: 00C1;607842eb;Brave;F643CD5F-6071-46AB-83AB-390BA944DEC5
# 00c1 -- It has been allowed to eexcute this file (QTN_FLAG_USER_APPROVED = 0x0040)
# 607842eb -- Timestamp
# Brave -- App
# F643CD5F-6071-46AB-83AB-390BA944DEC5 -- UID assigned to the file downloaded

実際、プロセスは䜜成したファむルに quarantine フラグを蚭定できたす䜜成したファむルに USER_APPROVED フラグを適甚しようずしたしたが、適甚されたせんでした:

゜ヌスコヌド: quarantine フラグの適甚 ```c #include #include

enum qtn_flags { QTN_FLAG_DOWNLOAD = 0x0001, QTN_FLAG_SANDBOX = 0x0002, QTN_FLAG_HARD = 0x0004, QTN_FLAG_USER_APPROVED = 0x0040, };

#define qtn_proc_alloc _qtn_proc_alloc #define qtn_proc_apply_to_self _qtn_proc_apply_to_self #define qtn_proc_free _qtn_proc_free #define qtn_proc_init _qtn_proc_init #define qtn_proc_init_with_self _qtn_proc_init_with_self #define qtn_proc_set_flags _qtn_proc_set_flags #define qtn_file_alloc _qtn_file_alloc #define qtn_file_init_with_path _qtn_file_init_with_path #define qtn_file_free _qtn_file_free #define qtn_file_apply_to_path _qtn_file_apply_to_path #define qtn_file_set_flags _qtn_file_set_flags #define qtn_file_get_flags _qtn_file_get_flags #define qtn_proc_set_identifier _qtn_proc_set_identifier

typedef struct _qtn_proc *qtn_proc_t; typedef struct _qtn_file *qtn_file_t;

int qtn_proc_apply_to_self(qtn_proc_t); void qtn_proc_init(qtn_proc_t); int qtn_proc_init_with_self(qtn_proc_t); int qtn_proc_set_flags(qtn_proc_t, uint32_t flags); qtn_proc_t qtn_proc_alloc(); void qtn_proc_free(qtn_proc_t); qtn_file_t qtn_file_alloc(void); void qtn_file_free(qtn_file_t qf); int qtn_file_set_flags(qtn_file_t qf, uint32_t flags); uint32_t qtn_file_get_flags(qtn_file_t qf); int qtn_file_apply_to_path(qtn_file_t qf, const char *path); int qtn_file_init_with_path(qtn_file_t qf, const char path); int qtn_proc_set_identifier(qtn_proc_t qp, const char bundleid);

int main() {

qtn_proc_t qp = qtn_proc_alloc(); qtn_proc_set_identifier(qp, “xyz.hacktricks.qa”); qtn_proc_set_flags(qp, QTN_FLAG_DOWNLOAD | QTN_FLAG_USER_APPROVED); qtn_proc_apply_to_self(qp); qtn_proc_free(qp);

FILE *fp; fp = fopen(“thisisquarantined.txt”, “w+”); fprintf(fp, “Hello Quarantine\n”); fclose(fp);

return 0;

}

</details>

そしおその属性を**削陀**しおください:
```bash
xattr -d com.apple.quarantine portada.png
#You can also remove this attribute from every file with
find . -iname '*' -print0 | xargs -0 xattr -d com.apple.quarantine

そしお、次のコマンドで隔離されたファむルをすべお芋぀けたす:

find / -exec ls -ld {} \; 2>/dev/null | grep -E "[x\-]@ " | awk '{printf $9; printf "\n"}' | xargs -I {} xattr -lv {} | grep "com.apple.quarantine"

Quarantine information is also stored in a central database managed by LaunchServices in ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2 which allows the GUI to obtain data about the file origins. Moreover this can be overwritten by applications which might be interested in hiding its origins. Moreover, this can be done from LaunchServices APIS.

libquarantine.dylib

このラむブラリは、拡匵属性フィヌルドを操䜜するためのいく぀かの関数を゚クスポヌトしおいたす。

qtn_file_* APIs はファむルの怜疫ポリシヌを扱い、qtn_proc_* APIs はプロセスそのプロセスが䜜成したファむルに適甚されたす。゚クスポヌトされおいない __qtn_syscall_quarantine* 関数矀はポリシヌを適甚するもので、最初の匕数に “Quarantine” を指定しお mac_syscall を呌び出し、Quarantine.kext にリク゚ストを送りたす。

Quarantine.kext

このカヌネル拡匵は システム䞊のカヌネルキャッシュを介しおのみ利甚可胜 ですが、https://developer.apple.com/ から Kernel Debug Kit をダりンロヌドすれば、シンボル化されたバヌゞョンの拡匵が含たれおいたす。

この Kext は MACF を介しおいく぀かの呌び出しをフックし、ファむルのラむフサむクルむベント䜜成、オヌプン、リネヌム、ハヌドリンク化 をすべお捕捉したす。setxattr による com.apple.quarantine 拡匵属性の蚭定を防ぐこずさえしたす。

It also uses a couple of MIBs:

  • security.mac.qtn.sandbox_enforce: Sandbox ず連携しお怜疫を匷制する
  • security.mac.qtn.user_approved_exec: 怜疫されたプロセスは承認されたファむルのみ実行できる

Provenance xattr (Ventura and later)

macOS 13 Ventura では、怜疫されたアプリが初めお実行を蚱可されたずきに蚭定される別の provenance メカニズムが導入されたした。2぀のアヌティファクトが䜜成されたす

  • The com.apple.provenance xattr on the .app bundle directory (fixed-size binary value containing a primary key and flags).
  • A row in the provenance_tracking table inside the ExecPolicy database at /var/db/SystemPolicyConfiguration/ExecPolicy/ storing the app’s cdhash and metadata.

Practical usage:

# Inspect provenance xattr (if present)
xattr -p com.apple.provenance /Applications/Some.app | hexdump -C

# Observe Gatekeeper/provenance events in real time
log stream --style syslog --predicate 'process == "syspolicyd"'

# Retrieve historical Gatekeeper decisions for a specific bundle
log show --last 2d --style syslog --predicate 'process == "syspolicyd" && eventMessage CONTAINS[cd] "GK scan"'

XProtect

XProtectはmacOSに組み蟌たれたanti-malware機胜です。XProtectは、アプリケヌションが最初に起動されたずきや倉曎されたずきに、既知のマルりェアや危険なファむルタむプのデヌタベヌスず照合したす。Safari、Mail、たたは Messages のような特定のアプリを通じおファむルをダりンロヌドするず、XProtectはそのファむルを自動的にスキャンしたす。デヌタベヌスの既知のマルりェアず䞀臎した堎合、XProtectはファむルの実行を防止し、脅嚁を通知したす。

XProtectのデヌタベヌスは、Appleによっお新しいマルりェア定矩で定期的に曎新され、これらの曎新はMacに自動的にダりンロヌドおよびむンストヌルされたす。これにより、XProtectは垞に最新の既知の脅嚁に察応できたす。

ただし、XProtectはフル機胜のantivirus゜リュヌションではない点に泚意しおください。既知の脅嚁の特定のリストのみをチェックし、ほずんどのantivirus゜フトりェアのようなon-access scanningは実行したせん。

最新のXProtectアップデヌトに関する情報は、次のコマンドを実行しお取埗できたす:

system_profiler SPInstallHistoryDataType 2>/dev/null | grep -A 4 "XProtectPlistConfigData" | tail -n 5

XProtectはSIPで保護された堎所、/Library/Apple/System/Library/CoreServices/XProtect.bundle にあり、バンドル内にはXProtectが䜿甚する情報が含たれおいたす:

  • XProtect.bundle/Contents/Resources/LegacyEntitlementAllowlist.plist: これらのcdhashを持぀コヌドがレガシヌ゚ンタむトルメントを䜿甚するこずを蚱可したす。
  • XProtect.bundle/Contents/Resources/XProtect.meta.plist: BundleIDやTeamIDでロヌドが犁止されおいるプラグむンや拡匵機胜の䞀芧、たたは最小バヌゞョンを瀺したす。
  • XProtect.bundle/Contents/Resources/XProtect.yara: マルりェア怜出甚のYaraルヌル。
  • XProtect.bundle/Contents/Resources/gk.db: ブロックされたアプリケヌションのハッシュずTeamIDを栌玍したSQLite3デヌタベヌス。

/Library/Apple/System/Library/CoreServices/XProtect.app に関連する別のAppが存圚したすが、これはGatekeeperのプロセスには関䞎しおいたせん。

XProtect Remediator: 珟代のmacOSでは、Appleはlaunchd経由で定期的に実行されるオンデマンドスキャナXProtect Remediatorを提䟛しおおり、マルりェアファミリの怜出ず修埩を行いたす。これらのスキャンはナニファむドログで確認できたす:

log show --last 2h --predicate 'subsystem == "com.apple.XProtectFramework" || category CONTAINS "XProtect"' --style syslog

Gatekeeperではない

Caution

Gatekeeperがアプリを実行するたびに毎回実行されるわけではないこずに泚意しおください。実行枈みか぀Gatekeeperで怜蚌枈みのアプリを実行する堎合、AppleMobileFileIntegrityAMFIは実行可胜コヌドの眲名のみを怜蚌したす。

そのため、以前はアプリをGatekeeperでキャッシュするために䞀床実行し、その埌アプリの実行ファむルでないファむルElectronのasarやNIBファむルなどを倉曎し、他に保護がなければ、アプリは悪意ある远加を含んだ状態で実行されおしたう可胜性がありたした。

しかし珟圚は、macOSがアプリケヌションバンドル内のファむルの倉曎を防止するため、これは䞍可胜です。したがっお、Dirty NIB 攻撃を詊みおも、Gatekeeperでキャッシュするために䞀床アプリを実行した埌はバンドルを倉曎できないため、もはや悪甚できたせん。䟋えばexploitで瀺されおいるようにContentsディレクトリの名前をNotConに倉曎し、アプリのメむンバむナリをGatekeeperでキャッシュするために実行するず、゚ラヌが発生しお実行されなくなりたす。

Gatekeeperのバむパス

GatekeeperをバむパスするGatekeeperが蚱可しないはずのものをナヌザにダりンロヌドさせ実行させる方法は、macOSの脆匱性ず芋なされたす。過去にGatekeeperをバむパスする手法に割り圓おられたCVEの䟋は次のずおりです:

CVE-2021-1810

Archive Utilityを䜿甚しお解凍した堎合、パスが886文字を超えるファむルに察しおはcom.apple.quarantine拡匵属性が付䞎されないこずが芳枬されたした。この状況により、これらのファむルが意図せずGatekeeperのセキュリティチェックを回避しおしたう可胜性がありたした。

詳现はoriginal reportを参照しおください。

CVE-2021-30990

Automatorで䜜成されたアプリケヌションでは、実行に必芁な情報が実行ファむルではなく application.app/Contents/document.wflow の䞭にあり、実行ファむル自䜓はAutomator Application Stubず呌ばれる汎甚のAutomatorバむナリです。

したがっお、application.app/Contents/MacOS/Automator\ Application\ Stub をシステム内の別のAutomator Application Stubぞのシンボリックリンクに向けるpoint with a symbolic linkこずができれば、document.wflow の䞭身あなたのスクリプトをGatekeeperをトリガヌせずに実行できたす。これは実際の実行ファむルがquarantineのxattrを持っおいないためです。

䟋: 期埅される堎所は /System/Library/CoreServices/Automator\ Application\ Stub.app/Contents/MacOS/Automator\ Application\ Stub です。

詳现はoriginal reportを参照しおください。

CVE-2022-22616

このバむパスでは、アプリケヌションを application.app ではなく application.app/Contents から圧瞮し始めるようにzipファむルが䜜成されたした。そのため、quarantine属性は application.app/Contents 内のすべおのファむルには適甚されたしたが、Gatekeeperがチェックしおいる application.app には適甚されたせんでした。結果ずしお、application.app がトリガヌされたずきにquarantine属性が付いおいないため、Gatekeeperがバむパスされおしたいたした。

zip -r test.app/Contents test.zip

詳现はoriginal reportを確認しおください。

CVE-2022-32910

構成芁玠は異なっおいおも、この脆匱性の悪甚方法は前のものず非垞に䌌おいたす。
このケヌスでは、application.app/Contents から Apple Archive を生成するため、application.app は quarantine attr を受け取りたせんArchive Utility によっお解凍されたずき。

aa archive -d test.app/Contents -o test.app.aar

詳现に぀いおは、original report をご確認ください。

CVE-2022-42821

ACL writeextattr は、ファむルに属性を曞き蟌むこずを誰にも蚱可しないようにするために䜿甚できたす:

touch /tmp/no-attr
chmod +a "everyone deny writeextattr" /tmp/no-attr
xattr -w attrname vale /tmp/no-attr
xattr: [Errno 13] Permission denied: '/tmp/no-attr'

さらに、AppleDouble file format は ACEs を含むファむルをコピヌしたす。

In the source code it’s possible to see that the ACL text representation stored inside the xattr called com.apple.acl.text is going to be set as ACL in the decompressed file. So, if you compressed an application into a zip file with AppleDouble file format with an ACL that prevents other xattrs to be written to it
 the quarantine xattr wasn’t set into de application:

chmod +a "everyone deny write,writeattr,writeextattr" /tmp/test
ditto -c -k test test.zip
python3 -m http.server
# Download the zip from the browser and decompress it, the file should be without a quarantine xattr

詳现に぀いおはoriginal reportを確認しおください。

なお、これは AppleArchives を䜿甚しおも悪甚可胜です:

mkdir app
touch app/test
chmod +a "everyone deny write,writeattr,writeextattr" app/test
aa archive -d app -o test.aar

CVE-2023-27943

macOS の内郚的な問題により、ダりンロヌドしたファむルに察しお Google Chrome wasn’t setting the quarantine attribute こずが刀明したした。

CVE-2023-27951

AppleDouble ファむル圢匏は、ファむルの属性を ._ で始たる別ファむルに保存したす。これにより、ファむル属性を across macOS machines にコピヌするのに圹立ちたす。しかし、AppleDouble ファむルを展開した埌、._ で始たるファむルに wasn’t given the quarantine attribute こずが確認されたした。

mkdir test
echo a > test/a
echo b > test/b
echo ._a > test/._a
aa archive -d test/ -o test.aar

# If you downloaded the resulting test.aar and decompress it, the file test/._a won't have a quarantitne attribute

quarantine属性が蚭定されないファむルを䜜成できれば、Gatekeeperをバむパスするこずが可胜だった。 トリックは、AppleDouble呜名芏則._で始めるを䜿っおDMG file applicationを䜜成し、quarantine属性のないこの隠しファむルに察しお可芖のファむルをsym linkずしお䜜成するこずだった。
このdmg fileが実行されるず、quarantine属性がないためGatekeeperをバむパスする。

# Create an app bundle with the backdoor an call it app.app

echo "[+] creating disk image with app"
hdiutil create -srcfolder app.app app.dmg

echo "[+] creating directory and files"
mkdir
mkdir -p s/app
cp app.dmg s/app/._app.dmg
ln -s ._app.dmg s/app/app.dmg

echo "[+] compressing files"
aa archive -d s/ -o app.aar

[CVE-2023-41067]

macOS Sonoma 14.0で修正されたGatekeeperのバむパスにより、现工されたアプリがプロンプトなしで実行される可胜性がありたした。パッチ適甚埌に詳现が公開され、修正前に実際に悪甚されおいたした。Sonoma 14.0以降がむンストヌルされおいるこずを確認しおください。

[CVE-2024-27853]

macOS 14.42024幎3月リリヌスでの、悪意あるZIPをlibarchiveが凊理するこずに起因するGatekeeperのバむパスにより、アプリが評䟡を回避できたした。Appleがこの問題に察凊した14.4以降にアップデヌトしおください。

CVE-2024-44128

ダりンロヌドされたアプリに埋め蟌たれたAutomator Quick Action workflowが、ワヌクフロヌがデヌタずしお扱われ、Automatorヘルパヌによっお通垞のnotarizationプロンプト経路の倖で実行されるため、Gatekeeperの評䟡なしにトリガヌされる可胜性がありたした。シェルスクリプトを実行するQuick Actionをバンドルした现工された.app䟋: Contents/PlugIns/*.workflow/Contents/document.wflow内が起動時に即座に実行される可胜性がありたした。Appleは远加の同意ダむアログを導入し、Ventura 13.7、Sonoma 14.7、Sequoia 15で評䟡経路を修正したした。

Third‑party unarchivers mis‑propagating quarantine (2023–2024)

人気の解凍ツヌル䟋: The Unarchiverにおける耇数の脆匱性により、アヌカむブから抜出されたファむルにcom.apple.quarantine xattrが付䞎されず、Gatekeeperのバむパスに぀ながる可胜性がありたした。テストする際は垞にmacOSのArchive Utilityたたは修正枈みのツヌルを䜿甚し、抜出埌にxattrを怜蚌しおください。

uchg (この talk より)

  • アプリを含むディレクトリを䜜成する。
  • アプリに uchg を远加する。
  • アプリを tar.gz ファむルに圧瞮する。
  • tar.gz ファむルを被害者に送る。
  • 被害者が tar.gz を開きアプリを実行する。
  • Gatekeeper はアプリをチェックしない。

Prevent Quarantine xattr

“.app” バンドルに quarantine xattr が远加されおいない堎合、実行時に Gatekeeper はトリガヌされたせん。

References

Tip

AWSハッキングを孊び、実践するHackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを孊び、実践するHackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを孊び、実践するHackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポヌトする