This is the script:
#!/usr/bin/expect
set level [lindex $argv 0]
set password [lindex $argv 1]
spawn ssh bandit$level@bandit.labs.overthewire.org
expect "password: "
send $password\r
sleep 2
send ls\r
expect "$ "
interact
You can invoke it with script_name # PASS, where script_name is whatever you name the script, # is the level number you are on, and PASS in the password for that level. If you name the script ssh_bandit, you can get to the first level (level 0) with:
ssh_bandit 0 bandit0
To look at the script line - by - line, we can see it:
1) Tells bash what program to use to run the script.
2) Sets the level variable to the first argument value.
3) Sets the password variable to the second argument value.
4) Starts an SSH session as the bandit<level#> user @ the server.
5) Waits for the password prompt.
6) Sends the password, and return.
7) Waits two seconds.
8) Sends the ls command, and a newline. (This is handy because you will often want to do a directory listing first thing.)
9) Waits for a prompt.
10) Switches to interactive mode. (Without this, typing exit to leave the SSH shell exits the bash shell.)
(Note: This may not cover the first connection for you, since the bandit server's key may not be in your known hosts, and it does not account for this variation. Feel free to improve upon it.)
(Note: This may not cover the first connection for you, since the bandit server's key may not be in your known hosts, and it does not account for this variation. Feel free to improve upon it.)
No comments:
Post a Comment