GH-026 T1548.001 PHASE RED INSIDE

The Borrowed Crown

A binary owned by root sits in the lab with the setuid bit set. On an ordinary machine, anyone who runs it runs as root. On this machine the kernel refuses the transfer, and this file shows you the exact mechanism that refuses it, then hunts the planted bit the way a defender would.

TechniqueSetuid and Setgid (T1548.001)
Target OSUbuntu 24.04.5 LTS
Toolchaingcc 13
LevelIntermediate
Time25 min

OBJECTIVES

  1. Plant a root-owned binary with the setuid bit set and watch the kernel refuse the transfer
  2. Hunt the planted bits with find -perm and convict by package provenance
  3. Strip the bits with evidence first and harden the mounts against the next plant
  4. Take the IOC checklist and the one-sentence lesson
01

Intel Brief

CONTEXT

MITRE ATT&CK T1548.001: adversaries plant setuid and setgid binaries so a later run inherits a privileged identity. This file plants the crown, watches the kernel refuse to transfer it, and names the exact mechanism. Two actors: the attacker, who owns every plant in the red phase; and the defender, who owns every hunt, strip, and rule in the blue phases.

Why this technique. The operating system's core promise is that your processes run as you. setuid is the sanctioned exception: passwd, sudo, and su all need to act with privileges their caller does not have, so the kernel lets a marked binary borrow its owner's identity at exec. An attacker who gains root once plants their own exception: a binary that hands root back on demand, later, without the original hole. The stealth is in the artifact: the plant is a single letter in a directory listing, an s where an x used to be. No new user, no password change, nothing in the account database for an auditor to find.

Why not the obvious alternative. The obvious move for re-entry is a backdoor root account: one new row in /etc/passwd with UID 0. It works, and it is exactly what account inventories are built to catch: the row shows in every user audit, in lastlog, in every compliance scan. The setuid plant shows up in none of those places. The other obvious move is simpler still: just read the secret file. The red phase tries it first, as the unprivileged user, and the kernel answers Permission denied. That denial is the whole reason the crown exists: the file cannot be read as nobody, so the attacker borrows an identity that can.

The mechanism, in one paragraph. The setuid bit is mode 04000. At exec, the kernel sets the process's effective user ID to the file owner's UID; the real UID stays the caller's, and permission checks use the effective one. The setgid bit is mode 02000: the same transfer for the effective group ID and the file's group. In ls -l the owner's x becomes s (-rwsr-xr-x) and the group's x becomes s (-rwxr-sr-x); in octal the modes read 4755 and 2755. One boundary the kernel draws itself: the bits are ignored on scripts. Exec of a #! script runs the interpreter, and the interpreter does not inherit the bit, so the crown has to be a real binary.

The concrete case, before the abstraction. The lab plants /tmp/gh026/crown: root-owned, mode 4755, a reader for a root-only vault holding GHOSTLIGHT-CANARY-026. Run it as the unprivileged user on an ordinary host and the output line reads uid=65534 euid=0, then the canary. Run it in this lab and the line reads uid=65534 euid=65534, then open: Permission denied. Same binary, same bit, different kernel answer. The red phase then runs the control experiment: the crown copied to the root filesystem, where no nosuid flag exists. Still refused. The mount was never the binding constraint.

Terms, earned. The effective UID (euid) is the identity the kernel checks permissions against; the real UID (ruid) is who launched the process. NO_NEW_PRIVS is a per-process kernel flag: once set, exec grants no new privileges, and it can never be cleared. nosuid is a mount flag: the kernel ignores setuid and setgid bits on binaries executed from that mount. T1548.001 is the planting and abuse of these bits for privilege escalation.

Scope. T1548.001 covers planting setuid/setgid binaries and abusing existing ones. This file works the plant end to end: the bit set on disk, the hunt that finds it, the provenance check that convicts it, the evidence-first strip, and the mount hardening that prevents the next one. The canary is a benign token. The lab runs in a disposable PID and mount namespace with a private /tmp; the lab directory is /tmp/gh026; teardown removes it and the namespace's death reaps every stray. Nothing persists outside the lab.

02

Target Environment

LOADOUT

Ubuntu 24.04.5 LTS, x86-64, gcc 13.3.0, root inside a disposable PID and mount namespace used only for this lab. Two properties of this sandbox shape the file, and both are verified live rather than assumed: the whole process tree runs with NO_NEW_PRIVS (even PID 1 carries it), and every new mount gets nosuid from the user namespace. The plant is real; the transfer is refused; both are shown.

1

Build the lab

umask 022 first: the default 0007 of this shell would lock the unprivileged user out of the lab directory itself, which would break the demo for the wrong reason. rm -rf starts clean. Two heredocs stage the sources shown and glossed in the next steps: crown.c, the planted reader, and as-nobody, the privilege-dropper. gcc builds the crown; the two vaults are written, chowned, and locked down (root:root mode 600 for the canary, root:nogroup mode 640 for the group canary). ls -l shows the staged lab: no s bits yet.

