Last active
March 31, 2020 19:47
-
-
Save emilio1625/6982abc4683cbb7f2928b4f6ee52f46d to your computer and use it in GitHub Desktop.
Script to help you to connect to the next level of the bandit game of overthewire.org
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# $1 = starting level, zero if unset | |
# $2 = end level, 34 if unset | |
NORMAL="\e[0m" | |
RED="\e[1;31m" | |
i=${1:-0} | |
end=${2:-34} | |
while [[ $i -le $end ]]; do | |
# if there is a key file, try that first | |
if [[ -f "level${i}.priv" ]]; then | |
ssh "bandit${i}@bandit.labs.overthewire.org" -p 2220 -i "level${i}.priv" | |
elif [[ $i -eq 18 ]]; then | |
ssh "bandit${i}@bandit.labs.overthewire.org" -p 2220 | |
echo -e "${RED}\nDid work right?\n Now give me your custom ssh command:${NORMAL}" | |
read ssh_cmd | |
$ssh_cmd | |
else | |
ssh "bandit${i}@bandit.labs.overthewire.org" -p 2220 | |
fi | |
# ssh endded gracefully | |
if [[ $? -eq 0 ]]; then | |
# in level 16 you get a ssh key | |
if [[ $i -eq 16 ]]; then | |
echo -e "${RED}Write the ssh priv key (ctrl+d to finish)${NORMAL}\n" | |
cat > "level$((i+1)).priv" | |
chmod 400 "level$((i+1)).priv" | |
fi | |
i=$((i+1)) | |
# error on ssh command, probably wrong password | |
else | |
echo -ne "\n${RED}Wrong password! ${NORMAL}Try to find again? [Y/n] " | |
read again; | |
if [[ $again == "n" ]]; then | |
exit -1 | |
else | |
i=$((i-1)) | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment