Skip to content
SQL injection Write-up Intermediate

Case: Local File Inclusion-SQLi

A login form on a non-standard HTTP port returned the raw SQL query in its error response, letting the author dump the database and recover credentials. Those credentials then gave access to a file-viewing page that accepted a file path, which was used to read system files and to run an uploaded PHP file as a reverse shell.

medium.com

Published on medium.com

In this scenario, we will exploit the LFI vulnerability to perform a SQL injection attack on the target machine. Then, we will exploit a vulnerability on SUID to elevate privilege.

Baris Dincer, 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 login endpoint concatenated user input into its SQL query and echoed the query in error messages, and the file page passed a user-supplied path straight to a file read without validation.

Impact

An attacker could read the whole database, including user passwords, and then use the file inclusion to run their own code on the server as the web user.

What the attacker needed

Network access to the target; a valid email address for the login form; ability to upload a file to the site

How it was found

  1. Browse to the admin page on the non-standard HTTP port and note the email address shown
  2. Submit a login with a random password and observe the SQL query returned in the error
  3. Run an automated SQL injection scan against the login endpoint to dump the database
  4. Use the recovered credentials to log in to the file page
  5. Supply a file path parameter to read a system file and confirm the inclusion
  6. Upload a PHP file disguised with an image extension, then request it through the file parameter to get a shell

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 login form built a database question (a SQL query) by pasting in whatever the user typed. When the login failed, the site showed that question back, so the author could see how it was built and change the input to make the database reveal stored passwords. Separately, a page that showed a file by name could be pointed at any file on the server, including one the author had uploaded, which then ran as code.

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.