Weak ACLs and Attack Paths as a Graph
Every object in AD (user, group, computer, OU, GPO, the domain itself) has a security descriptor whose DACL says who may read it, change it, reset its password, add members, or rewrite the DACL itself. A large domain has millions of such entries, written over twenty years by admins, installers, migrations and products. Most are fine. A few, chained together with group memberships, local admin rights and who is logged on where, form paths from an ordinary user to Domain Admins. In 2016 the BloodHound project showed that the right way to find them is to stop reading ACLs one by one and treat the directory as a graph: nodes for principals and computers, edges for "can take control of". Attackers use it to find a path; defenders use exactly the same analysis to find the few edges whose removal cuts most paths. This lesson builds that analysis in NetworkX on a synthetic domain.
Edges that mean "control"
| Edge | Meaning | Why it's control |
|---|---|---|
MemberOf |
the source is a member of the group | inherits all the group's rights |
AdminTo |
local admin on a computer | can read credentials of everyone logged on there |
HasSession |
(computer → user) the user is logged on to that computer | an admin of the computer can take that user's credentials |
GenericAll |
full control of the object | reset password, add members, write any attribute |
GenericWrite / WriteProperty |
write attributes | add an SPN (then Kerberoast), set msDS-AllowedToActOnBehalfOfOtherIdentity (RBCD), write member on a group, change a logon script path |
WriteDacl |
change the object's permissions | grant yourself GenericAll |
WriteOwner / Owns |
change or be the owner | owners can always change the DACL |
ForceChangePassword |
the "Reset password" extended right | set a new password without knowing the old one |
AddMember / AddSelf |
write the member attribute of a group |
join the group |
DCSync |
the two replication rights on the domain object | read every account's keys (DCSync) |
BloodHound collects these with its SharpHound (or other) collectors over LDAP and SMB, and stores them in a graph database; its "shortest paths to Domain Admins" query and its newer attack-path management features are graph algorithms over this data. Microsoft Defender for Identity and other products compute similar "lateral movement paths".
The analysis
The synthetic directory below has three paths to Domain Admins. Edges have a cost of fixing: membership changes are usually harder to negotiate (people need their groups), so they cost 2; a stray ACE or an admin's session in the wrong place costs 1. The program finds every user who can reach Domain Admins, the shortest path for each, and the cheapest set of edges whose removal cuts all paths (a minimum cut, solved as max-flow).
import networkx as nx
E = [ # (source, target, edge type)
*[(u, "Domain Users", "MemberOf") for u in ["alice", "bob", "carol", "dave", "helpdesk01", "srv-admin", "da-erin"]],
("helpdesk01", "IT-Helpdesk", "MemberOf"),
("Domain Users", "WS02", "AdminTo"), # 'everyone is admin on the shared dev box'
("WS02", "srv-admin", "HasSession"),
("srv-admin", "Server-Admins", "MemberOf"),
("Server-Admins", "SQL01", "AdminTo"),
("SQL01", "da-erin", "HasSession"), # a domain admin logged on to a server
("da-erin", "Domain Admins", "MemberOf"),
("IT-Helpdesk", "carol", "ForceChangePassword"), # help desk may reset carol, a former IT lead
("carol", "Server-Admins", "AddMember"), # carol's old right on Server-Admins
("dave", "Exchange-Perms", "MemberOf"),
("Exchange-Perms", "corp.lab.test", "WriteDacl"), # legacy product ACE on the domain object
("corp.lab.test", "Domain Admins", "DCSync"), # control of the domain object = control of the domain
]
g = nx.DiGraph()
for a, b, kind in E:
cost = {"MemberOf": 2, "DCSync": 10**6}.get(kind, 1) # DCSync: a consequence, not a fixable edge
g.add_edge(a, b, kind=kind, capacity=cost)
users = ["alice", "bob", "carol", "dave", "helpdesk01", "srv-admin"]
target = "Domain Admins"
exposed = [u for u in users if nx.has_path(g, u, target)]
print(f"{len(exposed)} of {len(users)} non-admin users have a path to {target}")
for u in exposed:
p = nx.shortest_path(g, u, target)
print(f" {u:10} {len(p) - 1} hops: " + " ".join(f"-{g.edges[a, b]['kind']}->{b}" for a, b in zip(p, p[1:])))
h = g.copy()
for u in users:
h.add_edge("SRC", u, capacity=10**6) # the user set itself is not "fixable"
cost, (reach, _) = nx.minimum_cut(h, "SRC", target)
cut = sorted((a, b) for a in reach for b in h.successors(a) if b not in reach)
print(f"\ncheapest fix: cost {cost}, remove {len(cut)} edge(s):")
for a, b in cut:
print(f" {a} -{g.edges[a, b]['kind']}-> {b}")
g.remove_edges_from(cut)
print("users with a path after the fix:", [u for u in users if nx.has_path(g, u, target)])6 of 6 non-admin users have a path to Domain Admins
alice 7 hops: -MemberOf->Domain Users -AdminTo->WS02 -HasSession->srv-admin -MemberOf->Server-Admins -AdminTo->SQL01 -HasSession->da-erin -MemberOf->Domain Admins
bob 7 hops: -MemberOf->Domain Users -AdminTo->WS02 -HasSession->srv-admin -MemberOf->Server-Admins -AdminTo->SQL01 -HasSession->da-erin -MemberOf->Domain Admins
carol 4 hops: -AddMember->Server-Admins -AdminTo->SQL01 -HasSession->da-erin -MemberOf->Domain Admins
dave 3 hops: -MemberOf->Exchange-Perms -WriteDacl->corp.lab.test -DCSync->Domain Admins
helpdesk01 6 hops: -MemberOf->IT-Helpdesk -ForceChangePassword->carol -AddMember->Server-Admins -AdminTo->SQL01 -HasSession->da-erin -MemberOf->Domain Admins
srv-admin 4 hops: -MemberOf->Server-Admins -AdminTo->SQL01 -HasSession->da-erin -MemberOf->Domain Admins
cheapest fix: cost 2, remove 2 edge(s):
Exchange-Perms -WriteDacl-> corp.lab.test
SQL01 -HasSession-> da-erin
users with a path after the fix: []
Read the output as a remediation plan. Every user in the domain reaches Domain Admins (through WS02, where an admin had a session), and the help desk and Dave have their own routes. You don't need to fix all 20 edges: removing the two edges of the cut closes every path. The session edge SQL01 -> da-erin is a tiering fix (domain admins don't log on to servers: Tiered Administration); the WriteDacl on the domain object is an ACL fix. The rest (everyone admin on WS02, the help desk's reset right on Carol, Carol's leftover right) still deserve cleanup, but they no longer lead to Tier 0. Rerun the analysis after every change: new paths appear as the directory evolves.
The attack-path lab animates the same idea on a smaller directory of its own. Breadth-first search from alice (the phished user) reveals one level of hops at a time, then draws the shortest path: in the office domain alice → Helpdesk → carol → Domain Admins, 3 edges, one of 3 paths. The readouts name the edge on most paths, alice → Helpdesk (2 of 3). Remove it and one path remains, 6 edges long, through alice's admin rights on WS01 and bob's session there: cutting the busiest edge is not the same as cutting all of them, which is why the program above solves a minimum cut. In the nested-groups directory both paths share PRN01 → svc_backup, so removing that one edge leaves none, and the tiered directory has no path at all.
Lab session: the same question in BloodHound
A lab session (sample output, abbreviated) in the BloodHound Community Edition UI's Cypher search, after a collection in the lab domain corp.lab.test by an authorised tester. The query is the graph question above:
MATCH p = shortestPath((u:User {enabled: true})-[*1..]->(g:Group))
WHERE g.objectid ENDS WITH '-512' AND NOT u.admincount
RETURN u.name, length(p) ORDER BY length(p)
u.name length(p)
DAVE@CORP.LAB.TEST 3
CAROL@CORP.LAB.TEST 4
SRV-ADMIN@CORP.LAB.TEST 4
HELPDESK01@CORP.LAB.TEST 6
...The UI then draws each path; defenders export the edges and feed them into the same kind of cut analysis, or use the product's built-in "choke point" views.
How ACL abuse is detected
Paths are configuration; abuse is the moment an edge is used:
- 5136 (directory object modified) for
nTSecurityDescriptorchanges on sensitive objects (the domain root, AdminSDHolder, privileged groups, Tier 0 OUs and GPOs): theWriteDaclstep. With a SACL, 4662 shows the control-access right used (Reset Password, the replication GUIDs). - 4724 (an attempt was made to reset an account's password) where the actor isn't the account itself or the help desk's provisioning tool; for a Tier 0 account, always an alert.
- 4728 / 4732 / 4756 additions to groups that expand into privileged SIDs (
Server-Adminsin the model), and 5136 adding an SPN to a user (the setup for targeted Kerberoasting). - Attack-path drift: run the analysis weekly and alert when the number of users with a path to Tier 0 grows.
How it is fixed or prevented
- Cut the cheapest edges first, as computed; then clean up the rest.
- Tier 0 isolation: privileged accounts sign in only to Tier 0 systems, which removes most
HasSessionedges into Tier 0. - ACL hygiene: remove ACEs granted to broad groups (Domain Users, Authenticated Users, Everyone) on users, groups, computers and OUs; review legacy product permissions (old Exchange setups granted
WriteDaclon the domain object, fixed in later updates); check ownership of privileged objects. - AdminSDHolder: members of protected groups get their DACL reset every 60 minutes from
CN=AdminSDHolder,CN=System; that protects them only if AdminSDHolder's own DACL is clean. Monitor it. - Continuous auditing of ACLs: Auditing ACLs and AD CS Continuously.
Pitfalls
- Fixing the longest or most visible path instead of the choke points; the cut is often small.
- Ignoring sessions because they change all the time. They are the edges that connect ACL paths to Tier 0, and the ones tiering removes.
- Reading inherited ACEs only on the object. An ACE on an OU applies to everything below it.
- Forgetting owners: the creator of an object is its owner and can rewrite its DACL, which is how many computer and group objects end up controlled by former employees.
Practice
1. Why does every user, including alice and bob, reach Domain Admins in the model?
Through Domain Users -AdminTo-> WS02: every user is local admin on WS02, srv-admin has a session there, srv-admin's group administers SQL01, and a domain admin is logged on to SQL01.
2. Change the capacity of HasSession edges to 5 (sessions are hard to control without tiering). What does the cut become?
The cut avoids the session edge and picks cheaper edges that also break all paths, for example Server-Admins -AdminTo-> SQL01 and the WriteDacl, for a total cost of 2. Run it to confirm. The lesson: the "cheapest" fix depends on what your organisation can change.
3. A 5136 shows nTSecurityDescriptor changed on DC=corp,DC=lab,DC=test by dave, followed by 4662 events with replication GUIDs from dave's workstation. What happened?
The WriteDacl -> DCSync path was used: dave granted himself replication rights and replicated secrets. Treat it as a full domain compromise: remove the ACE, then follow the krbtgt and credential-reset procedure of Golden and Silver Tickets.
Test yourself
Which right lets the holder grant itself full control of an object?
- ReadProperty
- WriteDacl
- ListChildren
- Delete
What does a minimum edge cut between all users and Domain Admins give a defender?
- The longest path
- The smallest (or cheapest) set of edges whose removal breaks every path
- The list of all admins
- The password policy
Which event shows a password reset attempt by another account?
- 4724
- 4625
- 4769
- 7045
Why are HasSession edges dangerous?
- Sessions encrypt traffic
- An admin of the computer can take the credentials of users logged on to it, so a privileged session on a lower-tier machine connects that machine to Tier 0
- They disable UAC
- They create SPNs
In the attack-path lab's office domain, you remove alice → Helpdesk, the edge on 2 of the 3 paths. What is left?
- No path
- One path of 6 edges, through WS01 and bob's session
- Two paths of 3 edges
- The same 3 paths