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/bandit/bandit2.md
URL /wargames/bandit/bandit2/
Date 2026-04-07

Bandit Level 2

Bandit Level 2 — read a file literally named "-" and learn why commands treat a leading dash as an option.

Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.

Level Goal

The password for the next level is stored in a file called - located in the home directory

Commands you may need to solve this level

ls , cd , cat , file , du , find

Helpful Reading Material

Study guide

Level map: logged in as bandit1, find the password for bandit2.

What this level teaches

Why some filenames break commands, and how to talk to a command about a file that looks like an option.

Key ideas

  • Options start with a dash. cat -n file means “number the lines”. A bare - is conventionally “standard input”, so a command that receives only - does not see a file at all.
  • The shell passes arguments through unchanged. It is the program, not the shell, that decides - is special.
  • Two standard remedies exist: make the argument unmistakably a path, or tell the program that options have ended. Both are described in the man pages of nearly every command.

How to approach it

  1. Run ls and notice the odd filename. Try cat on it and observe what happens; failing on purpose is a good way to learn.
  2. Think about how to write a path that does not begin with a dash. The current directory has a short name you already know.
  3. Search man cat or man bash for the “end of options” convention, which is useful for every command you will ever use.

Why it matters

Attackers deliberately create files whose names look like command-line flags, which can trick scripts that run rm * or tar * into executing options. Knowing the mechanism is how you defend against it.