PowerShell helper functions used to automate repetitive tasks while working through the OverTheWire Bandit wargame.
This project was created as a learning exercise to improve:
- PowerShell scripting
- bash scripting
- SSH automation
- Secure credential handling
- Command-line workflow efficiency
- Linux administration skills
- Cybersecurity fundamentals
The toolkit wraps common SSH operations and provides simple commands for connecting to Bandit levels, executing remote commands, and managing credentials.
- Store level passwords locally
- Automatically generate usernames (
bandit0,bandit1, etc.) - Resolve Bandit server IP dynamically via DNS
- Launch SSH sessions with a single command
- Execute remote commands without opening an interactive session
- Support SSH private key authentication for key-based levels
- PowerShell parameter validation and error handling
Developed using PowerShell 5.1, but should also work in Windows PowerShell 7.
This project relies on plink.exe, which is included with PuTTY.
Download PuTTY:
Verify installation:
plink -VIf PowerShell cannot find plink, add the PuTTY installation directory to your system PATH.
Windows 10/11 typically includes OpenSSH.
Verify installation:
ssh -Vconnect and exec use sshpass to supply the password non-interactively.
installation:
sudo apt install sshpassClone the repository:
git clone https://github.com/<your-username>/<repo-name>.git
cd <repo-name>Import the script:
. .\bandit.ps1The leading period is required to dot-source the script and make the functions available in the current session.
Modify the root path near the top of the script:
$root_path = "D:\personal\code\bandit_solver"This directory stores:
bandit0-pw.txt
bandit1-pw.txt
bandit2-pw.txt
...
bandit14_sshkey_private.txt
These files are intentionally excluded from source control.
record_pw 5 myPasswordHereCreates:
bandit5-pw.txt
setlevel 5Output:
bandit5 using D:\...\bandit5-pw.txt
levelvarclearDisplays the resolved server IP and login information without connecting.
test_connectconnectEquivalent to:
ssh bandit5@bandit.labs.overthewire.org -p 2220exec "ls -la"Example:
exec "cat readme"Useful when scripting level solutions or performing quick verification checks.
Some Bandit levels require SSH key authentication.
Connect using:
ssh_connect 14Supported levels:
14
17
26
The script verifies that the private key file exists before attempting connection.
Stores a password for a specific Bandit level.
Parameters:
| Parameter | Type | Description |
|---|---|---|
| lvl | String | Bandit level |
| pw | String | Password |
Configures the active level, username, and password file.
Parameters:
| Parameter | Type |
|---|---|
| level | String |
Displays the current active level.
Clears session variables.
Performs DNS resolution for:
bandit.labs.overthewire.org
Returns the current IP address.
Displays connection information without opening a session.
Opens an interactive SSH session using plink.
Executes a command remotely through SSH.
Parameters:
| Parameter | Type |
|---|---|
| cmd_string | String |
Connects using a private SSH key.
Parameters:
| Parameter | Type |
|---|---|
| level | String |
Valid values:
14
17
26
This repository intentionally excludes:
- Password files
- SSH private keys
- Personal configuration files
Credentials are stored locally and should never be committed to source control.
This project was built while completing the OverTheWire Bandit wargame:
https://overthewire.org/wargames/bandit/
The goal was to reduce repetitive administrative tasks and focus on solving the challenges themselves while gaining experience with:
- PowerShell automation
- SSH workflows
- Linux command-line environments
- Cybersecurity fundamentals
- Infrastructure scripting
Potential enhancements:
- Secure credential storage using gpg encrypted file
- Improved exception handling
MIT License