Skip to main content

implant

implant

A proof-of-concept for asynchronous adhoc remote procedure calls in Python.

This is work in progress and serves basically as an exercise.

Features

  • Python >= 3.5 asyncio

  • adhoc transferable remote procedures

  • remote part of a implant.core.Command may reside in a separate module

  • a implant.core.Command specific implant.core.Channel enables arbitrary protocols between local and remote side

  • events

  • quite small core

  • tests

Limitations

  • Python >= 3.5

  • only pure Python modules are supported for remote import, if no venv is used

  • implant.core.Command s must reside in a module other then __main__

  • at the moment sudo must not ask for password

Example

General application

import asyncio
import pathlib

from implant import core, connect, commands


async def remote_tasks():
    # create a connector for a python process
    connector = connect.Lxd(
        container='zesty',
        hostname='localhost'
    )
    connector_args = {
        'python_bin': pathlib.Path('/usr/bin/python3')
    }
    # connect to a remote python process
    remote = await connector.launch(**connector_args)

    # start remote communication tasks
    com_remote = asyncio.ensure_future(remote.communicate())
    try:
        # execute command
        cmd = commands.SystemLoad()
        result = await remote.execute(cmd)

        print("Remote system load:", result)

    finally:
        # stop communication tasks
        com_remote.cancel()
        await com_remote


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(remote_tasks())
    loop.close()

An example Echo Command

import logging
import os

from implant import core


log = logging.getLogger(__name__)


class Echo(core.Command):

    """Demonstrate the basic command API."""

    async def local(self, context):
        """The local side of the RPC.

           :param context: :py:obj:`implant.core.DispatchLocalContext`
        """
        # custom protocol
        # first: send
        await context.channel.send_iteration("send to remote")

        # second: receive
        from_remote = []
        async for x in context.channel:
            from_remote.append(x)
        log.debug("************ receiving from remote: %s", from_remote)

        # third: wait for remote to finish and return result
        remote_result = await context.remote_future

        result = {
            'from_remote': ''.join(from_remote),
        }
        result.update(remote_result)
        return result

    async def remote(self, context):
        """The remote side of the RPC.

           :param context: :py:obj:`implant.core.DispatchRemoteContext`
        """
        # first: receive
        from_local = []
        async for x in context.channel:
            from_local.append(x)
        log.debug("************ receiving from local: %s", from_local)

        # second: send
        await context.channel.send_iteration("send to local")

        # third: return result
        return {
            'from_local': ''.join(from_local),
            'remote_self': self,
            'pid': os.getpid()
        }

Internals

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

Metadata

Release files for implant 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for implant 0.1.2
File Size Uploaded
implant-0.1.2.tar.gz 34.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for implant 0.1.2
File Interpreter ABI Platform
implant-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 75.0 kB

Release files / implant-0.1.2.tar.gz

Download URL implant-0.1.2.tar.gz
Size 34.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ace257625b46a2644d74d97ddfc867561c54f3d041f606ec68ef711af4f69a73
BLAKE2b-256 checksum
How to use checksums
9c3755a8048e40d4ba6497497f87af847910752a929120ce0c87732305b8a411
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / implant-0.1.2-py3-none-any.whl

Download URL implant-0.1.2-py3-none-any.whl
Size 40.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c08d251be9e63e0027bded83607244a6382f34e784ad4276f586e693ef85973c
BLAKE2b-256 checksum
How to use checksums
60e172c18f680f6aef28ca4c52c43b20105de25d97375936c32e8f200a5b03d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page