bash
$ umask 022  # this shell's default 0007 would lock the unprivileged user out of the lab dir itself
rm -rf /tmp/gh026; mkdir -p /tmp/gh026
cat > /tmp/gh026/crown.c <<'CEOF'
/* crown.c - GH-026 lab: the planted crown (attacker's side).
 *
 * Benign: prints real/effective UIDs and GIDs, then reads the path given
 * as argv[1] (default /tmp/gh026/vault) and prints its first line.
 * Compiled, chown root:root, chmod 4755: on a normal host, whoever runs
 * it reads as root. In this lab the kernel refuses the transfer; the
 * red phase shows the refusal and names the mechanism. */
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv) {
    char buf[128];
    FILE *f;
    const char *path = argc > 1 ? argv[1] : "/tmp/gh026/vault";

    printf("uid=%d euid=%d gid=%d egid=%d\n",
           getuid(), geteuid(), getgid(), getegid());
    f = fopen(path, "r");
    if (!f) { perror("open"); return 1; }
    if (!fgets(buf, sizeof buf, f)) { perror("read"); return 1; }
    printf("vault: %s", buf);
    fclose(f);
    return 0;
}
CEOF
cat > /tmp/gh026/as-nobody <<'PYEOF'
#!/usr/bin/env python3
"""as-nobody - GH-026 lab scaffolding: become nobody:nogroup, exec argv.

Drops privilege with setresuid/setresgid and does NOT set NO_NEW_PRIVS,
so setuid/setgid bits on the target are honored or refused by the kernel
exactly as policy dictates. su, runuser, and setpriv all set NO_NEW_PRIVS
on this VM (verified live), which would neuter the very bit being
demonstrated.
"""
import os
import sys

os.setresgid(65534, 65534, 65534)
os.setresuid(65534, 65534, 65534)
os.execvp(sys.argv[1], sys.argv[1:])
PYEOF
chmod 755 /tmp/gh026/as-nobody
gcc -O2 -o /tmp/gh026/crown /tmp/gh026/crown.c && echo 'build OK'
echo 'GHOSTLIGHT-CANARY-026' > /tmp/gh026/vault
chown root:root /tmp/gh026/vault && chmod 600 /tmp/gh026/vault
echo 'GHOSTLIGHT-CANARY-026-G' > /tmp/gh026/vault-g
chown root:nogroup /tmp/gh026/vault-g && chmod 640 /tmp/gh026/vault-g
ls -l /tmp/gh026
build OK
total 36
-rwxr-xr-x 1 root root      527 Oct  5 10:46 as-nobody
-rwxr-xr-x 1 root root    16400 Oct  5 10:46 crown
-rw-r--r-- 1 root root      875 Oct  5 10:46 crown.c
-rw------- 1 root root       22 Oct  5 10:46 vault
-rw-r----- 1 root nogroup    24 Oct  5 10:46 vault-g
2

The payload: crown.c

The planted reader, in full. Line by line: the header comment states the contract (benign reader, planted with the bit, refused by this kernel). #include <stdio.h> and <unistd.h> bring file I/O and the UID/GID calls. main takes argc/argv: the vault path comes from argv[1], defaulting to /tmp/gh026/vault, so the setgid twin reuses the same binary on a different vault. buf[128] and FILE *f are the read buffer and handle. The printf line is the instrument of the experiment: it prints ruid, euid, rgid, egid before touching the file, so the transfer, or its refusal, is on the record. fopen(path, "r") is the permission check under test: as the unprivileged user this fails without the crown. The two error branches call perror to name the failing call and return 1 to mark the refusal. fgets reads the first line, printf("vault: %s") prints the canary, fclose cleans up, return 0 marks success.

c: crown.c
/* crown.c - GH-026 lab: the planted crown (attacker's side).
 *
 * Benign: prints real/effective UIDs and GIDs, then reads the path given
 * as argv[1] (default /tmp/gh026/vault) and prints its first line.
 * Compiled, chown root:root, chmod 4755: on a normal host, whoever runs
 * it reads as root. In this lab the kernel refuses the transfer; the
 * red phase shows the refusal and names the mechanism. */
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv) {
    char buf[128];
    FILE *f;
    const char *path = argc > 1 ? argv[1] : "/tmp/gh026/vault";

    printf("uid=%d euid=%d gid=%d egid=%d\n",
           getuid(), geteuid(), getgid(), getegid());
    f = fopen(path, "r");
    if (!f) { perror("open"); return 1; }
    if (!fgets(buf, sizeof buf, f)) { perror("read"); return 1; }
    printf("vault: %s", buf);
    fclose(f);
    return 0;
}
3

The scaffolding: as-nobody

The privilege-dropper, in full. The docstring states why this file exists: su, runuser, and setpriv all set NO_NEW_PRIVS on this VM (verified live), which would neuter the very bit being demonstrated before the kernel ever sees it. import os, sys brings the privilege calls and argv. setresgid then setresuid to 65534: group first, then user, because dropping the UID first would revoke the right to change the GID. os.execvp(sys.argv[1], sys.argv[1:]) replaces the process with the target, carrying argv through: no new process, no shell, no NO_NEW_PRIVS. The kernel sees a plain unprivileged exec and applies its setuid policy honestly, which is exactly what the red phase needs.

