Skip to content
dadevelPublic

About

Utilities for Pentesting with BloodHound

Topics

Resources

Stars

23 stars

Watchers

1 watching

Forks

Repository files navigation

bhcli

Screenshot

A command line utility to aid in Pentesting with BloodHound. Not related to the official bloodhound-cli.

Setup

  1. Install Podman and docker-compose.

  2. Configure rootless containers for Podman.

  3. Enable the Podman socket for your user.

    systemctl --user enable --now podman.socket
  4. Install this Python package with uv or pipx.

    uv tool install git+https://github.com/dadevel/bhcli.git@main
    pipx install git+https://github.com/dadevel/bhcli.git@main

Custom Queries

If you don't want to use bhcli and are here just for the custom queries run the command below. Otherwise the queries are automatically installed when you create your first bhcli project.

curl -Lo ~/.config/bloodhound/customqueries.json https://github.com/dadevel/bhcli/raw/main/src/bhcli/data/customqueries.json

The queries are based on work by @luemmelsec and @martinsohn. Thank you!

Project Management

Projects are managed with Podman containers. Only one project can be active at a time. Each project consists of BloodHound Community Edition, Neo4j and Postgres.

bhcli setup-project example1
bhcli shutdown-project example1
bhcli setup-project example2
bhcli list-projects
bhcli destroy-project example1
bhcli destroy-project example2

Authentication

  • BloodHound Legacy: bolt://localhost:7687/, username neo4j, empty password
  • Neo4j: http://localhost:7474/, username neo4j, empty password
  • BloodHound Community Edition: http://localhost:7575/, username admin, password admin

Data Collection

Ingest files from AzureHound and modern SharpHound.

bhcli import-bhce ./azurehound.json ./*_BloodHound.zip

Files from bloodhound.py and old SharpHound must be imported with BloodHound Legacy.

CLI Integration

Quickly fetch data from Neo4j for use with other tools or import data from other tools into BloodHound.

bhcli query 'MATCH (u:User {enabled: true}) RETURN u.samaccountname' > ./users.txt
bhcli query -s 'MATCH (u:User {name: toUpper($stdin)} SET u.owned=true RETURN u.name' << EOF
john.doe@corp.local
jane.doe@corp.local
EOF
bhcli query -s -j 'MATCH (u:User {name: $stdin.name}) SET u.foo=$stdin.value RETURN u.name' << EOF
{"name": "john.doe@corp.local", "value": "bar"}
{"name": "jane.doe@corp.local", "value": "baz"}
EOF

Enrichment

Execute a set of post-processing queries to mark certain objects with additional attributes and add additional edges for certain situations.

bhcli enrich

These attributes are:

  • tier=0 for a standard set of tier 0 objects
  • highvalue=true for objects with potential path to tier 0
  • active=true for accounts with login in last 90 days
  • sensitive=true for members of Protected Users

Weighted Graph

The enrichment also assigns weights to edges in BloodHound (based on work by @riccardoancarani and @jmbesnard).

This allows to search for the easiest instead of the shortest path to Domain Admin.

MATCH (a {owned: true}) MATCH (b {highvalue: true}) CALL apoc.algo.dijkstra(a, b, '>', 'cost') YIELD path RETURN path;

NTDS Import

Run a DCSync from impacket-secretsdump with multiple wordlists and rulesets trough Hashcat. LM hashes and pre-created computer accounts are automatically cracked unless --no-lm-brute respective --no-pre2k is specified.

impacket-secretsdump -just-dc -outputfile corp.local -k -no-pass dc01.corp.local
bhcli generate-wordlist > ./custom-words.txt  # made of usernames, descriptions, etc.
bhcli hashcat-ntds -t ./clem9669-wordlists/dictionnaire_de ./clem9669-hashcat-rules/clem9669_medium.rule -t ./custom-words.txt ./unicorn-hashcat-rules/unicorn\ rules/SuperUnicorn.rule -t ./weakpass-3.txt ./unicorn-hashcat-rules/unicorn\ rules/Unicorn250.rule -p ./hashcat.potfile ./*.ntds

Import the DCSync output and Hashcat potfile into BloodHound (inspired by @knavesec and @syss-research). This adds Credential objects with nthash, lmhash and password properties and HasCredential as well as AssignedTo edges between users and credentials.

bhcli import-ntds -p ./hashcat.potfile ./*.ntds

Note: bhcli assumes that the name of the NTDS file minus the .ntds suffix is the FQDN of the domain. This means a DCSync from dc01.subdomain.corp.local must be named subdomain.corp.local.ntds.

ADIDNS Import

Import adidnsdump into BloodHound to add an ipaddress attribute to computers. For hosts that appear in ADIDNS but don't exist in BloodHound, standalone computer objects are created.

bhcli import-adidns corp.local ./records.csv

NetExec Integration

Import nodes for standalone computers and local users by leveraging the SQLite database of NetExec. This includes nthash properties from SAM dumps and AdminTo as well as HasCredential and AssignedTo edges e.g. to identify local admin password reuse.

bhcli import-netexec ~/.nxc/workspaces/default/smb.db

Manual Session Collection

Add historical session data as well as inferred RDP and local admin edges (original idea from @rantasec). First export recent logons from Windows Event Logs with Get-RecentLogons.ps1, then transfer the JSON output to your computer and finally import it into Neo4j.

bhcli import-winevents ./logons.json

ServiceDetector Integration

Import SMB Signing, WebClient and EFS info from ServiceDetector.

bhcli query 'MATCH (c:Computer {active: true}) RETURN c.name' > ./computers.txt
servicedetector -c coercion -d corp.local -u jdoe -p 'passw0rd' $(< ./computers.txt) | tee -a ./servicedetector.json
jq -r 'select(.category=="coercion" and .product=="WebClient" and .state=="running")|.host' ./servicedetector.json | bhcli query -s 'MATCH (c:Computer {name: $stdin}) SET c.webclient=true RETURN c.name'
jq -r 'select(.category=="coercion" and .product=="EFS" and .state=="running")|.host' ./servicedetector.json | bhcli query -s 'MATCH (c:Computer {name: $stdin}) SET c.efs=true RETURN c.name'
jq -r 'select(.category=="smb" and .signing==false)|.host' ./servicedetector.json | bhcli query -s 'MATCH (c:Computer {name: $stdin}) SET c.smbsigning=false RETURN c.name'

About

Utilities for Pentesting with BloodHound

Topics

Resources

Stars

23 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages