ssh.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:SameKeyProxy 作者: xzhou 项目源码 文件源码
def configure_client_socket(self):

        self.log.info("SSHProtocol: ccs: configuring client socket")

        host_key = paramiko.RSAKey(filename='test_rsa.key')

        self.sourcet = paramiko.Transport(self.source)
        try:
            self.sourcet.load_server_moduli()
        except:
            self.log.error("SSHProtocol: Failed to load moduli -- gex " \
                           "will be unsupported.)")
            raise
        self.sourcet.add_server_key(host_key)



        # Initialize the SSH connection to the server
        # BUGFIX: client must init before the server start. A race condition
        # was created between the server and the client. If the client can
        # get credentials to SSHServer before client socket config 
        # this method there will be an error.
        self.log.info("SSHProtocol: initializing client to server SSH")
        self.init_ssh_client()

        # Start up the SSH server.                     
        server = SSHServer(self)                
        try:
            self.sourcet.start_server(server=server)
        except paramiko.SSHException, x:
            self.log.error("SSHProtocol: SSH negotiation failed.")
            return

        # wait for auth
        chan = self.sourcet.accept(20)
        if chan is None:
            self.log.error("*** No channel.")
            sys.exit(1)
        self.log.info("SSHProtocol: User authenticated!")


        server.event.wait(10)
        if not server.event.isSet():
            self.log.warn("SSHProtocol: client never asked for a anything.")
            return

        chan.send('\r\n\r\nThings just got real.\r\n\r\n')

        self.sourceschan = chan
        self.log.debug("SSHProtocol: finished configuring client socket")

        self.destschan = self.destt.open_session()
        self.destschan.get_pty()
        self.destschan.invoke_shell()

#    chan = t.open_session()
#    chan.get_pty()
#    chan.invoke_shell()

        #chan.close()
        #self.sourcet.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号