From 28cf7080ee465349ecab1a1b2fdcdef6a2c94c3b Mon Sep 17 00:00:00 2001 From: Mathieu Moran Date: Mon, 26 Oct 2026 23:14:52 -0400 Subject: [PATCH] tools: decode BloodHound JSON into exploitable edges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bloodhound-python only writes JSON for the GUI, so a terminal user sees a successful collection and nothing else. bh_clues.py answers the question that matters: for one account, its groups, SPNs, non-inherited ACEs and local-admin/PSRemote edges — with GetChanges+GetChangesAll collapsed into DCSync. Shipped in both tool ISOs and copied by the Kali setup; the student sheet uses it after the collector. --- session1/README.md | 1 + session1/content/lib/cmd_kali.sh | 3 + session1/content/scripts/bh_clues.py | 131 ++++++++++++++++++ session1/docs/etudiant.md | 5 +- session1/docs/instructeur.md | 1 + .../platforms/proxmox/backends/proxmox.sh | 6 + 6 files changed, 146 insertions(+), 1 deletion(-) create mode 100755 session1/content/scripts/bh_clues.py diff --git a/session1/README.md b/session1/README.md index 613a94c..71c6995 100644 --- a/session1/README.md +++ b/session1/README.md @@ -118,6 +118,7 @@ pour que `reset` la conserve : ```bash sudo mkdir -p /opt/norbourg/wordlists sudo mount /dev/sr0 /mnt && sudo cp /mnt/norbourg.txt /opt/norbourg/wordlists/ +sudo cp /mnt/bh_clues.py /opt/norbourg/ && sudo chmod +x /opt/norbourg/bh_clues.py ``` Pour ajouter des outils qui ne sont pas dans l'image (Internet requis, donc avant de basculer le diff --git a/session1/content/lib/cmd_kali.sh b/session1/content/lib/cmd_kali.sh index 4cf1381..9c36bac 100644 --- a/session1/content/lib/cmd_kali.sh +++ b/session1/content/lib/cmd_kali.sh @@ -23,6 +23,7 @@ _kali_build_tools() { mkdir -p "$(dirname "$iso")" cp "$CONTENT_DIR/scripts/wordlists/norbourg.txt" "$dir/" + cp "$CONTENT_DIR/scripts/bh_clues.py" "$dir/" cat > "$dir/README.txt" <<'EOF' Outils de l'atelier Norbourg ============================ @@ -35,6 +36,8 @@ Installation dans Kali : sudo mkdir -p /opt/norbourg/wordlists sudo cp /media/cdrom/norbourg.txt /opt/norbourg/wordlists/ sudo chmod 644 /opt/norbourg/wordlists/norbourg.txt + sudo cp /media/cdrom/bh_clues.py /opt/norbourg/ + sudo chmod +x /opt/norbourg/bh_clues.py EOF if have_cmd genisoimage; then genisoimage -quiet -volid NORBOURG_TOOLS -J -R -o "$iso" "$dir" diff --git a/session1/content/scripts/bh_clues.py b/session1/content/scripts/bh_clues.py new file mode 100755 index 0000000..730ce7e --- /dev/null +++ b/session1/content/scripts/bh_clues.py @@ -0,0 +1,131 @@ +#!/usr/bin/env python3 +"""Print the actionable BloodHound edges for one account. + +The collector writes JSON for the GUI; this reads it back and answers the +question a participant actually has: "what can this account touch?" + + bloodhound-python -d norbourg.lab -u svc_backup -p '...' -ns 10.10.10.10 -c All + python3 bh_clues.py svc_backup + +The directory argument defaults to the current one; the newest collection of +each type is used. +""" + +from __future__ import annotations + +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 main() -> int: + if len(sys.argv) < 2: + print(__doc__.strip().splitlines()[0], file=sys.stderr) + return 2 + who = sys.argv[1].lower() + directory = sys.argv[2] if len(sys.argv) > 2 else "." + + 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("no *_users.json here — run bloodhound-python 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"user not found in the collection: {who}", 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(f"\n{short(target)}") + spns = target.get("Properties", {}).get("serviceprincipalnames") or [] + for spn in spns: + 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 has the two rights. + for target in {t for r, t in rows if r in ("GetChanges", "GetChangesAll")}: + rights = {r for r, t in rows if t == target and r in ("GetChanges", "GetChangesAll")} + if {"GetChanges", "GetChangesAll"} <= rights: + rows = [(r, t) for r, t in rows + if not (t == target and r in ("GetChanges", "GetChangesAll"))] + rows.append(("DCSync", target)) + + found = len(rows) + for right, target in sorted(rows): + print(f" {right:<18} -> {target}") + + 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()) diff --git a/session1/docs/etudiant.md b/session1/docs/etudiant.md index 38dc4d6..d8cfc33 100644 --- a/session1/docs/etudiant.md +++ b/session1/docs/etudiant.md @@ -124,9 +124,12 @@ smbclient //10.10.10.10/'$' -U 'NORBOURG\%' -c 'ls; get ' -p '' -ns 10.10.10.10 -c all +# quels droits ce compte peut-il réellement exercer ? (lecture des JSON) +python3 /opt/norbourg/bh_clues.py '' + # quels droits ce compte a-t-il sur une cible ? (module daclread de netexec) nxc ldap 10.10.10.10 -d norbourg.lab -u '' -p '' \ -M daclread -o TARGET='' PRINCIPAL='' diff --git a/session1/docs/instructeur.md b/session1/docs/instructeur.md index a4fc7d7..795ac39 100644 --- a/session1/docs/instructeur.md +++ b/session1/docs/instructeur.md @@ -62,6 +62,7 @@ site et le partage `Public`, `ws01` est joint au domaine avec `user.txt` en plac ```bash sudo mkdir -p /opt/norbourg/wordlists sudo mount /dev/sr0 /mnt && sudo cp /mnt/norbourg.txt /opt/norbourg/wordlists/ + sudo cp /mnt/bh_clues.py /opt/norbourg/ && sudo chmod +x /opt/norbourg/bh_clues.py ``` Puis figez l'état : `cd platforms/qemu && ./lab.sh kali snapshot`. Sans cela, `kali reset` diff --git a/session1/platforms/proxmox/backends/proxmox.sh b/session1/platforms/proxmox/backends/proxmox.sh index 53c42c0..64cc2eb 100644 --- a/session1/platforms/proxmox/backends/proxmox.sh +++ b/session1/platforms/proxmox/backends/proxmox.sh @@ -587,6 +587,7 @@ _px_kali_tools() { dir=$(mktemp -d) cp "$CONTENT_DIR/scripts/wordlists/norbourg.txt" "$dir/" + cp "$CONTENT_DIR/scripts/bh_clues.py" "$dir/" cat > "$dir/README.txt" <<'EOF' Outils de l'atelier Norbourg ============================ @@ -697,6 +698,11 @@ fi if [ -n "$src" ]; then cp "$src" /opt/norbourg/wordlists/ chmod 644 /opt/norbourg/wordlists/norbourg.txt + root=$(dirname "$src") + if [ -f "$root/bh_clues.py" ]; then + cp "$root/bh_clues.py" /opt/norbourg/ + chmod +x /opt/norbourg/bh_clues.py + fi umount /mnt/tools 2>/dev/null || true fi if ip -4 -br addr show | grep -q '10\.10\.10\.'; then echo NET_OK; else echo NET_FAIL; fi