python: as-nobody
#!/usr/bin/env python3
"""as-nobody - GH-026 lab scaffolding: become nobody:nogroup, exec argv.

Drops privilege with setresuid/setresgid and does NOT set NO_NEW_PRIVS,
so setuid/setgid bits on the target are honored or refused by the kernel
exactly as policy dictates. su, runuser, and setpriv all set NO_NEW_PRIVS
on this VM (verified live), which would neuter the very bit being
demonstrated.
"""
import os
import sys

os.setresgid(65534, 65534, 65534)
os.setresuid(65534, 65534, 65534)
os.execvp(sys.argv[1], sys.argv[1:])
03

Phase Red: place the crown

ATTACK

The attacker in this scenario has already been root once: that is the standard plant story, a backdoor for re-entry after the original hole closes. The plant is compiled, the vaults are locked, the crown is set, and the unprivileged user tries it on.

Real screen recording 276.2s
What you are watching: The lab is staged, the obvious read breaks on permissions, the setuid and setgid crowns are planted, and the kernel refuses the transfer: the control run and NO_NEW_PRIVS name the mechanism. Every command below is copy-pasteable.
1

Stage the lab

The namespace gives a private /tmp and private PIDs; the lab directory is /tmp/gh026. umask, clean slate, the two sources by heredoc, the build, the locked vaults, the listing. Everything the page shows is built here, on camera.

bash
$ umask 022  # this shell's default 0007 would lock the unprivileged user out of the lab dir itself
rm -rf /tmp/gh026; mkdir -p /tmp/gh026
cat > /tmp/gh026/crown.c <<'CEOF'
/* crown.c - GH-026 lab: the planted crown (attacker's side).
 *
 * Benign: prints real/effective UIDs and GIDs, then reads the path given
 * as argv[1] (default /tmp/gh026/vault) and prints its first line.
 * Compiled, chown root:root, chmod 4755: on a normal host, whoever runs
 * it reads as root. In this lab the kernel refuses the transfer; the
 * red phase shows the refusal and names the mechanism. */
#include <stdio.h>
#include <unistd.h>

int main(int argc, char **argv) {
    char buf[128];
    FILE *f;
    const char *path = argc > 1 ? argv[1] : "/tmp/gh026/vault";

    printf("uid=%d euid=%d gid=%d egid=%d\n",
           getuid(), geteuid(), getgid(), getegid());
    f = fopen(path, "r");
    if (!f) { perror("open"); return 1; }
    if (!fgets(buf, sizeof buf, f)) { perror("read"); return 1; }
    printf("vault: %s", buf);
    fclose(f);
    return 0;
}
CEOF
cat > /tmp/gh026/as-nobody <<'PYEOF'
#!/usr/bin/env python3
"""as-nobody - GH-026 lab scaffolding: become nobody:nogroup, exec argv.

Drops privilege with setresuid/setresgid and does NOT set NO_NEW_PRIVS,
so setuid/setgid bits on the target are honored or refused by the kernel
exactly as policy dictates. su, runuser, and setpriv all set NO_NEW_PRIVS
on this VM (verified live), which would neuter the very bit being
demonstrated.
"""
import os
import sys

os.setresgid(65534, 65534, 65534)
os.setresuid(65534, 65534, 65534)
os.execvp(sys.argv[1], sys.argv[1:])
PYEOF
chmod 755 /tmp/gh026/as-nobody
gcc -O2 -o /tmp/gh026/crown /tmp/gh026/crown.c && echo 'build OK'
echo 'GHOSTLIGHT-CANARY-026' > /tmp/gh026/vault
chown root:root /tmp/gh026/vault && chmod 600 /tmp/gh026/vault
echo 'GHOSTLIGHT-CANARY-026-G' > /tmp/gh026/vault-g
chown root:nogroup /tmp/gh026/vault-g && chmod 640 /tmp/gh026/vault-g
ls -l /tmp/gh026
build OK
total 36
-rwxr-xr-x 1 root root      527 Oct  5 10:46 as-nobody
-rwxr-xr-x 1 root root    16400 Oct  5 10:46 crown
-rw-r--r-- 1 root root      875 Oct  5 10:46 crown.c
-rw------- 1 root root       22 Oct  5 10:46 vault
-rw-r----- 1 root nogroup    24 Oct  5 10:46 vault-g
2

The obvious attempt breaks

The unprivileged user reads the vault directly: Permission denied. Then runs the plain binary: uid=65534 euid=65534, open: Permission denied. The permission model is working exactly as designed, and that working is the whole reason the crown exists: the file cannot be read as nobody, so the attacker borrows an identity that can.

