← Back to Home

OverTheWire Bandit: Level 6 → Level 7

Technical Note

Prerequisites

Before starting this level, ensure you have logged in as bandit6 using the password found in Level 5: ssh bandit6@bandit.labs.overthewire.org -p 2220

Context

In the previous level, we only searched within our current directory (inhere). However, in real-world scenarios, we might not know where the file is located and need to scan the entire file system (/).

This presents a major obstacle: Permission Errors. As a regular user, scanning the entire root directory triggers “Permission denied” errors for every folder we cannot access, flooding our terminal.

This level teaches us about file ownership and how to manage standard error streams.

Goal

The password is stored somewhere on the server and has the following properties:

  1. owned by user bandit7
  2. owned by group bandit6
  3. 33 bytes in size

Solution

We need to start our search from the root directory (/).

First Attempt (Noisy Method):

find / -user bandit7 -group bandit6 -size 33c

Running this will spam your screen with hundreds of “Permission denied” errors, burying the actual result.

Suppressing Errors (Error Redirection)

In Linux, Standard Output (stdout) is channel 1, and Standard Error (stderr) is channel 2. We can redirect errors to the “null device” (/dev/null) effectively preventing them from showing up on the screen.

find / -user bandit7 -group bandit6 -size 33c 2>/dev/null

Command Breakdown:

  • /: Start from the root directory.
  • -user bandit7: Find files owned by user bandit7.
  • -group bandit6: Find files owned by group bandit6.
  • -size 33c: Find files exactly 33 bytes in size.
  • 2>/dev/null: Redirect error messages (stderr) to the void.

Output:

/var/lib/dpkg/info/bandit7.password

We found it! Let’s read it:

cat /var/lib/dpkg/info/bandit7.password
# The password appears

Key Takeaways

  1. Ownership Filters: The find command can filter files based on the owner (-user) and group (-group).
  2. Stderr Redirection (2>): Redirecting error streams is a crucial skill for cleaner output. /dev/null is Linux’s black hole; anything sent there disappears.