def ConnectServer(self, host, port): if self.ep == 'ncan_ip_tcp': self.debug(0, 'Using ncan_ip_tcp endpoint') self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.sock.settimeout(self.timeout) try: self.debug(0, 'Connecting to ', host, ':', str(port)) self.sock.connect((host, port)) self.connected = 1 except: self.debug(0, 'Failed to connect') return False return True elif self.ep == 'ncan_np': self.debug(0, 'Using ncan_np endpoint') self.debug(0, 'Doing SMB Negotiation') try: self.sock = SMB.SMB(self.smb_serv_name, host, my_name=self.smb_my_name, sess_port=port, timeout=self.timeout) except SMB.SessionError: self.debug(1, 'SMB Negotiation Failed') return False self.debug(0, 'Doing SMB SessionSetupAndX') try: self.sock.login(self.smb_user, self.smb_pass) except SMB.SessionError: self.debug(1, 'SMB SessionSetupAndX Failed') return False self.debug(0, 'Connecting to SMB Share ', self.smb_share) try: self.smb_tid = self.sock.connect_tree(self.smb_share, '?????\x00', self.smb_pass) except SMB.SessionError: self.debug(1, 'Failed to connected to share: ', self.smb_share) return False self.debug(0, 'Opening named pipe ', self.smb_pipe, ' for reading/writing') try: self.smb_fid = self.sock.nt_create(self.smb_tid, self.smb_pipe) except SMB.SessionError: self.debug(1, 'Failed to open pipe: ', self.smb_pipe) return False self.connected = 1 return True else: self.debug(1, 'Unknown DCERPC endpoint') return False