Narnia Level 0
Narnia Level 0 — overflow a buffer to overwrite a neighbouring variable and learn how data is laid out in memory.
Table of Contents
Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.
There is no information for this level, intentionally.
Study guide
Level map: logged in as narnia0, find the password for narnia1.
What this level teaches
The simplest memory bug: writing more data than a buffer holds so that it spills into the next variable.
Key ideas
- Adjacent variables. Local variables sit next to each other on the stack, so overflowing one can change another.
- Little-endian values. The target value must be written into memory least-significant byte first.
- Printing bytes you cannot type. A
printforperl -e 'print ...'command can emit arbitrary bytes for you. - Keeping the shell open. The program may run a shell that exits immediately if its input ends; read about how to keep standard input open.
How to approach it
- Read the source and note the size of the buffer, the other variable and the check that depends on it.
- Find the exact number of bytes needed to reach that variable and what value it must hold.
- Send the input from a command and keep the connection open so the shell stays usable.
Why it matters
Overwriting an adjacent flag, length or permission field is a real-world pattern as well as a teaching one.