bash
$ echo '--- the obvious attempt: read the vault directly as the unprivileged user'
/tmp/gh026/as-nobody cat /tmp/gh026/vault; echo "rc=$?"
echo '--- the plain binary, no crown yet:'
/tmp/gh026/as-nobody /tmp/gh026/crown; echo "rc=$?"
--- the obvious attempt: read the vault directly as the unprivileged user
cat: /tmp/gh026/vault: Permission denied
rc=1
--- the plain binary, no crown yet:
uid=65534 euid=65534 gid=65534 egid=65534
open: Permission denied
rc=1
3

Plant the crown

chown root:root and chmod 4755: stat reads 4755 root:root, ls reads -rwsr-xr-x. The setgid twin: chgrp nogroup, chmod 2755, -rwxr-sr-x. Two plants, one pattern: the s sits where the x was, and at a glance the line still reads as an ordinary executable.

bash
$ echo '--- plant the setuid crown:'
chown root:root /tmp/gh026/crown && chmod 4755 /tmp/gh026/crown
stat -c '%a %U:%G %n' /tmp/gh026/crown
echo '--- plant the setgid twin:'
cp /tmp/gh026/crown /tmp/gh026/crown-g
chgrp nogroup /tmp/gh026/crown-g && chmod 2755 /tmp/gh026/crown-g
ls -l /tmp/gh026/crown /tmp/gh026/crown-g
echo 'planted: the s sits where the x was'
--- plant the setuid crown:
4755 root:root /tmp/gh026/crown
--- plant the setgid twin:
-rwsr-xr-x 1 root root    16400 Oct  5 10:46 /tmp/gh026/crown
-rwxr-sr-x 1 root nogroup 16400 Oct  5 10:46 /tmp/gh026/crown-g
planted: the s sits where the x was
4

The kernel refuses

The unprivileged run: uid=65534 euid=65534, open: Permission denied. The crown did not transfer. The control experiment: the same binary copied to the root filesystem, where findmnt shows no nosuid flag. Still refused. The mount was never the binding constraint. The kernel states its reason: NoNewPrivs: 1, on this shell and on PID 1. This entire VM runs with NO_NEW_PRIVS, the flag that tells exec to grant no new privileges. The crown is placed; the kernel refuses to let it be worn.

bash
$ echo '--- the unprivileged run:'
/tmp/gh026/as-nobody /tmp/gh026/crown; echo "rc=$?"
echo '--- is it the nosuid mount? retest on the root filesystem (no nosuid there):'
mkdir -p /gh026x && cp /tmp/gh026/crown /gh026x/crown && chmod 4755 /gh026x/crown
findmnt -n -o OPTIONS /tmp | tr ',' '\n' | grep nosuid && echo '/tmp: nosuid present'
findmnt -n -o OPTIONS / | tr ',' '\n' | grep -q nosuid && echo '/: nosuid present' || echo '/: no nosuid flag'
/tmp/gh026/as-nobody /gh026x/crown; echo "rc=$?"
rm -rf /gh026x
echo '--- the kernel stated reason:'
grep NoNewPrivs /proc/self/status
grep NoNewPrivs /proc/1/status
--- the unprivileged run:
uid=65534 euid=65534 gid=65534 egid=65534
open: Permission denied
rc=1
--- is it the nosuid mount? retest on the root filesystem (no nosuid there):
nosuid
nosuid
/tmp: nosuid present
/: no nosuid flag
uid=65534 euid=65534 gid=65534 egid=65534
open: Permission denied
rc=1
--- the kernel stated reason:
NoNewPrivs:	1
NoNewPrivs:	1
Plant confirmed

The artifact is on disk, root-owned, bit set, byte-identical to a plant on an ordinary host, and every scanner in the blue phase finds it. The transfer is refused by NO_NEW_PRIVS, verified live on this shell and on PID 1, with the nosuid mount ruled out by the control run on the root filesystem. The stealth point stands regardless: the s hides among the x characters in a casual listing; only the bit-aware hunt sees it.

04

Phase Blue: hunt the bit

DEFENSE

The defender never trusts the listing. The defender hunts the bit, convicts by provenance, strips with evidence first, and hardens the mounts. Every command below ran against the planted lab.

Here is the trap: opening the directory listing, seeing two ordinary-looking executables, and moving on. The s is one letter among dozens, and the eye reads -rwsr-xr-x as -rwxr-xr-x at speed. The checks that work never read the listing the way a human does; they ask the kernel for the mode bits directly.

Real screen recording 192.6s
What you are watching: The defender hunts both planted bits, convicts by package provenance, captures evidence before stripping the bits, and stages the prevention controls with every dependency stated. Every command below is copy-pasteable.
1

DETECTION: hunt the bits

ls -l first, read by someone who knows where the s hides. Then the hunt proper: find /tmp/gh026 -perm -4000 -ls names the setuid plant; -perm -2000 -ls names the setgid twin. -perm -4000 matches any file with the setuid bit, regardless of the other mode bits; -ls prints the long form. This is the query that sees what the listing hides. D3FEND names the heavier forms File Hashing (D3-FH) and File Integrity Monitoring (D3-FIM): hash the setuid inventory, and alert when it changes.

