Skip to content
SQL injection Write-up Advanced

1. Introduction

A PL/pgSQL function built dynamic SQL by placing user input into an unquoted column-name position, and its regex sanitizer stripped single quotes, semicolons, backslashes and hyphens but not dollar signs. An attacker could use dollar-quoted strings and scalar subqueries to perform blind SQL injection and extract data through a boolean oracle, though a default OWASP CRS WAF blocked the payloads.

jrbusiness.github.io

Published on jrbusiness.github.io

We present a blind SQL injection technique that exploits PostgreSQL's dollar-quoting string syntax to evade an application-level regex sanitizer. By injecting scalar subqueries through unquoted column-name positions in dynamically-constructed EXECUTE statements, an attacker can enumerate all database objects visible…

Jerry Luong, on jrbusiness.github.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the function concatenated user input into an unquoted SQL identifier position and relied on a regex denylist that did not account for PostgreSQL dollar-quoting.

Impact

An attacker could enumerate database objects and extract arbitrary data visible to the executing role, but a default OWASP CRS 4.25.0 WAF blocked the payloads, so the technique only works against applications with a custom sanitizer and no WAF or a weaker WAF.

What the attacker needed

HTTP access to an endpoint using the vulnerable function; Observable boolean oracle (rows vs no rows); No prior schema knowledge needed; Executing role can read target data

The fix

The function should use format() with %I for identifiers and %L for literals, or parameterise queries, and should not rely on regex denylists.

How it was found

  1. Send a filter string containing a scalar subquery in the column-name position, using dollar-quoted literals to avoid stripped characters.
  2. Ensure the payload contains exactly one equals sign at the top level so the function's split_part parsing works.
  3. Use lowercase 'and' inside subqueries to avoid being split on uppercase ' AND '.
  4. Observe whether products are returned (TRUE) or not (FALSE) to infer the subquery result.
  5. Enumerate schemas, tables, columns and rows via information_schema using boolean probes.
  6. Extract data character by character using substr or ascii comparisons.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

The application took a user-supplied filter and pasted part of it directly into a database command without wrapping it in quotes. The developer tried to clean the input by removing certain characters, but missed the dollar sign, which PostgreSQL uses to mark string literals. This let an attacker sneak in extra database instructions and ask yes/no questions to slowly read out secrets.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

Similar reports

View all

Same bug class and techniques, clearest first.

SQL injection

The lesson behind this report.

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.