Exemplo n.º 1
0
def main():
    options, server, remote = parse_options()
    password = ""
    if options.readpass:
        password = getpass.getpass("Enter SSH password: "******"Connecting to ssh host %s:%d ..." % (server[0], server[1]))
    try:
        proxy_uri = ""
        url = urllib.parse.urlparse(proxy_uri)
        http_con = http.client.HTTPConnection(url.hostname, url.port)

        headers = {}
        if url.username and url.password:
            auth = '%s:%s' % (url.username, url.password)
            headers['Proxy-Authorization'] = 'Basic ' + base64.b64encode(auth)
        http_con.set_tunnel(server[0], server[1], headers)
        http_con.connect()
        sock = http_con.sock
        #sock = http_proxy_tunnel_connect(proxy=("",),target=(server[0],server[1]),timeout=500)
        data = sock.recv(5)
        print(data.decode())
        sock.send("HELLO BACK".encode())
        #sock.send("\nClient: HELLO BACK".encode())
        #print(data.decode())
        client.connect(hostname=server[0],
                       port=server[1],
                       sock=sock,
                       username=options.user,
                       password=password,
                       banner_timeout=4)
    except Exception as e:
        print(
            ("*** Failed to connect to %s:%d: %r" % (server[0], server[1], e)))
        raise e
        sys.exit(1)

    verbose("Now forwarding remote port %d to %s:%d ..." %
            (options.port, remote[0], remote[1]))

    try:
        reverse_forward_tunnel(options.port, remote[0], remote[1],
                               client.get_transport())
    except KeyboardInterrupt:
        print("C-c: Port forwarding stopped.")
        sys.exit(0)
Exemplo n.º 2
0
    def connect(self):
        logger.debug(
            "Opening SSH connection to {host}:{port}".format(
                host=self.host, port=self.port))
        client = SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(AutoAddPolicy())

        try:
            client.connect(
                self.host,
                port=self.port,
                username=self.username,
                timeout=self.timeout, )
        except ValueError as e:
            logger.error(e)
            logger.warning(
                """
Patching Crypto.Cipher.AES.new and making another attempt.

See here for the details:
http://uucode.com/blog/2015/02/20/workaround-for-ctr-mode-needs-counter-parameter-not-iv/
            """)
            client.close()
            import Crypto.Cipher.AES
            orig_new = Crypto.Cipher.AES.new

            def fixed_AES_new(key, *ls):
                if Crypto.Cipher.AES.MODE_CTR == ls[0]:
                    ls = list(ls)
                    ls[1] = ''
                return orig_new(key, *ls)

            Crypto.Cipher.AES.new = fixed_AES_new
            client.connect(
                self.host,
                port=self.port,
                username=self.username,
                timeout=self.timeout, )
        return client
Exemplo n.º 3
0
    def connect(self):
        logger.debug(
            "Opening SSH connection to {host}:{port}".format(
                host=self.host, port=self.port))
        client = SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(AutoAddPolicy())

        try:
            client.connect(
                self.host,
                port=self.port,
                username=self.username,
                timeout=self.timeout, )
        except ValueError as e:
            logger.error(e)
            logger.warning(
                """
Patching Crypto.Cipher.AES.new and making another attempt.

See here for the details:
http://uucode.com/blog/2015/02/20/workaround-for-ctr-mode-needs-counter-parameter-not-iv/
            """)
            client.close()
            import Crypto.Cipher.AES
            orig_new = Crypto.Cipher.AES.new

            def fixed_AES_new(key, *ls):
                if Crypto.Cipher.AES.MODE_CTR == ls[0]:
                    ls = list(ls)
                    ls[1] = ''
                return orig_new(key, *ls)

            Crypto.Cipher.AES.new = fixed_AES_new
            client.connect(
                self.host,
                port=self.port,
                username=self.username,
                timeout=self.timeout, )
        return client