The idea
Enumeration did its job: you hold the lever, carried here as evidence — a Setuid and setgid binary at
/usr/bin/nice. Now you use it. The skill of this
stage is not memorising one trick; it is matching the escalation to the lever. A lever has a kind, and each
kind wants a different move: a sudo rule wants sudo <binary>, a file capability wants the capability
escape, and a setuid bit wants you to run the binary so its root privileges carry into a shell you control.
GTFOBins is the lookup that, binary by binary, gives the exact line. You will read your lever's kind,
pick the matching move, and climb it to a root read of /etc/shadow — the file ops was refused.
Steps
-
The lever you carry
Place yourself first. Click Start to open the foothold shell as
ops, then read two things: the appliance's record of the lever you carried in, and the lever itself on disk. The record names itskindand where it is;ls -lshows thesin-rwsr-xr-xthat makes it dangerous.Read that
scarefully, because the whole climb turns on it. It is the Setuid and setgid bit: anyone who runs/usr/bin/niceruns it as its owner,root.niceis an ordinary scheduling helper — but a scheduling helper that runs as root, and can launch any program you hand it, is a door to root. That is the lever's kind, and the kind decides the move.attacker:~# ssh box
-
Match the move to the lever
Before you type anything, make the call this stage is really about: which escape fits this lever? A lever is not one trick — it has a kind, and the kind picks the move:
- A sudo rule (
opsmay run a program as root): the move issudo <binary>, and you make that binary launch a shell — the escape runs throughsudo. - A file capability (a binary granted a slice of root's powers, like
cap_setuid): the move is that binary's capability escape — nosudo, no setuid bit, the power is baked into the file. - A setuid bit (your lever): the move is to run the binary directly. Because the setuid bit already makes
it run as root, you do not need
sudoor a capability — you make the binary spawn a shell, and the shell inherits root.
Your lever's kind is
suid, so the move is the setuid escape: runnice, and have it launch/bin/sh. One detail matters — the shell must keep the borrowed privileges with-p. Without it, a careful shell drops back toopson start; withsh -p, it stays root. GTFOBins gives this exact line fornice. - A sudo rule (
-
Climb it to root
Now run the escape.
nice /bin/sh -ptells the setuid-rootniceto launch a shell, and-pkeeps that shell running with root's privileges. Put a command after it with-cand it runs that command as root. First prove it withid, then take the prize:cat /etc/shadow, the fileopswas flatly refused in the last playbook.Watch what
idreports:euid=0(root). Your real user is stillops— the login never changed — but your effective user, the one the kernel checks against every file, is now root. That is enough: the shadow file is read against the effective user, so root's effective privileges open it. A borrowed-power shell like this is a full foothold into root's world.attacker:~# ssh box 'nice /bin/sh -p -c "id"' attacker:~# ssh box 'nice /bin/sh -p -c "cat /etc/shadow"'
-
The defender's answer
The climb turned on one thing: a binary carrying a setuid bit it never needed. Take the bit away and the lever is gone —
chmod u-s /usr/bin/nicedrops it, andnicegoes back to running as whoever calls it. Do that, then run the exact same escape again and watch it come up empty: no borrowed root, onlyops.That is the defender's whole answer to this stage, and it is least privilege: a program should hold only the powers its job needs. The fixes line up behind that one idea — audit the setuid binaries and drop the bit from any that do not truly need it, scope sudo rules to a short list of commands rather than a blanket grant, and grant capabilities narrowly instead of reaching for a setuid bit. Climbing a lever is a one-liner; the work that stops it is making sure no such lever is ever left lying around.
dispatch:~# chmod u-s /usr/bin/nice attacker:~# ssh box 'nice /bin/sh -p -c "id"'
Run these steps on real machines