At login
Reopened Applications: macOS Login Persistence
How macOS reopens apps at login from the ByHost loginwindow plist (TALAppsToRelaunchAtLogin), how attackers add their own app, and how to check and clean it.
- MITRE ATT&CK
- T1547.007
- Tactics
- Persistence, Execution
- Runs
- At login
- Set up by
- Any user
- Locations
- ~/Library/Preferences/ByHost/com.apple.loginwindow.*.plist
How it works
When a user logs out, restarts or shuts down from the Apple menu, the confirmation dialog offers "Reopen windows when logging back in". With the box ticked, loginwindow saves the list of running apps; at the next login it launches them again, and each app then restores its own windows from its Saved Application State.
The list is a per-user, per-Mac preference:
~/Library/Preferences/ByHost/com.apple.loginwindow.<UUID>.plist
<UUID> is the Mac's hardware UUID (ioreg -rd1 -c IOPlatformExpertDevice | grep IOPlatformUUID), which is why the file sits in ByHost. The key is TALAppsToRelaunchAtLogin (TAL stands for Transparent App Lifecycle), an array with one dictionary per app:
| Key | Meaning |
|---|---|
BundleID | The app's bundle identifier |
Path | Full path to the .app bundle |
Hide | Relaunch the app hidden |
BackgroundState | Set by loginwindow; its values are not documented |
The apps are started by loginwindow in the user's session, as the user, through Launch Services, so the usual Gatekeeper checks apply to an app that still carries a quarantine attribute. loginwindow rewrites the file at each logout or shutdown made through the dialog: the list reflects what was running then, and its modification time is the last logout, not the last change by anyone else. As far as we know, entries here are not registered with Background Task Management, so they raise no "Background Items Added" notification and do not appear in Login Items settings; the user sees only the app opening.
Where it lives
| Path | What | Who can write it |
|---|---|---|
/System/Library/CoreServices/loginwindow.app | The program that reads the list | Nobody: sealed system volume |
~/Library/Preferences/ByHost/com.apple.loginwindow.<UUID>.plist | Apps to reopen for this user on this Mac | The user (and loginwindow at logout) |
/private/var/root/Library/Preferences/ByHost/com.apple.loginwindow.<UUID>.plist | The same for root, if root ever logged in at the GUI | root |
~/Library/Saved Application State/<bundle id>.savedState | Each app's restored windows (a separate mechanism) | The user |
There is no system-wide version: each user has their own list, and a home folder copied to another Mac keeps a file whose UUID no longer matches that Mac.
How attackers use it
The attacker adds a dictionary to TALAppsToRelaunchAtLogin pointing at their app, hidden at launch. No privileges are needed, no launchd plist is created, and the item does not show in Login Items. MITRE lists the technique as T1547.007; we know of no widely documented macOS malware family that relies on it, so treat it as a pattern. A planted entry, as plutil -p shows it:
"TALAppsToRelaunchAtLogin" => [
0 => {
"BackgroundState" => 2
"BundleID" => "com.example.helper"
"Hide" => true
"Path" => "/Users/alice/Library/Application Support/.helper/Helper.app"
}
]
The weakness is that loginwindow rewrites the list at every logout. An attacker works around it in three ways: keep the app running, so that loginwindow itself writes it back each time the user logs out with the box ticked; rewrite the entry after each login from another foothold; or lock the file against changes:
chflags uchg ~/Library/Preferences/ByHost/com.apple.loginwindow.*.plist
The target must be an app bundle, but a minimal bundle around a shell script is enough. Attackers also point the entry at an app on a mounted volume or in Downloads, or swap the executable inside an app the user really does reopen, which leaves the list itself unchanged.
How to check a host
On a live Mac, read-only, for the logged-in user (repeat with sudo for other homes):
ls -lO@ ~/Library/Preferences/ByHost/com.apple.loginwindow.*.plist # uchg flag, xattrs
plutil -p ~/Library/Preferences/ByHost/com.apple.loginwindow.*.plist
defaults -currentHost read com.apple.loginwindow TALAppsToRelaunchAtLogin
codesign -dv --verbose=4 "/path/to/Helper.app"
spctl -a -vv "/path/to/Helper.app"
xattr -l "/path/to/Helper.app" # quarantine record
stat -f 'born %SB modified %Sm' "/path/to/Helper.app"
For each Path: does the app exist, is it in /Applications or ~/Applications, who signed it, and does the BundleID match the bundle's real identifier? Compare the list with what the user says they had open and with the folders in ~/Library/Saved Application State. An immutable flag (uchg in ls -lO) on this file has no legitimate reason.
From a collection: take the ByHost plist of every user (the collection command does) and, if you can, the apps the list names. Line the app's birth time and quarantine data up with the user's downloads and the unified log. macOS Persistence lists every entry offline.
What macOS Persistence flags
parseReopenedApps reads TALAppsToRelaunchAtLogin in every ByHost/com.apple.loginwindow.*.plist of the collection and makes one entry per app, named by its bundle ID, with the path as the command and the user from the home folder:
- Reopened app outside /Applications: the path is not under
/Applications,/System/Applications,/System/Libraryor a user's~/Applications. - Runs from a temporary or shared folder: the path is in
/tmp,/private/var/folders/…/Tor/Users/Shared. - Runs from a hidden folder: a dot-folder in the path, such as
~/Library/Application Support/.helper.
The recency flag is deliberately not applied: the file is rewritten at each logout, so its time says nothing about tampering. There are no package flags either, since the file is per user.
Limits: the tool reads the list, not the apps. It does not check that the app exists, verify its signature, compare BundleID with the bundle, or see BSD file flags such as uchg. An app the user really uses, with a replaced executable inside, looks like a normal entry: check the bundle with codesign.
Cleaning up
- Preserve: copy the ByHost plist and the app with their times (
tarkeeps them), hash both, and save theplutil -poutput. - Quit the app, then clear any lock:
chflags nouchgon the plist. - Remove the entry: delete the app's dictionary with
/usr/libexec/PlistBuddyfrom an admin session while the user is logged out (so their preferences daemon cannot write a cached copy back), or quit the app and log out normally so loginwindow rewrites the list. Confirm withplutil -p, then delete the app. - Look for the same app in Login Items, LaunchAgents and login hooks: this entry is often a second foothold next to another one.
- Rotate what the user's session could reach: browser sessions, keychain items and tokens.
References
See also
Related techniques
On Mac Forensics
The artifacts behind this technique, in the Mac Forensics reference: