Skip to content

At login

Login Items and BTM: macOS Persistence at Login

How macOS login items, SMAppService helpers and the Background Task Management store work, how attackers abuse them, and how to audit them with sfltool.

MITRE ATT&CK
T1547.015
Tactics
Persistence, Execution
Runs
At login
Set up by
Users and root
Locations
  • /private/var/db/com.apple.backgroundtaskmanagement/BackgroundItems-v*.btm
  • /Applications/*.app/Contents/Library/LoginItems/*.app
  • ~/Library/Application Support/com.apple.backgroundtaskmanagementagent/backgrounditems.btm
  • ~/Library/Preferences/com.apple.loginitems.plist

How it works

"Login items" covers three things that macOS now shows in one place, System Settings > General > Login Items (Login Items & Extensions on recent releases):

  • Open at Login apps: added by the user, by an app for itself (SMAppService.mainApp, formerly the LSSharedFileList API), or by a script through System Events. They open as the user at each login.
  • Helper login items: an app embedded in Contents/Library/LoginItems of a parent app, registered with SMLoginItemSetEnabled (deprecated in Ventura 13) or SMAppService.loginItem(identifier:).
  • Background items: launch agents and daemons. Legacy plists in /Library/LaunchAgents, ~/Library/LaunchAgents and /Library/LaunchDaemons, and, since Ventura, plists that stay inside an app bundle (Contents/Library/LaunchAgents or LaunchDaemons) registered with SMAppService.agent(plistName:) or .daemon(plistName:). Registered agents start at once and at every login; registered daemons wait until an administrator allows them.

Where the list is kept changed over time. Up to macOS 10.12 the Open at Login list was ~/Library/Preferences/com.apple.loginitems.plist, a shared file list of aliases. From High Sierra 10.13 to Monterey 12 it was ~/Library/Application Support/com.apple.backgroundtaskmanagementagent/backgrounditems.btm, a keyed archive of bookmarks.

Ventura 13 introduced Background Task Management (BTM). backgroundtaskmanagementd keeps one system-wide store, /private/var/db/com.apple.backgroundtaskmanagement/BackgroundItems-v<N>.btm (the number changes between releases), with every login item, agent and daemon it has seen, filed per user. Each record has a type and a disposition, as sudo sfltool dumpbtm prints them:

FieldValues
Typeapp, login item, agent, daemon, legacy agent, legacy daemon, developer (a grouping record)
Dispositionenabled/disabled, allowed/disallowed, visible/hidden, notified
Identityname, developer name, team identifier (from the code signature), bundle ID, URL, executable path, parent

When a new item appears, the user sees a "Background Items Added" notification (on current releases also titled "Login Item Added" or "Multiple Items Added") pointing to Login Items settings, where every item can be switched off. Organisations can pre-approve items with the Managed Login Items payload (com.apple.servicemanagement), matching on team ID, bundle ID or launchd label; the user then sees a single "Managed Login Items Added" notice. BTM does not block anything: it records, notifies and lets the user disable.

Where it lives

PathWhatWho can write it
/System/Library/LaunchAgents, /System/Library/LaunchDaemonsApple's background itemsNobody: sealed system volume
/private/var/db/com.apple.backgroundtaskmanagement/BackgroundItems-v*.btmBTM store, all users (13+)backgroundtaskmanagementd; reading needs root and Full Disk Access
/Applications/*.app/Contents/Library/LoginItems/*.appHelper login itemsWhoever can write the app
/Applications/*.app/Contents/Library/LaunchAgents/*.plist, .../LaunchDaemons/*.plistSMAppService agents and daemons (13+)Whoever can write the app
/Library/LaunchAgents, /Library/LaunchDaemonsLegacy background itemsroot
~/Library/LaunchAgentsLegacy per-user agentsThe user
~/Library/Application Support/com.apple.backgroundtaskmanagementagent/backgrounditems.btmOpen at Login list, 10.13 to 12The user
~/Library/Preferences/com.apple.loginitems.plistOpen at Login list, 10.12 and earlierThe user

How attackers use it

Adding an app to Open at Login needs no privileges and no file in a launchd folder. The classic one-liner, which runs the target hidden at each login:

osascript -e 'tell application "System Events" to make login item at end with properties {path:"/Users/Shared/.sys/Updater.app", hidden:true}'

Since Ventura this raises the BTM notification, so attackers rely on the user dismissing it, or on a name that looks expected ("Updater", a browser helper). An app built for the purpose registers its own helper or agent with SMAppService; the BTM record then carries a Developer ID team. Check that the team matches the vendor the name suggests:

Name: Chrome Helper
Developer Name: Example Labs Ltd
Team Identifier: A1B2C3D4E5
Type: agent (0x8)
Disposition: [enabled, allowed, visible, notified] (0xb)
Executable Path: /Applications/Chrome Helper.app/Contents/MacOS/helper

The record above is an illustration: a helper named after a browser, signed by an unrelated team. Other patterns: a legacy agent or daemon dropped in a launchd folder (see LaunchAgents), which BTM records as a legacy agent with no team identifier when it is not signed with a Developer ID; a trojanized copy of a real app whose embedded login item was replaced. Researchers have shown ways to keep the notification from appearing on some releases (Patrick Wardle, DEF CON 31, 2023), and an attacker with root can wipe the store with sfltool resetbtm. A missing notification proves nothing.

How to check a host

On a live Mac, read-only:

sudo sfltool dumpbtm > btm.txt         # every item, every user
osascript -e 'tell application "System Events" to get the path of every login item'
plutil -p "/Applications/Example.app/Contents/Library/LaunchAgents/com.example.agent.plist"
codesign -dv --verbose=4 "/Applications/Example.app"
spctl -a -vv "/Applications/Example.app"
log show --last 7d --info --predicate 'subsystem == "com.apple.backgroundtaskmanagement"'

The System Events query may trigger an automation consent prompt. In btm.txt, read each record's type, disposition, developer and team ID, URL and executable path. Question records with no team ID, team IDs that do not match the app's vendor, executables outside /Applications or in hidden folders, and items enabled for a user who never installed the app. Run codesign and spctl on the executables, and check xattr -l for the quarantine record that says where an app came from.

From a collection: the BTM store (copied as root, with Full Disk Access), the legacy per-user files on older Macs, the launchd folders, and the app bundles that hold SMAppService plists if you can take them. Join BTM records to the plists they name and to installer receipts, and line up file times with the unified log. The collection command takes the BTM folder and the legacy files; macOS Persistence reads them offline.

What macOS Persistence flags

The BTM store is parsed by parseBtm (lib/persist/btm.ts), which recognises records by shape because Apple renames classes and keys between store versions, and keeps unknown type or disposition bits as hex. Records are mapped to users through the account records in the collection.

  • A record that points at a launch plist in the collection is joined to it: the agent or daemon entry gains BTM's type, disposition, developer and team ID, and is marked disabled when BTM says so.
  • Other records become entries of their own: agents and daemons whose plist is not in the collection (typically SMAppService items inside app bundles), with the note "plist not in the collection", and app and login-item records as login items. developer grouping records are skipped.
  • Unknown developer in BTM: the record has no team identifier and no developer name, or the name says unknown.
  • Runs from a temporary or shared folder and Runs from a hidden folder: on the record's executable path.
  • Not in Background Task Management: on a non-Apple launch plist that has no record, when a store was collected.
  • program also runs from mechanisms: the same executable is started by another mechanism too.

parseLegacyLoginItems reads backgrounditems.btm and com.apple.loginitems.plist: each item's name, and its path when it can be recovered from the bookmark (best effort), flagged with the same two path rules. Those files can also get Changed date when modified in the 7 days before the newest collected file. BTM-only entries get no package or recency flags: they have no file of their own.

Limits: the tool does not open app bundles, so it never reads an SMAppService plist or a helper app, only the BTM record about it. The team ID shown is what BTM recorded; signatures are not verified. It does not see the Open at Login list of a running session, only what is stored.

Cleaning up

  1. Preserve: sudo sfltool dumpbtm > btm.txt, a root copy of /private/var/db/com.apple.backgroundtaskmanagement, the legacy files, and the app or executable with its times and hashes.
  2. Disable the item in Login Items settings, or remove an Open at Login entry with osascript -e 'tell application "System Events" to delete login item "Updater"'.
  3. Quit and delete the app or helper; for a legacy plist, launchctl bootout and delete it as described on the LaunchDaemons page.
  4. Check every user's records in the dump and the same executable in other mechanisms. Do not run sfltool resetbtm as a clean-up step: it discards every record, approval and the evidence of when items appeared; Apple's guide suggests a restart after it if you ever must.
  5. Rotate what the user's session could reach, and, if a daemon was approved, what root could reach.

References

See also

On Mac Forensics

The artifacts behind this technique, in the Mac Forensics reference: