Tactical LogHuntress CTF 2026 // team archive

Days / Day 19 / Web Exploitation / Query Me This

DAY 19//LANE: WEB EXPLOITATION//STATUS: CORRECT x3

Query Me This

Web Exploitation SSTTMM Modes reported CORRECT in this write-up

Day 3 - Web Exploitation - boolean-blind SQL injection in a search box - all three modes CORRECT on 2026-10-19 via the homestation Commander (same backlog pickup as Permission to Slip; agent-6 did not claim it on the daily release).

ModeGM resultFlagAuthor of the solving method
Single SolveCORRECTa2a8205565ab4d70a2ff470f81544c84team shared pool (earned pre-this-run via a peer session; our own extraction confirmed the same proof_cb727cb1... value from the same target bytes)
Time TrialCORRECT9331abb4b47fa1f59a38f73dc17617d4Commander (homestation) - parallel extractor, 5.6s end-to-end
MasteryCORRECT0ade81cc896e517a8c259612a1b54d01Commander (homestation) - mixed SQLi + deploy-backup

GM evidence for every mode: the real op=submit response had "result":"CORRECT" and solved_by.name:"the team solver". Nothing was guessed; every proof came from the live target's own data via a boolean-blind oracle.

Prompt and lane

Prompt (verbatim from the GM start response):

The search box trusts you a little too much. Ask the database one pointed question and read the row it was never supposed to show you.

Category: Web Exploitation. Same shared live-Web slot as the IDOR challenge (one live Web target per team at a time). GM delivers a live target URL in targets[0].url per started attempt. Mastery hands back TWO targets at once.

Why it looks SQLi but behaves oddly

