Skip to content
SQL injection Write-up Advanced

Root user account takeover via SQL Injection

A blind SQL injection in the orgId parameter of a JSON API allowed an attacker to read arbitrary database fields. By reading the unhashed password reset code for the admin user, the attacker could reset the admin password and take over the root account.

SW Follow

Published on infosecwriteups.com

Recently, I discovered a few interesting SQL injections. I came across this while testing an ASP.NET application with an MS SQL Server database at the backend.

SW, on infosecwriteups.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 orgId parameter was concatenated into an SQL query without parameterisation, and password reset codes were stored without hashing.

Impact

An attacker could take over the root user account and access other features, potentially uncovering more bugs.

What the attacker needed

Access to the web application; ability to send crafted JSON requests

The fix

The application should use parameterised queries for the orgId parameter and hash password reset codes before storing them.

How it was found

  1. Find a JS file listing API endpoints and extract parameter names.
  2. Send a single quote in many parameters to many endpoints and look for SQL errors.
  3. Confirm time-based injection with a wait command.
  4. Convert to boolean-based injection using error messages.
  5. Use SQLmap with a custom boolean test to extract data.
  6. Read the admin's password reset code and reset the password.

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 application put user input directly into database queries, so an attacker could ask the database questions and read answers through error messages. The password reset code was stored in plain text, so once the attacker could read it, they could reset the admin's password and log in as the admin.

What is SQL injection?

Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.

More by SW

View all

1 more disclosed report, best first.

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.