Don't fear the bark, tsrewrite to dodge the mark
A SQL injection vulnerability was found, but a WAF blocked payloads containing SELECT and FROM. The attacker bypassed the WAF by using PostgreSQL's ts_rewrite function to execute a SELECT statement encoded to avoid the blocked keywords, enabling time-based blind exploitation.
synacktiv.com
Published on synacktiv.com
Written by Gaetan Ferry - 26/11/2020 - in Pentest - Download
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
Impact
An attacker could bypass the WAF and perform time-based blind SQL injection to extract arbitrary data from the database, though the technique is limited to time-based or blind extraction and may be blocked by stricter WAFs.
What the attacker needed
SQL injection vulnerability; WAF blocking SELECT and FROM; PostgreSQL database
How it was found
- Identify a SQL injection point where basic payloads work but SELECT/FROM are blocked.
- Discover that PostgreSQL's ts_rewrite function evaluates its second argument as a SQL query.
- Encode the desired SELECT statement (e.g., using escape encoding) to avoid the blocked keywords.
- Use decode and encode functions to convert the encoded string back to text for ts_rewrite.
- Craft a payload that uses ts_rewrite to execute a time-delay query (pg_sleep) to confirm execution.
- Extend the technique to extract data by using ts_rewrite to return query results, then cast to text for blind 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.
A SQL injection lets an attacker insert database commands into a web form. A firewall (WAF) tried to block common attack words like SELECT and FROM. The attacker found a database function that could run a hidden command without using those words, so they could still steal data.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.