Narnia Level 2
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 narnia2, find the password for narnia3.
What this level teaches¶
The textbook "smash the stack" attack.
Key ideas¶
- Stack frame. Each function call stores its locals, a saved frame pointer and a return address.
- Control flow hijack. Overwriting the return address makes the function return to a place you choose instead of its caller.
- Finding the offset. A cyclic pattern in
gdborpwntoolsshows exactly how many bytes are needed to reach the return address. - Where to jump. Into your own shellcode, whose address you must find reliably.
- Reading material. "Smashing the Stack for Fun and Profit" is the classic paper.
How to approach it¶
- Read the source and note the buffer size and the unsafe copy.
- In
gdb, crash the program with a pattern to find the offset. - Place shellcode where you can predict its address and aim the return address at it.
Why it matters¶
Understanding this attack explains stack canaries, non-executable stacks and address randomisation, all of which exist to stop it.