tools: decode BloodHound JSON into exploitable edges
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.
This commit is contained in:
@@ -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"
|
||||
|
||||
Executable
+131
@@ -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())
|
||||
Reference in New Issue
Block a user