Leviathan Level 2
Leviathan Level 2 — a setuid program checks whether you may read a file before printing it; learn what that check really verifies.
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 leviathan2, find the password for leviathan3.
What this level teaches
How a program decides whether you are allowed to read a file, and how the name it checks can differ from the file it finally opens.
Key ideas
- Check, then use. Many programs test permission first and open the file afterwards. Anything that can change between the two steps is an opportunity.
- File names are strings. Spaces, symbolic links and relative paths all affect which file a name finally refers to.
- Trace it.
ltraceshows the library calls used to check and open files.
How to approach it
- Run the program under
ltracewith a file you own and watch its calls. - Compare what it checks with what it opens, and think about a name that means different things in each place.
- Use a private directory under
/tmpfor your experiments.
Why it matters
This class of bug, known as time-of-check to time-of-use, has caused real privilege escalations in widely used software.