c2工具sliver的python客户端无法修改grpc超时时间的解决办法

发布时间 2023-08-21 19:08:46作者: 干炸小黄鱼

业务需要,调用了很多implants来执行对应系统上的命令, 但是无论怎么指定interactive.py中execute方法参数, 命令执行超时时间总是30.
后面通过扩展execute方法增加一个grpc超时参数后解决;具体方法如下:

async def execute_ex(self, exe: str, args: List[str], output: bool, timeout: int = 60) -> sliver_pb2.Execute:
        '''Execute a command/subprocess on the remote system
        :param exe: Command/subprocess to execute
        :type exe: str
        :param args: Arguments to the command/subprocess
        :type args: List[str]
        :param output: Enable capturing command/subprocess stdout
        :type output: bool
        :param timeout: grpc超时时间
        :type timeout: int
        :return: Protobuf Execute object
        :rtype: sliver_pb2.Execute
        '''
        execute_req = sliver_pb2.ExecuteReq(Path=exe, Args=args, Output=output)
        req = self._request(execute_req)
        req.Request.Timeout = timeout * 1000000000 * 2 # 秒需要转换为纳秒单位
        rpc_timeout = timeout + self.timeout
        return (await self._stub.Execute(req, timeout=rpc_timeout))