An open API service indexing awesome lists of open source software.

https://github.com/p0dalirius/bhopengraph

A python library to create BloodHound OpenGraphs
https://github.com/p0dalirius/bhopengraph

bloodhound library opengraph python

Last synced: 10 months ago
JSON representation

A python library to create BloodHound OpenGraphs

Awesome Lists containing this project

README

          

# 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


## 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](https://bloodhound.specterops.io/opengraph/schema) and [best practices](https://bloodhound.specterops.io/opengraph/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](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](https://github.com/p0dalirius/bhopengraph) python library to model the [Minimal Working JSON](https://bloodhound.specterops.io/opengraph/schema#minimal-working-json) from the OpenGraph Schema documentation:

```py
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](https://bloodhound.specterops.io/opengraph/schema#minimal-working-json) as per the documentation:

```json
{
"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

- [BloodHound OpenGraph Best Practices](https://bloodhound.specterops.io/opengraph/best-practices)
- [BloodHound OpenGraph Schema](https://bloodhound.specterops.io/opengraph/schema)
- [BloodHound OpenGraph API](https://bloodhound.specterops.io/opengraph/api)
- [BloodHound OpenGraph Custom Icons](https://bloodhound.specterops.io/opengraph/custom-icons)