Skip to content

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 … -roleAccount creates new ones in that range.
  • root is UID 0 and disabled for login until someone runs dsenableroot or sets its password.
  • Being an administrator means being in the admin group (GID 80), which the stock /etc/sudoers turns into full sudo.
  • IsHidden set 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 used Hide500Users and HiddenUsersList in /Library/Preferences/com.apple.loginwindow.plist instead; 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

PathWhatWho can write it
/var/db/dslocal/nodes/Default/users/*.plistOne record per local account, including Apple's service accounts (/var is /private/var)root, through opendirectoryd
/var/db/dslocal/nodes/Default/groups/admin.plistAdministratorsroot
/var/db/dslocal/nodes/Default/groups/com.apple.access_ssh.plistSSH allow list, when Remote Login is restrictedroot
/Library/Preferences/com.apple.loginwindow.plistHiddenUsersList, Hide500Users and other login window settingsroot
/Users/<name>, or any path in homeHome folders; a hidden account often gets one outside /Usersroot, 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): IsHidden is set, the UID is 500 or more and the shell is a login shell (sh, bash, zsh, ksh, csh, tcsh or fish).
  • 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

  1. Preserve: copy the user record (it holds the password hash), admin.plist and com.apple.access_ssh.plist with their times, save dscl . -read /Users/<name> and accountPolicyData, archive the home folder with ditto, and export last and the logs for sshd, screensharingd and sudo.
  2. Disable before deleting, so nothing breaks mid-investigation: sudo pwpolicy -u svc_update disableuser, sudo dscl . -create /Users/svc_update UserShell /usr/bin/false, and sudo dseditgroup -o edit -d svc_update -t user admin.
  3. Delete it once evidence is safe: sudo sysadminctl -deleteUser svc_update (or sudo dscl . -delete /Users/svc_update), then remove the home folder. For a UID 0 clone, delete the record; do not touch the real root.
  4. 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.
  5. 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

On Mac Forensics

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