Natas Level 24
Natas Level 24 — a password check uses strcmp, which behaves unexpectedly when it is given the wrong type of input; learn PHP type confusion.
Table of Contents
Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.
Username: natas24
URL: http://natas24.natas.labs.overthewire.org
Study guide
Level map: sign in as natas24 and find the password for natas25.
What this level teaches
How unexpected input types can defeat a security comparison.
Key ideas
- Parameters can be arrays. In PHP, a form field written like
name[]arrives as an array, not a string. - Functions misbehave on the wrong type. Passing an array where a string is expected produces a warning and a surprising return value.
- Loose comparison of that value. The check then treats the result as success.
- Read the manual. The PHP documentation for
strcmplists its return values.
How to approach it
- Work out what the code compares and how it interprets the result.
- Consider what input types you can send that the developer did not imagine.
How developers prevent it
Validate input types, use strict comparison, and modern PHP versions that raise errors when the wrong type is passed.