连接到Paramiko SSH服务器时“输入时MAC损坏”

时间:2019-07-23 18:47:58

标签: python ssh paramiko

我正在尝试使用Paramiko库编写自定义SSH服务器。我正在设置PTY交互性。这一切都让我感到困惑,但是我认为我已将PTY设置为正确读取/写入SSH通道?

不幸的是,当我尝试使用OpenSSH(ssh -p 2222 user @ localhost)连接到服务器时,在成功进行身份验证之后,我收到响应“输入时MAC损坏”。

这是我的Server类代码:

case DISLIKE_POST_SUCCESS:
  const { imageIdToChange, likeIdToChange } = action.payload
  const images = [...state.images]; 
  const imageIdx = images.findIndex( (img) => img.id === imageIdToChange)
  if (imageIdx === -1) return state

  const likeIdx = images[imageIdx].likes.findIndex( like => like.id === likeIdToChange)
  if (likeIdx === -1) return state

  const imageToMutate = {...images[imageIdx]}
  imageToMutate.likes.splice(likeIdx, 1)
  images[imageIdx] = imageToMutate
  return {
    ...state,
    images: [...images]
  }

在创建服务器对象并进行身份验证之后,我只运行了class Server(paramiko.ServerInterface): def __init__(self): self.event = threading.Event() self.input = "" def check_channel_request(self, kind, chanid): if kind == "session": return paramiko.OPEN_SUCCEEDED return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED def check_auth_password(self, username, password): if (username == "user") and (password == "foo"): return paramiko.AUTH_SUCCESSFUL return paramiko.AUTH_FAILED def check_auth_publickey(self, username, key): key_for_user = paramiko.RSAKey(filename="{0}_key".format(username)) if (key == key_for_user): return paramiko.AUTH_SUCCESSFUL return paramiko.AUTH_FAILED def check_auth_gssapi_with_mic(self, username, gss_authenticated=paramiko.AUTH_FAILED, cc_file=None): return paramiko.AUTH_FAILED def check_auth_gssapi_keyex(self, username, gss_authenticated=paramiko.AUTH_FAILED, cc_file=None): return paramiko.AUTH_FAILED def enable_auth_gssapi(self): return False def get_allowed_auths(self, username): return "password,publickey" def check_channel_shell_request(self, channel): self.event.set() return True def check_channel_pty_request(self, channel, term, width, height, pixelwidth, pixelheight, modes): (self.pty_pid, self.pty_fd) = pty.fork() return True def run_pty(self, channel): x = chan.recv(1024).decode("utf-8") chan.send(x) if x == "\r": os.write(self.pty_fd, self.input) output = os.read(self.pty_fd, 1024) output = output.stdout.strip("\n") chan.send(output) self.input = "" else: self.input += x return x def check_channel_forward_agent_request(self, channel): return True def check_channel_direct_tcpip_request(self, channelID, origin, dest): print("Forwarding request received") response = paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED if origin[0] == "localhost" or origin[0] == "127.0.0.1": print("TCP/IP Forwarding request accepted") response = paramiko.OPEN_SUCCEEDED return response 循环以使用while方法。

从我在各个地方输入的调试语句来看,它似乎进入了PTY分配阶段,并在此之后似乎失败了。

我希望您能在此方面提供任何清晰说明。我已经尝试为服务器打印首选的HMAC,这似乎与OpenSSH期望的匹配,所以我认为HMAC不匹配不是原因。

0 个答案:

没有答案