Skip to content
SQL injection Write-up Intermediate

Unexpected Zero in MySQL Injection

A search parameter was vulnerable to SQL injection in MySQL, but filters blocked comments, the sleep function and enumeration tricks. The author found that supplying a string expression that MySQL coerces to the integer 0 made the query match all rows, allowing retrieval of all data without comments.

Dimaz Arno Follow

Published on dimazarno.medium.com

When conducting a pentest on a client (sorry, I cannot provide real screenshots here), I discovered a SQL injection vulnerability, but there were some limitations that seemed to be implemented as coding filters.

Dimaz Arno, on dimazarno.medium.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 search value was concatenated into a SQL query without parameterisation, and MySQL's loose type coercion let a string expression evaluate to 0, matching all rows.

Impact

An attacker could retrieve all rows from the queried table despite the filters, though the text does not show extraction of other data such as credentials.

What the attacker needed

A reachable search endpoint; no authentication stated

How it was found

  1. Test the search parameter with simple MySQL function calls to confirm injection.
  2. Observe that comments, sleep and substring-based enumeration are filtered or give no output.
  3. Reproduce the behaviour in an online MySQL interface by putting a string-plus-zero expression in a WHERE clause.
  4. Confirm the same behaviour on a local MySQL instance and note PostgreSQL errors instead.
  5. Send a string-plus-zero expression through the vulnerable parameter to return all records.

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 website was building a database query directly from what a user typed into a search box, so extra database code could be slipped in. Normally an attacker adds special characters to comment out the rest of the query, but those characters were blocked here. The author noticed that MySQL quietly treats a piece of text plus zero as the number zero, and a query asking for zero matches every row, so all records came back.

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.