Skip to main content
🧠Educationalbeginner11 min read
β€’

OverTheWire Bandit Level 5: Finding Human-Readable Files

OverTheWire Bandit Level 5 walkthrough. Learn how to identify human-readable files using the file command, handle files with dashes in their names, and distinguish between text and binary files.

OverTheWireBanditLinuxbeginnerCTFfile operationsfile command

πŸ“„ OverTheWire Bandit Level 5: Finding Human-Readable Files

Level 5 introduces a practical skill you'll use constantly in penetration testing: identifying file types. When you're dealing with multiple files and only one contains readable text, you need a way to quickly figure out which one. That's where the file command comes in.

Level 5 teaches you:

  • How to identify file types using the file command
  • Distinguishing between human-readable text and binary files
  • Using wildcards to check multiple files at once
  • Combining skills from previous levels (handling files with dashes)

This level combines concepts from earlier levelsβ€”you'll navigate directories, handle files with dashes, and now learn to identify which files are actually readable. This is a real-world skill that will save you time during security assessments.


🎯 The Objective

After logging into bandit4, your goal is to find the password for Level 5. The password is in a file inside the inhere directory, but there are multiple filesβ€”and only one is human-readable. The others are binary files (gibberish).

What Level 5 teaches:

  • Using the file command to identify file types
  • Understanding the difference between text and binary files
  • Using wildcards to check multiple files efficiently
  • Finding the needle in a haystack

The challenge: Navigate to inhere, identify which file is human-readable (ASCII text), and read it. The other files are binary and will show gibberish if you try to read them.


πŸ” Understanding the Problem

Let's start by connecting to Level 4 and seeing what we're dealing with:

sshpass -p `cat bandit4` ssh bandit4@bandit.labs.overthewire.org -p 2220

Once connected, navigate to the inhere directory:

cd inhere
ls -la

You should see multiple files, and they all have hyphens in their names (like -file01, -file02, etc.). Remember from Level 2β€”you'll need to use ./ to read files that start with dashes.

The problem: If you try to read these files, most will show gibberish (binary data). Only one file contains human-readable text. How do you find it without reading every file manually?

The answer: Use the file command to check the file type of each file. The human-readable one will show as "ASCII text" while the others will show as "data" or other binary types.


🧠 Understanding File Types

Let's dive deeper into file types, because this distinction matters:

Text Files vs. Binary Files

Text files (human-readable):

  • Contain readable characters (letters, numbers, symbols)
  • Can be opened in text editors
  • Examples: .txt, .sh, .py, .conf
  • Show as "ASCII text" with the file command

Binary files (not human-readable):

  • Contain non-text data (executable code, images, data formats)
  • Show as gibberish when read with cat
  • Examples: executables, images, compiled programs
  • Show as "data" or specific binary types with the file command

Why This Matters

In penetration testing, you'll constantly need to:

  • Identify which files contain readable data
  • Distinguish between text configs and binary executables
  • Find files that might contain credentials or useful information
  • Avoid wasting time trying to read binary files

πŸ“‹ Step-by-Step Walkthrough

Step 1: Connect to Level 4

sshpass -p `cat bandit4` ssh bandit4@bandit.labs.overthewire.org -p 2220

Step 2: Navigate to the inhere Directory

cd inhere

Step 3: List Files

ls -la

You should see multiple files, all with hyphens in their names. Remember from Level 2β€”you'll need ./ to read files that start with dashes.

Step 4: Check File Types Using file

Instead of reading each file manually, use the file command with a wildcard to check all files at once:

