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.
Published on mahmoudsec.blogspot.com
February 13, 2023
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
- Found an unauthenticated endpoint that took an id parameter.
- Tested the id parameter with a boolean condition and saw different responses, confirming SQL injection.
- Tried normal injection queries but the WAF blocked keywords like select, from and dual.
- Used Oracle XML functions to execute a hex-encoded query and REGEXP_LIKE to get a boolean result.
- 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.