At login
Local Accounts: Hidden and UID 0 Users on macOS
How attackers persist on macOS with hidden admin users, UID 0 clones and service-looking accounts in dslocal, and how to find and remove them safely.
- Tactics
- Persistence, Privilege escalation, Defense evasion
- Runs
- At login
- Set up by
- root
- Locations
- /var/db/dslocal/nodes/Default/users/*.plist
- /var/db/dslocal/nodes/Default/groups/admin.plist
- /Library/Preferences/com.apple.loginwindow.plist
How it works
macOS keeps local accounts in the local directory node (/Local/Default), served by opendirectoryd. Each user is a binary property list in /var/db/dslocal/nodes/Default/users/<name>.plist, and every attribute is an array of strings: name, uid, gid, home, shell, realname, generateduid, IsHidden, authentication_authority, ShadowHashData (the password hash) and accountPolicyData (an embedded property list with creationTime, passwordLastSetTime and failed-login counters). Groups live next door in groups/; admin.plist lists its members by short name in users (GroupMembership in dscl) and by UUID in groupmembers.
The conventions an attacker plays with:
- People get UIDs from 501 up; the first account created at setup is 501.
- Service accounts have names that start with an underscore and UIDs below 500;
sysadminctl -addUser … -roleAccountcreates new ones in that range. rootis UID 0 and disabled for login until someone runsdsenablerootor sets its password.- Being an administrator means being in the
admingroup (GID 80), which the stock/etc/sudoersturns into full sudo. IsHiddenset to 1 keeps an account off the login window and out of Users & Groups in System Settings; Apple documents this in its support article on hiding a user. Older hiding guides usedHide500UsersandHiddenUsersListin/Library/Preferences/com.apple.loginwindow.plistinstead; check those keys too.
An account is persistence that needs no code at all: whoever knows its password can come back through SSH (Remote Login), Screen Sharing, su or the login window, and an admin account brings root with it. When Remote Login is limited to some users, the allow list is the com.apple.access_ssh group, which pam_sacl checks. On FileVault Macs, accounts created with dscl usually lack a Secure Token, so they cannot unlock the disk at startup, but they can log in once it is unlocked.
Where it lives
| Path | What | Who can write it |
|---|---|---|
/var/db/dslocal/nodes/Default/users/*.plist | One record per local account, including Apple's service accounts (/var is /private/var) | root, through opendirectoryd |
/var/db/dslocal/nodes/Default/groups/admin.plist | Administrators | root |
/var/db/dslocal/nodes/Default/groups/com.apple.access_ssh.plist | SSH allow list, when Remote Login is restricted | root |
/Library/Preferences/com.apple.loginwindow.plist | HiddenUsersList, Hide500Users and other login window settings | root |
/Users/<name>, or any path in home | Home folders; a hidden account often gets one outside /Users | root, then the user |
Nothing on the sealed system volume describes local accounts; the directory database is on the Data volume and readable only by root.
How attackers use it
A hidden administrator. The classic backdoor: create a user with a forgettable name, hide it, give it a shell and a home outside /Users, and add it to admin (run as root):
dscl . -create /Users/svc_update
dscl . -create /Users/svc_update UniqueID 503
dscl . -create /Users/svc_update PrimaryGroupID 20
dscl . -create /Users/svc_update UserShell /bin/zsh
dscl . -create /Users/svc_update NFSHomeDirectory /var/svc_update
dscl . -create /Users/svc_update IsHidden 1
dscl . -passwd /Users/svc_update 'example-password'
dseditgroup -o edit -a svc_update -t user admin
A second root. Any account with UID 0 is root under another name, whatever its password:
dscl . -create /Users/backup UniqueID 0
An account that looks like a service. A name such as _softwareupdated2 with a UID below 500 blends in with Apple's own _-prefixed accounts; give it /bin/zsh instead of /usr/bin/false and it can log in.
Reviving what exists. Instead of creating anything, the attacker sets a password on root (dsenableroot), changes an existing service account's shell, adds a normal user to admin or to com.apple.access_ssh, or pairs a dormant account with an SSH key. These leave fewer new files than a new account, so compare with a known-good list.
How to check a host
On a live Mac (most commands work as any admin, root is needed only for the raw records):
dscl . -list /Users UniqueID | awk '$2 == 0 || $2 >= 500' # root, people, anything odd
dscl . -list /Users UniqueID | awk '$2 > 0 && $2 < 500' | grep -v '^_'
dscl . -list /Users IsHidden
dscl . -list /Users UserShell | grep -vE '/usr/bin/false$'
dscl . -read /Groups/admin GroupMembership GroupMembers
dscl . -read /Groups/com.apple.access_ssh GroupMembership 2>/dev/null
dscl . -read /Users/svc_update accountPolicyData # creationTime, passwordLastSetTime
sysadminctl -secureTokenStatus svc_update
defaults read /Library/Preferences/com.apple.loginwindow 2>/dev/null
last | head -30
Every UID 0 account other than root, every hidden account with a shell, and every admin nobody can name is a finding. creationTime is Unix time (date -r 1763000000): line it up with the account's home folder, its sudoers entries, its SSH keys and the logs of sshd and screensharingd.
Offline, the collection command archives the user records and admin.plist. They contain password hashes: handle the archive as evidence. Read a record with plutil -p, and its creation time with plutil -extract accountPolicyData.0 raw -o - users/svc_update.plist | base64 -D | plutil -p -. Then compare the list with the people and services the Mac should have, and check each account's home for launch agents, keys and shell files. macOS Persistence reads the records offline and never the hashes.
What macOS Persistence flags
The tool reads every user record and the admin group, uses them to attribute home-folder files and Background Task Management items to accounts, and reports an entry for each account that raises one of these flags:
- Second UID 0 account (high): UID 0 and a name other than
root. - Hidden user account (medium, high when the account is an administrator):
IsHiddenis set, the UID is 500 or more and the shell is a login shell (sh,bash,zsh,ksh,csh,tcshorfish). - System account with a login shell (medium): a UID from 1 to 499, a name that does not start with an underscore, and a login shell.
- Member of group (info): every administrator with a UID of 500 or more, so the list of admins is always in front of you.
Accounts get no package or recency checks. The tool reads names, UIDs, homes, shells, generateduid and the hidden and admin markers; it never reads ShadowHashData beyond noting that it exists, and it does not flag password state, so an enabled root account raises nothing.
Limits: admin membership comes from the group's users list and its groupmembers UUIDs (matched to each account's generateduid), not from nested groups. It does not read accountPolicyData, the com.apple.access_ssh group or the login window's hidden-user settings. An underscore name below UID 500 with a shell is treated as a service account and not flagged, and a hidden account with /usr/bin/false is not flagged either. Directory accounts (Active Directory, LDAP) that have no local record are not covered.
Cleaning up
- Preserve: copy the user record (it holds the password hash),
admin.plistandcom.apple.access_ssh.plistwith their times, savedscl . -read /Users/<name>andaccountPolicyData, archive the home folder withditto, and exportlastand the logs forsshd,screensharingdandsudo. - Disable before deleting, so nothing breaks mid-investigation:
sudo pwpolicy -u svc_update disableuser,sudo dscl . -create /Users/svc_update UserShell /usr/bin/false, andsudo dseditgroup -o edit -d svc_update -t user admin. - Delete it once evidence is safe:
sudo sysadminctl -deleteUser svc_update(orsudo dscl . -delete /Users/svc_update), then remove the home folder. For a UID 0 clone, delete the record; do not touch the real root. - Look for what the account set up: launch agents and login items in its home, SSH keys, sudoers rules naming it, cron tabs, and PAM changes that may have let it in.
- Rotate every administrator password and any SSH keys the attacker could have read, disable root again if it was enabled, and rotate the FileVault recovery key if the account held a Secure Token.
References
See also
Related techniques
On Mac Forensics
The artifacts behind this technique, in the Mac Forensics reference: