I Found an SQL Injection in an Internal API (Behind Cloudflare) — A Full Story from Discovery to Data Dump
An internal API endpoint was vulnerable to SQL injection in the 'id' parameter, allowing an attacker to extract database contents. The tester bypassed Cloudflare WAF protections and dumped user data including emails and hashed passwords.
Published on infosecwriteups.com
This post is a deep dive into how I discovered and exploited an SQL Injection vulnerability in one of our internal APIs, despite it being behind Cloudflare WAF and using a PostgreSQL backend. I’ll walk you through the story from the first scan in Burp Suite to bypassing defenses and dumping sensitive data with SQLMap.
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 built SQL queries by concatenating the user-supplied 'id' parameter directly into the query string without parameterisation.
What the attacker needed
A Bearer token for authentication; access to the internal API endpoint; Cloudflare WAF bypass needed
The fix
The bug was fixed by using parameterized queries, enforcing strict WAF rules, and applying input validation.
How it was found
- Intercept the request to the API endpoint with the 'id' parameter using Burp Suite.
- Run an active scan in Burp Suite, which flags a high-severity SQL injection.
- Manually verify by sending payloads that compare true and false conditions, observing different responses.
- Use SQLMap with the authentication header and PostgreSQL database type to confirm the injection.
- When Cloudflare blocks requests, switch to a random user agent and a tamper script that replaces spaces with comments.
- Use SQLMap to list databases, tables, and dump the users 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.
SQL injection is when user input is inserted directly into a database command, letting an attacker change the command's meaning. Here, the 'id' value in the URL was not properly separated from the SQL query, so adding quotes and conditions could make the database return different results. This let the tester read data from the database.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.