Skip to content

At authentication

Authorization Plugins: macOS Persistence at Login

How SecurityAgent authorization plugins and auth.db mechanisms give root code and passwords at every macOS login, and how to find and remove one.

MITRE ATT&CK
T1556
Tactics
Persistence, Credential access
Runs
At authentication
Set up by
root
Locations
  • /Library/Security/SecurityAgentPlugins/*.bundle
  • /var/db/auth.db

How it works

Authorization Services decide whether a process may do something that needs more than the current user's rights: log in at the login window, unlock settings, install software. The authorization daemon (authd) looks up the requested right in the authorization database, /var/db/auth.db, a SQLite file it seeds from Apple's defaults in /System/Library/Security/authorization.plist. OS X 10.9 Mavericks moved this database there from the old /etc/authorization property list.

A right of class evaluate-mechanisms runs an ordered list of mechanisms. Each is written plugin:mechanism, optionally followed by ,privileged:

  • builtin, loginwindow, HomeDirMechanism, MCXMechanism, CryptoTokenKit, PSSOAuthPlugin and others are Apple's, as bundles in /System/Library/CoreServices/SecurityAgentPlugins;
  • any other plugin name refers to /Library/Security/SecurityAgentPlugins/<plugin>.bundle;
  • privileged mechanisms run as root in authorizationhost; the others run in SecurityAgent, which can draw user interface.

The right that matters most is system.login.console, evaluated at every login at the login window. On a current Mac its mechanisms run loginwindow:login (collect the user name and password), then builtin:authenticate,privileged, home folder setup, loginwindow:done and more. Mechanisms share an evaluation context: a mechanism placed after loginwindow:login can read the user name and password that were typed, and a privileged one does so as root.

That is exactly what legitimate identity products need: Jamf Connect, XCreds and similar tools install a plugin to sync the local password with a cloud identity. It is also what an attacker wants: root code at every login, with the password in hand. Two things are needed, and both need root: a bundle in /Library/Security/SecurityAgentPlugins, and a mechanism string added to a right in auth.db with security authorizationdb write. A bundle that no right references never runs.

Where it lives

PathWhatWho can write it
/System/Library/CoreServices/SecurityAgentPlugins/*.bundleApple's pluginsNobody: sealed system volume
/System/Library/Security/authorization.plistDefault rights and rules auth.db is built fromNobody: sealed system volume
/Library/Security/SecurityAgentPlugins/*.bundleThird-party plugins (macOS ships the folder empty)root
/var/db/auth.db (with -wal, -shm)The live authorization database: rights, rules, mechanismsroot, through authd (security authorizationdb write)

There is no per-user location. Each rule in the database carries created and modified timestamps, in seconds since 2001-01-01.

How attackers use it

Credential capture and root at every login. The attacker copies a plugin bundle and inserts its mechanism into the login right, after the step that collects the password:

cp -R Helper.bundle /Library/Security/SecurityAgentPlugins/
security authorizationdb read system.login.console > /tmp/rule.plist
# edit /tmp/rule.plist, then:
security authorizationdb write system.login.console < /tmp/rule.plist

The edited rule then contains a line no clean Mac has:

<string>loginwindow:login</string>
<string>Helper:invoke,privileged</string>
<string>builtin:login-begin</string>

The mechanism returns "allow" so the login proceeds normally; meanwhile it writes the password to disk, sends it to https://example.com/c or starts a payload as root. It runs again at every login, after every reboot, and keeps working after the user changes the password.

Blending in. The bundle takes a vendor-like name or a com.apple. bundle identifier, or replaces a legitimate identity product's plugin binary while keeping its name, so the rule looks untouched. The mechanism can also be added to rights other than the login console (any evaluate-mechanisms right), where fewer people look.

Weakening instead of adding. Removing or reordering Apple's own mechanisms changes how login behaves without any third-party code; only a comparison with the defaults shows it.

Plugins pair with PAM modules: both see passwords, both need root, and an attacker who has one often tries the other. The legacy login hook is the older, noisier way to run as root at login.

How to check a host

On a live Mac, start with the folder (it is empty on a stock install) and the login right:

ls -le@ /Library/Security/SecurityAgentPlugins
security authorizationdb read system.login.console
plutil -p /Library/Security/SecurityAgentPlugins/Helper.bundle/Contents/Info.plist
codesign -dv --verbose=4 /Library/Security/SecurityAgentPlugins/Helper.bundle
codesign --verify --deep --strict -v /Library/Security/SecurityAgentPlugins/Helper.bundle
pkgutil --file-info /Library/Security/SecurityAgentPlugins/Helper.bundle/Contents/Info.plist

Compare the mechanisms array with the system.login.console entry under rights in /System/Library/Security/authorization.plist from the same build. To see every mechanism every right uses, query the database (root only):

sudo sqlite3 /var/db/auth.db 'SELECT plugin, param, privileged FROM mechanisms ORDER BY plugin'

Any plugin name without a bundle under /System/Library/CoreServices/SecurityAgentPlugins is third-party; account for each one. Convert a rule's modified value to a date with date -r $((978307200 + 800000000)) (put the rule's value in place of the second number), and line it up with installer receipts, the bundle's file times and unified logs for authd and SecurityAgent.

Offline, the collection command archives /Library/Security/SecurityAgentPlugins, binaries included. It does not take the database: add /private/var/db/auth.db with its -wal and -shm files, or the output of security authorizationdb read for the rights you care about. macOS Persistence then lists the plugin bundles offline; you check the rules yourself with sqlite3.

What macOS Persistence flags

The tool reads Contents/Info.plist of each bundle in /Library/Security/SecurityAgentPlugins and reports one entry per bundle, with its bundle identifier, version and executable name.

  • Authorization plugin (medium): every bundle there. Only security and identity products install one, so each deserves an explanation.
  • Imitates an Apple label (high): the bundle identifier starts with com.apple., while Apple's own plugins live on the sealed volume.
  • Runs from a hidden folder (medium): the bundle's name starts with a dot.
  • Not installed by any package (medium): installer receipts are in the collection and none lists the bundle's Info.plist.
  • Differs from package package (medium): a receipt lists the file but its checksum no longer matches.
  • Changed date (low): the Info.plist was modified in the 7 days before the newest file in the collection.

Limits: the engine does not read auth.db. It cannot tell whether any right references a bundle (an unreferenced bundle is inert), and it cannot see a rule that was edited, reordered or pointed at a renamed bundle. It reads only the Info.plist, so a replaced plugin binary with an untouched Info.plist looks unchanged unless a receipt checksum covers it. It does not verify code signatures or team IDs.

Cleaning up

  1. Preserve: copy the bundle with ditto (keeps times and extended attributes), hash its executable, copy /var/db/auth.db with -wal and -shm, and save security authorizationdb read output for every right that names the plugin.
  2. Keep a second way in (an SSH or admin Terminal session) before you touch the login right: a rule that names a missing or broken plugin can block every login at the login window.
  3. Remove the mechanism first. Write back a clean rule, taken from your saved copy minus the foreign lines or from authorization.plist of the same build: sudo security authorizationdb write system.login.console < clean.plist. Repeat for any other right that names the plugin.
  4. Then delete the bundle, restart, and test a login before closing your backup session.
  5. Treat the password of every account that logged in while the plugin was active as stolen: rotate them, and any reused elsewhere. Then check PAM stacks, launch daemons and local accounts for the same actor.

References

See also

On Mac Forensics

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