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.1-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bhopengraph-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d9074a0c431baf4874350ff67098135c5b8daea1526f7514abef7e24ab3b813a
MD5 4fc4c092be87bb11fe1c9b9e15f6092c
BLAKE2b-256 76dc6885dcc0bad19a09271fb51f0956ab568deb2f3440617a5d30bfb896a0c3

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