Overview
Beyond Launch Agents and Launch Daemons (covered separately), macOS provides several additional persistence mechanisms that cause programs to execute automatically. Login Items run when a user logs in, cron and at jobs execute on schedules, periodic scripts run daily/weekly/monthly, and login/logout hooks execute shell scripts during the authentication process. Collectively, these represent the full persistence landscape that must be examined during a forensic investigation.
Forensic Significance
| Mechanism | Forensic Value |
|---|
| Login Items | Applications auto-starting at user login |
| Cron jobs | Scheduled command execution |
| At jobs | One-time scheduled commands |
| Periodic scripts | Daily/weekly/monthly maintenance scripts |
| Login/logout hooks | Scripts run during authentication |
| Kernel extensions | Code loaded into the kernel |
| System extensions | Modern kernel extension replacements |
| Authorization plugins | Authentication process customisation |
| Configuration profiles | MDM-installed policies and settings |
File Locations
| Mechanism | Path | Format |
|---|
| Login Items (modern) | ~/Library/Application Support/com.apple.backgroundtaskmanagementagent/backgrounditems.btm | Binary |
| Login Items (legacy) | ~/Library/Preferences/com.apple.loginitems.plist | Plist |
| Cron jobs (user) | /usr/lib/cron/tabs/<username> | Crontab |
| Cron jobs (system) | /etc/crontab | Crontab |
| At jobs | /usr/lib/cron/jobs/ | Text |
| Periodic scripts | /etc/periodic/daily/, /etc/periodic/weekly/, /etc/periodic/monthly/ | Scripts |
| Custom periodic | /usr/local/etc/periodic/ | Scripts |
| Login hooks | /var/root/Library/Preferences/com.apple.loginwindow.plist | Plist |
| Startup Items (deprecated) | /Library/StartupItems/, /System/Library/StartupItems/ | Directory |
| Kernel extensions | /Library/Extensions/*.kext | Bundle |
| System extensions | /Library/SystemExtensions/ | Bundle |
| Auth plugins | /Library/Security/SecurityAgentPlugins/ | Bundle |
| Config profiles | /var/db/ConfigurationProfiles/ | Plist |
Key Fields for Analysis
Login Items
# Modern login items (macOS 13+)
sfltool dumpbtm
# Legacy login items
defaults read ~/Library/Preferences/com.apple.loginitems.plist 2>/dev/null
Cron Jobs
# List current user's cron jobs
crontab -l
# List all user cron tabs
ls -la /usr/lib/cron/tabs/
# System crontab
cat /etc/crontab
Login/Logout Hooks
# Check for login hooks
defaults read /var/root/Library/Preferences/com.apple.loginwindow LoginHook 2>/dev/null
defaults read /var/root/Library/Preferences/com.apple.loginwindow LogoutHook 2>/dev/null
Kernel/System Extensions
# Loaded kernel extensions
kextstat | grep -v com.apple
# System extensions
systemextensionsctl list
Configuration Profiles
# List installed profiles
profiles list
Analysis Notes
- Full persistence audit: A thorough forensic examination must check all persistence mechanisms, not just Launch Agents/Daemons. Attackers specifically target less-monitored mechanisms like cron jobs and login hooks.
- Login hooks are rare: Apple deprecated login/logout hooks. Their presence on a modern system is unusual and warrants investigation.
- Startup Items are legacy:
/Library/StartupItems/ is a pre-launchd mechanism. Items here on modern macOS are highly suspicious. - Kernel extension restrictions: Since macOS 11, third-party kernel extensions require explicit user approval and a reboot. Unauthorized kexts indicate significant compromise.
- Configuration profiles: MDM profiles in
/var/db/ConfigurationProfiles/ can modify system behaviour extensively. On unmanaged systems, installed profiles are suspicious. - Cron vs. launchd: Apple discourages cron usage in favour of launchd. Cron jobs on a Mac are less common and deserve scrutiny, especially if they execute from unusual locations.
| Tool | Support |
|---|
| macfor | Not yet implemented (planned) |
| sfltool (macOS built-in) | Dump login items |
| KnockKnock (Objective-See) | Comprehensive persistence scanner |
| BlockBlock (Objective-See) | Real-time persistence monitoring |
| Autoruns for Mac | Persistence enumeration |
References