except springboard to achieve penetration landing remote server machine

Foreword


Companies have more than one server, you must be logged in stepping stones, stepping stones again from the login server, enter the command frequently very complicated, there is no better way to achieve.
expect can help you perfect

The concept involves


Tcl : (Tool the Command Language) is a very powerful scripting language
the Expect : Tcl-based development language pack, please install it yourself

except central command


the send : send the command string to the process.
the Expect : Some command string to wait for the process. regular expressions and can expect support while waiting for more than one string, and perform different actions for each string. expect but also to understand some special cases, such as timeouts and end of the file.
spawn : activate a Unix program for interactive operation.
InterAct : allows user interaction

send command usage


send "hello god.wei"

Output
[Picture dump outside the chain fails, the source station may have a security chain mechanism, it is recommended to save the pictures uploaded directly down (img-C0BZ7A7K-1580201367165) (/ img / bVbk79E)]
the send command string will be sent directly to the process
that if I want to run the command it, it can be

send "pwd\r"

expect command


For receiving the output of the process, then we can perform different operations by judgment result
expect patlist1 action1 patlist2 action2 ...
command and waits until the output of at least one pattern matches the current process, or wait longer than a specific time length, or wait until the end of file encountered so far.

such as

#!/usr/bin/expect
expect apple
send "I want an apple\n"

Output
[pictures of foreign chains dump fails, the source station may have a security chain mechanism, it is recommended to save the picture down directly upload (img-PaVUu4UH-1580201367167) (/ img / bVbk8av)]
the Expect listens standard output of the current process, if they meet expectations , continues to run the following command

spawn a new process to handle


spawn command is used to start a new process. After the spawn send and expect commands are open and spawn processes interact)

spawn ssh [email protected]
expect apple
send "I want an apple\n"

So that when the process is returned apple when it will output to the process I want an apple

interact: allow user interaction


That does not shut down after the finish if I want to perform remote operation terminal, remain connected how to do, this time interact comes in handy.

spawn ssh [email protected]
interact

So you can stay connected to the remote server

so?

So that we can connect springboard machine and then execute ssh command on the springboard machine to connect to the remote server

Portal : Use except springboard to achieve penetration landing remote server machine

##### Acknowledgments:
1. TCL basic syntax
2. the except Tutorial Chinese version

Published 20 original articles · won praise 4 · views 30000 +

Guess you like

Origin blog.csdn.net/Csw_PHPer/article/details/104100712