Skip to content
SQL injection Write-up Beginner

From a Single Quote to SQL Injection: How I Discovered a Vulnerability in a University Web…

A university web application displayed a database error when a single quote was added to the facultyid parameter, indicating possible SQL injection. Using SQLMap, the author confirmed the injection and enumerated database names, potentially allowing access to sensitive data.

vignesh12 Follow

Published on medium.com

Sql Injection

Vignesh T, 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. 5 min read.

Context

A university web application, referred to throughout as target.com because the researcher does not name the institution, exposed a page that takes two identifiers in the query string: a department and a faculty member. The page is reached through index.php and the two parameters are deptid and facultyid. The report does not describe what the page renders or which roles can reach it; it only shows the URL shape and the behaviour of one parameter.

The finding is an error-based SQL injection in facultyid, confirmed and enumerated with SQLMap. The author reports being able to access the database within a few minutes of noticing the parameter.

Setup

No account, role or credential is described. No account, role or credential is described. and the author closes by stressing that testing should stay within an authorised scope. The only tool named is SQLMap, used with its error-based technique. No version numbers are given for SQLMap, PHP, the database engine or the web server.

Finding it

While browsing the site at random, the author came across a URL of this form:

Text
https://target.com/index.php?deptid=80&facultyid=12

The parameter facultyid=12 stood out as worth testing. The first probe was to append a single quote after the value:

Text
facultyid=12'

The application responded with a database error. That was the signal: an application that returns a raw database error in response to a stray quote is very likely placing the value into a SQL query without proper handling. The author's reasoning at this point was that the parameter might be interacting directly with a query, and the next question was whether data could actually be extracted through it.

Exploitation

The author notes two routes for confirming and exploiting the issue: crafting queries by hand and reading the responses, or using an automated tool such as SQLMap. SQLMap was chosen because it automates much of the process. The error already observed made error-based injection the natural technique to target.

Step 1: confirm the injection and enumerate databases

Bash
sqlmap -u "https://target.com/index.php?deptid=80&facultyid=12" --technique=E --dbs --batch

The options do the following:

  • -u supplies the URL to test, including both query parameters exactly as the site uses them.
  • --technique=E restricts SQLMap to error-based injection, matching the database error seen during manual probing.
  • --dbs asks SQLMap to enumerate the databases reachable through the injection.
  • --batch accepts SQLMap's default answers to its interactive prompts so the run proceeds unattended.

Step 2: read the result

SQLMap confirmed the SQL injection and began enumerating database information. The report does not reproduce the tool's output, the names of any databases, tables or columns, or the volume of data retrieved. What it does state is that the whole path, from a single quote to database enumeration, took only a few minutes.

Root cause

The parameter itself is not the defect. The problem is how the application processes user-controlled input and passes it to the database. When input is concatenated directly into a SQL query without proper handling, an attacker can alter the structure of that query and reach data they should not be able to see. The immediate database error on a single quote is consistent with that pattern: the quote broke out of the intended string or numeric context and the engine's complaint was returned to the browser.

Two factors made the issue easy to find. First, detailed database errors were displayed to the user, which turned a blind probe into a confirmed finding. Second, the author recommends validating that facultyid is an integer, which suggests input validation was a gap.

Impact

Under the conditions observed, the query behind facultyid could be manipulated and use the resulting database errors to enumerate the databases the application's database account can reach. The author describes this as access to the database within a few minutes. The report does not quantify how much data was exposed, whether write access was possible, or which tables were reachable; the demonstrated capability is enumeration through error-based injection.

Fix

The author lists four measures, all of them recommendations rather than changes confirmed as deployed:

  1. Use parameterised queries or prepared statements instead of concatenating user input into SQL. The input should be passed separately as a parameter rather than joined into the query string.
  2. Validate input. If facultyid is supposed to be an integer, the application should enforce that it is one.
  3. Do not expose database errors to users. Detailed SQL errors should be logged internally rather than rendered in the response.
  4. Give the application's database account only the permissions it needs, following least privilege, so that a successful injection has a smaller blast radius.

Variants to test

  • Other numeric identifiers on the same site. Parameters such as deptid in the same URL, or other *id values on sibling pages, are worth the same single-quote probe. A positive result is a database error in the response, or a change in page content that disappears when the quote is removed.
  • Quote plus comment terminators. Where a quote alone produces an error, appending a comment sequence can reveal whether the rest of the query can be neutralised. A positive result is the error disappearing and the page rendering normally with altered data.
  • Error-based enumeration with SQLMap. Reuse the same command shape against a suspected parameter, restricting to --technique=E when errors are visible. A positive result is SQLMap reporting the injection and listing database names.
  • Boolean and time-based fallbacks. On parameters where errors are suppressed, compare true and false conditions, or measure response time for a deliberate delay. A positive result is a consistent difference in content or latency between the two cases.
  • Integer validation bypass. Where the application claims to expect an integer, try values that are numeric in appearance but carry SQL syntax. A positive result is the same error behaviour seen here, showing the validation is cosmetic.

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 was browsing a university website. He noticed that the address of one page contained two numbers, one for the department and one for the member of staff. He tried adding a single quote character to the end of one of those numbers, and the website replied with an error message that had clearly come from the database behind it. That error was the clue he needed. Using a free automated tool called SQLMap, he confirmed that the page was vulnerable to a class of bug called SQL injection, and the tool then listed the databases the site could reach. The whole thing took a few minutes. This article walks through exactly what he did, explains every term from scratch, and then covers how developers can stop this kind of problem.

