Sunday

Sunday
Sistema operativo Dificultad Fecha de Lanzamiento Creador
Linux Easy 28 Abril 2018 Agent22

Resumen

En este post, abordaremos la máquina Sunday de la plataforma HTB. Comenzaremos aprovechando el servicio Finger (puerto 79) para enumerar usuarios potenciales. Tras identificar algunos usuarios, realizaremos un ataque de fuerza bruta al protocolo SSH utilizando Hydra y un diccionario de contraseñas personalizado para obtener acceso al sistema. Una vez dentro, llevaremos a cabo una enumeración básica y encontraremos un archivo shadow con hashes de contraseñas, los cuales descifraremos para obtener la contraseña de otro usuario. Con estas nuevas credenciales, accederemos nuevamente al sistema. Finalmente, realizaremos una escalada de privilegios sencilla aprovechando una mala configuración de sudo.

Reconocimiento

Lanzamos una traza ICMP a la máquina objetivo para comprobar que tengamos conectividad.

sunday

Enumeración inicial

Realizamos un escaneo con nmap para descubrir que puertos TCP se encuentran abiertos en la máquina víctima.

 nmap -sS -p- --min-rate 5000 -Pn -n 10.10.10.76 -oG open_ports -vvv
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-07-07 10:53 EDT
Initiating SYN Stealth Scan at 10:53
Scanning 10.10.10.76 [65535 ports]
Discovered open port 111/tcp on 10.10.10.76
Discovered open port 515/tcp on 10.10.10.76
Warning: 10.10.10.76 giving up on port because retransmission cap hit (10).
SYN Stealth Scan Timing: About 22.84% done; ETC: 10:55 (0:01:45 remaining)
Discovered open port 79/tcp on 10.10.10.76
SYN Stealth Scan Timing: About 45.31% done; ETC: 10:55 (0:01:14 remaining)
Discovered open port 22022/tcp on 10.10.10.76
SYN Stealth Scan Timing: About 67.72% done; ETC: 10:55 (0:00:43 remaining)
Discovered open port 6787/tcp on 10.10.10.76
Completed SYN Stealth Scan at 10:55, 139.95s elapsed (65535 total ports)
Nmap scan report for 10.10.10.76
Host is up, received user-set (0.15s latency).
Scanned at 2024-07-07 10:53:01 EDT for 140s
Not shown: 60025 filtered tcp ports (no-response), 5505 closed tcp ports (reset)
PORT      STATE SERVICE   REASON
79/tcp    open  finger    syn-ack ttl 59
111/tcp   open  rpcbind   syn-ack ttl 63
515/tcp   open  printer   syn-ack ttl 59
6787/tcp  open  smc-admin syn-ack ttl 59
22022/tcp open  unknown   syn-ack ttl 63

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 140.03 seconds
           Raw packets sent: 694791 (30.571MB) | Rcvd: 5526 (221.064KB)

Lanzamos una serie de script básicos de enumeración propios de nmap, para conocer la versión y servicio que esta corriendo bajo los puertos.

> nmap -sCV -p79,111,515,6787,22022 10.10.10.76 -oN service_scan -vvv
# Nmap 7.94SVN scan initiated Sun Jul  7 11:00:19 2024 as: nmap -sCV -p79,111,515,6787,22022 -oN service_scan -vvv 10.10.10.76
Nmap scan report for 10.10.10.76 (10.10.10.76)
Host is up, received echo-reply ttl 254 (0.15s latency).
Scanned at 2024-07-07 11:00:19 EDT for 106s