file ./*

What this does:

  • file β€” Identifies the type of each file
  • ./* β€” Wildcard that matches all files in the current directory (the ./ ensures files starting with dashes are handled correctly)

What you'll see:

./-file00: data
./-file01: data
./-file02: ASCII text
./-file03: data

The file that shows "ASCII text" is the human-readable oneβ€”that's your target.

Step 5: Read the Human-Readable File

Now that you know which file is readable, read it using the relative path:

cat ./-file02

(Replace -file02 with the actual filename that showed "ASCII text")

The output will be the password for Level 5.

Step 6: Save the Password

Copy the password and save it:

On Linux/macOS:

echo "PASSWORD_HERE" > bandit5

On Windows (PowerShell):

"PASSWORD_HERE" | Out-File -FilePath bandit5 -NoNewline

Step 7: Connect to Level 5

sshpass -p `cat bandit5` ssh bandit5@bandit.labs.overthewire.org -p 2220

πŸ’‘ Understanding the file Command

Let's dive deeper into file, because it's incredibly useful:

What file Does

The file command examines a file and tells you what type it is:

file filename

What it checks:

  • File headers (magic numbers)
  • File structure
  • Content patterns
  • File extensions (as a hint, but not relied upon)

Common outputs:

  • ASCII text β€” Plain text file
  • data β€” Binary data file
  • executable β€” Compiled program
  • PNG image β€” Image file
  • gzip compressed β€” Compressed archive

Using Wildcards with file

You can check multiple files at once using wildcards:

file ./*          # All files in current directory
file /path/*.txt  # All .txt files in /path
file *            # All files (if you're in the directory)

For Level 5: We use file ./* to check all files in the inhere directory.

Why ./ Matters

Remember from Level 2β€”files starting with dashes need ./ to be treated as filenames, not options. The file command is no different:

file -file01      # Wrong - might be interpreted as an option
file ./-file01    # Right - treated as a filename
file ./*          # Right - wildcard with ./ handles all files correctly

πŸ› οΈ Alternative Methods

Here are different ways to find the human-readable file:

cd inhere
file ./*
cat ./-file02    # Use the filename that showed "ASCII text"

Pros: Fast, efficient, checks all files at once Cons: None really

Method 2: Read Files One by One

cd inhere
cat ./-file00
cat ./-file01
cat ./-file02
# ... until you find readable text

Pros: Simple, no new commands Cons: Slow, tedious, might miss it

Method 3: Using grep to Filter

cd inhere
file ./* | grep "ASCII text"

Pros: Automatically filters to show only text files Cons: Requires understanding grep (you'll learn this in Level 8)

For Level 5, use Method 1 β€” it's the most efficient and teaches you valuable skills.


πŸ”’ Real-World Context

Why does this matter in penetration testing?

In real security assessments, you'll constantly need to identify file types:

1. Configuration Files

Configuration files are often human-readable and contain:

  • Database credentials
  • API keys
  • Service account passwords
  • Connection strings

Example: Finding readable config files:

file /etc/*.conf | grep "ASCII text"

2. Log Files

Log files are usually text and contain:

  • Access attempts
  • Error messages
  • User activity
  • System events

Example: Identifying log files:

file /var/log/* | grep "ASCII text"

3. Backup Files

Backup files might be text or binary:

  • .bak files might contain old passwords
  • Database dumps might be readable SQL
  • Configuration backups might be readable

Example: Checking backup files:

file *.bak *.old *.backup

4. Data Files

When analyzing data dumps, you need to know:

  • Which files are readable
  • Which are binary databases
  • Which are compressed archives

Example: Analyzing a directory of files:

file dump/* | grep "ASCII text"

5. Malware Analysis

When analyzing malware, you need to distinguish:

  • Executable binaries (the malware)
  • Text configs (C2 server addresses)
  • Data files (stolen information)

Example: Analyzing a suspicious directory:

file suspicious_folder/* | grep -v "executable"

The skill you're learning: How to quickly identify which files contain readable, useful information. This is essential when:

  • Enumerating directories
  • Finding configuration files
  • Analyzing log files
  • Processing data dumps
  • Identifying file types during investigations

🚨 Common Mistakes

Mistake 1: Trying to Read Binary Files

Wrong:

cat ./-file00
# Shows gibberish - binary file

Right:

file ./*              # Check file types first
cat ./-file02         # Read only the ASCII text file

Why: Binary files show gibberish when read with cat. Check file types first to save time.

Mistake 2: Forgetting ./ with Dashes

Wrong:

file -file01
# Might be interpreted as an option

Right:

file ./-file01
# Or use wildcard: file ./*

Why: Files starting with dashes need ./ to be treated as filenames.

Mistake 3: Reading Every File Manually

Wrong:

cat ./-file00
cat ./-file01
cat ./-file02
# ... slow and tedious

Right:

file ./*              # Check all files at once
cat ./-file02         # Read only the readable one

Why: file is much faster than reading every file manually.

Mistake 4: Not Understanding the Output

Confusion: "What does 'data' mean? What does 'ASCII text' mean?"

Clarification:

  • ASCII text β€” Human-readable, can read with cat
  • data β€” Binary file, will show gibberish
  • executable β€” Compiled program, binary

For Level 5: Look for the file that shows "ASCII text" β€” that's your password file.

Mistake 5: Not Using Wildcards

Wrong:

file ./-file00
file ./-file01
file ./-file02
# ... typing each filename

Right:

file ./*
# Checks all files at once

Why: Wildcards save time and ensure you don't miss any files.


πŸ’» Practice Exercise

Try these to reinforce what you learned:

  1. Create test files:

    echo "readable text" > ./test-text.txt
    echo -e "\x00\x01\x02" > ./test-binary.bin
    
  2. Check their types:

    file ./test-text.txt
    file ./test-binary.bin
    
  3. Use wildcards:

    file ./test-*
    
  4. Read the readable one:

    cat ./test-text.txt
    
  5. Try reading the binary (see what happens):

    cat ./test-binary.bin
    # Shows gibberish or control characters
    
  6. Clean up:

    rm ./test-text.txt ./test-binary.bin
    

πŸŽ“ Understanding Wildcards

This is a good time to understand wildcards, because they're incredibly useful:

Common Wildcards

* β€” Matches any characters (zero or more)

  • file * β€” All files in current directory
  • file *.txt β€” All .txt files

? β€” Matches exactly one character

  • file file?.txt β€” Matches file1.txt, file2.txt, etc.

[] β€” Matches any character in brackets

  • file file[0-9].txt β€” Matches file0.txt through file9.txt

For Level 5: We use ./* which matches all files in the current directory.

Why Wildcards Are Powerful

Wildcards let you:

  • Process multiple files at once
  • Avoid typing long lists
  • Ensure you don't miss files
  • Work with patterns

Example:

# Instead of:
file file1 file2 file3 file4 file5

# Use:
file file*

πŸ”— What's Next?

Level 6 introduces the find commandβ€”one of the most powerful Linux tools. You'll learn to search for files based on specific criteria like size and permissions, which is essential for finding files in large directory structures.

Before moving on, make sure you:

  • βœ… Successfully navigated to the inhere directory
  • βœ… Used file ./* to check file types
  • βœ… Identified the ASCII text file
  • βœ… Read the password from the human-readable file
  • βœ… Understand the difference between text and binary files

πŸ“š Key Takeaways

After completing Level 5, you should understand:

  1. file command β€” Identifies file types (text vs. binary)
  2. Wildcards β€” Using * to match multiple files
  3. File types β€” ASCII text is readable, data/binary is not
  4. Efficiency β€” Check file types before reading to save time
  5. Combining skills β€” Using ./ with dashes and file together

🎯 Quick Reference

ProblemSolutionExample
Check file typeUse filefile filename
Check multiple filesUse wildcardfile ./*
Find readable filesFilter outputfile ./* | grep "ASCII"
Read file with dashUse ./cat ./-file
Identify binary filesLook for "data"file ./* shows types

Questions about Level 5 or using the file command? Reach out directly:


M Square LLC
Cybersecurity | Penetration Testing | No-Nonsense Advice

Found this helpful? Share it:

Need Help With This?

Have questions about implementing these security practices? Let's discuss your specific needs.

Get in Touch

More in Educational

Explore more articles in this category.

Browse 🧠 Educational

Related Articles