Automatic ssh Interaction Using Reverse CT

Source: Internet
Author: User
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

}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.