macOS Launch/Environment Constraints & Trust Cache
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 μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.
Basic Information
macOSμ λ°μΉ μ μ½ μ‘°κ±΄μ νλ‘μΈμ€κ° μ΄λ»κ², λꡬμ μν΄, μ΄λμ μμλ μ μλμ§λ₯Ό κ·μ νμ¬ λ³΄μμ κ°ννκΈ° μν΄ λμ λμμ΅λλ€. macOS Venturaμμ μμλ μ΄λ€μ κ° μμ€ν λ°μ΄λ리λ₯Ό λ³κ°μ μ μ½ λ²μ£Όλ‘ λΆλ₯νλ νλ μμν¬λ₯Ό μ 곡ν©λλ€. μ΄ λ²μ£Όλ μ λ’° μΊμ λ΄μ μ μλμ΄ μμΌλ©°, μμ€ν λ°μ΄λ리μ ν΄λΉ ν΄μ λͺ©λ‘μ ν¬ν¨ν©λλ€. μ΄λ¬ν μ μ½μ μμ€ν λ΄μ λͺ¨λ μ€ν κ°λ₯ν λ°μ΄λ리μ μ μ©λλ©°, νΉμ λ°μ΄λ리λ₯Ό μ€ννκΈ° μν μꡬ μ¬νμ μ€λͺ νλ κ·μΉ μΈνΈλ₯Ό ν¬ν¨ν©λλ€. κ·μΉμ λ°μ΄λλ¦¬κ° μΆ©μ‘±ν΄μΌ νλ μκΈ° μ μ½, λΆλͺ¨ νλ‘μΈμ€κ° μΆ©μ‘±ν΄μΌ νλ λΆλͺ¨ μ μ½, κ·Έλ¦¬κ³ λ€λ₯Έ κ΄λ ¨ μν°ν°κ° μ€μν΄μΌ νλ μ± μ μ μ½μ ν¬ν¨ν©λλ€.
μ΄ λ©μ»€λμ¦μ macOS SonomaλΆν° νκ²½ μ μ½μ ν΅ν΄ μλνν° μ±μΌλ‘ νμ₯λμ΄, κ°λ°μκ° νκ²½ μ μ½μ μν ν€μ κ°μ μΈνΈλ₯Ό μ§μ νμ¬ μ±μ 보νΈν μ μλλ‘ ν©λλ€.
λ°μΉ νκ²½ λ° λΌμ΄λΈλ¬λ¦¬ μ μ½μ launchd μμ± λͺ©λ‘ νμΌμ μ μ₯νκ±°λ μ½λ μλͺ
μ μ¬μ©νλ λ³λμ μμ± λͺ©λ‘ νμΌμ μ μν©λλ€.
μ μ½μ μ’ λ₯λ 4κ°μ§μ λλ€:
- μκΈ° μ μ½: μ€ν μ€μΈ λ°μ΄λ리μ μ μ©λλ μ μ½.
- λΆλͺ¨ νλ‘μΈμ€: νλ‘μΈμ€μ λΆλͺ¨μ μ μ©λλ μ μ½ (μ: **
launchd**κ° XP μλΉμ€λ₯Ό μ€ννλ κ²½μ°) - μ± μ μ μ½: XPC ν΅μ μμ μλΉμ€λ₯Ό νΈμΆνλ νλ‘μΈμ€μ μ μ©λλ μ μ½
- λΌμ΄λΈλ¬λ¦¬ λ‘λ μ μ½: λ‘λν μ μλ μ½λλ₯Ό μ νμ μΌλ‘ μ€λͺ νκΈ° μν΄ λΌμ΄λΈλ¬λ¦¬ λ‘λ μ μ½μ μ¬μ©ν©λλ€.
λ°λΌμ νλ‘μΈμ€κ° λ€λ₯Έ νλ‘μΈμ€λ₯Ό μμνλ €κ³ ν λ β execve(_:_:_:) λλ posix_spawn(_:_:_:_:_:_:)λ₯Ό νΈμΆνμ¬ β μ΄μ 체μ λ μ€ν νμΌμ΄ μκΈ° μ μ½μ μΆ©μ‘±νλμ§ νμΈν©λλ€. λν λΆλͺ¨ νλ‘μΈμ€μ μ€ν νμΌμ΄ μ€ν νμΌμ λΆλͺ¨ μ μ½μ μΆ©μ‘±νλμ§ νμΈνκ³ , μ±
μ νλ‘μΈμ€μ μ€ν νμΌμ΄ μ€ν νμΌμ μ±
μ νλ‘μΈμ€ μ μ½μ μΆ©μ‘±νλμ§ νμΈν©λλ€. μ΄λ¬ν λ°μΉ μ μ½ μ€ νλλΌλ μΆ©μ‘±λμ§ μμΌλ©΄ μ΄μ 체μ λ νλ‘κ·Έλ¨μ μ€ννμ§ μμ΅λλ€.
λΌμ΄λΈλ¬λ¦¬λ₯Ό λ‘λν λ λΌμ΄λΈλ¬λ¦¬ μ μ½μ μΌλΆκ° μ°Έμ΄ μλ κ²½μ°, νλ‘μΈμ€λ λΌμ΄λΈλ¬λ¦¬λ₯Ό λ‘λνμ§ μμ΅λλ€.
LC Categories
LCλ μ¬μ€κ³Ό λ Όλ¦¬ μ°μ°(and, or..)μΌλ‘ ꡬμ±λμ΄ μ¬μ€μ κ²°ν©ν©λλ€.
LCκ° μ¬μ©ν μ μλ μ¬μ€μ λ¬Έμνλμ΄ μμ΅λλ€. μλ₯Ό λ€μ΄:
- is-init-proc: μ€ν νμΌμ΄ μ΄μ 체μ μ μ΄κΈ°ν νλ‘μΈμ€(
launchd)μ¬μΌ νλμ§λ₯Ό λνλ΄λ λΆμΈ κ°. - is-sip-protected: μ€ν νμΌμ΄ μμ€ν λ¬΄κ²°μ± λ³΄νΈ(SIP)λ‘ λ³΄νΈλ νμΌμ΄μ΄μΌ νλμ§λ₯Ό λνλ΄λ λΆμΈ κ°.
on-authorized-authapfs-volume:μ΄μ 체μ κ° μΈμ¦λ APFS λ³Όλ₯¨μμ μ€ν νμΌμ λ‘λνλμ§λ₯Ό λνλ΄λ λΆμΈ κ°.on-authorized-authapfs-volume: μ΄μ 체μ κ° μΈμ¦λ APFS λ³Όλ₯¨μμ μ€ν νμΌμ λ‘λνλμ§λ₯Ό λνλ΄λ λΆμΈ κ°.- Cryptexes λ³Όλ₯¨
on-system-volume:μ΄μ 체μ κ° νμ¬ λΆν λ μμ€ν λ³Όλ₯¨μμ μ€ν νμΌμ λ‘λνλμ§λ₯Ό λνλ΄λ λΆμΈ κ°.- /System λ΄λΆβ¦
- β¦
Apple λ°μ΄λλ¦¬κ° μλͺ λλ©΄ μ λ’° μΊμ λ΄μ LC λ²μ£Όμ ν λΉλ©λλ€.
- iOS 16 LC λ²μ£Όλ μ¬κΈ°μμ μμΌλ‘ λ¬Έμνλμμ΅λλ€.
- νμ¬ **LC λ²μ£Ό (macOS 14 - Sonoma)**λ μμΌλ‘ λ¬ΈμνλμμΌλ©° κ·Έ μ€λͺ μ μ¬κΈ°μμ μ°Ύμ μ μμ΅λλ€.
μλ₯Ό λ€μ΄ λ²μ£Ό 1μ:
Category 1:
Self Constraint: (on-authorized-authapfs-volume || on-system-volume) && launch-type == 1 && validation-category == 1
Parent Constraint: is-init-proc
(on-authorized-authapfs-volume || on-system-volume): μμ€ν λλ Cryptexes λ³Όλ₯¨μ μμ΄μΌ ν©λλ€.launch-type == 1: μμ€ν μλΉμ€μ¬μΌ ν©λλ€ (LaunchDaemonsμ plist).validation-category == 1: μ΄μ 체μ μ€ν νμΌμ λλ€.is-init-proc: Launchd
LC μΉ΄ν κ³ λ¦¬ 리λ²μ±
μ¬κΈ°μ λν λ λ§μ μ 보λ μ¬κΈ°μμ νμΈν μ μμ§λ§, κΈ°λ³Έμ μΌλ‘ **AMFI (AppleMobileFileIntegrity)**μμ μ μλ©λλ€. λ°λΌμ KEXTλ₯Ό μ»κΈ° μν΄ Kernel Development Kitμ λ€μ΄λ‘λν΄μΌ ν©λλ€. **kConstraintCategory**λ‘ μμνλ κΈ°νΈκ° ν₯λ―Έλ‘μ΄ κΈ°νΈμ
λλ€. μ΄λ€μ μΆμΆνλ©΄ DER (ASN.1) μΈμ½λ© μ€νΈλ¦Όμ μ»μ μ μμΌλ©°, μ΄λ₯Ό ASN.1 Decoder λλ python-asn1 λΌμ΄λΈλ¬λ¦¬μ κ·Έ dump.py μ€ν¬λ¦½νΈλ₯Ό μ¬μ©νμ¬ λμ½λν΄μΌ ν©λλ€. andrivet/python-asn1λ‘ λ μ΄ν΄νκΈ° μ¬μ΄ λ¬Έμμ΄μ μ»μ μ μμ΅λλ€.
νκ²½ μ μ½
μ΄λ€μ μλνν° μ ν리μΌμ΄μ μμ μ€μ λ Launch Constraintsμ λλ€. κ°λ°μλ μ ν리μΌμ΄μ μμ μ κ·Όμ μ ννκΈ° μν΄ μ¬μ©ν μ¬μ€κ³Ό λ Όλ¦¬ μ°μ°μλ₯Ό μ νν μ μμ΅λλ€.
μ ν리μΌμ΄μ μ νκ²½ μ μ½μ λμ΄νλ κ²μ κ°λ₯ν©λλ€:
codesign -d -vvvv app.app
μ λ’° μΊμ
macOSμλ λͺ κ°μ§ μ λ’° μΊμκ° μμ΅λλ€:
/System/Volumes/Preboot/*/boot/*/usr/standalone/firmware/FUD/BaseSystemTrustCache.img4/System/Volumes/Preboot/*/boot/*/usr/standalone/firmware/FUD/StaticTrustCache.img4/System/Library/Security/OSLaunchPolicyData
iOSμμλ **/usr/standalone/firmware/FUD/StaticTrustCache.img4**μ μλ κ² κ°μ΅λλ€.
Warning
Apple Silicon μ₯μΉμμ μ€νλλ macOSμμ Apple μλͺ μ΄μ§ νμΌμ΄ μ λ’° μΊμμ μμΌλ©΄ AMFIκ° μ΄λ₯Ό λ‘λνλ κ²μ κ±°λΆν©λλ€.
μ λ’° μΊμ μ΄κ±°
μ΄μ μ λ’° μΊμ νμΌμ IMG4 λ° IM4P νμμ΄λ©°, IM4Pλ IMG4 νμμ νμ΄λ‘λ μΉμ μ λλ€.
λ°μ΄ν°λ² μ΄μ€μ νμ΄λ‘λλ₯Ό μΆμΆνλ €λ©΄ pyimg4λ₯Ό μ¬μ©ν μ μμ΅λλ€:
# Installation
python3 -m pip install pyimg4
# Extract payloads data
cp /System/Volumes/Preboot/*/boot/*/usr/standalone/firmware/FUD/BaseSystemTrustCache.img4 /tmp
pyimg4 img4 extract -i /tmp/BaseSystemTrustCache.img4 -p /tmp/BaseSystemTrustCache.im4p
pyimg4 im4p extract -i /tmp/BaseSystemTrustCache.im4p -o /tmp/BaseSystemTrustCache.data
cp /System/Volumes/Preboot/*/boot/*/usr/standalone/firmware/FUD/StaticTrustCache.img4 /tmp
pyimg4 img4 extract -i /tmp/StaticTrustCache.img4 -p /tmp/StaticTrustCache.im4p
pyimg4 im4p extract -i /tmp/StaticTrustCache.im4p -o /tmp/StaticTrustCache.data
pyimg4 im4p extract -i /System/Library/Security/OSLaunchPolicyData -o /tmp/OSLaunchPolicyData.data
(λ λ€λ₯Έ μ΅μ μ λꡬ img4toolλ₯Ό μ¬μ©νλ κ²μ λλ€. μ΄ λꡬλ 릴리μ€κ° μ€λλμλλΌλ M1μμ μ€νλλ©°, μ μ ν μμΉμ μ€μΉνλ©΄ x86_64μμλ μ€νλ©λλ€).
μ΄μ λꡬ trustcacheλ₯Ό μ¬μ©νμ¬ μ½κΈ° μ¬μ΄ νμμΌλ‘ μ 보λ₯Ό μ»μ μ μμ΅λλ€:
# Install
wget https://github.com/CRKatri/trustcache/releases/download/v2.0/trustcache_macos_arm64
sudo mv ./trustcache_macos_arm64 /usr/local/bin/trustcache
xattr -rc /usr/local/bin/trustcache
chmod +x /usr/local/bin/trustcache
# Run
trustcache info /tmp/OSLaunchPolicyData.data | head
trustcache info /tmp/StaticTrustCache.data | head
trustcache info /tmp/BaseSystemTrustCache.data | head
version = 2
uuid = 35EB5284-FD1E-4A5A-9EFB-4F79402BA6C0
entry count = 969
0065fc3204c9f0765049b82022e4aa5b44f3a9c8 [none] [2] [1]
00aab02b28f99a5da9b267910177c09a9bf488a2 [none] [2] [1]
0186a480beeee93050c6c4699520706729b63eff [none] [2] [2]
0191be4c08426793ff3658ee59138e70441fc98a [none] [2] [3]
01b57a71112235fc6241194058cea5c2c7be3eb1 [none] [2] [2]
01e6934cb8833314ea29640c3f633d740fc187f2 [none] [2] [2]
020bf8c388deaef2740d98223f3d2238b08bab56 [none] [2] [3]
μ λ’° μΊμλ λ€μ ꡬ쑰λ₯Ό λ°λ¦ λλ€. λ°λΌμ LC μΉ΄ν κ³ λ¦¬λ 4λ²μ§Έ μ΄μ λλ€.
struct trust_cache_entry2 {
uint8_t cdhash[CS_CDHASH_LEN];
uint8_t hash_type;
uint8_t flags;
uint8_t constraintCategory;
uint8_t reserved0;
} __attribute__((__packed__));
κ·Έλ° λ€μ, μ΄ μ€ν¬λ¦½νΈμ κ°μ μ€ν¬λ¦½νΈλ₯Ό μ¬μ©νμ¬ λ°μ΄ν°λ₯Ό μΆμΆν μ μμ΅λλ€.
κ·Έ λ°μ΄ν°μμ launch constraints κ°μ΄ 0μΈ μ±μ νμΈν μ μμΌλ©°, μ΄λ μ μ½μ΄ μλ μ±μ
λλ€ (μ¬κΈ°μμ νμΈ κ° κ°μ΄ 무μμΈμ§).
곡격 μν
Launch Constraintsλ νλ‘μΈμ€κ° μμμΉ λͺ»ν 쑰건μμ μ€νλμ§ μλλ‘ λ³΄μ₯ν¨μΌλ‘μ¨ μ¬λ¬ μ€λλ 곡격μ μννμ κ²μ λλ€: μλ₯Ό λ€μ΄ μμμΉ λͺ»ν μμΉμμ μ€νλκ±°λ μμμΉ λͺ»ν λΆλͺ¨ νλ‘μΈμ€μ μν΄ νΈμΆλλ κ²½μ°(launchdλ§μ΄ μ΄λ₯Ό μ€νν΄μΌ νλ κ²½μ°).
κ²λ€κ°, Launch Constraintsλ λ€μ΄κ·Έλ μ΄λ 곡격λ μνν©λλ€.
κ·Έλ¬λ, μ΄λ€μ μΌλ°μ μΈ XPC λ¨μ©, Electron μ½λ μ£Όμ λλ dylib μ£Όμ μ λΌμ΄λΈλ¬λ¦¬ κ²μ¦ μμ΄ μννμ§ μμ΅λλ€(λ‘λν μ μλ ν IDκ° μλ €μ Έ μμ§ μλ ν).
XPC λ°λͺ¬ 보νΈ
μλ Έλ§ λ¦΄λ¦¬μ€μμ μ£Όλͺ©ν μ μ λ°λͺ¬ XPC μλΉμ€μ μ± μ ꡬμ±μ λλ€. XPC μλΉμ€λ μ°κ²°λ ν΄λΌμ΄μΈνΈκ° μ± μμ§λ κ²μ΄ μλλΌ μ€μ€λ‘ μ± μμ μ§λλ€. μ΄λ νΌλλ°± λ³΄κ³ μ FB13206884μ λ¬Έμνλμ΄ μμ΅λλ€. μ΄ μ€μ μ XPC μλΉμ€μμ νΉμ μνΈμμ©μ νμ©νλ―λ‘ κ²°ν¨μ΄ μλ κ²μ²λΌ λ³΄μΌ μ μμ΅λλ€:
- XPC μλΉμ€ μμ: λ²κ·Έλ‘ κ°μ£Όλλ€λ©΄, μ΄ μ€μ μ 곡격μ μ½λλ‘ XPC μλΉμ€λ₯Ό μμνλ κ²μ νμ©νμ§ μμ΅λλ€.
- νμ± μλΉμ€μ μ°κ²°: XPC μλΉμ€κ° μ΄λ―Έ μ€ν μ€μΈ κ²½μ°(μλ μ ν리μΌμ΄μ μ μν΄ νμ±νλμμ κ°λ₯μ±μ΄ μμ), μ°κ²°νλ λ° μ₯μ λ¬Όμ΄ μμ΅λλ€.
XPC μλΉμ€μ λν μ μ½μ ꡬννλ κ²μ μ μ¬μ 곡격μ μ°½μ μ’νμΌλ‘μ¨ μ μ΅ν μ μμ§λ§, μ£Όμ λ¬Έμ λ₯Ό ν΄κ²°νμ§λ μμ΅λλ€. XPC μλΉμ€μ 보μμ 보μ₯νλ €λ©΄ μ°κ²° ν΄λΌμ΄μΈνΈλ₯Ό ν¨κ³Όμ μΌλ‘ κ²μ¦νλ κ²μ΄ κ·Όλ³Έμ μΌλ‘ νμν©λλ€. μ΄λ μλΉμ€μ 보μμ κ°ννλ μ μΌν λ°©λ²μΌλ‘ λ¨μ μμ΅λλ€. λν, μΈκΈλ μ± μ ꡬμ±μ νμ¬ μ΄μ μ€μ΄λ©°, μ΄λ μλλ μ€κ³μ μΌμΉνμ§ μμ μ μμ΅λλ€.
Electron 보νΈ
μ ν리μΌμ΄μ
μ΄ LaunchServiceμ μν΄ μ΄λ €μΌ νλ€λ μκ΅¬κ° μλλΌλ(λΆλͺ¨ μ μ½μμ). μ΄λ **open**μ μ¬μ©νμ¬(env λ³μλ₯Ό μ€μ ν μ μμ) λλ Launch Services APIλ₯Ό μ¬μ©νμ¬(env λ³μλ₯Ό μ§μ ν μ μμ) λ¬μ±ν μ μμ΅λλ€.
μ°Έκ³ λ¬Έν
- https://youtu.be/f1HA5QhLQ7Y?t=24146
- https://theevilbit.github.io/posts/launch_constraints_deep_dive/
- https://eclecticlight.co/2023/06/13/why-wont-a-system-app-or-command-tool-run-launch-constraints-and-trust-caches/
- https://developer.apple.com/videos/play/wwdc2023/10266/
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 μ§μνκΈ°
- ꡬλ κ³ν νμΈνκΈ°!
- **π¬ λμ€μ½λ κ·Έλ£Ή λλ ν λ κ·Έλ¨ κ·Έλ£Ήμ μ°Έμ¬νκ±°λ νΈμν° π¦ @hacktricks_liveλ₯Ό νλ‘μ°νμΈμ.
- HackTricks λ° HackTricks Cloud κΉνλΈ λ¦¬ν¬μ§ν 리μ PRμ μ μΆνμ¬ ν΄νΉ νΈλ¦μ 곡μ νμΈμ.


