Skip to content
SQL injection Write-up Advanced

SQL Injection: Utilizing XML Functions in Oracle and PostgreSQL to bypass WAFs

The author found SQL injection in an Oracle-backed endpoint and a PostgreSQL-backed endpoint, but a WAF blocked common payloads. They used built-in XML functions to execute hex-encoded queries and regex or XPath checks to extract data without triggering the WAF.

Mahmoud Gamal Follow

Published on mahmoudsec.blogspot.com

February 13, 2023

Mahmoud Gamal, on mahmoudsec.blogspot.com

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 application passed user input directly into SQL queries without proper parameterisation, and the WAF relied on keyword matching that could be evaded with database XML functions and hex encoding.

Impact

An attacker could extract arbitrary data from the database, bypassing the WAF's protections.

What the attacker needed

Unauthenticated access to endpoint; WAF present but bypassable

How it was found

  1. Found an unauthenticated endpoint that took an id parameter.
  2. Tested the id parameter with a boolean condition and saw different responses, confirming SQL injection.
  3. Tried normal injection queries but the WAF blocked keywords like select, from and dual.
  4. Used Oracle XML functions to execute a hex-encoded query and REGEXP_LIKE to get a boolean result.
  5. For PostgreSQL, used query_to_xml with hex-encoded query and xpath_exists for boolean or error-based extraction.

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.

SQL injection lets an attacker insert database commands into a web request. A web application firewall (WAF) tries to block such attacks by matching known patterns. Here the author used database features that turn a query into XML, hiding the real query in hex so the WAF did not recognise it.

What is SQL injection?

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

More by Mahmoud Gamal

View all

4 more disclosed reports, best first.

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.