Twisted Conch MockSSH:实施 'stty -echo'
Twisted Conch MockSSH: implement 'stty -echo'
我正在尝试使用 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' 命令时同样有效。
经过几天的工作,我找到了一个适合我的目的的解决方案,从 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 协议中设置一个标志以 enable/disable 输入打印。
我了解到 recvline.HistoricRecvLine.characterRecieved() 方法处理来自终端的输入文本,terminal.write() 用于打印到 STDOUT。
我正在尝试使用 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' 命令时同样有效。
经过几天的工作,我找到了一个适合我的目的的解决方案,从 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 协议中设置一个标志以 enable/disable 输入打印。
我了解到 recvline.HistoricRecvLine.characterRecieved() 方法处理来自终端的输入文本,terminal.write() 用于打印到 STDOUT。