Finding and Cutting Paths to Domain Admin
Work through a small BloodHound-CE-like graph export with a Python shortest-path script: find which users can reach Domain Admins, read the path hop by hop through MemberOf, GenericAll, AdminTo, HasSession and WriteDacl edges, then write a fixed copy of the graph without the riskiest ACL edge and with the stale privileged account disabled, and re-run to watch the paths disappear. Learn why sessions are choke points and why control over a group is a path.
Contentsand lesson path
On this page
- The problem
- The edges, and what each one means
- Step 1: The graph and the search
- Step 2: Find the paths
- Step 3: Pick the choke point
- Kerberos delegation edges are hops too
- Common mistakes
- Check your understanding
- Apply it
- Review prompt
Lessons of Windows & Active Directory Security
- How a Windows Domain Decides Who You Are Concept · 20 min
- Hardening a Lab Domain Through Group Policy Lab · 30 min
- Finding and Cutting Paths to Domain Admin Worked example · 25 min
- Windows Telemetry for Credential Theft and Lateral Movement Lab · 30 min
- PowerShell and Living-off-the-Land from the Defender's Side Worked example · 20 min
- Windows & Active Directory Check Knowledge check · 8 questions
What you will learn
- Map attack paths to privileged groups in a lab domain with a graph-based analysis tool and remove the riskiest delegations, ACL grants and stale privileged accounts.
- Explain how a Windows domain authenticates and authorises users and machines (Kerberos tickets, NTLM fallback, LDAP, security groups, Group Policy) and how hybrid identity extends it to a cloud directory such as Microsoft Entra ID.
01. The problem
Attackers rarely jump straight to Domain Admin. They chain small, legitimate rights: a help-desk group that can reset a password, an admin session left on a server, an access-control entry nobody reviewed. Each hop looks normal on its own. Put together, they form a path from an ordinary account to full control of the domain. Defenders use the same graph to find and cut those paths before an attacker walks them.
The real tool for this is BloodHound Community Edition (BloodHound CE), which collects objects and relationships from AD into a graph database and finds paths for you. You do not run its collectors here, and you never run them against a domain you do not own. Instead you use a small export in the same shape and a short Python script, to see what the tool computes.
The goal: given the graph export below, find which enabled users can reach the DOMAIN ADMINS group, read why, then remove the single riskiest edge, disable the one stale account and show that the paths are gone. You need Python 3.10 or later, standard library only, and a folder paths-lab.
02. The edges, and what each one means
In a BloodHound graph, nodes are principals (users, groups, computers) and edges are relationships. The direction of an edge is the direction of attacker control: an edge from A to B means that controlling A gives a way to control or act as B. The ones in this export are:
- MemberOf: A is a member of group B, so A has B's rights.
- GenericAll: A has full control over B. If B is a group, A can add itself to B and so gain B's rights; if B is a user, A can reset its password. Control over a group is therefore a path, not just an administrative convenience.
- AdminTo: A is a local administrator on computer B, so A can run code there and read secrets in its memory.
- HasSession: user B has a logon session on computer A, so an attacker with admin on A may be able to steal B's credential material.
- WriteDacl: A can modify the access-control list of B, so A can grant itself any right over B, including, on the domain object, the replication rights that enable DCSync.
03. Step 1: The graph and the search
Save the export as graph.json. It has nine nodes and nine edges from a lab domain, with made-up names under example.invalid.
{
"comment": "Tiny BloodHound-CE-like export for a lab. All names are made up.",
"comment2": "Edges point in the direction of attacker control (A can act on B).",
"nodes": [
{"id": "[email protected]", "type": "User", "enabled": true},
{"id": "[email protected]", "type": "User", "enabled": true},
{"id": "[email protected]", "type": "User", "enabled": true,
"note": "no logon in 400 days; password never expires"},
{"id": "[email protected]", "type": "Group"},
{"id": "[email protected]", "type": "Group"},
{"id": "[email protected]", "type": "Group"},
{"id": "DOMAIN [email protected]", "type": "Group"},
{"id": "APP01.example.invalid", "type": "Computer"},
{"id": "FS01.example.invalid", "type": "Computer"}
],
"edges": [
{"from": "[email protected]", "to": "[email protected]",
"type": "MemberOf"},
{"from": "[email protected]", "to": "[email protected]",
"type": "MemberOf"},
{"from": "[email protected]", "to": "[email protected]",
"type": "MemberOf"},
{"from": "[email protected]", "to": "[email protected]",
"type": "GenericAll"},
{"from": "[email protected]", "to": "APP01.example.invalid",
"type": "AdminTo"},
{"from": "[email protected]", "to": "FS01.example.invalid",
"type": "AdminTo"},
{"from": "APP01.example.invalid", "to": "[email protected]",
"type": "HasSession"},
{"from": "FS01.example.invalid", "to": "[email protected]",
"type": "HasSession"},
{"from": "[email protected]", "to": "DOMAIN [email protected]",
"type": "WriteDacl"}
]
}Now the search. paths.py reads the graph, builds an adjacency list, and runs a breadth-first search (BFS) from every enabled user to the target. BFS explores the graph level by level, so the first time it reaches the target it has found a shortest path. The visited set is important here: the SERVER-OPS, FS01 and jdoe nodes form a cycle, and without visited the search would circle it forever.
"""Shortest attack paths to a target group in a BloodHound-like graph.
Usage: python3 paths.py <graph.json> [target]
Edges point in the direction of attacker control: an edge A -> B means that
controlling A gives a way to control or act as B. We do a breadth-first search
from every enabled User to the target and print the shortest path for each.
"""
import json
import sys
from collections import deque
TARGET = "DOMAIN [email protected]"
def load(path):
data = json.load(open(path))
adj = {}
for n in data["nodes"]:
adj.setdefault(n["id"], [])
for e in data["edges"]:
adj.setdefault(e["from"], []).append((e["to"], e["type"]))
kind = {n["id"]: n["type"] for n in data["nodes"]}
enabled = {n["id"] for n in data["nodes"] if n.get("enabled", True)}
return adj, kind, enabled
def shortest_path(adj, start, target):
# BFS; queue holds (node, path-so-far). Visited stops it circling cycles.
queue = deque([(start, [(start, None)])])
visited = {start}
while queue:
node, path = queue.popleft()
if node == target:
return path
for nxt, etype in adj.get(node, []):
if nxt not in visited:
visited.add(nxt)
queue.append((nxt, path + [(nxt, etype)]))
return None
def render(path):
# one hop per line so no line is too long to read
lines = [f" {path[0][0]}"]
for node, etype in path[1:]:
lines.append(f" --{etype}--> {node}")
return "\n".join(lines)
def main(path, target):
adj, kind, enabled = load(path)
users = sorted(n for n in adj if kind.get(n) == "User" and n in enabled)
print(f"target: {target}")
reachable = 0
for user in users:
p = shortest_path(adj, user, target)
if p:
reachable += 1
hops = len(p) - 1
unit = "hop" if hops == 1 else "hops"
print(f"PATH to target in {hops} {unit}:")
print(render(p))
else:
print(f"none: {user} has no path")
print(f"{reachable}/{len(users)} enabled users can reach the target")
return 0
if __name__ == "__main__":
graph = sys.argv[1] if len(sys.argv) > 1 else "graph.json"
main(graph, sys.argv[2] if len(sys.argv) > 2 else TARGET)04. Step 2: Find the paths
Run the script against the full graph.
cd paths-lab
python3 paths.py graph.jsontarget: DOMAIN [email protected]
PATH to target in 5 hops:
[email protected]
--MemberOf--> [email protected]
--GenericAll--> [email protected]
--AdminTo--> APP01.example.invalid
--HasSession--> [email protected]
--WriteDacl--> DOMAIN [email protected]
none: [email protected] has no path
PATH to target in 1 hop:
[email protected]
--WriteDacl--> DOMAIN [email protected]
2/3 enabled users can reach the targetTwo of the three users can reach DOMAIN ADMINS. Read amira's five-hop path as a story. She is a member of HELPDESK (MemberOf). HELPDESK has GenericAll over WKS-ADMINS, so she can add herself to WKS-ADMINS and inherit its rights. WKS-ADMINS is admin on APP01 (AdminTo), so she can run code on APP01. The stale service account stale-svc has a session on APP01 (HasSession), so from APP01 she may steal its credential. And stale-svc has WriteDacl on the domain group, so it can grant itself membership of Domain Admins.
jdoe has no path: his edges only lead round the cycle from SERVER-OPS to FS01 and back to himself, which never reaches the target. You cannot see these chains by reading group memberships one at a time; you have to follow the edges.
05. Step 3: Pick the choke point
Both paths to the target end with the same hop: the WriteDacl from stale-svc to the domain group. stale-svc reaches it in one hop on its own, and amira reaches it through the session stale-svc left on APP01. stale-svc is a choke point: a node that many paths pass through, so removing it cuts many paths at once. It is also one of the worst kinds of account to leave lying around: a stale privileged account. Its note says no logon in 400 days and a password that never expires, yet it can write the domain group's ACL. Its use would be easy to miss, and its old password may already be weak or cracked.
The fix follows the choke point. Remove the WriteDacl edge (the excessive ACL that lets stale-svc reach Domain Admins) and disable the stale account itself. In the real directory that is removing one access-control entry and disabling one user. Domain Admins is a protected group, so the SDProp process resets its ACL to match the AdminSDHolder object about every 60 minutes by default. An entry added directly to the group usually disappears within the hour, so a WriteDacl that persists across collections most likely sits on AdminSDHolder itself, and that is where you remove it. Here, fix_graph.py makes the same two changes to a copy of the export and writes graph_fixed.json.
"""Write graph_fixed.json: graph.json after the two fixes from step 3."""
import json
STALE = "[email protected]"
with open("graph.json") as fh:
graph = json.load(fh)
before = len(graph["edges"])
# Fix 1: remove the WriteDacl entry that lets stale-svc change DOMAIN ADMINS.
graph["edges"] = [e for e in graph["edges"]
if not (e["from"] == STALE and e["type"] == "WriteDacl")]
# Fix 2: disable the stale account, so it is no longer an enabled start user.
for node in graph["nodes"]:
if node["id"] == STALE:
node["enabled"] = False
with open("graph_fixed.json", "w") as fh:
json.dump(graph, fh, indent=2)
print(f"edges: {before} -> {len(graph['edges'])}; {STALE} enabled: False")python3 fix_graph.pyedges: 9 -> 8; [email protected] enabled: FalseNow run the same search over the fixed copy.
python3 paths.py graph_fixed.jsontarget: DOMAIN [email protected]
none: [email protected] has no path
none: [email protected] has no path
0/2 enabled users can reach the targetNo enabled user can reach Domain Admins now. One ACL removal and one disabled account closed every path, because both ran through the same choke point. Choosing the hop with the highest leverage gave the biggest reduction for the least change, which is how you would usually prioritise when a real graph shows forty paths instead of two.
You could also have cut the GenericAll edge from HELPDESK to WKS-ADMINS, which would break amira's path higher up. On a real graph you fix both: the stale account because it should not exist, and the GenericAll because a help-desk group should not fully control a workstation-admin group.
06. Kerberos delegation edges are hops too
Delegated ACL rights are one kind of delegation. Kerberos delegation, which lets a service act as a user towards other services, adds hops of its own, and BloodHound CE draws each kind as an edge:
- Unconstrained delegation (
TRUSTED_FOR_DELEGATION, decoded in lesson 01): users who authenticate to the host send it their TGT, so whoever controls the host can act as them anywhere. BloodHound CE draws it asCoerceToTGT, an edge to the domain itself, because a captured domain controller ticket would mean domain compromise. - Constrained delegation (
msDS-AllowedToDelegateToon the source): the account can impersonate any user to the listed services on the target computer, drawn asAllowedToDelegate. - Resource-based constrained delegation (RBCD,
msDS-AllowedToActOnBehalfOfOtherIdentityon the target): each principal listed there can impersonate any user to that computer, drawn asAllowedToAct.
Read each as "control of the source becomes control of the target, as any user". To cut them, remove delegation no service needs, and replace unconstrained delegation with constrained delegation to named services. Then stop privileged accounts from being impersonated: set "Account is sensitive and cannot be delegated" (NOT_DELEGATED, 0x100000) on them, or add them to Protected Users, whose members cannot be delegated. These flags do not remove an edge, but they stop it being used to act as those accounts.
07. Common mistakes
08. Check your understanding
09. Apply it
For the skill project, make the analysis your own:
- Add a node and two edges that create a second, longer path to the target (for example a WriteDacl on a service account that is AdminTo a jump host). Re-run and confirm the script finds the shortest one.
- Extend
paths.pyto print, for each node, how many paths pass through it, and use that to rank choke points instead of eyeballing them. - In your own isolated lab domain, with BloodHound CE's documented collection, compare one path it reports with what the Python model shows for the same edges. Collect only from a domain you own and are authorised to assess.
10. Review prompt
Without looking back, explain: what the direction of an edge means; what MemberOf, GenericAll, AdminTo, HasSession and WriteDacl each let an attacker do; why control over a group is a path; what a choke point is; why a stale privileged account matters; which Kerberos delegation settings BloodHound draws as edges, and two ways to protect a privileged account from them; and three changes that do not actually remove a path.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.