π 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
filecommand - 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
filecommand 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
filecommand
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
filecommand
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 filedataβ Binary data fileexecutableβ Compiled programPNG imageβ Image filegzip 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:
Method 1: file with Wildcard (Recommended)
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:
.bakfiles 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 withcatdataβ Binary file, will show gibberishexecutableβ 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:
-
Create test files:
echo "readable text" > ./test-text.txt echo -e "\x00\x01\x02" > ./test-binary.bin -
Check their types:
file ./test-text.txt file ./test-binary.bin -
Use wildcards:
file ./test-* -
Read the readable one:
cat ./test-text.txt -
Try reading the binary (see what happens):
cat ./test-binary.bin # Shows gibberish or control characters -
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 directoryfile *.txtβ All .txt files
? β Matches exactly one character
file file?.txtβ Matchesfile1.txt,file2.txt, etc.
[] β Matches any character in brackets
file file[0-9].txtβ Matchesfile0.txtthroughfile9.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
inheredirectory - β
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:
filecommand β Identifies file types (text vs. binary)- Wildcards β Using
*to match multiple files - File types β ASCII text is readable, data/binary is not
- Efficiency β Check file types before reading to save time
- Combining skills β Using
./with dashes andfiletogether
π― Quick Reference
| Problem | Solution | Example |
|---|---|---|
| Check file type | Use file | file filename |
| Check multiple files | Use wildcard | file ./* |
| Find readable files | Filter output | file ./* | grep "ASCII" |
| Read file with dash | Use ./ | cat ./-file |
| Identify binary files | Look for "data" | file ./* shows types |
Questions about Level 5 or using the file command? Reach out directly:
- Email: m1k3@msquarellc.net
- Phone: (559) 670-3159
- Schedule: Book a free consultation
M Square LLC
Cybersecurity | Penetration Testing | No-Nonsense Advice