argparse usage with an example, a header line in the output stating it is a Norbourg-lab tool, and explicit messages for a missing collection or an unknown account. The tool ISOs describe the script next to the wordlist.
182 lines
6.2 KiB
Python
Executable File
182 lines
6.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""bh_clues.py — BloodHound JSON reader for the Norbourg workshop lab.
|
|
|
|
bloodhound-python writes JSON for the BloodHound GUI, so a terminal user
|
|
sees a successful collection and nothing else. This script answers the
|
|
question a participant actually has: for one account, what can it touch?
|
|
|
|
It prints:
|
|
* the account's SPNs and groups (including nested groups),
|
|
* non-inherited ACEs held by the account or one of its groups,
|
|
* local AdminTo / PSRemote / CanRDP / CanDCOM edges,
|
|
and collapses GetChanges + GetChangesAll into a single DCSync line.
|
|
|
|
Written for the Norbourg lab (norbourg.lab). It only reads the JSON files
|
|
produced by the collector; it never talks to the network.
|
|
|
|
Typical use:
|
|
|
|
bloodhound-python -d norbourg.lab -u svc_backup -p 'Backup2023!' \
|
|
-ns 10.10.10.10 -c All
|
|
python3 bh_clues.py svc_backup
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import glob
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
INTERESTING = {
|
|
"GenericAll", "GenericWrite", "WriteDacl", "WriteOwner", "Owns",
|
|
"ForceChangePassword", "AddMember", "AddSelf", "AllExtendedRights",
|
|
"DCSync", "AddKeyCredentialLink", "ReadLAPSPassword",
|
|
"GetChanges", "GetChangesAll", "GetChangesInFilteredSet",
|
|
}
|
|
|
|
LOCAL = (("LocalAdmins", "AdminTo"), ("PSRemoteUsers", "PSRemote"),
|
|
("RemoteDesktopUsers", "CanRDP"), ("DcomUsers", "CanDCOM"))
|
|
|
|
|
|
def load(directory: str, suffix: str) -> list[dict]:
|
|
files = sorted(glob.glob(os.path.join(directory, f"*_{suffix}.json")))
|
|
if not files:
|
|
return []
|
|
with open(files[-1], encoding="utf-8") as fh:
|
|
return json.load(fh).get("data", [])
|
|
|
|
|
|
def short(obj: dict) -> str:
|
|
props = obj.get("Properties", {})
|
|
name = (props.get("name") or "").split("@")[0]
|
|
sam = props.get("samaccountname")
|
|
return f"{name} ({sam})" if sam else name
|
|
|
|
|
|
def parse_args(argv: list[str]) -> argparse.Namespace:
|
|
parser = argparse.ArgumentParser(
|
|
prog="bh_clues.py",
|
|
description=(
|
|
"Print the BloodHound edges of one account from the collector's JSON. "
|
|
"Built for the Norbourg workshop lab (norbourg.lab); it reads files only, "
|
|
"no network access."
|
|
),
|
|
epilog=(
|
|
"examples:\n"
|
|
" bloodhound-python -d norbourg.lab -u svc_backup -p 'Backup2023!' "
|
|
"-ns 10.10.10.10 -c All\n"
|
|
" python3 bh_clues.py svc_backup\n"
|
|
" python3 bh_clues.py svc_backup /tmp/collection\n"
|
|
),
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
)
|
|
parser.add_argument(
|
|
"account",
|
|
help="sAMAccountName to inspect (for example svc_backup or m.legault)",
|
|
)
|
|
parser.add_argument(
|
|
"directory",
|
|
nargs="?",
|
|
default=".",
|
|
help="directory holding the *_users.json files (default: current directory)",
|
|
)
|
|
return parser.parse_args(argv)
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
args = parse_args(sys.argv[1:] if argv is None else argv)
|
|
who = args.account.lower()
|
|
directory = args.directory
|
|
|
|
users = load(directory, "users")
|
|
groups = load(directory, "groups")
|
|
computers = load(directory, "computers")
|
|
extra = load(directory, "domains") + load(directory, "ous") + load(directory, "containers")
|
|
|
|
if not users:
|
|
print(
|
|
f"no *_users.json in {directory!r} — run bloodhound-python there first",
|
|
file=sys.stderr,
|
|
)
|
|
return 1
|
|
|
|
target = next(
|
|
(u for u in users
|
|
if (u.get("Properties", {}).get("samaccountname") or "").lower() == who
|
|
or (u.get("Properties", {}).get("name") or "").split("@")[0].lower() == who),
|
|
None,
|
|
)
|
|
if not target:
|
|
print(
|
|
f"account not found in this collection: {args.account}\n"
|
|
"check the spelling, or collect again with -c All",
|
|
file=sys.stderr,
|
|
)
|
|
return 1
|
|
|
|
sid = target["ObjectIdentifier"]
|
|
principals = {sid}
|
|
changed = True
|
|
while changed:
|
|
changed = False
|
|
for group in groups:
|
|
gid = group["ObjectIdentifier"]
|
|
if gid in principals:
|
|
continue
|
|
members = group.get("Members") or []
|
|
if any(m.get("ObjectIdentifier") in principals for m in members):
|
|
principals.add(gid)
|
|
changed = True
|
|
|
|
print("\n# bh_clues.py — Norbourg lab (norbourg.lab)")
|
|
print(f"# collection: {directory}")
|
|
print(f"\n{short(target)}")
|
|
for spn in target.get("Properties", {}).get("serviceprincipalnames") or []:
|
|
print(f" SPN {spn}")
|
|
for group in groups:
|
|
if group["ObjectIdentifier"] in principals and group["ObjectIdentifier"] != sid:
|
|
print(f" MemberOf {short(group)}")
|
|
|
|
rows: list[tuple[str, str]] = []
|
|
for obj in users + groups + computers + extra:
|
|
for ace in obj.get("Aces") or []:
|
|
if ace.get("IsInherited"):
|
|
continue
|
|
if ace.get("PrincipalSID") not in principals:
|
|
continue
|
|
right = ace.get("RightName")
|
|
if right not in INTERESTING:
|
|
continue
|
|
rows.append((right, short(obj)))
|
|
|
|
# The GUI shows a single DCSync edge; the JSON carries the two rights.
|
|
for target_name in {t for r, t in rows if r in ("GetChanges", "GetChangesAll")}:
|
|
rights = {r for r, t in rows if t == target_name and r in ("GetChanges", "GetChangesAll")}
|
|
if {"GetChanges", "GetChangesAll"} <= rights:
|
|
rows = [(r, t) for r, t in rows
|
|
if not (t == target_name and r in ("GetChanges", "GetChangesAll"))]
|
|
rows.append(("DCSync", target_name))
|
|
|
|
found = len(rows)
|
|
for right, name in sorted(rows):
|
|
print(f" {right:<18} -> {name}")
|
|
|
|
for computer in computers:
|
|
for key, label in LOCAL:
|
|
results = (computer.get(key) or {}).get("Results") or []
|
|
if any(r.get("ObjectIdentifier") in principals for r in results):
|
|
print(f" {label:<18} -> {short(computer)}")
|
|
found += 1
|
|
|
|
if not found:
|
|
print(" (no exploitable edge — this account is a dead end)")
|
|
|
|
print()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|