通过stdin/stdout消息远程执行。

implant的Python项目详细描述


https://travis-ci.org/diefans/implant.svg?branch=masterPyPI - Python VersionPyPIRead the Docshttps://codecov.io/gh/diefans/implant/branch/master/graph/badge.svg

implant

植入物

python中异步临时远程过程调用的概念证明。

这是一项正在进行的工作,基本上是一项练习。

功能

  • python>;=3.5异步
  • 临时可转让远程程序
  • implant.core.command的远程部分可以位于单独的模块中
  • aimplant.core.commandspecificimplant.core.channel 在本地和远程端之间启用任意协议
  • 事件
  • 相当小的磁芯
  • 测试

限制

  • python>;=3.5
  • 如果未使用venv,则远程导入仅支持纯python模块
  • implant.core.commands必须位于除main>以外的模块中
  • 目前,sudo不能要求输入密码

示例

一般应用
importasyncioimportpathlibfromimplantimportcore,connect,commandsasyncdefremote_tasks():# create a connector for a python processconnector=connect.Lxd(container='zesty',hostname='localhost')connector_args={'python_bin':pathlib.Path('/usr/bin/python3')}# connect to a remote python processremote=awaitconnector.launch(**connector_args)# start remote communication taskscom_remote=asyncio.ensure_future(remote.communicate())try:# execute commandcmd=commands.SystemLoad()result=awaitremote.execute(cmd)print("Remote system load:",result)finally:# stop communication taskscom_remote.cancel()awaitcom_remoteif__name__=='__main__':loop=asyncio.get_event_loop()loop.run_until_complete(remote_tasks())loop.close()

回声命令示例
importloggingimportosfromimplantimportcorelog=logging.getLogger(__name__)classEcho(core.Command):"""Demonstrate the basic command API."""asyncdeflocal(self,context):"""The local side of the RPC.

           :param context: :py:obj:`implant.core.DispatchLocalContext`
        """# custom protocol# first: sendawaitcontext.channel.send_iteration("send to remote")# second: receivefrom_remote=[]asyncforxincontext.channel:from_remote.append(x)log.debug("************ receiving from remote: %s",from_remote)# third: wait for remote to finish and return resultremote_result=awaitcontext.remote_futureresult={'from_remote':''.join(from_remote),}result.update(remote_result)returnresultasyncdefremote(self,context):"""The remote side of the RPC.

           :param context: :py:obj:`implant.core.DispatchRemoteContext`
        """# first: receivefrom_local=[]asyncforxincontext.channel:from_local.append(x)log.debug("************ receiving from local: %s",from_local)# second: sendawaitcontext.channel.send_iteration("send to local")# third: return resultreturn{'from_local':''.join(from_local),'remote_self':self,'pid':os.getpid()}

内部

master <-----------------------------------------> remote
                            |
                       stdin/stdout
                            |
                          chunks
                            |
                         channels
                            |
    --> send ---> |                   |  --> queue -->
                  | module:class/fqin |
    <-- queue <-- |                   |  <--- send <--

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java无法在未设置数据源的情况下启动springboot应用程序   返回/泛型的类型?   java通过在navigationView中按id重新加载navigationView内容   java实现安卓的状态更新   java Equals()对于两个相等的字符串不返回true   java如何保存屏幕截图(matlab)   java GWT如何在重新加载页面之前确保函数已完全执行   java在Groovy中实现ObjectJSON映射的标准方法是什么?   java在ApacheTomcat中,是否可以通过连接器过滤多个访问日志文件?   java当JVM达到其Xmx限制时,它会强制垃圾收集吗?   如何在JAVA中生成包含特定数字的不同随机数列表?   rcp中透视图之间的java切换   java理解名为“分区”的Linkedlist算法中的无限循环   RestTemplate的java测微计统计信息   Android中使用自定义服务BLE的java读/写特性   java验证输入以确保负数   关于Java扫描器的io基本查询   java如何使用子字符串或其他函数将字符串拆分为单词?   java Storm群集重复元组