Natas Level 14
Natas Level 14 — a login form builds its SQL query by pasting in your input; learn the basics of SQL injection and authentication bypass.
Table of Contents
Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.
Username: natas14
URL: http://natas14.natas.labs.overthewire.org
Study guide
Level map: sign in as natas14 and find the password for natas15.
What this level teaches
SQL injection: input that changes the meaning of a database query.
Key ideas
- String concatenation is the flaw. The code inserts the username and password directly into a query string, so quotes in your input can end the string and add logic.
- Boolean logic. A condition such as
1=1is always true, so aWHEREclause containingORof it matches every row. - Comments. SQL comment markers can discard the remainder of a query.
- Read the source. The page provides it; the exact query shape tells you what to inject.
How to approach it
- Read the query the code builds and imagine the final text for ordinary input.
- Work out how to complete or break out of the quoted strings to make the check always succeed.
How developers prevent it
Use parameterised queries (prepared statements) so input is always data, never SQL.