Hacktricks-skills macos-file-system-security
macOS file system, permissions, binaries, and security reference. Use this skill whenever the user asks about macOS file structures, directory layouts, file permissions, plist files, bundles, dyld shared cache, file flags, ACLs, extended attributes, resource forks, or any macOS security concepts. This includes questions about where to find configuration files, how to read plist files, understanding file permissions and flags, analyzing binaries, or investigating macOS security mechanisms. Make sure to use this skill for any macOS security research, pentesting, or system administration tasks involving files, permissions, or binaries.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/macos-hardening/macos-security-and-privilege-escalation/macos-files-folders-and-binaries/macos-files-folders-and-binaries/SKILL.MDmacOS File System & Security Reference
This skill provides comprehensive guidance on macOS file systems, permissions, binaries, and security mechanisms for security researchers, pentesters, and system administrators.
File Hierarchy Layout
Root Directory Structure
| Path | Purpose |
|---|---|
| Installed apps accessible to all users |
| Command line binaries |
| Core dumps (if exists) |
| Hardware devices (treated as files) |
| Configuration files |
| Preferences, caches, logs (root and per-user) |
| Undocumented; many folders symlink here |
| Essential system binaries (administration) |
| OS X system files (Apple-specific) |
| Temporary files (deleted after 3 days, symlink to ) |
| User home directories |
| Config and system binaries |
| Log files |
| Mounted drives |
| Access files by volume/inode: |
Applications Folders
- System applications:
/System/Applications - Installed applications:
or/Applications~/Applications - Application data (root):
/Library/Application Support - Application data (user):
~/Library/Application Support - Privileged helper tools:
(root daemons)/Library/PrivilegedHelperTools/ - Sandboxed apps:
(named by bundle ID, e.g.,~/Library/Containers/
)com.apple.Safari - Kernel:
/System/Library/Kernels/kernel - Apple kernel extensions:
/System/Library/Extensions - Third-party kernel extensions:
/Library/Extensions
macOS-Specific File Extensions
| Extension | Description |
|---|---|
| Apple Disk Image (common for installers) |
| Kernel extension bundle (driver) |
| Property list (XML or binary format) |
| Application bundle (directory structure) |
| Dynamic library (like Windows DLL) |
| Installer package (XAR format) |
| Directory attributes/customizations |
| Spotlight index folder (root of volumes) |
| Prevents Spotlight indexing of volume |
| Prevents Spotlight indexing of file/folder |
| AppleScript interaction specification |
Reading Plist Files
# Read binary plist defaults read config.plist # PlistBuddy /usr/libexec/PlistBuddy -c print config.plist # plutil (print as XML) plutil -p ~/Library/Preferences/com.apple.screensaver.plist # Convert to XML plutil -convert xml1 ~/Library/Preferences/com.apple.screensaver.plist -o - # Convert to JSON plutil -convert json ~/Library/Preferences/com.apple.screensaver.plist -o -
File Permissions & Flags
Folder Permissions
- Read: List directory contents
- Write: Delete and create files
- Execute: Traverse directory
Note: A user with read permission on a file inside a directory where they lack execute permission cannot read the file.
File Flags
Check flags with:
ls -lO /path/directory
| Flag | Description | Command |
|---|---|---|
(uchange) | Prevents modification/deletion | |
| Protected by SIP (cannot be added manually) | - |
| Only owner/root can rename/delete files (e.g., ) | - |
Complete Flag Reference
From
sys/stat.h:
Owner-settable flags (UF_SETTABLE 0x0000ffff):
(0x00000001): Do not dump fileUF_NODUMP
(0x00000002): File may not be changedUF_IMMUTABLE
(0x00000004): Writes may only appendUF_APPEND
(0x00000008): Directory opaque wrt unionUF_OPAQUE
(0x00000020): File is compressedUF_COMPRESSED
(0x00000040): No notifications for deletes/renamesUF_TRACKED
(0x00000080): Entitlement required for read/writeUF_DATAVAULT
(0x00008000): Hint to hide from GUIUF_HIDDEN
Superuser flags (SF_SETTABLE 0x3fff0000):
(0x00010000): File is archivedSF_ARCHIVED
(0x00020000): File may not be changedSF_IMMUTABLE
(0x00040000): Writes may only appendSF_APPEND
(0x00080000): Entitlement required for writingSF_RESTRICTED
(0x00100000): Item may not be removed/renamedSF_NOUNLINK
(0x00800000): File is a firmlinkSF_FIRMLINK
(0x40000000): File is dataless objectSF_DATALESS
File ACLs (Access Control Lists)
Files with ACLs show a
+ in permissions: drwx------+
Directory ACEs
,list
,search
,add_file
,add_subdirectorydelete_child
File ACEs
,read
,write
,appendexecute
ACL Commands
# Read ACLs ls -lde Movies # Find all files with ACLs (slow) ls -RAle / 2>/dev/null | grep -E -B1 "\d: "
Extended Attributes
View with:
ls -@ or xattr -l <file>
Common Extended Attributes
| Attribute | Purpose |
|---|---|
| Resource fork (Alternate Data Streams) |
| Gatekeeper quarantine mechanism |
| Various metadata (, ) |
| Last file use date |
| Finder information (color tags, etc.) |
| Text encoding for ASCII files |
| Used by logd in |
| Generational storage metadata |
| System Integrity Protection label |
| Boot epoch UUID markings |
| Transparent file compression |
| Per-file encryption data |
| Installer metadata (, ) |
Resource Forks (macOS ADS)
# Create resource fork echo "Hello" > a.txt echo "Hello Mac ADS" > a.txt/..namedfork/rsrc # Read extended attributes xattr -l a.txt # Find files with resource forks find / -type f -exec ls -ld {} \; 2>/dev/null | grep -E "[x\-]@ " | awk '{printf $9; printf "\n"}' | xargs -I {} xattr -lv {} | grep "com.apple.ResourceFork"
decmpfs (Compressed Files)
Files with
com.apple.decmpfs attribute:
reports size of 0ls -l- Data stored in extended attribute
- Decrypted in memory on access
- Flagged with
(visible viaUF_COMPRESSED
)ls -lO
# Remove compressed flag (breaks decompression) chflags nocompressed </path/to/file> # Force decompress afscexpand <file>
Dyld Shared Library Cache (SLC)
All system shared libraries combined into a single file for performance.
Locations
- macOS:
/System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld/ - Older macOS:
/System/Library/dyld/ - iOS:
/System/Library/Caches/com.apple.dyld/
Extraction Tools
# dyld_shared_cache_util dyld_shared_cache_util -extract ~/shared_cache/ /System/Volumes/Preboot/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_arm64e # dyldextractor dyldex -l [dyld_shared_cache_path] # List libraries dyldex_all [dyld_shared_cache_path] # Extract all
Override SLCs
# Load custom shared library cache DYLD_SHARED_REGION=private DYLD_SHARED_CACHE_DIR=</path/dir> DYLD_SHARED_CACHE_DONT_VALIDATE=1 # Avoid shared cache (use individual libraries) DYLD_SHARED_CACHE_DIR=avoid
SLC Mapping
: Check if SLC mapped (returns address)shared_region_check_np
: Map the SLCshared_region_map_and_slide_np- All processes use the same copy (ASLR implications)
Universal Binaries & Mach-O Format
Universal binaries support multiple architectures in one file. Use
lipo to inspect:
# Show architectures lipo -info binary # Extract specific architecture lipo -thin x86_64 -output binary_x86 binary
Important Configuration Locations
| Path | Purpose | Security Considerations |
|---|---|---|
| Feature flag plists | Tampering could enable hidden code paths |
| OS version metadata | May trick apps into accepting unsupported versions |
| System preferences | Writable prefs can inject settings |
| Background daemon plists | Malicious plist = persistence |
| User agent plists | Persistence mechanism |
| Hostname ↔ IP mappings | Traffic interception/spoofing |
| Sudo configuration | Corrupted file = privilege escalation |
| User account plists | Account creation/modification |
| Kernel extensions | Kernel-level control (SIP protected) |
| Third-party kexts | Kernel-level control |
| Policy enforcement config | Circumvent Gatekeeper/notarization |
| SSH configuration | Weak SSH security |
| Sandbox profiles (SBPL) | Sandbox escape vectors |
Note: Many paths under
are SIP-protected and require SIP bypass to modify./System
Log Files
| Path | Contents |
|---|---|
| Downloaded files with URLs |
| Main system log |
| Apple System Logs |
| Recently accessed files/apps |
| Startup items |
| Disk Utility logs (USB/drive info) |
| Wireless access point data |
| Deactivated daemons |
Risk Category Files
Location:
/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/System
| Category | Behavior |
|---|---|
| Automatically opened after download |
| No warning, not auto-opened |
| Warning: file is an application |
| Warning for archives (unless verified safe) |
Common Commands Reference
# Find stat.h for flag definitions mdfind stat.h | grep stat.h # Check if syslogd is running launchctl list | grep "com.apple.syslogd" # Read plist plutil -p <file.plist> -o - # List extended attributes xattr -l <file> # Remove extended attribute xattr -d <attribute> <file> # Set file flag chflags uchg <file> # Remove file flag chflags nouchg <file> # List ACLs ls -lde <file> # Find files with ACLs ls -RAle / 2>/dev/null | grep -E -B1 "\d: "
Security Considerations
-
SIP (System Integrity Protection): Protects
and other critical directories. Many operations require SIP bypass./System -
Gatekeeper: Uses
extended attribute to track downloaded files.com.apple.quarantine -
Sandboxing: Apps in
are sandboxed with restricted access.~/Library/Containers/ -
Kernel Extensions: Require signature validation and SIP considerations.
-
File Flags:
anduchg
flags can prevent modification even by root (in some cases).restricted -
Shared Cache: All processes share the same SLC copy, which has ASLR implications.
When to Use This Skill
Use this skill when:
- Investigating macOS file systems for security research
- Understanding macOS permissions and ACLs
- Analyzing plist files and configuration
- Working with macOS binaries and Mach-O format
- Researching macOS security mechanisms (SIP, Gatekeeper, sandboxing)
- Finding sensitive configuration files
- Understanding extended attributes and resource forks
- Working with dyld shared cache
- Pentesting macOS systems
- System administration tasks involving macOS file structures