Node

class bhopengraph.Node.Node(id, kinds=None, properties=None)[source]

Bases: object

Node class representing a node in the OpenGraph.

Follows BloodHound OpenGraph schema requirements with unique IDs, kinds, and properties.

Sources: - https://bloodhound.specterops.io/opengraph/developer/nodes - https://bloodhound.specterops.io/opengraph/developer/graph-data

Parameters:
__init__(id, kinds=None, properties=None)[source]

Initialize a Node.

Parameters:
  • id (-) – Universally unique identifier for the node

  • kinds (-) – List of node types/classes (at most MAX_KINDS)

  • properties (-) – Node properties

add_kind(kind)[source]

Add a kind/type to the node if it doesn’t already exist.

The BloodHound OpenGraph schema limits a node to at most MAX_KINDS (3) kinds. Returns True if the node has the kind after the call (it was added or was already present) and False if the kind could not be added because the node already holds the maximum number of kinds.

Parameters:

kind (-) – Kind/type to add

Returns:

True if the node has the kind after the call, False otherwise

Return type:

  • bool

remove_kind(kind)[source]

Remove a kind/type from the node.

Parameters:

kind (-) – Kind/type to remove

has_kind(kind)[source]

Check if node has a specific kind/type.

Parameters:

kind (-) – Kind/type to check

Returns:

True if node has the kind, False otherwise

Return type:

  • bool

set_property(key, value)[source]

Set a property on the node.

Parameters:
  • key (-) – Property name

  • value (-) – Property value

get_property(key, default=None)[source]

Get a property from the node.

Parameters:
  • key (-) – Property name

  • default (-) – Default value if property doesn’t exist

Returns:

  • Property value or default

remove_property(key)[source]

Remove a property from the node.

Parameters:

key (-) – Property name to remove

to_dict()[source]

Convert node to dictionary for JSON serialization.

Returns:

Node as dictionary following BloodHound OpenGraph schema

Return type:

  • dict

classmethod from_dict(node_data)[source]

Create a Node instance from a dictionary.

Parameters:

node_data (-) – Dictionary containing node data

Returns:

Node instance or None if data is invalid

Return type:

  • Node

__eq__(other)[source]

Check if two nodes are equal based on their ID.

Parameters:

other (-) – The other node to compare to

Returns:

True if the nodes are equal, False otherwise

Return type:

  • bool

__hash__()[source]

Hash based on node ID for use in sets and as dictionary keys.

Returns:

Hash of the node ID

Return type:

  • int

validate()[source]

Validate the node against the NODE_SCHEMA.

Returns:

(is_valid, list_of_errors)

Return type:

  • tuple[bool, list[str]]