首页 文章

Facebook Thrift SSH帧大小错误

提问于
浏览
0

我正在我的机器上运行Facebook Thrift服务 . 我使用示例代码来显示其工作情况:

import asyncio

from fbnet.command_runner.thrift_client import AsyncioThriftClient

# Import FCR Thrift Types
from fbnet.command_runner_asyncio.CommandRunner import ttypes as fcr_ttypes

# Import FCR Service Client
from fbnet.command_runner_asyncio.CommandRunner.Command import Client as FcrClient

import getpass

# Device Information
hostname = 'my_vm'
username = 'root'
password = getpass.getpass('%s Password: ' % username)

# Destination device
device = fcr_ttypes.Device(hostname=hostname, username=username,     password=password)

async def run(cmd, device):
    async with AsyncioThriftClient(FcrClient, 'x.x.x.x',22 ) as client:
        res = await client.run(cmd, device)
        # type of res is `struct CommandResult`
        print(res.output)

loop = asyncio.get_event_loop()
loop.run_until_complete(run('uname -a', device))

但是我收到以下错误:

帧大小1397966893对于THeaderProtocol Traceback而言太大(最近一次调用最后一次):文件“pgm1.py”,第28行,在loop.run_until_complete中(运行('uname -a',device))文件“/ usr / local / lib /python3.6/asyncio/base_events.py“,第467行,在run_until_complete中返回future.result()文件”pgm1.py“,第23行,在运行res = await client.run(cmd,device)thrift.transport . TTransport.TTransportException:连接已关闭

有关如何纠正此问题的任何想法?

1 回答

  • 0

    @Kenster的评论表明这里存在真正的问题 .

    0x5353482D是四个字符“SSH-”,它恰好是ssh服务器连接到它时发送的第一个数据

    some server implementations that require TFramedProtocol by design . 换句话说,它是强制性的,客户端必须使用它,只是因为服务器期望它 .

    对于知道 TFramedProtocol 添加了一个4字节标头,其中包含要遵循的数据帧大小的人来说,这种见解很快就会出现 . 如果客户端不使用 TFramedProtocol ,则服务器会将前四个数据字节解释为帧大小 - 因此出现错误消息 .

    解决方案

    在客户端将 TFramedProtocol 添加到Thrift传输/协议堆栈 .

相关问题