bash
$ echo '--- DETECTION: the listing, read by someone who knows where the s hides'
ls -l /tmp/gh026
echo '--- hunt: every setuid bit under the lab'
find /tmp/gh026 -perm -4000 -ls
echo '--- hunt: every setgid bit under the lab'
find /tmp/gh026 -perm -2000 -ls
--- DETECTION: the listing, read by someone who knows where the s hides
total 56
-rwxr-xr-x 1 root root      527 Oct  5 10:46 as-nobody
-rwsr-xr-x 1 root root    16400 Oct  5 10:46 crown
-rwxr-sr-x 1 root nogroup 16400 Oct  5 10:46 crown-g
-rw-r--r-- 1 root root      875 Oct  5 10:46 crown.c
-rw------- 1 root root       22 Oct  5 10:46 vault
-rw-r----- 1 root nogroup    24 Oct  5 10:46 vault-g
--- hunt: every setuid bit under the lab
       10     20 -rwsr-xr-x   1 root     root        16400 Oct  5 10:46 /tmp/gh026/crown
--- hunt: every setgid bit under the lab
       13     20 -rwxr-sr-x   1 root     nogroup     16400 Oct  5 10:46 /tmp/gh026/crown-g
2

DETECTION: rogue or legitimate?

stat -c reads the raw modes: 4755 root:root, 2755 root:nogroup. Then provenance: dpkg -S asks which package owns the file. /tmp/gh026/crown: no path found matching pattern. Not from any package: rogue. /usr/bin/sudo: sudo: /usr/bin/sudo. From the sudo package: legitimate. The last command lists the legitimate inventory, the haystack the rogue hides in: a dozen package-owned setuid binaries in /usr/bin. Good is package-owned, in a system path, expected. Bad is unowned, in /tmp, unexpected. The discriminator is provenance, not the bit: the bit alone convicts nothing.

bash
$ echo '--- DETECTION: rogue or legitimate? read the mode, then the provenance'
stat -c '%a %U:%G %n' /tmp/gh026/crown /tmp/gh026/crown-g
echo '--- package ownership: the discriminator'
dpkg -S /tmp/gh026/crown 2>&1
dpkg -S /usr/bin/sudo
echo '--- the legitimate inventory (the haystack the rogue hides in)'
find /usr/bin -perm -4000 2>/dev/null
--- DETECTION: rogue or legitimate? read the mode, then the provenance
4755 root:root /tmp/gh026/crown
2755 root:nogroup /tmp/gh026/crown-g
--- package ownership: the discriminator
dpkg-query: no path found matching pattern /tmp/gh026/crown
sudo: /usr/bin/sudo
--- the legitimate inventory (the haystack the rogue hides in)
/usr/bin/chfn
/usr/bin/chsh
/usr/bin/gpasswd
/usr/bin/mount
/usr/bin/newgidmap
/usr/bin/newgrp
/usr/bin/newuidmap
/usr/bin/passwd
/usr/bin/su
/usr/bin/sudo
/usr/bin/umount
3

MITIGATION: evidence first, the bit is stripped second

mkdir evidence. The sha256sum of both crowns, the stat of both, copies of both: captured BEFORE the strip, because the strip changes the artifact and the hashes must describe the planted state. Then chmod u-s and chmod g-s: the bits come off, the files stay for forensics. ls -l confirms: the s is gone. The re-run fails closed: still Permission denied, and now the crown could not transfer on any host.

bash
$ echo '--- MITIGATION: evidence first, the bit is stripped second'
mkdir -p /tmp/gh026/evidence
sha256sum /tmp/gh026/crown /tmp/gh026/crown-g | tee /tmp/gh026/evidence/hashes.txt
stat /tmp/gh026/crown /tmp/gh026/crown-g | tee /tmp/gh026/evidence/stat.txt
cp /tmp/gh026/crown /tmp/gh026/crown-g /tmp/gh026/evidence/ && echo 'binaries preserved'
echo '--- now strip the crowns:'
chmod u-s /tmp/gh026/crown
chmod g-s /tmp/gh026/crown-g
ls -l /tmp/gh026/crown /tmp/gh026/crown-g
echo '--- verify: fails closed'
/tmp/gh026/as-nobody /tmp/gh026/crown; echo "rc=$?"
--- MITIGATION: evidence first, the bit is stripped second
7cef9b773849c5822a7ff43ed81d116ec743c4884d66c2bd88657534b3453006  /tmp/gh026/crown
7cef9b773849c5822a7ff43ed81d116ec743c4884d66c2bd88657534b3453006  /tmp/gh026/crown-g
  File: /tmp/gh026/crown
  Size: 16400     	Blocks: 40         IO Block: 4096   regular file
