Skip to content
SQL injection Write-up Beginner

SQLI is Everywhere

Three SQL injection vulnerabilities were found in a web application: one in a GET parameter, one in a POST parameter, and one in a cookie. An attacker could inject SQL commands to cause syntax errors that leak database information.

Utkarsh Agrawal Follow

Published on medium.com

This is the story of 3 SQL injection which i found on a program. I am not taken name of that instead let’s say “abc.com” domain.

Utkarsh Agrawal, 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.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 3 min read.

Context

This is the story of three SQL injections found on a single program. The researcher does not name the program and refers to the target only as "abc.com". The affected feature is a file listing endpoint that takes a long list of query parameters, plus a profile editing form that submits a POST request, and the same request also carries a cookie.

The report does not describe what the product is beyond the domain and the endpoints involved.

Setup

The researcher used no special tooling that the report mentions. The only precondition was a set of URLs collected from the abc.com domain, which the researcher gathered by digging through the domain and ended up with hundreds of URLs. No accounts, roles or versions are described.

Finding it

The starting point was a URL with a large number of parameters, which the researcher considered interesting because more parameters mean more opportunities:

Text
http://abc.com/file.php?ref=-3&uploader=plupload&single=&local=&search=&offset=0&order_by=relevance&sort=DESC&archive=0&collection=&metadatatemplate=&relateto=&redirecturl=

