Skip to content
SQL injection Write-up Intermediate

XPATH Error Based SQL Injection

The getcolumns parameter of an API endpoint was vulnerable to error-based SQL injection via MySQL's extractvalue and updatexml functions. An attacker could extract the database version and name, and potentially dump sensitive data.

medium.com

Published on medium.com

In this blog, I focus on API security, and SQL Injection real-world exploitation.

webcipher101, on 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 application directly concatenated the getcolumns parameter into a SQL query without parameterisation or validation.

Impact

An attacker could extract complete database schema information, dump sensitive data from all accessible tables, retrieve user credentials and authentication tokens, access call records and telecommunications data, and potentially execute administrative database operations.

What the attacker needed

Access to the API endpoint

How it was found

  1. Send a normal request to the endpoint with an empty getcolumns parameter and observe a success response.
  2. Inject an extractvalue function call with a tilde and version() to trigger an error that reveals the database version.
  3. Inject an updatexml function call with a tilde and database() to trigger an error that reveals the database name.

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 into a database query without proper handling, letting an attacker change the query's meaning. Here, the attacker used special database functions that produce error messages containing the results of other database commands, so the error messages leaked information like the database version and name.

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.