Device: 0,92	Inode: 10          Links: 1
Access: (4755/-rwsr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-10-05 10:46:54.802312902 +0000
Modify: 2026-10-05 10:46:54.739024229 +0000
Change: 2026-10-05 10:46:54.800581745 +0000
 Birth: 2026-10-05 10:46:54.711581745 +0000
  File: /tmp/gh026/crown-g
  Size: 16400     	Blocks: 40         IO Block: 4096   regular file
Device: 0,92	Inode: 13          Links: 1
Access: (2755/-rwxr-sr-x)  Uid: (    0/    root)   Gid: (65534/ nogroup)
Access: 2026-10-05 10:46:54.812859131 +0000
Modify: 2026-10-05 10:46:54.808801204 +0000
Change: 2026-10-05 10:46:54.812633242 +0000
 Birth: 2026-10-05 10:46:54.807581745 +0000
binaries preserved
--- now strip the crowns:
-rwxr-xr-x 1 root root    16400 Oct  5 10:46 /tmp/gh026/crown
-rwxr-xr-x 1 root nogroup 16400 Oct  5 10:46 /tmp/gh026/crown-g
--- verify: fails closed
uid=65534 euid=65534 gid=65534 egid=65534
open: Permission denied
rc=1
4

PREVENTION: three controls, one proven live

nosuid: findmnt shows this lab's /tmp already mounts nosuid (forced by the sandbox's user namespace), while / carries no nosuid flag: the control, working, on camera. On an ordinary host this is mount -o remount,nosuid /tmp or the fstab entry. auditd: the staged rule watches both crowns for writes and attribute changes; command -v finds auditctl, pgrep finds no daemon: rule staged, not loaded, stated with its dependency. NO_NEW_PRIVS: grep on /proc/1/status shows 1: the control this lab proved live, set on the whole tree, the reason the planted crown never transferred.

bash
$ echo '--- PREVENTION 1: nosuid mounts ignore the bit at exec'
findmnt -n -o OPTIONS /tmp | tr ',' '\n' | grep nosuid && echo '/tmp: nosuid present (this lab, live)'
findmnt -n -o OPTIONS / | tr ',' '\n' | grep -q nosuid && echo '/: nosuid present' || echo '/: no nosuid flag'
echo '--- PREVENTION 2: auditd watches the plant (staged; daemon absent, stated plainly)'
cat > /tmp/gh026/ghostlight-026.rules <<'REOF'
-w /tmp/gh026/crown -p wa -k setuid_plant
-w /tmp/gh026/crown-g -p wa -k setgid_plant
REOF
cat /tmp/gh026/ghostlight-026.rules
command -v auditctl
pgrep -x auditd >/dev/null && echo 'auditd running: rules loadable' || echo 'auditd NOT running: rule staged, not loaded'
echo '--- PREVENTION 3: NO_NEW_PRIVS, the control this lab proved live'
grep NoNewPrivs /proc/1/status
echo 'set on the whole tree: even PID 1 carries it'
--- PREVENTION 1: nosuid mounts ignore the bit at exec
nosuid
nosuid
/tmp: nosuid present (this lab, live)
/: no nosuid flag
--- PREVENTION 2: auditd watches the plant (staged; daemon absent, stated plainly)
-w /tmp/gh026/crown -p wa -k setuid_plant
-w /tmp/gh026/crown-g -p wa -k setgid_plant
/usr/sbin/auditctl
auditd NOT running: rule staged, not loaded
--- PREVENTION 3: NO_NEW_PRIVS, the control this lab proved live
NoNewPrivs:	1
set on the whole tree: even PID 1 carries it
5

Teardown

rm -rf /tmp/gh026: the lab, the crowns, the evidence copies, the staged rule, all gone. ls -A /tmp: the private tmp is empty. The namespace's death reaps every stray.

bash
$ echo '--- teardown: remove the lab'
rm -rf /tmp/gh026
ls -A /tmp
echo 'private /tmp empty; namespace death reaps every stray'
--- teardown: remove the lab
private /tmp empty; namespace death reaps every stray
Detection verified

The hunt found both planted bits; provenance convicted them (no package owns them); the hashes, stats, and binaries were captured before the strip; the strip removed both bits and the re-run fails closed; nosuid was shown working on the lab's /tmp; the auditd rule is staged with its dependency stated; NO_NEW_PRIVS was proven live as the binding control. The crown never transferred, and every step of that is on the record.

05

Countermeasures

DEFENSE

Three moves, in order: strip with evidence first, sweep on a schedule, harden so the next plant cannot transfer. Each is one way, not the way.

1

Mitigate: capture, strip, verify

Proven first against the planted crowns: the hashes, stats, and binaries are captured into evidence/ BEFORE the strip, because the strip changes the artifact. chmod u-s and chmod g-s take the crowns off; the files stay for forensics. ls -l confirms the s is gone; the re-run fails closed. The plant is contained without deleting the evidence it is made of.

