← SQL Injection lesson
InjectionSQL InjectionIntermediate35 min+100 XP

Directory String Theory

The Customer Directory concatenates the search term into a SQL LIKE query. Retrieve the hidden record.

“The login form asked for a password. The database answered a different question.”

CWE-89OWASP Top 10 A03:2021OWASP ASVS 5.3.4
The story
A query is a sentence with grammar. User input is supposed to be a noun inside that sentence. Injection happens when the input changes the grammar instead of filling the blank.

String concatenation places raw input inside a query. A quote closes the intended string, OR changes the predicate, and a comment removes the rest. The database then executes the attacker's sentence with the application's privileges.

Your objective
  • Test the search field
  • Break out of the LIKE predicate
  • Retrieve the hidden record and capture the flag
Boundary under test

Client string to SQL parser

Field guide · request anatomy

Where to look before you type a payload

01Collect

The application receives a search term, login, filter, sort key or API parameter.

02Concatenate

The value is placed into SQL text instead of being bound as a parameter.

03Parse

The database parser treats attacker-controlled text as SQL syntax and may change the query structure.

04Execute

The modified query runs with the application's database privileges.

Progressive hints

Open one hint at a time. The first two build the model; the last two point at the boundary.

Hint 1

Send a single quote and watch for errors or changes in behavior.

Hint 2

Try a boolean tautology in the login or search field.

Hint 3

The search term is inside a LIKE pattern. Try a tautology and a comment.

Hint 4 · near the answer

Bypass authentication or return every record, then capture the flag.

Guided workbench

Observe → Hypothesize → Test → Prove → Explain

This is the same loop a reviewer expects in a report. Your draft stays in this browser; nothing is submitted until you choose to export it.

0/15steps complete
Observe0/3
Hypothesize0/3
Test0/3
Prove0/3
Explain0/3

Evidence log

Write for a reviewer who was not in the room. Every claim needs a request, response or state change behind it.

Preview the evidence report
# Lab evidence report — Directory String Theory

- Family: SQL Injection
- Lab ID: web-sqli-customer-search
- Date: 2026-12-05

## Workflow

### Observe

- [ ] Open "Directory String Theory" and record /search, the HTTP method and the role you are given.
- [ ] List every parameter, header, cookie and object identifier the normal flow exposes.
- [ ] Save a baseline response: status, body shape, timing and the fields that change by user.

### Hypothesize

- [ ] Name the server decision that protects /search, and the evidence it should use.
- [ ] Use the clue as a constraint, not an answer: The search term is inserted inside a single-quoted LIKE pattern.
- [ ] Predict the exact status, body or state change that would prove the decision is missing.

### Test

- [ ] Start from the baseline and change one value: the search field.
- [ ] Keep the request replayable; vary encoding, method or identifier location only after the first result.
- [ ] Capture the full request and response for the winning attempt, including the flag.

### Prove

- [ ] Capture the flag and name the exact foreign object, role or state change it proves.
- [ ] Repeat from a clean session and confirm the result is not cached or stale.
- [ ] State impact precisely: what data or action did you actually obtain?

### Explain

- [ ] State the root cause without naming the payload: which decision failed?
- [ ] Name the control that prevents recurrence and the layer where it belongs.
- [ ] Write one regression test that fails before the fix and passes after it.

## Evidence

### Target and baseline

_Not recorded._

### Hypothesis

_Not recorded._

### Winning request

_Not recorded._

### Proof

_Not recorded._

### Root cause

_Not recorded._

### Control and regression test

_Not recorded._

## Analyst conclusion

The proof demonstrates the missing control above. The regression test should fail against the vulnerable behavior and pass after remediation.
Solution and debrief
Locked until you capture the flag.

The full request, the reasoning and the debrief unlock after a successful capture. That is deliberate: struggle first, then consolidate.

What a reviewer will ask

False positives to rule out

  • A single quote causes a generic 500: it may be a parser error, but confirm with boolean and time-based tests before calling it injectable.
  • A WAF blocks a payload: encoding, alternate syntax and different parameters may still reach the query; never treat the WAF as the fix.
  • The ORM is used: raw fragments, order clauses and dynamic identifiers can still be concatenated.

Regression tests to name

  • Login tautology: Authentication fails and the query is unchanged
  • Search union: The value is treated as literal text and no extra columns appear
  • Sort identifier: The server maps only allowlisted columns and rejects the rest
The defender's move
  • Use parameterized queries or a query builder that binds values.
  • Allowlist identifiers such as sort columns; never concatenate them.
  • Run the database with least privilege and return generic errors.
See the secure-code pattern and all 4 regression tests →
الخلاصة

أي إدخال يغيّر بنية الاستعلام هو حقن، وليس مجرد علامة اقتباس.