0

我正在尝试使用MockSSH设置模拟 ssh shell 服务器。

为了测试我正在处理的特定应用程序,我需要能够阻止 shell 回显输入。应用程序总是通过发出“stty -echo”命令启动,因此 stdout 只包含输出。前任:

user@host> echo "hello world"
hello world
user@host> stty -echo
user@host>
hello world
user@host>
I swear I just typed 'echo "hello world"'!

默认情况下禁用回显,或者在发出“stty -echo”命令时同样有效。

4

1 回答 1

1

经过几天的工作,我找到了一个适合我的解决方案,从 SSHProtocol 实现的 characterReceived 方法中注释掉“self.termina.write(ch)”,完全禁用输入打印,就像“stty -echo”一样命令已在 bash 中运行。

class SSHProtocol(recvline.HistoricRecvLine):
    [...]
    def characterReceived(self, ch, moreCharactersComing):
        self.lineBuffer[self.lineBufferIndex:self.lineBufferIndex+1] = [ch]
        self.lineBufferIndex += 1

        #if not self.password_input:
        #    self.terminal.write(ch)

这适用于我的目的,我相信您可以轻松地在 SSH 协议中设置一个标志来启用/禁用输入打印。

我了解到的是 recvline.HistoricRecvLine.characterRecieved() 方法处理来自终端的输入文本,并且 terminal.write() 用于打印到 STDOUT。

于 2015-08-02T19:22:00.437 回答