Skip to main content

OpenC2 Utilities for Python - Library and applications

Project description

otupy: OpenC2 Utilities for Python

Description

otupy (/'əʊtu:paɪ/) is an open-source implementation of the OpenC2 language written in Python. It is particullary suited for:

  • developers that are looking for a common interface to control their remote cybersecurity functions;
  • researchers that design new profiles for cybersecurity functions;
  • system integrators that need a common language for their cybersecurity frameworks.

The otupy framework is build around a pluggable and powerful core library, designed with flexibility and extensibility in mind. Profiles, transfer protocols, serialization formats, and actuators can be easily added without impacting the core library itself. The framework currently includes:

  • the core library that implements the OpenC2 Architecture and Language Specification;
  • json/yaml/xml/cbor serialization;
  • implementation of the HTTP/MQTT transfer protocol;
  • the definition of the SLPF profile;
  • the Context Discovery profile and its actuators for OpenStack and Kubernetes;
  • a dumb implementation of an actuator for the SLPF profile.

Usage and extension of otupy have a shallow learning curve because data structures are explicitly designed to follow the language specification.

Quick start

Before using otupy you must be familiar with the OpenC2 Language Specification. Even if not strictly required to getting started with the code, the OpenC2 Architecture Specification provides a good introduction to OpenC2 architectural patterns and terminology.

While the Language Specification is somehow confusing about the concept of profile and actuator, otupy makes a sharp distinction between these terms:

  • a profile is a language extension that abstract a specific class of security functions (this is also indicated ad Actuator Profile by the standard);
  • an actuator is the concrete implementation of a profile for a specific security appliance; it may be either integrated in the appliance itself or act as a proxy to a legacy implementation (in this last case it is also referred as Actuator Manager.

Software requirements

Python 3.11+ is required to use otupy.

Download and setup

Otupy is available as source code and Python package.

Install it and its dependencies from TestPyPi:

pip install -i https://test.pypi.org/simple/otupy

Alternatively, dowload it from github:

git clone https://github.com/mattereppe/openc2.git

and install the necessary dependecies:

python3 -m venv .oc2-env
. .oc2-env/bin/activate
pip install -r requirements.txt

Usage

A few scripts are available in the examples folder of the repository for sending a simple commmand from a controller to a remote server (hosting the actuator).

Basic usage consists in instantiating the Provider and Consumer classes that implements the OpenC2 Provider and Consumer role, respectively. This includes the creation of a protocol stack, namely the serialization format and transfer protocol. The Consumer also loads the available Actuators. Note that in the otupy implementation, the security services and transport protocols are already embedded in each specific transfer protocol.

Create the Server

A Server instantiates and runs the OpenC2 Consumer.

The otupy module only includes the core libraries, while all extensions for serialization, transfer protocols, profile definition, and actuator implementations are grouped in specific modules (encoders, trasfers, profiles, and actuators).

import otupy as oc2

from otupy.encoders.json_encoder import JSONEncoder
from otupy.transfers.http_transfer import HTTPTransfer

import otupy.profiles.slpf as slpf
from otupy.actuators.iptables_actuator import IptablesActuator

First, we instantiate the IptablesActuator as an implementation of the slpf profile:

 actuators = {}
 actuators[(slpf.nsid,'iptables')]=IptablesActuator()

(there is no specific configuration here because the IptablesActuator is currently a mockup)

Next, we create the Consumer by instantiating its execution environment with the list of served Actuators and the protocol stack. We also provide an identification string:

consumer = oc2.Consumer("consumer.example.net", actuators, JSONEncoder(), HTTPTransfer("127.0.0.1", 8080))

(the server will be listening on the loopback interface, port 8080)

Finally, start the server:

 consumer.run()

Create the Controller

A Controller instantiates an OpenC2 Producer and to use it to control a remote security function. Note that the Producer is totally unaware of the concrete actuators and its implementation.

from otupy.encoders.json_encoder import JSONEncoder
from otupy.transfers.http_transfer import HTTPTransfer

import otupy.profiles.slpf as slpf

producer = oc2.Producer("producer.example.net", JSONEncoder(), HTTPTransfer("127.0.0.1", 8080))

Next we create a Command, by combining the Action, Target, Arguments, and Actuator. We will query the remote slpf actuator for its capabilities. Note how we mix common language elements with specific extensions for the slpf profile, as expected by the Specification:

pf = slpf.slpf({'hostname':'firewall', 'named_group':'firewalls', 'asset_id':'iptables'})
arg = slpf.ExtArgs({'response_requested': oc2.ResponseType.complete})
 
cmd = oc2.Command(oc2.Actions.query, oc2.Features(), actuator=pf)

Finally, we send the command and catch the response:

resp = p.sendcmd(cmd)

(print out resp to check what the server returned)

A more useful implementation of a Controller would also include the business logic to update rules on specific events (even by specific input from the user).

Advanced usage

See the full documentation available from readthedocs.io.

Authors and acknowledgment

  • The Context Discovery profile, its actuators and use cases have been developed by Silvio Tanzarella.

License

Licensed under the EUPL v1.2.

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

otupy-1.1.0.tar.gz (14.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

otupy-1.1.0-py3-none-any.whl (163.9 kB view details)

Uploaded Python 3

File details

Details for the file otupy-1.1.0.tar.gz.

File metadata

  • Download URL: otupy-1.1.0.tar.gz
  • Upload date:
  • Size: 14.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for otupy-1.1.0.tar.gz
Algorithm Hash digest
SHA256 419d6370dcb793033306daf589bd0c7e533c3d8ba447a2c48ff9382a04869134
MD5 05da2dac7f042ccaa305dab76fc7e8a6
BLAKE2b-256 d556417f70f70dc056e6db639eb826a60da32d9373ab376da5e1873dc0d8706d

See more details on using hashes here.

File details

Details for the file otupy-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: otupy-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 163.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for otupy-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ade113fac4394bfe588135541183da2be9eb2c7ad29c2a9b1b4f8de4142d846
MD5 b0dce7ba6ba2f975bc6c2ba67964c591
BLAKE2b-256 1d29af27b4ebdee650c65c23fdffb01a5c73463a462f6ebb7b95d7ea45f7000e

See more details on using hashes here.

Supported by

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