Narnia Level 5
Narnia Level 5 — a format-string bug; learn how printf-style functions can be made to read and write arbitrary 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 narnia5, find the password for narnia6.
What this level teaches
Format-string vulnerabilities.
Key ideas
- Why it happens. Passing a user-controlled string as the format argument lets the user include conversion specifiers such as
%xand%n. - Reading memory.
%xand positional specifiers like%7$xprint values from the stack. - Writing memory.
%nstores the number of characters printed so far at an address taken from the stack, so you can control what is written and where. - Address placement. You put the target address in your own input and find its position on the stack.
- Reading material. Scut’s format string paper, referenced in the Blacksun reading list, is the classic.
How to approach it
- Read the source to see what value must change and how the format string is used.
- Print stack values until you find your own input, to learn its position.
- Combine padding and
%nto write the value you need.
Why it matters
Format-string bugs were once everywhere. Compilers now warn about them, but the technique teaches how arbitrary-write primitives work.