Skip to content
Tutorials Center
My learning

Topics

Lesson 28 of 38 ยท Common Vulnerability Workflows

SQL Injection Testing Workflow with Burp

A safe, authorised workflow for finding SQL injection with Burp: spot candidates, compare benign probes in Repeater, confirm with evidence, and recommend parameterised queries.

SQL injection (SQLi) happens when an application builds a database query by gluing user input into SQL text. The database cannot tell where the programmer's query ends and the user's data begins, so input can change the meaning of the query. It has been on the OWASP Top 10 list for two decades, and every web tester needs a calm, repeatable way to look for it.

This lesson is about finding and proving the problem in an authorised test, using harmless probes, and then recommending the fix. It does not teach data theft. Burp screens are labelled example output; the Python blocks are offline stand-ins using an in-memory SQLite database that you create yourself.

Test only systems you own or are authorised to test, ideally a lab or staging copy with fake data. Even a "harmless" probe can break a query or lock a table. Stop at the smallest proof that the flaw exists; never extract real personal data.

Why it happens

Here is the vulnerable pattern, shown as read-only code (labelled example):

Python
# VULNERABLE: input becomes part of the SQL text
query = "SELECT name, price FROM products WHERE category = '" + category + "'"

If category is books, the query is fine. If it contains a single quote, the quote ends the string early, and what follows is parsed as SQL. That is the whole bug.

The testing workflow

flowchart TD
  A["1. List inputs<br/>(params, headers, JSON)"] --> B["2. Send a benign<br/>baseline value"]
  B --> C["3. Send probe:<br/>one quote, then two"]
  C --> D{"Behaviour<br/>changes in a<br/>consistent way?"}
  D -- No --> E["Record: not obviously<br/>injectable here"]
  D -- Yes --> F["4. Confirm with<br/>arithmetic or boolean pair"]
  F --> G["5. Capture evidence,<br/>stop, report"]

Move from the least intrusive probe to the next only when the previous one gives a signal.

Step 1: pick inputs

Use Proxy history and the site map to list every input that probably reaches a database: search boxes, filters (category, sort), IDs in the URL, login fields, JSON values, cookies. Sorting parameters (order=price) are often missed because they sit in ORDER BY, where quoting does not apply but injection still can.

Step 2 and 3: baseline, then the quote pair

Send the normal request to Repeater and note the response. Then:

  • Send the value with one single quote appended: books'
  • Send the value with two single quotes: books''

A single quote that breaks the SQL usually produces a database error, a 500, an empty page or a different layout. Two quotes make a valid escaped quote again, so the query runs without an error (it simply finds no match). A difference between one and two quotes is a strong hint.

TEXT
books      -> 200, length 5,120, 12 products
books''    -> 200, length 1,980, "No products found" (no error)
books'     -> 500, length   402, "unterminated quoted string"
books''    -> 200, length 1,980, "No products found" (no error)
Verdict: quote handling changes behaviour -> candidate for SQL injection

Step 4: confirm without harm

To show the input is interpreted rather than just erroring, use a pair of harmless boolean or arithmetic conditions and see the output differ in a controlled way:

  • A numeric ID: compare id=7 with id=8-1. If both return the same product, the database evaluated your arithmetic.
  • A string: compare category=books' AND '1'='1 with category=books' AND '1'='2. The first behaves like the baseline; the second returns nothing.

These conditions do not read or modify other data. They prove that your text became part of the query logic, which is all a report needs. Burp's Scanner automates this ("SQL injection" issues) and also uses time delays and out-of-band checks; always verify its finding by hand as in the triage lesson.

See the mechanics in a safe sandbox

This stand-in creates a tiny database in memory and runs a vulnerable function and a safe one. It lets you watch exactly what the quote pair and the boolean pair do. The data is fake and nothing leaves the page.

Python Vulnerable versus parameterised query (stand-in)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Look at the output: the vulnerable function errors on one quote, recovers with two, and answers the true and false conditions differently. The safe function treats every probe as plain text and simply finds no category with that odd name.

Other signals

  • Error messages: database names or syntax fragments in the response.
  • Time: a request that consistently takes N seconds longer when you add a delay condition. Repeat several times; network noise causes false positives.
  • Out-of-band: the database makes a DNS lookup to a host you control, which Burp Collaborator can detect (see SSRF and Collaborator).
  • Second-order: input is stored safely, then used unsafely later in another query. Test by storing a probe and triggering the later feature.

Notes for different positions

  • ORDER BY parameters: you cannot parameterise column names, so the fix is an allow-list of permitted columns.
  • JSON bodies and headers: apply the same quote-pair logic to each value; User-Agent and Referer are sometimes logged into a database.
  • Stored procedures and ORMs: still vulnerable if they concatenate strings.

What to write in the report

Capture: the exact request (copy from Repeater), the three responses of the quote/boolean pair, the affected parameter, and the worst realistic impact (reading or changing data the database account can access). Recommend the fix in plain terms:

  1. Parameterised queries / prepared statements everywhere, including ORMs (never string-build).
  2. Allow-lists for identifiers such as sort columns.
  3. Least privilege for the database account (no DROP, no file access).
  4. Input validation as a second layer, and generic error pages so SQL errors are not shown to users.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the root cause of SQL injection?

    When input becomes part of the SQL text, it can change the query's structure.
  2. 2. Sending books' causes an error but books'' returns a normal, error-free page. What does this suggest?

    One quote breaks the string, two quotes form an escaped quote again, so the input reaches the SQL parser.
  3. 3. Which is the correct primary fix?

    Parameterisation keeps data separate from SQL code, removing the cause.
  4. 4. How do you fix an injectable ORDER BY column parameter?

    Identifiers cannot be bound as parameters, so map user choices to a fixed list.
  5. 5. How far should an authorised proof go?

    Minimal evidence proves the flaw without exposing data or harming the system.

Summary

  • SQLi arises from concatenating input into SQL; the quote pair and a true/false pair reveal it.
  • Work from baseline to benign probes in Repeater, compare behaviour, and stop at minimal proof.
  • Also check time-based, error-based, out-of-band and second-order signals, plus ORDER BY and JSON inputs.
  • Fix with parameterised queries, identifier allow-lists, least privilege and generic errors.
  • Authorised, low-impact testing only; the code here runs on a fake in-memory database.

Next: XSS testing workflow