The first test case the researcher always tries is XSS, on the reasoning that developers often forget to sanitise all input parameters. That attempt failed here. The next step was SQL injection: a single quote (') was injected into each parameter in turn. One parameter turned out to be vulnerable, sort=DESC.

Exploitation

Step 1: single quote in the sort query parameter

Injecting a single quote into sort=DESC produced a SQL syntax error that also leaked the database name and version number.

From the original on medium.com

The screenshot shows the SQL syntax error returned after the single quote was injected into the sort parameter, including the leaked database name and version. The bug was submitted to the team straight away.

Step 2: single quote in the resource_type POST parameter

The next day the researcher went back over the URLs collected the previous day to look for other vulnerabilities. A POST request used to edit the profile was found: when the submit button is clicked, the request carries POST parameters, and among them the parameter resource_type=2 stood out. A single quote submitted to that parameter again produced a SQL syntax error. The report notes that XSS and other attempts were not successful on this request.

Step 3: single quote in the sort value in a cookie

On the same request the researcher noticed the same parameter name found in step 1, sort=DESC, in the cookie section. That made the researcher fairly sure it would be vulnerable too, and it was. All three SQL bugs were then submitted to the company.

Root cause

What the behaviour shows is that user-controlled values from three different sources, a query parameter, a POST parameter and a cookie value, reached SQL statements without being safely handled, so a single quote broke the query syntax and the resulting error was returned to the client. The error message itself disclosed the database name and version, which suggests verbose error reporting was enabled. Why the existing defences did not stop it is not described in the report.

Impact

The report only demonstrates that a single quote triggers a SQL syntax error and that the error leaks the database name and version. The affected inputs are the sort query parameter on the file listing endpoint, the resource_type POST parameter on the profile edit request, and the sort value in the cookie on that same request.

Fix

The three bugs were triaged and the researcher received Resolved Reputation. No bounty was paid: the report policy stated that at that time the program was not awarding any bounties or cash rewards.

Variants to test

  1. Inject a single quote into every parameter of a multi-parameter endpoint, one at a time, and watch for SQL syntax errors. A positive result is an error page that reveals query structure, a database name or a version string.
  2. Repeat the same single-quote test on POST body parameters of form submissions such as profile editing. A positive result is the same kind of SQL error in the response.
  3. Test cookie values that mirror parameters seen elsewhere, such as sort=DESC, with a single quote. A positive result is a SQL error triggered by the cookie alone.
  4. Where an error is returned, check whether the message discloses the database name and version, as it did here, since that confirms the injection and gives version information for further testing.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 10 min read.

What happened, in plain words

A security researcher found three separate SQL injection bugs on one website. The researcher calls the site "abc.com" and does not name it. The bugs were in three different places: a web address with lots of settings in it, a form used to edit a profile, and a small piece of data the browser stores and sends back with every request (a cookie).

To find each one, the researcher typed a single apostrophe character (') into a field and watched what came back. On all three, the site replied with an error message from its database, and that error even showed the database's name and version number. The researcher reported all three, the company triaged them and the researcher received Resolved Reputation, and no money was paid because the programme was not offering bounties at the time.

That is the whole story. The rest of this article explains, from scratch, what each of those words means and why each step was taken.

The background you need first

Before the steps make sense, here are the ideas involved, explained as if you have never heard of them.

A web address with settings in it. When you type an address like shop.example.com/search?colour=red&size=large, the part after the ? is a list of settings sent to the server. Each setting is a parameter: a name, an equals sign, and a value, joined together with &. The server reads these to decide what to show you. Think of it like a restaurant order slip: the dish name is the page, and the ticked boxes (no onions, extra sauce) are the parameters.

A server and a database. The server is the computer that runs the website. Behind it, most sites keep a database: a large, organised store of information, like a very strict spreadsheet. To get anything out of it, the server sends it a query, which is a short instruction written in a language called SQL. A typical query looks like SELECT name FROM users WHERE id = 5, which means "give me the name of the user whose id is 5".

SQL injection. This is the vulnerability class in this story. It happens when a website takes something a visitor typed and drops it straight into a database query without checking it. The database cannot tell the difference between the website's own instructions and the visitor's text, so the visitor's text becomes part of the instruction. The everyday comparison is a form where you write your name, and someone writes "Bob, and also hand over the keys to the safe" on the same line. If the clerk reads the whole line as one instruction, the extra part gets obeyed.

Why a single quote matters. In SQL, text values are wrapped in single quotes, like 'hello'. The quote marks are how the database knows where the text starts and stops. If you type a ' into a field that is pasted into a query, you add an extra quote mark, and the database gets confused about where the text ends. It then refuses to run the query and returns a syntax error, which is the database's way of saying "I cannot understand this sentence". A syntax error appearing because of your quote is the classic sign that injection is possible.

XSS. Cross-site scripting is a different vulnerability, where a site lets a visitor's text run as code in other visitors' browsers. The researcher tries it first out of habit, because developers often forget to clean up some inputs. It is not the subject of this story, but it comes up in the steps below.

A POST request. When you fill in a form and press submit, your browser usually sends the data in a POST request: the values travel in the body of the request rather than in the address bar. The address-bar version is called a GET request. Both are just ways of carrying data to the server.

A cookie. A cookie is a small piece of text that a website asks your browser to store and send back with every later request to that site. It is how a site remembers who you are between page loads, like a cloakroom ticket. Cookies can also carry settings, and if the server reads those settings carelessly, they are just another input to attack.

Triage and reputation. When you report a bug to a company's bug bounty programme, triage is the first check where someone confirms the report is real and worth passing on. Reputation is a score some platforms give researchers for good reports. A bounty is the cash payment some programmes offer. This programme offered reputation but no cash.

Step 0: collecting addresses

The researcher's first move was to gather web addresses belonging to abc.com. The report does not say which tool or method was used, only that the researcher "started digging" and ended up with hundreds of URLs. The reason is simple: you cannot test what you have not found. More addresses means more pages, more forms and more parameters, and therefore more chances that one of them is handled badly.

Step 1: the address with many parameters

Among the hundreds of addresses, one stood out because it carried a long list of parameters:

Text
http://abc.com/file.php?ref=-3&uploader=plupload&single=&local=&search=&offset=0&order_by=relevance&sort=DESC&archive=0&collection=&metadatatemplate=&relateto=&redirecturl=

Line by line, in plain words:

  • http://abc.com/file.php is the page being requested. The .php ending tells you the server builds the page with a programming language called PHP.
  • ? marks the start of the parameter list.
  • ref=-3, uploader=plupload, single=, local=, search=, offset=0, order_by=relevance, sort=DESC, archive=0, collection=, metadatatemplate=, relateto= and redirecturl= are thirteen separate settings, each a name and a value, separated by &.
  • Several of them are empty (nothing after the equals sign), which is normal: the page still receives the name with a blank value.
  • sort=DESC looks like it controls the order of a list, descending. offset=0 looks like it controls which page of results you are on. search= looks like a search box.

The researcher's reasoning was that more parameters mean more opportunities, because each parameter is another place where the server might paste your input into a query.

Trying XSS first

The researcher's first test on any input is always XSS, on the grounds that developers often forget to sanitise all input parameters. Sanitising means cleaning input so that dangerous characters cannot do harm. Here the XSS attempt failed, so the researcher moved on.

Trying SQL injection

The next step was to put a single quote (') into each parameter, one at a time, and look at the response. One parameter was vulnerable: sort=DESC. When the quote went into that parameter, the site returned a SQL syntax error, and the error message also revealed the database name and version number.

From the original on medium.com

The screenshot shows that error page: the SQL syntax error returned after the quote was injected into the sort parameter, with the database name and version visible in the message. That is the confirmation the researcher was looking for, and the bug was submitted to the team straight away.

Why this works: the server was taking the value of sort and placing it into a database query to decide the ordering. The quote broke the query's syntax, the database complained, and the site passed that complaint back to the visitor instead of hiding it. The leaked name and version are a bonus for an attacker, because knowing which database software and version is running helps choose further attacks.

Step 2: the profile edit form

The next day, the researcher went back over the addresses collected the day before, this time looking for other kinds of vulnerability. A POST request used to edit a profile turned up: when you click the submit button on that form, the browser sends the form's values in the request body. Among those values, one stood out: resource_type=2.

A single quote submitted in that parameter produced the same kind of SQL syntax error. The report notes that XSS and other attempts on this request did not succeed, so the quote test was what paid off.

Why this matters: the first bug was in the address bar, the second is in a form submission. They are different doors into the same building. A site can protect one and forget the other, which is exactly why the researcher tested both.

Step 3: the same name inside a cookie

On that same profile edit request, the researcher noticed the parameter name from step 1, sort=DESC, appearing in the cookie section. Since that name had already been vulnerable once, the researcher was fairly sure it would be vulnerable again, and it was: a single quote in the cookie value produced the SQL error too.

Why this matters: a cookie is just another box of text the browser sends back, and the server was treating its contents as trustworthy. The lesson is that input arrives from more places than the address bar and the form: cookies carry values too, and any of them can end up in a query.

All three bugs were then submitted to the company.

Why it happened

The report does not show the server-side code, so the exact mistake is not stated. What the behaviour tells us is that values controlled by the visitor, from three different sources (an address-bar parameter, a form field and a cookie), reached database queries without being handled safely. A single quote was enough to break the query, and the resulting error was sent back to the browser. The fact that the error revealed the database name and version suggests the site was set up to show detailed error messages to visitors rather than logging them privately. Why the site's existing protections did not catch this is not described.

What the impact was

The report only proves that a quote causes an error and that the error leaks the database name and version. The three affected inputs are the sort parameter in the address bar on the file listing page, the resource_type form field on the profile edit request, and the sort value in the cookie on that same request.

What was fixed

The three bugs were triaged and the researcher received Resolved Reputation. No bounty was paid: the programme's policy stated that at that time it was not awarding any bounties or cash rewards. The researcher notes not sleeping the whole night out of excitement, and that the feeling of finding the bugs is what stuck.

Things worth trying yourself

  1. Put a single quote into every parameter of a page with many parameters, one at a time, and watch for SQL syntax errors. A good sign is an error page that shows query structure, a database name or a version string.
  2. Repeat the same quote test on the form fields of submissions such as profile editing. A good sign is the same kind of SQL error coming back.
  3. Test cookie values that copy parameter names you have seen elsewhere, such as sort=DESC, with a single quote. A good sign is a SQL error caused by the cookie alone.
  4. When an error does appear, check whether the message reveals the database name and version, as it did here. That confirms the injection and gives you version information for further testing.

Glossary

  • Parameter: a named setting in a web address or form, written as name=value, that the server reads to decide what to do.
  • GET request: a request where the data travels in the address bar, after the ?.
  • POST request: a request where the data travels in the body, typically sent when you submit a form.
  • Server: the computer that runs a website and answers requests.
  • Database: an organised store of information that a website queries to build pages.
  • SQL: the language used to ask a database for information or to change it.
  • Query: a single instruction sent to a database in SQL.
  • Single quote ('): the character SQL uses to mark the start and end of a text value; injecting one often breaks a query and reveals whether injection is possible.
  • Syntax error: the database's message that it cannot understand the query it was given.
  • Sanitise: to clean input so that dangerous characters cannot cause harm.
  • Cookie: a small piece of text a site asks your browser to store and send back with later requests, often used to remember who you are or to keep settings.
  • Triage: the first review of a bug report, where someone confirms it is real and worth passing on.
  • Reputation: a score some bug bounty platforms give researchers for good reports.
  • Bounty: a cash payment some programmes offer for valid bug reports.
  • Bug bounty programme: a scheme where a company invites researchers to report security bugs, sometimes for rewards.
  • Resolved: the status showing a reported bug has been dealt with by the company.

More by Utkarsh Agrawal

View all

2 more disclosed reports, 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.