Skip to main content

Settings

Color Mode

Theme Skin

Background

Appearance preferences are saved in this browser only.

Environment

Current Environment Production

Built with JEKYLL_ENV=production. Changes require deployment.

Quick Links

Theme & Build

Jekyll v3.10.0
Last BuildNov 24, 17:25

Page Location

Page Info

Layout default
Collection wargames
Path _wargames/narnia/narnia5.md
URL /wargames/narnia/narnia5/
Date 2026-04-07

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 %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.