Skip to main content

A python library to create BloodHound OpenGraphs easily

Project description

bhopengraph: A python library to create BloodHound OpenGraphs

A python library to create BloodHound OpenGraphs easily
PyPI GitHub release (latest by date) YouTube Channel Subscribers Get BloodHound Enterprise Get BloodHound Community

This library also exists in: Go | Python

Features

This module provides Python classes for creating and managing graph structures that are compatible with BloodHound OpenGraph. The classes follow the BloodHound OpenGraph schema and best practices.

If you don't know about BloodHound OpenGraph yet, a great introduction can be found here: https://bloodhound.specterops.io/opengraph/best-practices

The complete documentation of this library can be found here: https://bhopengraph.readthedocs.io/en/latest/

Examples

Here is an example of a Python program using the bhopengraph python library to model the Minimal Working JSON from the OpenGraph Schema documentation:

from bhopengraph.OpenGraph import OpenGraph
from bhopengraph.Node import Node
from bhopengraph.Edge import Edge
from bhopengraph.Properties import Properties

# Create an OpenGraph instance
graph = OpenGraph(source_kind="Base")

# Create nodes
bob_node = Node(
    id="123",
    kinds=["Person", "Base"],
    properties=Properties(
        displayname="bob",
        property="a",
        objectid="123",
        name="BOB"
    )
)

alice_node = Node(
    id="234",
    kinds=["Person", "Base"],
    properties=Properties(
        displayname="alice",
        property="b",
        objectid="234",
        name="ALICE"
    )
)

# Add nodes to graph
graph.add_node(bob_node)
graph.add_node(alice_node)

# Create edge: Bob knows Alice
knows_edge = Edge(
    start_node=alice_node.id,
    end_node=bob_node.id,
    kind="Knows"
)

# Add edge to graph
graph.add_edge(knows_edge)

# Export to file
graph.export_to_file("minimal_example.json")

This gives us the following Minimal Working JSON as per the documentation:

{
  "graph": {
    "nodes": [
      {
        "id": "123",
        "kinds": [
          "Person",
          "Base"
        ],
        "properties": {
          "displayname": "bob",
          "property": "a",
          "objectid": "123",
          "name": "BOB"
        }
      },
      {
        "id": "234",
        "kinds": [
          "Person",
          "Base"
        ],
        "properties": {
          "displayname": "alice",
          "property": "b",
          "objectid": "234",
          "name": "ALICE"
        }
      }
    ],
    "edges": [
      {
        "kind": "Knows",
        "start": {
          "value": "123",
          "match_by": "id"
        },
        "end": {
          "value": "234",
          "match_by": "id"
        }
      }
    ]
  },
  "metadata": {
    "source_kind": "Base"
  }
}

Contributing

Pull requests are welcome. Feel free to open an issue if you want to add other features.

References

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

bhopengraph-1.3.0-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file bhopengraph-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: bhopengraph-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for bhopengraph-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 770eea7e14b50b33a39038f3b7d13607d7b9fc103add510325cc96b86ca17b88
MD5 05f34d34b8d47fdbbf4265437cfe819c
BLAKE2b-256 69350c1bc948abf0555315dc0c744854c8bfb11a8aad8e997b23618b4f90feac

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