Narnia Level 1
Narnia Level 1 — the program runs code taken from an environment variable; learn what shellcode is and how to supply it.
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 narnia1, find the password for narnia2.
What this level teaches
How executable code can be delivered through an environment variable, and what shellcode is.
Key ideas
- Environment variables are strings the shell passes to every program. Programs can read them and they can be arbitrarily set by the user.
- Shellcode is machine code written to perform an action such as starting a shell. It must avoid bytes that break copying or printing.
- Function pointers. The program treats the variable’s contents as a function and jumps to it.
- Match the architecture. Shellcode is specific to the CPU and word size; check what the binary is with
file.
How to approach it
- Read the source to see which variable is read and what is done with it.
- Obtain or write shellcode for the correct architecture and place it in that variable, ensuring bytes survive the shell.
- Run the program and observe which user you become.
Why it matters
It is the cleanest demonstration of why executing data as code is dangerous, and why modern systems mark data memory as non-executable.