Skip to content

Narnia Level 5

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 %x and %n.
  • Reading memory. %x and positional specifiers like %7$x print values from the stack.
  • Writing memory. %n stores 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

  1. Read the source to see what value must change and how the format string is used.
  2. Print stack values until you find your own input, to learn its position.
  3. Combine padding and %n to 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.