bash
$ echo '--- MITIGATION: evidence first, the bit is stripped second'
mkdir -p /tmp/gh026/evidence
sha256sum /tmp/gh026/crown /tmp/gh026/crown-g | tee /tmp/gh026/evidence/hashes.txt
stat /tmp/gh026/crown /tmp/gh026/crown-g | tee /tmp/gh026/evidence/stat.txt
cp /tmp/gh026/crown /tmp/gh026/crown-g /tmp/gh026/evidence/ && echo 'binaries preserved'
echo '--- now strip the crowns:'
chmod u-s /tmp/gh026/crown
chmod g-s /tmp/gh026/crown-g
ls -l /tmp/gh026/crown /tmp/gh026/crown-g
echo '--- verify: fails closed'
/tmp/gh026/as-nobody /tmp/gh026/crown; echo "rc=$?"
--- MITIGATION: evidence first, the bit is stripped second
7cef9b773849c5822a7ff43ed81d116ec743c4884d66c2bd88657534b3453006  /tmp/gh026/crown
7cef9b773849c5822a7ff43ed81d116ec743c4884d66c2bd88657534b3453006  /tmp/gh026/crown-g
  File: /tmp/gh026/crown
  Size: 16400     	Blocks: 40         IO Block: 4096   regular file
Device: 0,92	Inode: 10          Links: 1
Access: (4755/-rwsr-xr-x)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2026-10-05 10:46:54.802312902 +0000
Modify: 2026-10-05 10:46:54.739024229 +0000
Change: 2026-10-05 10:46:54.800581745 +0000
 Birth: 2026-10-05 10:46:54.711581745 +0000
  File: /tmp/gh026/crown-g
  Size: 16400     	Blocks: 40         IO Block: 4096   regular file
Device: 0,92	Inode: 13          Links: 1
Access: (2755/-rwxr-sr-x)  Uid: (    0/    root)   Gid: (65534/ nogroup)
Access: 2026-10-05 10:46:54.812859131 +0000
Modify: 2026-10-05 10:46:54.808801204 +0000
Change: 2026-10-05 10:46:54.812633242 +0000
 Birth: 2026-10-05 10:46:54.807581745 +0000
binaries preserved
--- now strip the crowns:
-rwxr-xr-x 1 root root    16400 Oct  5 10:46 /tmp/gh026/crown
-rwxr-xr-x 1 root nogroup 16400 Oct  5 10:46 /tmp/gh026/crown-g
--- verify: fails closed
uid=65534 euid=65534 gid=65534 egid=65534
open: Permission denied
rc=1

Honest limit. Stripping the bit ends this plant's future, not its past: the binary is still on disk, and the incident's real question is how the attacker wrote as root in the first place. If that access is still open, the attacker re-adds the bit with one chmod and the next hunt starts over. The strip is containment of the artifact, not of the intrusion: pair it with the root-cause hunt.

2

Monitor: sweep the bits on a schedule

The scheduled form of the phase-blue hunt: find / -perm -4000 -o -perm -2000 on a timer (the lab ran it scoped to /tmp/gh026), diffed against the known-good inventory, alerting only on the diff. The tell is concrete: good is package-owned in a system path; bad is unowned, or owned wrong, or somewhere a crown has no business being. Production versions add the inventory and the alerting, not new ideas. This is D3-FIM as a cron job: watch the setuid inventory, notice when it changes.

bash
$ echo '--- DETECTION: the listing, read by someone who knows where the s hides'
ls -l /tmp/gh026
echo '--- hunt: every setuid bit under the lab'
find /tmp/gh026 -perm -4000 -ls
echo '--- hunt: every setgid bit under the lab'
find /tmp/gh026 -perm -2000 -ls
--- DETECTION: the listing, read by someone who knows where the s hides
total 56
-rwxr-xr-x 1 root root      527 Oct  5 10:46 as-nobody
-rwsr-xr-x 1 root root    16400 Oct  5 10:46 crown
-rwxr-sr-x 1 root nogroup 16400 Oct  5 10:46 crown-g
-rw-r--r-- 1 root root      875 Oct  5 10:46 crown.c
-rw------- 1 root root       22 Oct  5 10:46 vault
-rw-r----- 1 root nogroup    24 Oct  5 10:46 vault-g
--- hunt: every setuid bit under the lab
       10     20 -rwsr-xr-x   1 root     root        16400 Oct  5 10:46 /tmp/gh026/crown
--- hunt: every setgid bit under the lab
       13     20 -rwxr-sr-x   1 root     nogroup     16400 Oct  5 10:46 /tmp/gh026/crown-g

Honest limit. The sweep finds bits, not intent: every sudo, su, and newgrp on the box matches -perm -4000, so an unbaselined sweep pages the on-call for the operating system. The scheduled form needs the known-good inventory (dpkg -S output, or a recorded find baseline) and alerts only on the diff. And the interval sets the floor: a plant that is used and removed between sweeps leaves no find trace behind; only the auditd watch, if running, sees it.

3

Prevent: nosuid, inventory, auditd, NO_NEW_PRIVS

