Skip to content
SQL injection Write-up Intermediate

How I bypassed Cloudflare's SQL Injection filter

A PHP application had an unsanitised parameter that allowed SQL injection, but Cloudflare's WAF blocked typical time-based blind payloads. The author bypassed the filter by using a boolean-based technique that relied on the server returning 200 OK for true results and 500 Internal Server Error for false results, and by obfuscating the payload with hex encoding and multi-line comments.

astrocamel.com

Published on astrocamel.com

In late 2018 I was tasked with performing a Web Application security assessment for a large client. After running the standard scans with automated tools, something interesting came up: a possible SQL injection which couldn’t be exploited using the tool.

The author, on astrocamel.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

Impact

An attacker could extract arbitrary data from the database, including table and column names and their contents, despite the WAF.

What the attacker needed

Access to the vulnerable web application; ability to send POST requests

The fix

Cloudflare fixed the WAF bypass, and the application should use prepared statements to prevent SQL injection.

How it was found

  1. Send a POST request with multipart form data to /index.php, injecting into the X-MARK parameter.
  2. Observe that a query returning results gives 200 OK, while a query returning no results gives 500 Internal Server Error.
  3. Use a boolean-based injection comparing characters, but replace '=' with a LIKE-based comparison to bypass the WAF.
  4. Hex-encode string literals (e.g., 'a' as 0x61) to avoid the WAF blocking plain strings.
  5. Insert multi-line comments between SQL keywords to evade keyword-based blocking.
  6. Automate the character-by-character extraction with a Python script.

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 the database questions. A firewall tried to block these questions, but the attacker found a way to ask yes/no questions and tell the answer from whether the page loaded normally or showed an error.

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.