bh_clues: --help, lab notice and clearer errors
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.
This commit is contained in:
@@ -30,6 +30,8 @@ Outils de l'atelier Norbourg
|
|||||||
|
|
||||||
norbourg.txt : liste de mots ciblee (1716 entrees), dimensionnee pour que le
|
norbourg.txt : liste de mots ciblee (1716 entrees), dimensionnee pour que le
|
||||||
cassage prenne quelques secondes.
|
cassage prenne quelques secondes.
|
||||||
|
bh_clues.py : lit les JSON de bloodhound-python et imprime les droits
|
||||||
|
exploitables d'un compte (outil concu pour ce laboratoire).
|
||||||
|
|
||||||
Installation dans Kali :
|
Installation dans Kali :
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,29 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
"""Print the actionable BloodHound edges for one account.
|
"""bh_clues.py — BloodHound JSON reader for the Norbourg workshop lab.
|
||||||
|
|
||||||
The collector writes JSON for the GUI; this reads it back and answers the
|
bloodhound-python writes JSON for the BloodHound GUI, so a terminal user
|
||||||
question a participant actually has: "what can this account touch?"
|
sees a successful collection and nothing else. This script answers the
|
||||||
|
question a participant actually has: for one account, what can it touch?
|
||||||
|
|
||||||
bloodhound-python -d norbourg.lab -u svc_backup -p '...' -ns 10.10.10.10 -c All
|
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
|
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
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
import glob
|
import glob
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
@@ -44,12 +55,40 @@ def short(obj: dict) -> str:
|
|||||||
return f"{name} ({sam})" if sam else name
|
return f"{name} ({sam})" if sam else name
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def parse_args(argv: list[str]) -> argparse.Namespace:
|
||||||
if len(sys.argv) < 2:
|
parser = argparse.ArgumentParser(
|
||||||
print(__doc__.strip().splitlines()[0], file=sys.stderr)
|
prog="bh_clues.py",
|
||||||
return 2
|
description=(
|
||||||
who = sys.argv[1].lower()
|
"Print the BloodHound edges of one account from the collector's JSON. "
|
||||||
directory = sys.argv[2] if len(sys.argv) > 2 else "."
|
"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")
|
users = load(directory, "users")
|
||||||
groups = load(directory, "groups")
|
groups = load(directory, "groups")
|
||||||
@@ -57,15 +96,24 @@ def main() -> int:
|
|||||||
extra = load(directory, "domains") + load(directory, "ous") + load(directory, "containers")
|
extra = load(directory, "domains") + load(directory, "ous") + load(directory, "containers")
|
||||||
|
|
||||||
if not users:
|
if not users:
|
||||||
print("no *_users.json here — run bloodhound-python first", file=sys.stderr)
|
print(
|
||||||
|
f"no *_users.json in {directory!r} — run bloodhound-python there first",
|
||||||
|
file=sys.stderr,
|
||||||
|
)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
target = next((u for u in users
|
target = next(
|
||||||
if (u.get("Properties", {}).get("samaccountname") or "").lower() == who
|
(u for u in users
|
||||||
or (u.get("Properties", {}).get("name") or "").split("@")[0].lower() == who),
|
if (u.get("Properties", {}).get("samaccountname") or "").lower() == who
|
||||||
None)
|
or (u.get("Properties", {}).get("name") or "").split("@")[0].lower() == who),
|
||||||
|
None,
|
||||||
|
)
|
||||||
if not target:
|
if not target:
|
||||||
print(f"user not found in the collection: {who}", file=sys.stderr)
|
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
|
return 1
|
||||||
|
|
||||||
sid = target["ObjectIdentifier"]
|
sid = target["ObjectIdentifier"]
|
||||||
@@ -77,14 +125,15 @@ def main() -> int:
|
|||||||
gid = group["ObjectIdentifier"]
|
gid = group["ObjectIdentifier"]
|
||||||
if gid in principals:
|
if gid in principals:
|
||||||
continue
|
continue
|
||||||
members = (group.get("Members") or [])
|
members = group.get("Members") or []
|
||||||
if any(m.get("ObjectIdentifier") in principals for m in members):
|
if any(m.get("ObjectIdentifier") in principals for m in members):
|
||||||
principals.add(gid)
|
principals.add(gid)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
|
print("\n# bh_clues.py — Norbourg lab (norbourg.lab)")
|
||||||
|
print(f"# collection: {directory}")
|
||||||
print(f"\n{short(target)}")
|
print(f"\n{short(target)}")
|
||||||
spns = target.get("Properties", {}).get("serviceprincipalnames") or []
|
for spn in target.get("Properties", {}).get("serviceprincipalnames") or []:
|
||||||
for spn in spns:
|
|
||||||
print(f" SPN {spn}")
|
print(f" SPN {spn}")
|
||||||
for group in groups:
|
for group in groups:
|
||||||
if group["ObjectIdentifier"] in principals and group["ObjectIdentifier"] != sid:
|
if group["ObjectIdentifier"] in principals and group["ObjectIdentifier"] != sid:
|
||||||
@@ -102,17 +151,17 @@ def main() -> int:
|
|||||||
continue
|
continue
|
||||||
rows.append((right, short(obj)))
|
rows.append((right, short(obj)))
|
||||||
|
|
||||||
# The GUI shows a single DCSync edge; the JSON has the two rights.
|
# The GUI shows a single DCSync edge; the JSON carries the two rights.
|
||||||
for target in {t for r, t in rows if r in ("GetChanges", "GetChangesAll")}:
|
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 and r in ("GetChanges", "GetChangesAll")}
|
rights = {r for r, t in rows if t == target_name and r in ("GetChanges", "GetChangesAll")}
|
||||||
if {"GetChanges", "GetChangesAll"} <= rights:
|
if {"GetChanges", "GetChangesAll"} <= rights:
|
||||||
rows = [(r, t) for r, t in rows
|
rows = [(r, t) for r, t in rows
|
||||||
if not (t == target and r in ("GetChanges", "GetChangesAll"))]
|
if not (t == target_name and r in ("GetChanges", "GetChangesAll"))]
|
||||||
rows.append(("DCSync", target))
|
rows.append(("DCSync", target_name))
|
||||||
|
|
||||||
found = len(rows)
|
found = len(rows)
|
||||||
for right, target in sorted(rows):
|
for right, name in sorted(rows):
|
||||||
print(f" {right:<18} -> {target}")
|
print(f" {right:<18} -> {name}")
|
||||||
|
|
||||||
for computer in computers:
|
for computer in computers:
|
||||||
for key, label in LOCAL:
|
for key, label in LOCAL:
|
||||||
@@ -123,6 +172,7 @@ def main() -> int:
|
|||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
print(" (no exploitable edge — this account is a dead end)")
|
print(" (no exploitable edge — this account is a dead end)")
|
||||||
|
|
||||||
print()
|
print()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|||||||
@@ -146,6 +146,10 @@ impacket-changepasswd 'norbourg.lab/<cible>@10.10.10.10' -reset -newpass '<nouve
|
|||||||
`-c all` n'est pas décoratif : la collecte par défaut n'inclut pas les listes de permissions
|
`-c all` n'est pas décoratif : la collecte par défaut n'inclut pas les listes de permissions
|
||||||
(`Aces`), et on conclut à tort qu'il n'y a aucun chemin.
|
(`Aces`), et on conclut à tort qu'il n'y a aucun chemin.
|
||||||
|
|
||||||
|
`bh_clues.py` est fourni avec le laboratoire (`--help` pour l'aide) : il lit les JSON du
|
||||||
|
collecteur — aucun accès réseau — et affiche les groupes, les SPN et les droits réellement
|
||||||
|
exploitables d'un compte. La mention « dead end » est une information, pas une erreur.
|
||||||
|
|
||||||
Dans `impacket-changepasswd`, le compte **ciblé** est celui de l'URL et le compte qui
|
Dans `impacket-changepasswd`, le compte **ciblé** est celui de l'URL et le compte qui
|
||||||
**s'authentifie** est passé par `-altuser`, sans préfixe de domaine : l'outil se connecte avec
|
**s'authentifie** est passé par `-altuser`, sans préfixe de domaine : l'outil se connecte avec
|
||||||
cette identité alternative pour modifier l'autre compte.
|
cette identité alternative pour modifier l'autre compte.
|
||||||
|
|||||||
@@ -594,6 +594,8 @@ Outils de l'atelier Norbourg
|
|||||||
|
|
||||||
norbourg.txt : liste de mots ciblee, dimensionnee pour un cassage de
|
norbourg.txt : liste de mots ciblee, dimensionnee pour un cassage de
|
||||||
quelques secondes.
|
quelques secondes.
|
||||||
|
bh_clues.py : lit les JSON de bloodhound-python et imprime les droits
|
||||||
|
exploitables d'un compte (outil concu pour ce laboratoire).
|
||||||
|
|
||||||
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/
|
||||||
|
|||||||
Reference in New Issue
Block a user