PORT      STATE SERVICE REASON         VERSION
79/tcp    open  finger? syn-ack ttl 59
|_finger: No one logged on\x0D
| fingerprint-strings: 
|   GenericLines: 
|     No one logged on
|   GetRequest: 
|     Login Name TTY Idle When Where
|     HTTP/1.0 ???
|   HTTPOptions: 
|     Login Name TTY Idle When Where
|     HTTP/1.0 ???
|     OPTIONS ???
|   Help: 
|     Login Name TTY Idle When Where
|     HELP ???
|   RTSPRequest: 
|     Login Name TTY Idle When Where
|     OPTIONS ???
|     RTSP/1.0 ???
|   SSLSessionReq, TerminalServerCookie: 
|_    Login Name TTY Idle When Where
111/tcp   open  rpcbind syn-ack ttl 63 2-4 (RPC #100000)
515/tcp   open  printer syn-ack ttl 59
6787/tcp  open  http    syn-ack ttl 59 Apache httpd
|_http-server-header: Apache
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-title: 400 Bad Request
22022/tcp open  ssh     syn-ack ttl 63 OpenSSH 8.4 (protocol 2.0)
| ssh-hostkey: 
|   2048 aa:00:94:32:18:60:a4:93:3b:87:a4:b6:f8:02:68:0e (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDsG4q9TS6eAOrX6zI+R0CMMkCTfS36QDqQW5NcF/v9vmNWyL6xSZ8x38AB2T+Kbx672RqYCtKmHcZMFs55Q3hoWQE7YgWOJhXw9agE3aIjXiWCNhmmq4T5+zjbJWbF4OLkHzNzZ2qGHbhQD9Kbw9AmyW8ZS+P8AGC5fO36AVvgyS8+5YbA05N3UDKBbQu/WlpgyLfuNpAq9279mfq/MUWWRNKGKICF/jRB3lr2BMD+BhDjTooM7ySxpq7K9dfOgdmgqFrjdE4bkxBrPsWLF41YQy3hV0L/MJQE2h+s7kONmmZJMl4lAZ8PNUqQe6sdkDhL1Ex2+yQlvbyqQZw3xhuJ
|   256 da:2a:6c:fa:6b:b1:ea:16:1d:a6:54:a1:0b:2b:ee:48 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAII/0DH8qZiCfAzZNkSaAmT39TyBUFFwjdk8vm7ze+Wwm
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port79-TCP:V=7.94SVN%I=7%D=7/7%Time=668AAD8A%P=x86_64-pc-linux-gnu%r(Ge
SF:nericLines,12,"No\x20one\x20logged\x20on\r\n")%r(GetRequest,93,"Login\x
SF:20\x20\x20\x20\x20\x20\x20Name\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\
SF:x20\x20\x20\x20\x20TTY\x20\x20\x20\x20\x20\x20\x20\x20\x20Idle\x20\x20\
SF:x20\x20When\x20\x20\x20\x20Where\r\n/\x20\x20\x20\x20\x20\x20\x20\x20\x
SF:20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\?\?\?\r\nGET\x20\x20
SF:\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\?\
SF:?\?\r\nHTTP/1\.0\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x2
SF:0\?\?\?\r\n")%r(Help,5D,"Login\x20\x20\x20\x20\x20\x20\x20Name\x20\x20\
SF:x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20TTY\x20\x20\x20\x20\
SF:x20\x20\x20\x20\x20Idle\x20\x20\x20\x20When\x20\x20\x20\x20Where\r\nHEL
SF:P\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x
SF:20\?\?\?\r\n")%r(HTTPOptions,93,"Login\x20\x20\x20\x20\x20\x20\x20Name\
SF:x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20TTY\x20\x20\
SF:x20\x20\x20\x20\x20\x20\x20Idle\x20\x20\x20\x20When\x20\x20\x20\x20Wher
SF:e\r\n/\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\
SF:x20\x20\x20\x20\x20\?\?\?\r\nHTTP/1\.0\x20\x20\x20\x20\x20\x20\x20\x20\
SF:x20\x20\x20\x20\x20\x20\?\?\?\r\nOPTIONS\x20\x20\x20\x20\x20\x20\x20\x2
SF:0\x20\x20\x20\x20\x20\x20\x20\?\?\?\r\n")%r(RTSPRequest,93,"Login\x20\x
SF:20\x20\x20\x20\x20\x20Name\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\
SF:x20\x20\x20\x20TTY\x20\x20\x20\x20\x20\x20\x20\x20\x20Idle\x20\x20\x20\
SF:x20When\x20\x20\x20\x20Where\r\n/\x20\x20\x20\x20\x20\x20\x20\x20\x20\x
SF:20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\?\?\?\r\nOPTIONS\x20\x20
SF:\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\?\?\?\r\nRTSP/1\.0
SF:\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\?\?\?\r\n")%r(
SF:SSLSessionReq,5D,"Login\x20\x20\x20\x20\x20\x20\x20Name\x20\x20\x20\x20
SF:\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20TTY\x20\x20\x20\x20\x20\x20
SF:\x20\x20\x20Idle\x20\x20\x20\x20When\x20\x20\x20\x20Where\r\n\x16\x03\x
SF:20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\
SF:x20\x20\?\?\?\r\n")%r(TerminalServerCookie,5D,"Login\x20\x20\x20\x20\x2
SF:0\x20\x20Name\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x
SF:20TTY\x20\x20\x20\x20\x20\x20\x20\x20\x20Idle\x20\x20\x20\x20When\x20\x
SF:20\x20\x20Where\r\n\x03\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20
SF:\x20\x20\x20\x20\x20\x20\x20\x20\x20\?\?\?\r\n");

Read data files from: /usr/bin/../share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Sun Jul  7 11:02:05 2024 -- 1 IP address (1 host up) scanned in 106.32 seconds

Enumeración de servicios

sunday

sunday

sunday

Por lo tanto cambiamos la url a https://10.10.10.76:6787 lo cual nos redirigue a la siguiente web.

sunday

Oracle Solaris es un sistema operativo Unix desarrollado por Oracle, conocido por su escalabilidad, seguridad y gestión avanzada. Sus características principales incluyen el sistema de archivos ZFS, la herramienta de análisis DTrace, la virtualización con Zones y la gestión de servicios SMF. Es popular en entornos empresariales críticos.

Probamos ingresar con admin:admin y credeciales tipicas pero nada.

Explotación inicial

Puerto 79 - Finger

https://book.hacktricks.xyz/network-services-pentesting/pentesting-finger

El programa/servicio Finger se utiliza para recuperar detalles sobre los usuarios de computadoras. Normalmente, la información proporcionada incluye el nombre de inicio de sesión del usuario, el nombre completo y, en algunos casos, detalles adicionales. Estos detalles adicionales podrían abarcar la ubicación de la oficina y el número de teléfono (si está disponible), la hora a la que el usuario inició sesión, el período de inactividad (tiempo de inactividad), la última vez que el usuario leyó el correo y el contenido del plan y archivos del proyecto.

Banner Grabbing/Basic connection

 nc -vn 10.10.10.76 79
(UNKNOWN) [10.10.10.76] 79 (finger) open
 echo "root" | nc -vn 10.10.10.76 79
(UNKNOWN) [10.10.10.76] 79 (finger) open
Login       Name               TTY         Idle    When    Where
root     Super-User            ssh          <Dec  7, 2023> 10.10.14.46  

Podemos enumerar usuarios utilizando la herramienta finger

 finger admin@10.10.10.76
Login       Name               TTY         Idle    When    Where
adm      Admin                              < .  .  .  . >
dladm    Datalink Admin                     < .  .  .  . >
netadm   Network Admin                      < .  .  .  . >
netcfg   Network Configuratio               < .  .  .  . >
dhcpserv DHCP Configuration A               < .  .  .  . >
ikeuser  IKE Admin                          < .  .  .  . >
lp       Line Printer Admin                 < .  .  .  . >

https://github.com/pentestmonkey/finger-user-enum/blob/master/finger-user-enum.pl

Podemos utilizar la herrameinta finger-user-enum.pl

 perl finger-user-enum.pl -U /usr/share/wordlists/seclists/Usernames/xato-net-10-million-usernames.txt -t 10.10.10.76
Starting finger-user-enum v1.0 ( http://pentestmonkey.net/tools/finger-user-enum )

 ----------------------------------------------------------
|                   Scan Information                       |
 ----------------------------------------------------------

Worker Processes ......... 5
Usernames file ........... /usr/share/wordlists/seclists/Usernames/xato-net-10-million-usernames.txt
Target count ............. 1
Username count ........... 8295455
Target TCP port .......... 79
Query timeout ............ 5 secs
Relay Server ............. Not used

######## Scan started at Sun Jul  7 11:32:42 2024 #########
admin@10.10.10.76: Login       Name               TTY         Idle    When    Where..adm      Admin                              < .  .  .  . >..dladm    Datalink Admin                     < .  .  .  . >..netadm   Network Admin                      < .  .  .  . >..netcfg   Network Configuratio               < .  .  .  . >..dhcpserv DHCP Configuration A               < .  .  .  . >..ikeuser  IKE Admin                          < .  .  .  . >..lp       Line Printer Admin                 < .  .  .  . >..
root@10.10.10.76: root     Super-User            ssh          <Dec  7, 2023> 10.10.14.46         ..
access@10.10.10.76: access No Access User                     < .  .  .  . >..nobody4  SunOS 4.x NFS Anonym               < .  .  .  . >..
sammy@10.10.10.76: sammy           ???            ssh          <Apr 13, 2022> 10.10.14.13         ..
7777777@10.10.10.76: Login       Name               TTY         Idle    When    Where..pkg5srv  pkg(7) server UID                  < .  .  .  . >..
777777@10.10.10.76: Login       Name               TTY         Idle    When    Where..pkg5srv  pkg(7) server UID                  < .  .  .  . >..
777@10.10.10.76: Login       Name               TTY         Idle    When    Where..pkg5srv  pkg(7) server UID                  < .  .  .  . >..
sunny@10.10.10.76: sunny           ???            ssh          <Apr 13, 2022> 10.10.14.13         ..
bin@10.10.10.76: bin             ???                         < .  .  .  . >..
7777@10.10.10.76: Login       Name               TTY         Idle    When    Where..pkg5srv  pkg(7) server UID                  < .  .  .  . >..
network@10.10.10.76: Login       Name               TTY         Idle    When    Where..netadm   Network Admin                      < .  .  .  . >..netcfg   Network Configuratio               < .  .  .  . >..
nobody@10.10.10.76: nobody   NFS Anonymous Access               < .  .  .  . >..
77777777@10.10.10.76: Login       Name               TTY         Idle    When    Where..pkg5srv  pkg(7) server UID                  < .  .  .  . >..
77777@10.10.10.76: Login       Name               TTY         Idle    When    Where..pkg5srv  pkg(7) server UID                  < .  .  .  . >..
Admin@10.10.10.76: Admin                 < .  .  .  . >..
films+pic+galeries@10.10.10.76: Login       Name               TTY         Idle    When    Where..films+pic+galeries       ???..

Vemos que existen tres usuarios que accedieron por ssh al sistema. Por lo tanto, podemos realizar fuerza bruta con hydra para encontrar las credenciales.

Podemos utilizar hydra y un diccionario personalizado antes de tirar del rockyou.

usert.txt

root
sunny
sammy

password.txt

root
sunny
sammy
sunday

Genial, descubrimos la contraseña del usuario sunny.

sunday

sunny:sunday

Enumeración / Movimiento lateral

Usuario sunny

sunday

Si enumaros con sudo -l vemos que podemos ejecutar el binario /root/troll sin solicitar contraseña.

sunday

Pero no nos lleva a nada.

Si miramos el archivo .bash_history observamos que se realizo una copia del shadow.

sunday

Si miramos el archivo, nos encontramos con lo siguiente:

sunday

Copiamos el archivo a nuestra máquina atacante y utilizamos john para romper los hashes y obtener la contraseña de sammy.

sunday

sammy:cooldude!

Nos logueamos por ssh con sammy.

Usuario sammy

sunday

Leemos la flag de user.txt

sunday

Elevación de privilegios

Si ejecutamos sudo -l vemos que el usuario sammy puede ejecutar cualquier comando como el usuario root.

sunday

Por lo que escalamos nuestros privilegios haciendo un sudo su -.

sunday

Leemos el flag de root.txt

sunday