Natas Level 20
Natas Level 20 — a custom session file handler trusts a newline in user input; learn how data written to server-side state can be forged.
Table of Contents
Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.
Username: natas20
URL: http://natas20.natas.labs.overthewire.org
Study guide
Level map: sign in as natas20 and find the password for natas21.
What this level teaches
How custom serialisation formats create injection bugs.
Key ideas
- Session storage. Server-side sessions keep a small file or record of values keyed by the session ID.
- Line-based format. The handler writes one
key valuepair per line, so a newline in your input looks like a new entry. - Two requests. The application reads the session at the start of a request, so a poisoned write on one request can take effect on the next.
- Read the code. The source for the custom
myreadandmywritehandlers is the whole puzzle.
How to approach it
- Read how a value you supply ends up inside the stored session.
- Think about what a line break lets you add.
- Make the first request to write the data, and the second to benefit from it.
How developers prevent it
Use your framework’s well-tested session handlers, and encode data (for example JSON) instead of inventing a format that can be broken by delimiters.