Skip to content
SQL injection Write-up Advanced

SQL injection to RCE

A PHP page included a filename taken from a database via an unsanitised 'page' parameter, allowing SQL injection to control the include path. The attacker used a PHP data wrapper to execute arbitrary commands, achieving remote code execution.

medium.com

Published on medium.com

In the next lines I will expose a case that I experimented some days ago working in a penetration testing for one of our customers atOpen Data Security, in my opinion was interest how I needed concatenate a few factors to get the RCE.

Efren Diaz, 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 'page' parameter was concatenated into a SQL query without parameterisation, and the result was used in a PHP include() without validation.

Impact

An attacker could execute arbitrary commands on the server, leading to full compromise.

What the attacker needed

Mod_Security enabled but outdated; Ability to send HTTP requests

How it was found

  1. Send a request to the load.php endpoint with a 'page' parameter containing a SQL injection that uses a UNION SELECT to control the include path.
  2. Bypass Mod_Security by using MySQL versioned comments in the injection.
  3. Use the php://filter wrapper to read source files and confirm the injection works.
  4. Use the data:// wrapper with PHP code that avoids the blocked 'system' string by concatenating 'sy' and 'stem'.
  5. The server executes the command and returns the output.

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 website had a page that loaded other files based on a value from its database. The value came from a URL parameter that was not properly checked, so an attacker could change the database query to make the page load a file of their choice. By loading a special kind of file that contains code, the attacker could run commands on the server.

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.