Four controls, in increasing strength. nosuid on writable mounts: shown live on this lab's /tmp; on an ordinary host, mount -o remount,nosuid or the fstab entry. Inventory reduction: baseline the legitimate setuid inventory with dpkg -S and chmod u-s what the host does not need (a procedure for the reader's own hosts; this lab touches no host binaries). auditd: the staged rule watches crowned files for writes and attribute changes, loaded where the daemon runs. NO_NEW_PRIVS: proven live in the red phase as the binding control: with it set, no planted crown can ever transfer.

bash
$ echo '--- PREVENTION 1: nosuid mounts ignore the bit at exec'
findmnt -n -o OPTIONS /tmp | tr ',' '\n' | grep nosuid && echo '/tmp: nosuid present (this lab, live)'
findmnt -n -o OPTIONS / | tr ',' '\n' | grep -q nosuid && echo '/: nosuid present' || echo '/: no nosuid flag'
echo '--- PREVENTION 2: auditd watches the plant (staged; daemon absent, stated plainly)'
cat > /tmp/gh026/ghostlight-026.rules <<'REOF'
-w /tmp/gh026/crown -p wa -k setuid_plant
-w /tmp/gh026/crown-g -p wa -k setgid_plant
REOF
cat /tmp/gh026/ghostlight-026.rules
command -v auditctl
pgrep -x auditd >/dev/null && echo 'auditd running: rules loadable' || echo 'auditd NOT running: rule staged, not loaded'
echo '--- PREVENTION 3: NO_NEW_PRIVS, the control this lab proved live'
grep NoNewPrivs /proc/1/status
echo 'set on the whole tree: even PID 1 carries it'
--- PREVENTION 1: nosuid mounts ignore the bit at exec
nosuid
nosuid
/tmp: nosuid present (this lab, live)
/: no nosuid flag
--- PREVENTION 2: auditd watches the plant (staged; daemon absent, stated plainly)
-w /tmp/gh026/crown -p wa -k setuid_plant
-w /tmp/gh026/crown-g -p wa -k setgid_plant
/usr/sbin/auditctl
auditd NOT running: rule staged, not loaded
--- PREVENTION 3: NO_NEW_PRIVS, the control this lab proved live
NoNewPrivs:	1
set on the whole tree: even PID 1 carries it

Honest limit. nosuid does not strip existing bits and does not cover other mounts: an attacker who can write to a non-nosuid mount simply plants there, which is why the control ships with the sweep, not instead of it. Inventory reduction has its own price: sudo needs its bit, and stripping a legitimate crown breaks the tool, so test before stripping. auditd needs the daemon running with rules loaded, and root can stop the daemon: it is a witness, not a wall. NO_NEW_PRIVS is the strongest of the four and the bluntest: it neuters every setuid transition on the box, legitimate tools included, which is why it lives in sandboxes and containers, not on general-purpose hosts.

Countermeasures verified

The planted bits were captured and stripped with the re-run failing closed; the scheduled sweep names its bit pattern, its baseline, and its interval floor; nosuid was shown live with its relocation bypass stated; the auditd rule is staged with the daemon dependency stated; NO_NEW_PRIVS was proven as the binding control with its price named. Every control names its bypass.

06

Debrief

TAKEAWAY

The setuid bit is a request the kernel may refuse: scanners read the request in the mode bits, but only the exec path decides the effective identity. Hunt the bit, convict by provenance, strip with evidence first, harden the mounts.

IOC checklist: signs this technique was used

  • A file with mode 4755 or 2755 outside /usr/bin, /bin, /usr/sbin (the planted crown's shape)
  • A setuid/setgid binary that no package owns (dpkg -S answers "no path found matching pattern")
  • A setuid binary with a recent mtime in a world-writable directory
  • A setuid binary whose owner or group does not match the package default (chown drift on a legitimate path)
  • auditd write/attribute records on a crowned binary, where the watch runs

Reproducibility checklist

  • Verified on Ubuntu 24.04.5 LTS, gcc 13.3.0, x86-64, on 2026-10-05
  • Both recordings are real executions on that platform, not simulations
  • The lab runs as root inside a PID and mount namespace (unshare -pfm --mount-proc) with a private /tmp; the lab directory is /tmp/gh026
  • This sandbox runs NO_NEW_PRIVS on the whole process tree (verified on PID 1) and forces nosuid on new mounts: the plant is real, the transfer is refused, both verified live with a control run on the root filesystem
  • Cleanup: rm -rf /tmp/gh026 (recorded); the namespace's death reaps every stray

Sources

MITRE ATT&CK T1548.001: Abuse Elevation Control Mechanism: Setuid and Setgid
MITRE ATT&CK T1548: Abuse Elevation Control Mechanism (the parent technique)
chmod(1) (the 4000/2000 modes)
find(1) (the -perm hunt)
prctl(2) (PR_SET_NO_NEW_PRIVS, the binding control)
mount(8) (the nosuid flag)
MITRE D3FEND: D3-FH, D3-FIM

Next file

GH-027 The Palimpsest

The next file overwrites a process's own command line and watches the process list report the forgery.