Bandit Level 26
Bandit Level 26 — discover that a user's login shell is not bash, then break out of the restricted program that replaced it.
Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.
Level Goal
Logging in to bandit26 from bandit25 should be fairly easy… The shell for user bandit26 is not /bin/bash, but something else. Find out what it is, how it works and how to break out of it.
NOTE: if you’re a Windows user and typically use Powershell to
sshinto bandit: Powershell is known to cause issues with the intended solution to this level. You should use command prompt instead.
Commands you may need to solve this level
ssh, cat, more, vi, ls, id, pwd
Study guide
Level map: logged in as bandit25, gain an interactive shell as bandit26.
What this level teaches
How login shells work, and that many ordinary programs have built-in escape hatches.
Key ideas
- Login shell. The final field of each line in
/etc/passwdnames the program run at login. It need not be a shell, and it can be a program that lets you do only one thing. - Pagers.
moreshows text one screenful at a time. Interactive pagers and editors such asvican launch commands, edit files and change settings, which makes them valuable stepping stones. - Terminal size matters. A pager only pauses when output is taller than your window, so the size of the window affects what you can do.
- GTFOBins. A public catalogue of normal Unix programs that can be abused to escape restrictions.
How to approach it
- Look at the shell recorded for
bandit26and read what that program does. - Think about what happens if the output is longer than your terminal, and what you can do in that state.
- From inside an editor, remember that it can run commands and change the shell it uses.
- If you use Windows, run
sshfrom Command Prompt rather than PowerShell, as the Level Goal advises.
Why it matters
Restricted shells, kiosk systems and sudo rules that permit “just one safe command” are all defeated by this kind of escape.