Skip to main content

Tools to ingest BloodHound graph data into NetworkX graph

Project description

bloodhound-networkx

Tools to ingest JSON BloodHound graph data into a NetworkX graph. Currently, it only works with "community edition" formatted JSON.

Install

Using pip:

pip install bloodhound-networkx

Usage (CLI)

There is a CLI interface, bnx-cli:

$ bnx-cli --help
Usage: bnx-cli [OPTIONS] COMMAND [ARGS]...

Options:
  --loglevel [debug|info|warning|error]
  --help                          Show this message and exit.

Commands:
  list-groups  List the AD Group objects.
  list-users   List the AD User objects.
  process      Process either a selection of JSON files or a directory...

bnx-cli process

This "processes" the Bloodhound JSON data into a gzipped-pickled version of the NetworkX graph.

$ bnx-cli process --help
Usage: bnx-cli process [OPTIONS] JSON_PATHS_OR_DIR...

  Process either a selection of JSON files or a directory containing JSON
  files.  Will save the graph data as a pickled then GZIPed NetworkX
  MultiDiGraph.  If a stem (-o/--output-stem) is provided, then that will be
  the name of the  saved file (plus '.pkl.gz'), otherwise the name of the
  shared parent directory  of all of the JSON files will be used as the
  filename. If they don't share a  common parent, then -o/--output-stem is
  required.

Options:
  -o, --output-stem TEXT  Filename stem for output graph data. Will use the
                          parent directory name of the  JSON files if they
                          share a common parent. If they do not share a common
                          parent, then this is required.
  --output-dir TEXT       Directory to output the graph data
  --force
  --help                  Show this message and exit.

For example:

$ cd bloodhound-networkx
$ ls tests/data/ad_sampledata/20240305110427
20240305110427_computers.json   20240305110427_domains.json  
20240305110427_groups.json  20240305110427_users.json
20240305110427_containers.json  20240305110427_gpos.json     
20240305110427_ous.json
$ bnx-cli process ./tests/data/ad_sampledata/20240305110427
2026-06-28 14:19:35 INFO   [bloodhound_networkx.cli.process: 104]  Saving NetworkX graph data to: 20240305110427.pkl.gz

bnx-cli list-users

This will list all AD User objects in the Bloodhound data. Can pass it either JSON or an already "processed" graph.

$ bnx-cli list-users --help
Usage: bnx-cli list-users [OPTIONS] JSON_OR_GRAPH...

  List the AD User objects. Must provide either a path to a persisted graph
  (from an earlier process call) or valid JSON paths/dir. By default, will
  print to stdout unless -o/--output-path is given.

Options:
  -o, --output-path TEXT  File path to output user data
  --disabled
  -c, --column TEXT       Columns desired in the output. If not provided, then
                          samaccountname will be used. Use -c/--column
                          multiple times for multiple columns.
  --column-counts         Print to stdout all the columns available for User
                          objects, with counts of non-zero values
  --columns-all-true      Only print a row if all of its values are "true"
                          (not False, empty, or null/None)
  --help                  Show this message and exit.

For example:

$ bnx-cli list-users 20240305110427.pkl.gz 
BH@GHOST.CORP
ADMINISTRATOR@GHOST.CORP

$ bnx-cli list-users 20240305110427.pkl.gz --disabled
BH@GHOST.CORP
TOM@GHOST.CORP
WALTER@GHOST.CORP
ADMINISTRATOR@GHOST.CORP
GUEST@GHOST.CORP
KRBTGT@GHOST.CORP
NETWORK SERVICE@GHOST.CORP

$ # There is a --column-counts option you can use to find which columns
# #   each User object has.
$ bnx-cli list-users 20240305110427.pkl.gz --column-counts
    2: admincount
    2: description
    2: displayname
    2: distinguishedname
    2: domain
    2: domainsid
    2: dontreqpreauth
    2: email
    2: enabled
    2: hasspn
    2: homedirectory
    2: isaclprotected
    2: lastlogon
    2: lastlogontimestamp
    2: logonscript
    2: name
    2: passwordnotreqd
    2: pwdlastset
    2: pwdneverexpires
    2: samaccountname
    2: sensitive
    2: serviceprincipalnames
    2: sfupassword
    2: sid
    2: sidhistory
    2: title
    2: trustedtoauth
    2: type                     # This is added: 'User', 'Group', etc.
    2: unconstraineddelegation
    2: unicodepassword
    2: unixpassword
    2: userpassword
    2: whencreated


$ bnx-cli list-users 20240305110427.pkl.gz --disabled  -c name  -c enabled -c admincount | column -t -s $'\t'
BH@GHOST.CORP               True   True
TOM@GHOST.CORP              False  True
WALTER@GHOST.CORP           False  True
ADMINISTRATOR@GHOST.CORP    True   True
GUEST@GHOST.CORP            False  False
KRBTGT@GHOST.CORP           False  True
NETWORK SERVICE@GHOST.CORP     

bnx-cli list-users

This will list all AD Group objects in the Bloodhound data. Can pass it either JSON or an already "processed" graph.

$ bnx-cli list-groups --help 
Usage: bnx-cli list-groups [OPTIONS] JSON_OR_GRAPH...

  List the AD Group objects. Must provide either a path to a persisted graph
  (from an earlier process call) or valid JSON paths/dir. By default, will
  print to stdout unless -o/--output-path is given.

Options:
  -o, --output-path TEXT  File path to output group data
  -c, --column TEXT       Columns desired in the output. If not provided, then
                          name will be used. Use -c/--column multiple times
                          for multiple columns.
  --column-counts         Print to stdout all the columns available for Group
                          objects, with counts of non-zero values
  --columns-all-true      Only print a row if all of its values are "true"
                          (not False, empty, or null/None)
  --help                  Show this message and exit.

Project details


Download files

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

Source Distribution

bloodhound_networkx-0.0.3.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

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

bloodhound_networkx-0.0.3-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file bloodhound_networkx-0.0.3.tar.gz.

File metadata

  • Download URL: bloodhound_networkx-0.0.3.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/7.0.12-201.fc44.x86_64

File hashes

Hashes for bloodhound_networkx-0.0.3.tar.gz
Algorithm Hash digest
SHA256 852096bac1338369aff0834667d6f97f17b9a0ec729503d70bb3f0f428c8b192
MD5 eb588b04bc4a274de51b899436c3e111
BLAKE2b-256 c46d46a7001dbd9da9dd4c6e5a6350caa8a5e4a4d6da9d0ad1955a5cfa764027

See more details on using hashes here.

File details

Details for the file bloodhound_networkx-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: bloodhound_networkx-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.6 Linux/7.0.12-201.fc44.x86_64

File hashes

Hashes for bloodhound_networkx-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 be68367d110772b97ed4802680076f513c5d82dc4c8841236fa25e9b13c1f7c0
MD5 8c34fda45666f41f90ab6ff0988ba80e
BLAKE2b-256 e2cc053b662386f495bbcce3172a8d361de55b3bb930ff8b728fd53882cd3885

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