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:
@@ -118,6 +118,7 @@ pour que `reset` la conserve :
|
|||||||
```bash
|
```bash
|
||||||
sudo mkdir -p /opt/norbourg/wordlists
|
sudo mkdir -p /opt/norbourg/wordlists
|
||||||
sudo mount /dev/sr0 /mnt && sudo cp /mnt/norbourg.txt /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
|
Pour ajouter des outils qui ne sont pas dans l'image (Internet requis, donc avant de basculer le
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ _kali_build_tools() {
|
|||||||
|
|
||||||
mkdir -p "$(dirname "$iso")"
|
mkdir -p "$(dirname "$iso")"
|
||||||
cp "$CONTENT_DIR/scripts/wordlists/norbourg.txt" "$dir/"
|
cp "$CONTENT_DIR/scripts/wordlists/norbourg.txt" "$dir/"
|
||||||
|
cp "$CONTENT_DIR/scripts/bh_clues.py" "$dir/"
|
||||||
cat > "$dir/README.txt" <<'EOF'
|
cat > "$dir/README.txt" <<'EOF'
|
||||||
Outils de l'atelier Norbourg
|
Outils de l'atelier Norbourg
|
||||||
============================
|
============================
|
||||||
@@ -35,6 +36,8 @@ Installation dans Kali :
|
|||||||
sudo mkdir -p /opt/norbourg/wordlists
|
sudo mkdir -p /opt/norbourg/wordlists
|
||||||
sudo cp /media/cdrom/norbourg.txt /opt/norbourg/wordlists/
|
sudo cp /media/cdrom/norbourg.txt /opt/norbourg/wordlists/
|
||||||
sudo chmod 644 /opt/norbourg/wordlists/norbourg.txt
|
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
|
EOF
|
||||||
if have_cmd genisoimage; then
|
if have_cmd genisoimage; then
|
||||||
genisoimage -quiet -volid NORBOURG_TOOLS -J -R -o "$iso" "$dir"
|
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())
|
||||||
@@ -124,9 +124,12 @@ smbclient //10.10.10.10/'<partage>$' -U 'NORBOURG\<user>%<pass>' -c 'ls; get <fi
|
|||||||
### Cartographie et permissions
|
### Cartographie et permissions
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# collecteur BloodHound (JSON, pas besoin de l'interface)
|
# collecteur BloodHound : écrit des JSON, l'interface n'est pas nécessaire
|
||||||
bloodhound-python -d norbourg.lab -u '<user>' -p '<pass>' -ns 10.10.10.10 -c all
|
bloodhound-python -d norbourg.lab -u '<user>' -p '<pass>' -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 '<user>'
|
||||||
|
|
||||||
# quels droits ce compte a-t-il sur une cible ? (module daclread de netexec)
|
# quels droits ce compte a-t-il sur une cible ? (module daclread de netexec)
|
||||||
nxc ldap 10.10.10.10 -d norbourg.lab -u '<user>' -p '<pass>' \
|
nxc ldap 10.10.10.10 -d norbourg.lab -u '<user>' -p '<pass>' \
|
||||||
-M daclread -o TARGET='<cible>' PRINCIPAL='<user>'
|
-M daclread -o TARGET='<cible>' PRINCIPAL='<user>'
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ site et le partage `Public`, `ws01` est joint au domaine avec `user.txt` en plac
|
|||||||
```bash
|
```bash
|
||||||
sudo mkdir -p /opt/norbourg/wordlists
|
sudo mkdir -p /opt/norbourg/wordlists
|
||||||
sudo mount /dev/sr0 /mnt && sudo cp /mnt/norbourg.txt /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`
|
Puis figez l'état : `cd platforms/qemu && ./lab.sh kali snapshot`. Sans cela, `kali reset`
|
||||||
|
|||||||
@@ -587,6 +587,7 @@ _px_kali_tools() {
|
|||||||
|
|
||||||
dir=$(mktemp -d)
|
dir=$(mktemp -d)
|
||||||
cp "$CONTENT_DIR/scripts/wordlists/norbourg.txt" "$dir/"
|
cp "$CONTENT_DIR/scripts/wordlists/norbourg.txt" "$dir/"
|
||||||
|
cp "$CONTENT_DIR/scripts/bh_clues.py" "$dir/"
|
||||||
cat > "$dir/README.txt" <<'EOF'
|
cat > "$dir/README.txt" <<'EOF'
|
||||||
Outils de l'atelier Norbourg
|
Outils de l'atelier Norbourg
|
||||||
============================
|
============================
|
||||||
@@ -697,6 +698,11 @@ fi
|
|||||||
if [ -n "$src" ]; then
|
if [ -n "$src" ]; then
|
||||||
cp "$src" /opt/norbourg/wordlists/
|
cp "$src" /opt/norbourg/wordlists/
|
||||||
chmod 644 /opt/norbourg/wordlists/norbourg.txt
|
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
|
umount /mnt/tools 2>/dev/null || true
|
||||||
fi
|
fi
|
||||||
if ip -4 -br addr show | grep -q '10\.10\.10\.'; then echo NET_OK; else echo NET_FAIL; fi
|
if ip -4 -br addr show | grep -q '10\.10\.10\.'; then echo NET_OK; else echo NET_FAIL; fi
|
||||||
|
|||||||
Reference in New Issue
Block a user