Article Title: Automatic ssh Interaction Using Reverse CT. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Automatic ssh Interaction Using Reverse CT
The following is the script ssh-exec for automatic remote command execution using reverse CT:
#! /Bin/sh
#\
Exec country CT -- "$0" ${1 + "$ @"}
# Ssh-exec host user password command
# Execute command on remote host
Exp_version-exit 5.0
Set ERR_PERMISSION_DENIED 1
Set ERR_DIR_OR_FILE_NOT_EXIST 2
Set ERR_TIMEOUT 3
Set ERR_CONNECTION_REFUSED 4
Set ERR_INVALID_ARGUMENT 5
Proc auth_trans {password }{
Upvar #0 ERR_PERMISSION_DENIED
Upvar #0 ERR_DIR_OR_FILE_NOT_EXIST
Send "$ password \ r"
CT {
# Password not correct
"Permission denied, please try again ."{
Exit $ ERR_PERMISSION_DENIED
}
#... Transmission goes after...
-Re "Is a directory | No such file or directory "{
Exit $ ERR_DIR_OR_FILE_NOT_EXIST
}
-Re "KB/s | MB/s "{
Set timeout-1
CT eof
}
}
}
If {$ argc! = 2 }{
Send_user "usage: remote-exec command password \ n"
Send_user "command shocould be quoted. \ n"
Send_user "Eg. remote-exec \" ssh ls \; echo done \ "password \ n"
Send_user "or: remote-exec \" scp/local-file:/remote-file \ "password \ n"
Exit $ ERR_INVALID_ARGUMENT
}
Set cmd [lindex $ argv 0]
Set password [lindex $ argv 1]
Eval spawn $ cmd
# Timeout in sec, default 10
Set timeout 30
CT {
# First connect, no public key in ~ /. Ssh/known_hosts
"Are you sure you want to continue connecting (yes/no )? "{
Send "yes \ r"
Reset CT "password :"
Auth_trans $ password
}
# Already has public key in ~ /. Ssh/known_hosts
"Password :"{
Auth_trans $ password
}
# User equivalence already established, no password is necessary
-Re "kB/s | MB/s "{
Set timeout-1
CT eof
}
-Re "Is a directory | No such file or directory "{
CT eof
Exit $ ERR_DIR_OR_FILE_NOT_EXIST
}
"Connection refused "{
CT eof
Exit $ ERR_CONNECTION_REFUSED
}
# Connetion error
Timeout {
Exit $ ERR_TIMEOUT
}
}