Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用twisted.conch作为客户端使用ssh接收扩展数据_Python_Ssh_Twisted_Twisted.conch - Fatal编程技术网

Python 使用twisted.conch作为客户端使用ssh接收扩展数据

Python 使用twisted.conch作为客户端使用ssh接收扩展数据,python,ssh,twisted,twisted.conch,Python,Ssh,Twisted,Twisted.conch,我目前正在通过蛮力学习ssh/继续黑客攻击直到我理解它的方法。经过一些尝试和错误,我已经能够成功地发送一个“pty req”和一个“shell”请求,我可以获得登录前导、发送命令和接收stdout,但我不确定如何告诉SSH服务我想要接收stderr和状态消息。阅读其他SSH实现(paramiko,Net::SSH)目前还不是一个很好的指南 也就是说,看看SSH的一个RFC,我相信可能列出的请求之一就是我要寻找的: 此外,我还尝试向远程shell添加一个明确的错误命令: self.writ

我目前正在通过蛮力学习ssh/继续黑客攻击直到我理解它的方法。经过一些尝试和错误,我已经能够成功地发送一个“pty req”和一个“shell”请求,我可以获得登录前导、发送命令和接收stdout,但我不确定如何告诉SSH服务我想要接收stderr和状态消息。阅读其他SSH实现(paramiko,Net::SSH)目前还不是一个很好的指南

也就是说,看看SSH的一个RFC,我相信可能列出的请求之一就是我要寻找的:

此外,我还尝试向远程shell添加一个明确的错误命令:

    self.write("ls -alF badPathHere\n\x00")
    try:
        data = yield self.getResponse()
    except Exception as e:
        print "Failed to catch response?", e
    else:            
        print data
        """
        ls -alF badPathHere
        ls: cannot access badPathHere: No such file or directory
        \x1B]0;dward@pristine: ~\x07dward@pristine:~$ 
        """

看起来stderr与stderr混合在一起了

挖掘OpenSSH的源代码,通道会话逻辑在at行中处理 2227函数->会话\输入\通道\请求,如果给定pty req,则“shell”请求将导致执行,最终导致调用会话\设置\ fds(s、ptyfd、fdout,-1、1、1)。第四个参数通常是负责处理stderr的文件描述符,但由于没有提供任何文件描述符,因此stderr不会有任何扩展数据


最终,即使我修改了openssh以提供stderr FD,问题仍然存在于shell中。在这一点上完成猜测是可行的,但我相信,与通过诸如xterm或putty之类的终端登录ssh服务类似,stderr和stdout会一起发送,除非通过ssh服务提供商范围之外的“2>someFile”之类的内容显式重定向。

如果您请求PTY,stderr和stdout放在同一个地方是有道理的:您可以将伪TTY本身想象成“屏幕”,显然您希望将stdout和stderr都发送到用户可以看到它们的地方。您是否查看了
exec
请求而不是
pty-req
请求会发生什么情况?有一个分支,exec在do_-exec_-pty和do_-exec_-no_-pty上拆分,没有捕获pty-stderr。在我的测试中,只有shell没有为执行提供returnval,这很有意义。
    self.write("ls -alF badPathHere\n\x00")
    try:
        data = yield self.getResponse()
    except Exception as e:
        print "Failed to catch response?", e
    else:            
        print data
        """
        ls -alF badPathHere
        ls: cannot access badPathHere: No such file or directory
        \x1B]0;dward@pristine: ~\x07dward@pristine:~$ 
        """