The researcher does not name the university, so throughout the article the site is called target.com.

The page and the two numbers in its address

When you type an address into your browser, everything after a question mark is called the query string. It is a list of small labelled values that the browser sends to the server along with the request for the page. Each label is a parameter, and each parameter has a value. The pattern is name=value, and several parameters are joined with &.

A useful everyday comparison: a query string is like the order slip you hand to a counter assistant. The slip has boxes for "size" and "colour", and you write a value in each box. The assistant reads the slip and fetches the matching item. The server reads the parameters and builds the page to match.

The page in question is reached through a file called index.php. The .php ending tells you the server runs a program written in the PHP language to produce the page, rather than just handing back a fixed file. The two parameters are deptid (department identifier) and facultyid (faculty member identifier). An identifier, often shortened to ID, is just a number that uniquely labels a record in a database, the way a student number labels a student.

The report does not say what the page displays or which visitors can reach it. It only shows the shape of the address and what happened when one parameter was changed.

Finding it

While browsing the site at random, the researcher came across an address of this form:

Text
https://target.com/index.php?deptid=80&facultyid=12

Reading this line by line:

  • https:// is the secure version of the protocol browsers use to fetch pages.
  • target.com is the placeholder name for the university's site.
  • /index.php is the program on the server that builds the page.
  • ? marks the start of the query string.
  • deptid=80 says "department number 80".
  • & separates the two parameters.
  • facultyid=12 says "faculty member number 12".

The parameter facultyid=12 stood out as worth testing. The first probe was to append a single quote character after the value:

Text
facultyid=12'

A single quote, ', is a special character in SQL, the language used to talk to databases. In SQL, text values are wrapped in single quotes, so a query might say WHERE name = 'Smith'. The quote tells the database where the text starts and ends. If a website pastes a visitor's input straight into a query, a stray quote can confuse the database about where the text ends, and the database complains.

The application responded with a database error. That was the signal. An application that returns a raw database error in response to a stray quote is very likely placing the value into a SQL query without proper handling. The researcher's reasoning at this point was that the parameter might be interacting directly with a query, and the next question was whether data could actually be extracted through it.

Two ways to dig deeper

The researcher notes two routes for confirming and exploiting the issue: crafting queries by hand and reading the responses, or using an automated tool such as SQLMap. SQLMap was chosen because it automates much of the process. The error already observed made error-based injection the natural technique to target.

SQL injection is a class of bug where an attacker's input changes the meaning of a database query, rather than just being treated as a value. Imagine a form that asks for your name and the clerk writes it into a sentence: "Please let [name] into the building." If you write your name as "Alice and also everyone else", the sentence now lets everyone in. The clerk treated your words as instructions instead of as a name. SQL injection works the same way with database queries.

Error-based injection is a specific flavour. The attacker deliberately causes the database to produce error messages, and reads information out of those messages. It is like asking a librarian for a book that does not exist and learning from the complaint which shelves and sections the library has.

SQLMap is a free, open-source command-line tool that automates the process of detecting and exploiting SQL injection. You give it a URL, and it tries many techniques, reports what it finds, and can list databases, tables and data. It is a command-line tool, meaning you run it by typing a command in a terminal window rather than clicking buttons.

Step 1: confirm the injection and enumerate databases

Bash
sqlmap -u "https://target.com/index.php?deptid=80&facultyid=12" --technique=E --dbs --batch

Line by line, in plain words:

  • sqlmap is the name of the program being run.
  • -u is an option that supplies the URL to test, including both query parameters exactly as the site uses them. The URL is in double quotes so the terminal treats it as one piece.
  • --technique=E restricts SQLMap to error-based injection, matching the database error seen during manual probing. The E stands for error-based.
  • --dbs asks SQLMap to enumerate the databases reachable through the injection. A database is an organised store of data, like a set of linked spreadsheets. A single database server often holds several databases, one per application or purpose.
  • --batch accepts SQLMap's default answers to its interactive prompts so the run proceeds unattended. Without it, the tool would stop and ask questions, and you would have to answer each one.

Step 2: read the result

SQLMap confirmed the SQL injection and began enumerating database information. The report does not reproduce the tool's output, the names of any databases, tables or columns, or the volume of data retrieved. What it does state is that the whole path, from a single quote to database enumeration, took only a few minutes.

Why this happens: the root cause

