The idea
Selma has a signed engagement against Droitwich Retail and a foothold on a point-of-sale back-office host as the
service account till. This box looks careful: no broad sudo rule, no stray setuid bit. till may
run exactly one root command with no password — a "nightly check" wrapper, with no arguments to abuse.
The hole is not in the wrapper's text; it is in how it finds its tools. The script calls date and uptime by
bare name, leaving the shell to resolve them through PATH. And sudo's secure_path — the PATH it hands
a root command — has a world-writable directory at its front. Put a program named date there and the trusted
wrapper runs your date, as root. You will read the rule, spot the two halves of the mistake, and use them.
Steps
-
The foothold, and the wall it stops at
You are on Selma's Kali box. The foothold is an SSH login on the POS host at
10.0.1.20as the service accounttill. Click Start to open a shell there, confirm who you are withid, then try/etc/shadowand watch it refused. That wall is what the sudo rule — used the wrong way — will get you past.kali:~# ssh box
-
Read the one rule you have
First question on any foothold: what may this account run as root?
sudo -n -llists it without prompting for a password (-n, non-interactive — it either tells you or fails, it never hangs). Read the whole answer, not only the command line: sudo prints the Defaults that apply to you as well, and that is wheresecure_pathis.kali:~# ssh box 'sudo -n -l'
-
Two innocent facts that are not
Look at the wrapper and at that first
secure_pathdirectory. The script is world-readable, so read it. It callsdateanduptimeby bare name — no/usr/bin/in front — so the shell resolves them throughPATH. And/opt/ops/bin, first in thatPATH, is world-writable. Either alone is a shrug; together, anything you drop in/opt/ops/binnameddateis what the root wrapper runs.kali:~# ssh box 'cat /usr/local/bin/ops-health; echo ---; ls -ld /opt/ops/bin'
-
Shadow the tool, run the wrapper
Plant a
dateof your own in/opt/ops/bin— a tiny script that prints who it is and reads the hash file — then trigger the wrapper withsudo. sudo runsops-healthas root with the box'ssecure_path; the wrapper's baredateresolves to your/opt/ops/bin/datefirst, and it runs as root. Youridcomes backuid=0(root), and/etc/shadow— refused in step one — prints.kali:~# ssh box 'printf "#!/bin/sh\nid\ncat /etc/shadow\n" > /opt/ops/bin/date && chmod +x /opt/ops/bin/date && ls -l /opt/ops/bin/date' kali:~# ssh box 'sudo /usr/local/bin/ops-health'
-
What Droitwich's admin should change
Selma's finding is not "sudo is dangerous" or "ops-health is bad" — the rule was meant to be tight. It is that a root program that resolves its tools through a writable PATH is a root shell. The fixes, any one of which closes it:
- Call tools by absolute path. In
ops-health,/usr/bin/dateand/usr/bin/uptimeinstead of bare names. Then noPATHentry can shadow them, writable or not. - Fix secure_path. It should list only root-owned, root-writable directories — never
/opt/ops/binwhile it is0777. Either tighten the directory to0755root-owned, or drop it fromsecure_path. - Audit for writable PATH directories.
findevery directory on any rootPATHorsecure_paththat a non-root user can write (find … -writable), and close it. The same check catches the next one.
One honest line: running any of this against a system whose owner has not authorised you in writing is unauthorised access, an offence under laws like the UK Computer Misuse Act and the United States' CFAA. Selma has a signed engagement; that permission is the only thing separating this from a crime.
kali:~# ssh box 'ls -ld /opt/ops/bin && grep secure_path /etc/sudoers.d/ops-health'
- Call tools by absolute path. In
Run these steps on real machines