️ From Payload to Pwn: How I Discovered SQL Injection in a BigQ
An update endpoint built on BigQuery concatenated user input directly into SQL, so a crafted value in the name field was executed as a SQL expression. An attacker could read the service account email, project ID, dataset and table names, and column names, and could force errors to confirm execution even without reflected output.
Published on medium.com
While BigQuery is known for its scalability and robustness as Google’s server-less data warehouse, it is still susceptible to the oldest trick in the book: SQL Injection.
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 backend built BigQuery SQL by string interpolation of the JSON name field instead of using parameterised queries.
Impact
The attacker could read the service account email, project ID, dataset names, table names and column names, and could confirm code execution even when output was not reflected.
What the attacker needed
Access to the update endpoint; ability to send JSON requests
The fix
The report recommends parameterised queries, input sanitisation and least-privilege service accounts; it does not state that the issue was fixed.
How it was found
- Intercept a form submission request to the update endpoint and note the name field in the JSON body.
- Send a classic tautology payload in name and observe a BigQuery syntax error mentioning UNION.
- Send a string concatenation payload to confirm expression evaluation, then use SESSION_USER() to retrieve the service account email.
- Query INFORMATION_SCHEMA.SCHEMATA to obtain the project ID and list datasets.
- List tables in a discovered dataset and optionally enumerate columns.
- Use ERROR() or division by zero to confirm execution when output is not reflected.
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 happens when a program builds a database command by gluing user text straight into it, so the text can change the command. Here the name field was placed inside a BigQuery query, letting the tester add extra SQL that ran on the server. That exposed cloud account details and the names of internal datasets and tables.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.