The parameter itself is not the defect. The problem is how the application processes user-controlled input and passes it to the database. When input is concatenated directly into a SQL query without proper handling, an attacker can alter the structure of that query and reach data they should not be able to see. The immediate database error on a single quote is consistent with that pattern: the quote broke out of the intended string or numeric context and the engine's complaint was returned to the browser.

Concatenation means gluing pieces of text together. If a program builds a query by gluing the visitor's value into a fixed sentence, the visitor's value becomes part of the sentence's grammar. That is the mistake.

Two factors made the issue easy to find. First, detailed database errors were displayed to the user, which turned a blind probe into a confirmed finding. Second, the author recommends validating that facultyid is an integer, which suggests input validation was a gap.

What an attacker could do with it

Under the conditions observed, the query behind facultyid could be manipulated and use the resulting database errors to enumerate the databases the application's database account can reach. Unauthenticated means without logging in; the visitor is just an ordinary person with a browser. The researcher describes this as access to the database within a few minutes. The report does not quantify how much data was exposed, whether write access was possible, or which tables were reachable; the demonstrated capability is enumeration through error-based injection.

How to fix it

The researcher lists four measures, all of them recommendations rather than changes confirmed as deployed:

  1. Use parameterised queries or prepared statements instead of concatenating user input into SQL. The input should be passed separately as a parameter rather than joined into the query string. A prepared statement is a query template with blank slots. The database is told the shape of the query first, and the values are handed over separately, so the database never treats a value as grammar. It is like a form with boxes: whatever you write in the box stays in the box.
  2. Validate input. If facultyid is supposed to be an integer, the application should enforce that it is one. Input validation means checking that what arrived matches what was expected, and rejecting it otherwise.
  3. Do not expose database errors to users. Detailed SQL errors should be logged internally rather than rendered in the response. Logging means writing the details to a file only staff can read, so developers can still debug without handing clues to attackers.
  4. Give the application's database account only the permissions it needs, following least privilege, so that a successful injection has a smaller blast radius. Least privilege means giving each account the minimum access required for its job, the way a hotel cleaner gets a key to the rooms but not to the safe.

Other places to look

  • Other numeric identifiers on the same site. Parameters such as deptid in the same URL, or other *id values on sibling pages, are worth the same single-quote probe. A positive result is a database error in the response, or a change in page content that disappears when the quote is removed.
  • Quote plus comment terminators. Where a quote alone produces an error, appending a comment sequence can reveal whether the rest of the query can be neutralised. A comment in SQL is text the database ignores, so an attacker can use it to silence the remainder of a query. A positive result is the error disappearing and the page rendering normally with altered data.
  • Error-based enumeration with SQLMap. Reuse the same command shape against a suspected parameter, restricting to --technique=E when errors are visible. A positive result is SQLMap reporting the injection and listing database names.
  • Boolean and time-based fallbacks. On parameters where errors are suppressed, compare true and false conditions, or measure response time for a deliberate delay. Boolean-based injection asks the database yes/no questions and watches how the page changes; time-based injection asks it to pause and watches how long the reply takes. A positive result is a consistent difference in content or latency between the two cases.
  • Integer validation bypass. Where the application claims to expect an integer, try values that are numeric in appearance but carry SQL syntax. A positive result is the same error behaviour seen here, showing the validation is cosmetic.

Final thoughts

The researcher closes by stressing that testing should stay within an authorised scope. Authorised scope means the owner of the system has given permission for the testing, usually through a bug bounty programme or a written agreement. Testing a site without permission is not research; it is unauthorised access.

Glossary

  • API: a defined way for one program to ask another for data or actions, like a waiter taking your order to the kitchen.
  • Authorised scope: the set of systems and actions a tester has explicit permission to test.
  • Boolean-based injection: a technique that asks the database yes/no questions and infers answers from how the page changes.
  • Concatenation: gluing pieces of text together to form one string.
  • Database: an organised store of data, often holding many tables of records.
  • Error-based injection: a technique that deliberately triggers database error messages and reads information from them.
  • Identifier (ID): a number or code that uniquely labels a record.
  • Input validation: checking that received input matches the expected format and rejecting it otherwise.
  • Integer: a whole number, with no decimal part.
  • Least privilege: giving each account only the minimum access it needs.
  • Logging: writing details of events to a file for later review by staff.
  • Parameter: a labelled value in a query string, written as name=value.
  • Parameterised query / prepared statement: a query template with separate value slots, so input is never treated as query grammar.
  • PHP: a programming language commonly used to build web pages on the server.
  • Query string: the part of a URL after the ?, carrying parameters to the server.
  • SQL: the language used to read and write data in relational databases.
  • SQL injection: a bug where attacker input changes the meaning of a database query.
  • SQLMap: a free command-line tool that automates detecting and exploiting SQL injection.
  • Time-based injection: a technique that makes the database pause and infers answers from response timing.
  • Unauthenticated: without logging in.
  • URL: the address of a resource on the web.

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.