> For the complete documentation index, see [llms.txt](https://pentest.mxhx.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pentest.mxhx.org/03-getting-in/postgres.md).

# Postgres

## Basics

```
postgres
su postgres  .. to get into his shell account
psql         .. to login to sql

Navigate the database:

\list     .... list the databases
\c [DB]   .... to select the database [DATABASE]
\d        .... to list the tables

select * from users;
```

## File Traverse

* You can read a file from psql, that you normally wouldnt be allowed!

```
CREATE TABLE demo(t text);
COPY demo from '[/var/lib/postgresql/9.4/key.txt]';
SELECT * FROM demo;
```

## Find Creds

```
/var/www
cat /var/www/classes/db.php

dbname=photoblog 
user=photoblog 
password=photoblog
>> psql -U photoblog
```
