def __init__(self, session):
     self.session = session
     self.callbacks = pysshct.buildCallbacks(
         pysshct.ssh_channel_callbacks_struct, pysshct.CB_CHANNEL_FUNCS,
         self)
     self.libssh_channel = pysshct.lib.ssh_new_channel(
         session.libssh_session, self.callbacks)
Exemple #2
0
 def __init__(self, session, linkedchannel=None):
     self.session = session
     self.callbacks = buildCallbacks(ssh_channel_callbacks_struct, CB_CHANNEL_FUNCS, self)
     self.libssh_channel = lib.ssh_new_channel(session.libssh_session, self.callbacks)
     self.linkedchannel = linkedchannel
     linkedchannel.linkedchannel = self
     self.channel_closed = False
     self.session.server.device_channels.append(self)
Exemple #3
0
    def __init__(self, client_socket, addr, host_key_file, pid_path=None):

        self.libssh_error = lib.ssh_new_error()
        self.username = None
        self.kbdint_response = None
        self.client_socket = client_socket
        self.client_socket.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1)
        self.local_ip, self.local_port = client_socket.getsockname()

        self.client_addr = addr[0]
        self.client_port = addr[1]
        self.host_key_file = host_key_file

        Logger().info("Incoming ssh connection from %s " % self.client_addr)

        self.buffer64 = ctypes.create_string_buffer(10000)

        self.server_callbacks = buildCallbacks(ssh_server_callbacks_struct,
                                               CB_SERVER_SESSION_FUNCS, self)
        self.libssh_mainloop = lib.ssh_new_poll_ctx()

        self.authmethods = (
            #            SSH_AUTH_METHOD_NONE
            SSH_AUTH_METHOD_PASSWORD
            #             | SSH_AUTH_METHOD_GSSAPI_MIC
            #             | SSH_AUTH_METHOD_PUBLICKEY
            #             | SSH_AUTH_METHOD_INTERACTIVE
        )
        self.libssh_session = lib.ssh_start_new_server_session(
            self.server_callbacks,
            self.libssh_mainloop,
            self.client_socket.fileno(),
            self.host_key_file,  # host keyfile contains RSA, DSA or ECDSA key
            self.authmethods)

        lib.ssh_event_set_session_server(self.libssh_mainloop,
                                         self.libssh_session)

        self.lastactiontime = time.time()

        while True:
            rc = lib.ssh_event_dopoll(self.libssh_mainloop, 20000)
            if rc == SSH_ERROR:
                break
            polltime = time.time()
            print "Polling %s" % str(polltime)
    def __init__(self, host, port, user, hostkeys):
        self.libssh_error = pysshct.lib.ssh_new_error()
        self.libssh_mainloop = pysshct.lib.ssh_new_poll_ctx()

        self.callbacks = pysshct.buildCallbacks(
            pysshct.ssh_client_callbacks_struct,
            pysshct.CB_CLIENT_SESSION_FUNCS, self)
        self.libssh_session = lib.ssh_new_client_session(
            self.callbacks, self.libssh_mainloop, host, port, user, hostkeys,
            "4", self.libssh_error)

        self.lastactiontime = time.time()

        while True:
            rc = pysshct.lib.ssh_event_dopoll(self.libssh_mainloop, 20000)
            if rc == pysshct.SSH_ERROR:
                break
            polltime = time.time()
            print "Polling %s" % str(polltime)
 def __init__(self, session):
     self.session = session
     self.callbacks = buildCallbacks(ssh_channel_callbacks_struct,
                                     CB_CHANNEL_FUNCS, self)
     self.libssh_agentchannel = lib.ssh_new_channel(session.libssh_session,
                                                    self.callbacks)
Exemple #6
0
    def __init__(self,
                 wabengine_proxy,
                 target_rights,
                 linkedchannel,
                 svr_obj,
                 x11session=False,
                 use_agent=False,
                 gssapi_token=None):

        self.userAuthNoneStatus = None
        self.libssh_error = lib.ssh_new_error()

        self.x11session = x11session
        self.use_agent = use_agent
        self.gssapi_token = gssapi_token

        self.wabengine_proxy = wabengine_proxy
        self.target_rights = target_rights
        self.server = svr_obj

        self.linkedchannel = linkedchannel

        self.pid = getpid()

        self.server._window_change_handler = self.window_change_handler

        self.client_addr = self.server.client_addr

        self.language = self.wabengine_proxy.get_language()

        login_info = self.wabengine_proxy.get_target_login_info()
        self.user = login_info.account_login
        self.autologon = login_info.autologon
        self.host = login_info.device_host
        self.port = login_info.service_port
        self.hname = login_info.target_name
        # self.conn_cmd = login_info.conn_cmd
        self.service_name = login_info.service_name

        self.started = STARTED_INIT

        # Complete target host context from transparent mode
        # if '/' in self.host and self.server.real_target_ip is not None:
        #     self.host = self.server.real_target_ip
        if '/' in self.host and self.server.target_context is not None:
            self.host = self.server.target_context.host
        # Complete target login context from passthrough mode
        if self.server.passthrough_login is not None:
            self.user = self.server.passthrough_login

        target_hostkeys = self.server.config.get('target_hostkeys_type')
        if not target_hostkeys:
            target_hostkeys = "ssh-rsa,ssh-dss"

        host = self.host.encode('utf-8')
        port = str(self.port)
        user = self.user.encode('utf-8')
        hostkeys = target_hostkeys
        verbosity = "4"
        hname = self.hname.encode('utf-8')
        service_name = self.service_name.encode('utf-8')

        self.callbacks = buildCallbacks(ssh_client_callbacks_struct,
                                        CB_CLIENT_SESSION_FUNCS, self)
        self.libssh_session = lib.ssh_new_client_session(
            self.callbacks, svr_obj.libssh_mainloop, host, port, user,
            hostkeys, "4", self.libssh_error)
        try:
            if self.libssh_session == None:
                raise SSHException(
                    lib.ssh_get_error(self.libssh_error).decode('utf-8'))

            #Verify fingerprint
            buf = ctypes.create_string_buffer(32)
            rc = lib.ssh_get_server_publickey_hash_value_client(
                self.libssh_session, SSH_PUBLICKEY_HASH_MD5, buf, 0,
                self.libssh_error)
            if (rc == SSH_ERROR):
                raise SSHException(
                    lib.ssh_get_error(self.libssh_error).decode('utf-8'))
            finger_raw = buf.raw[:16]

            status, message = self.wabengine_proxy.check_device_fingerprint(
                hname, service_name, finger_raw)
            #            status, message = self.wabengine_proxy.check_device_fingerprint(self.hname, finger_raw)
            if not status:
                self.linkedchannel.write_stderr_server(
                    "Cannot connect to target\r\n")
                self.linkedchannel.write_stderr_server("%s\r\n" % message)
                raise SSHClientError(message)
        except SSHClientError, m:
            Logger().info("Cannot connect to target.")
            Logger().info("%s" % m)
            self.started = STARTED_REJECTED