The target's /lookup?q=... (Single, Mastery T2 at /search; Time Trial at /explore) runs a Python string-interpolated WHERE col LIKE '%' + q + '%' query on an SQLite backend. Three things trip up a naive sqli attempt:

  1. -- is accepted but every attempt to close the string with a matching quote leaves the trailing %' the server appends disabled. The classic ' OR '1'='1'-- comment payload returns zero rows: the server's %' is still there, so the query becomes ... OR '1'='1'-- comment%' and the trailing fragment lives in a comment line that the SQL parser rejects as a syntax error (the whole statement errors; a Flask try/except Exception swallows it and renders "Nothing matched.").
  2. ' OR '1'='1 (no closing quote) returns 3 rows, but so does ' OR 'a'='b' and so does ' OR 'anything'='x. That is because pill LIKE '%' OR '<any>'='<any>%' is TRUE OR <stringcmp>; the LIKE '%' half always matches every row, so the OR fires regardless of the right-side comparison. It is NOT a real boolean oracle; it is a false witness, and we burned several minutes on it earlier.
  3. UNION SELECT with any column count 1..15 returns 0 rows. The actual underlying SQL joins multiple OR col LIKE ... clauses with the same q substituted into each, so a UNION in position 1 leaves the second and third LIKE patterns syntactically broken (trailing %'), and the whole statement errors. The entire UNION branch is a dead end on this app.

The real primitive: boolean sandwich via AND + LIKE prefix

The payload shape that is actually a boolean oracle is:

' AND (<predicate>) AND (1) LIKE '1

Server-interpolated: WHERE pill LIKE '%' AND (<predicate>) AND (1) LIKE '1%'. Parses cleanly because:

  • pill LIKE '%' is a trivial match (TRUE for every row).
  • <predicate> is a free boolean. If TRUE, the AND chain survives; if FALSE, the row is filtered out.
  • (1) LIKE '1' plus the server-appended %' becomes (1) LIKE '1%', a prefix LIKE comparing the integer 1 cast to text ('1') against the pattern 1%. That is TRUE unconditionally and gives the trailing %' a safe landing.

TRUE path -> the three visible rows render on the page (Record NNN x3). FALSE path -> "Nothing matched." That is the oracle.

Pattern variants used in the live solve:

  • ' AND (expr)<=<n> AND (1) LIKE '1 for binary search over an integer.
  • ' AND UNICODE(SUBSTR((<subq>),<pos>,1))<=<code> AND (1) LIKE '1 for a per-char binary search over printable ASCII (log2(95) == 7 requests per character).
  • ' AND (<subq>) LIKE '<prefix> as a prefix match: server-appended %' turns the prefix into <prefix>%' which is a LIKE prefix wildcard. (NOT used for blind-char extraction because _ is a LIKE single-char wildcard and silently matches anything.)

Backend fingerprinting (SQLite)

sqlite_master lookups returned non-empty; pg_tables and information_schema. tables returned empty (both FALSE on the oracle). The schema was:

articles(id INTEGER, title TEXT, topic TEXT, summary TEXT, visibility TEXT)

4 rows total, 2 distinct visibility values ('public' and 'private'), one private row. That private row's summary holds proof_<32 hex>.

Extraction pipeline

Per target:

  1. Fetch / with a User-Agent: curl/8. The home page's <form action='...'> names the search endpoint for this variant (/lookup, /search, or /explore). All variants share the same backend.
  2. Confirm the oracle: ' AND 1=1 AND (1) LIKE '1 -> 3 rows. ' AND 1=2 AND (1) LIKE '1 -> 0 rows.
  3. (OPTIONAL - skip once the pattern is proven across variants) extract the schema via sqlite_master and pragma_table_info('articles').
  4. Length of the private summary via binary search on LENGTH((SELECT summary FROM articles WHERE visibility='private' LIMIT 1)).
  5. Per character (parallel, ThreadPoolExecutor concurrency 24-32): binary search on UNICODE(SUBSTR((<subq>),<pos>,1)). Characters are independent of each other (each is addressed by position), so the whole 38-character string extracts in one logical round.
  6. Submit the recovered proof_<hex32> to the GM under answer_id proof-1.

Measured end-to-end against the Time Trial live target: 5.6 seconds, 38 chars, ~270 HTTP requests. The target enforces a 60-second per-attempt window server-side (the challenge's declared "untimed" refers to Hall-of-Fame ranking, not target liveness - the target returns 410 Gone after about 60s of inactivity from the first fetch). The parallel extractor fits comfortably.

Mastery: SQLi + deploy-backup mixed

Mastery returns two targets at once:

  • Target 2 is the exact SQLi template; same schema, same articles table, same private-row extraction (3.8s end to end on 2026-10-19).
  • Target 1 is a non-SQLi "Tiny Uptime" status page. Same deploy-backup leak as Permission to Slip Mastery T1: robots.txt disallows /archives-a7ba9/, which is a directory index serving release-settings-92415c.json.bak. That JSON's support_note field is the proof.

Submit both proofs in one op=submit.

Common dead-ends and traps

  • ' UNION SELECT ... -- on this app: never works regardless of column count or comment style. Skip the UNION branch after one confirmation.
  • ' OR '1'='1' ... as a boolean oracle: FALSE witness because the leading LIKE '%' is always TRUE. Use AND, not OR, to build an oracle on this app.
  • _ and % are LIKE wildcards: the extractor must use GLOB ranges or UNICODE(SUBSTR(...)) numeric compare per character, not a LIKE 'prefix+ch' prefix match (early build was fooled into returning ____ for every position).
  • The Time Trial attempt reconnects to the SAME attempt_id across op=start and op=retry while the target is active. Once the target expires (410 Gone from its own route prefix, elapsed_ms>60000), re-issuing op=start after the GM clears the attempt yields a fresh target with a new URL and route.
  • The homestation ctf_gm.GM().start(challenge="/time_trial") refuses by default (TimedStartRefused). Set HUNTRESS_TIMED_START=commander-override when the Commander owns the solve (the Web lane has no rehearsed prebrief).

Lessons learned (banked)

  • Boolean-blind SQLi on an interpolated LIKE '%'||q||'%' sink has one universal payload shape ' AND (<predicate>) AND (1) LIKE '1. The sandwich absorbs the server-appended %' into a safe LIKE prefix. See [[kb-web-blind-sqli-sandwich]].
  • Boolean oracle only works with AND, not OR, when the leading LIKE pattern is '%' (always TRUE). An OR branch would short-circuit TRUE regardless of the right-hand predicate.
  • Parallel per-character extraction is essential for timed targets. 60s is tight for sequential blind-SQLi; a ThreadPool with 24-32 workers lands the proof in ~5s.
  • Mixed-mode Mastery is a real possibility on the Web track: one SQLi target
    • one deploy-backup target under one attempt. Run the attack ladder on each target independently.
  • Robots.txt deploy-backup pattern recurs - exactly the same Disallow: -> directory index -> *.json.bak -> support_note on both days 02 and 03 Mastery T1. Promote it to a first-class web primitive.
  • Project's existing web_contracts.py doesn't cover live-API families - its four executors (hash/jwt/config/http) are all offline over static artifacts. The live-Web lane needs its own primitives file (web_live_primitives.py - committed this pass), hooked into the web_solvers.LADDER for next time.

Files

  • (this writeup) Query_Me_This_Writeup.md
  • GM record (authoritative): challenges/Day 03/_gm_record/web-exploitation-day-03-sqli.homestation.jsonl
  • Working probes (purged after solve per feedback-purge-gm-downloads): home-page snapshots per variant and lookup/search/explore response samples were written into the project directory, used, and removed. The small discovery scripts (sqli_fast_parallel.py, probe_endpoint.py, sqli_master.py) are retained one level up as reference implementations of the primitive now generalised in challenges/_lib/web_live_primitives.py.