Bypassing WAF to do advanced Error-Based SQL Injection
A news page parameter was vulnerable to SQL injection, and the site's WAF could be bypassed using versioned comments and hex encoding. An attacker could extract database names, table and column names, and user credentials.
medium.com
Published on medium.com
During penetration testing, I faced with a website which on this article I will name it as http://domain.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 concatenated the id parameter directly into a SQL query without parameterisation, and the WAF's pattern matching was bypassed with versioned comments and hex-encoded strings.
Impact
An attacker could extract the database name, table and column names, and user credentials, potentially leading to account takeover.
What the attacker needed
Access to the vulnerable endpoint; no authentication required
How it was found
- Find the news.php endpoint with an id parameter via Google dorking.
- Observe that a bad query produces two error messages, indicating boolean-based injection.
- Use ORDER BY with a boolean condition to determine the number of columns (5).
- Bypass the WAF with versioned comments and use UNION SELECT to find which columns are displayed.
- Dump the database name using database().
- Use a DIOS payload with hex encoding to dump table and column names, then extract username and password from the user table.
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 website put user input directly into a database query, so an attacker could change the query to ask for secret data. A firewall tried to block these queries, but the attacker disguised the query so the firewall did not recognise it. This let the attacker read the database structure and user passwords.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.