Group Policy Processing and Security Filtering
Group Policy is how AD configures thousands of machines at once: password rules, audit policy, firewall rules, local administrators, software, scripts at startup. A Group Policy Object (GPO) is two things: a directory object (groupPolicyContainer under CN=Policies,CN=System,DC=corp,DC=lab,DC=test) with its version and links, and a folder of files in SYSVOL (\\corp.lab.test\SYSVOL\corp.lab.test\Policies\{GUID}) that every domain member reads. Whoever can edit a GPO linked above a set of machines runs code on all of them as SYSTEM. So the security of Group Policy is a question of which GPOs apply where, who can edit them, and what secrets ended up in SYSVOL. This lesson covers the first and the third; editing rights are in GPO Abuse.
Processing order: LSDOU
Computer settings apply at boot and every 90 minutes (with a random offset of up to 30 minutes; every 5 minutes on DCs); user settings at sign-in and on the same cycle. GPOs are applied in the order Local, Site, Domain, OU (parent OUs before child OUs), and later wins when two GPOs set the same value. Within one container, links are applied from the highest link-order number to link order 1, so link order 1 wins. Two switches change the rule:
- Block Inheritance on an OU: GPOs linked above it don't apply, except
- Enforced links: they apply even through Block Inheritance, and an enforced GPO wins over non-enforced ones (among enforced GPOs, the one higher in the tree wins).
Then come the filters that decide whether a linked GPO applies to a given computer or user at all:
- Security filtering: the GPO applies only to principals that have Read and Apply group policy on it. The default is Authenticated Users. Since the 2016 update MS16-072, user policy is read in the computer's security context, so the computer must be able to read the GPO too (keep Authenticated Users or Domain Computers with Read when you filter to a user group).
- WMI filters: a WQL query evaluated on the client (for example "only Windows Server").
- Loopback processing for kiosks and terminal servers: user settings come from the computer's GPOs.
Computing the resulting set of policy
The program implements those rules for the lab: five GPOs set a password rule, LLMNR, the local Administrators policy and a proxy; the question is what WS01 (in OU=Workstations,OU=Tier2) and SRV-TEST (in OU=Test with Block Inheritance) actually get. This is what gpresult /r or the Group Policy Results wizard shows on a real machine.
gpos = {
"Default Domain Policy": {"MinPasswordLength": 7},
"Baseline-Hardening": {"LLMNR": "off", "LocalAdmins": "restricted"},
"Tier2-Workstations": {"LocalAdmins": "helpdesk allowed"},
"Test-Relaxed": {"LLMNR": "on", "LocalAdmins": "everyone"},
"Site-HQ-Proxy": {"Proxy": "proxy.corp.lab.test"},
}
# links in processing order of the tree: (container, gpo, link_order, enforced)
links = [
("site:HQ", "Site-HQ-Proxy", 1, False),
("domain", "Default Domain Policy", 2, False),
("domain", "Baseline-Hardening", 1, True), # enforced
("ou:Tier2", "Tier2-Workstations", 1, False),
("ou:Test", "Test-Relaxed", 1, False),
]
block_inheritance = {"ou:Test"}
security_filter = {"Tier2-Workstations": {"WS01", "WS02"}} # Apply group policy only for these
def rsop(computer, containers):
applied = [] # (gpo, enforced, depth) in processing order
for depth, cont in enumerate(containers):
blocked_above = any(c in block_inheritance for c in containers[depth + 1:])
here = sorted((l for l in links if l[0] == cont), key=lambda l: -l[2]) # highest link order first
for _, gpo, _, enforced in here:
if blocked_above and not enforced:
continue
if gpo in security_filter and computer not in security_filter[gpo]:
continue
applied.append((gpo, enforced, depth))
# normal GPOs: later wins; enforced GPOs win over normal ones, higher (smaller depth) enforced wins
order = [a for a in applied if not a[1]] + sorted((a for a in applied if a[1]), key=lambda a: -a[2])
settings, source = {}, {}
for gpo, _, _ in order:
for k, v in gpos[gpo].items():
settings[k], source[k] = v, gpo
return [a[0] for a in applied], settings, source
for computer, containers in [("WS01", ["site:HQ", "domain", "ou:Tier2"]),
("SRV-TEST", ["site:HQ", "domain", "ou:Test"]),
("WS99", ["site:HQ", "domain", "ou:Tier2"])]:
applied, settings, source = rsop(computer, containers)
print(f"{computer}: applied {applied}")
for k in sorted(settings):
print(f" {k:17} = {str(settings[k]):20} (from {source[k]})")WS01: applied ['Site-HQ-Proxy', 'Default Domain Policy', 'Baseline-Hardening', 'Tier2-Workstations']
LLMNR = off (from Baseline-Hardening)
LocalAdmins = restricted (from Baseline-Hardening)
MinPasswordLength = 7 (from Default Domain Policy)
Proxy = proxy.corp.lab.test (from Site-HQ-Proxy)
SRV-TEST: applied ['Baseline-Hardening', 'Test-Relaxed']
LLMNR = off (from Baseline-Hardening)
LocalAdmins = restricted (from Baseline-Hardening)
WS99: applied ['Site-HQ-Proxy', 'Default Domain Policy', 'Baseline-Hardening']
LLMNR = off (from Baseline-Hardening)
LocalAdmins = restricted (from Baseline-Hardening)
MinPasswordLength = 7 (from Default Domain Policy)
Proxy = proxy.corp.lab.test (from Site-HQ-Proxy)
Three lessons in one output. WS01 doesn't get "helpdesk allowed" although that GPO is linked to its own OU, because the domain-level Baseline-Hardening is enforced and wins. SRV-TEST blocks inheritance, which drops the site and Default Domain Policy GPOs but not the enforced baseline, so the relaxed test GPO loses on both settings it tries to change. WS99 sits in the same OU as WS01 but isn't in the security filter, so Tier2-Workstations doesn't apply to it at all. A reviewer who reads only the GPOs linked to an OU gets all three wrong.
Secrets in SYSVOL
SYSVOL is readable by every authenticated user. Two kinds of secret have historically ended up there:
- Group Policy Preferences passwords. Before 2014, GPP let admins set local account passwords, mapped drives and scheduled tasks with a
cpasswordattribute in XML files such asGroups.xml. The value was AES-encrypted with a key Microsoft had published in its own protocol documentation, so anyone could decrypt it. Update MS14-025 removed the ability to create such entries, but did not delete existing files, and old ones are still found in assessments. - Scripts with credentials: logon and startup scripts (
.bat,.ps1,.vbs) that map drives or install software with a hard-coded password.
Finding them is a defender's job, and it is a plain text search. The session below builds a mock SYSVOL tree in your sandbox (the cpassword value is a placeholder, not an encrypted secret) and searches it the way a scheduled check would.
P=sysvol/corp.lab.test/Policies
mkdir -p "$P/{31B2F340}/Machine" "$P/{6AC1786C}/Machine/Preferences/Groups" "$P/{9F3A0C11}/User/Scripts/Logon"
printf '[Unicode]\nUnicode=yes\n[System Access]\nMinimumPasswordLength = 7\n' > "$P/{31B2F340}/Machine/GptTmpl.inf"
cat > "$P/{6AC1786C}/Machine/Preferences/Groups/Groups.xml" <<'XML'
<Groups><User name="labadmin (built-in)"><Properties action="U" userName="labadmin" cpassword="PLACEHOLDER-NOT-A-SECRET"/></User></Groups>
XML
printf 'net use S: \\\\fs01\\share /user:CORP\\svc-map Lab-Only-Pw1\n' > "$P/{9F3A0C11}/User/Scripts/Logon/map.bat"
echo "== GPP files with cpassword (MS14-025 leftovers)"
grep -rl --include='*.xml' 'cpassword=' sysvol
echo "== scripts that pass a password on the command line"
grep -rniE --include='*.bat' --include='*.ps1' --include='*.vbs' '(/user:|password|-pass)' sysvol | sed 's/Lab-Only-Pw1/<redacted>/'== GPP files with cpassword (MS14-025 leftovers)
sysvol/corp.lab.test/Policies/{6AC1786C}/Machine/Preferences/Groups/Groups.xml
== scripts that pass a password on the command line
sysvol/corp.lab.test/Policies/{9F3A0C11}/User/Scripts/Logon/map.bat:1:net use S: \\fs01\share /user:CORP\svc-map <redacted>
Both findings mean the same thing: the credential is compromised (anyone in the domain could read it) and must be changed, then the file deleted. Searching for cpassword is also exactly what attackers do on day one, which is why the check belongs in your own routine.
How misuse is detected
- GPO changes: 5136 on
groupPolicyContainerobjects (attributeversionNumber,gPCMachineExtensionNames,gPLinkon OUs) with Directory Service Changes auditing; 5145 (detailed file share) for writes under\SYSVOL\…\Policies\. Correlate: a version change without a change ticket is an alert. - New links: a change of
gPLinkon an OU or the domain root, especially linking an existing GPO to the Domain Controllers OU. - Reads of GPP files are normal (clients read SYSVOL all the time), so detect the presence of
cpasswordinstead, as above.
How it is hardened
- Keep a documented, small set of GPOs; review links, enforcement and filters as in the model (
Get-GPResultantSetOfPolicy,gpresult /h). - Delete every GPP file with
cpassword, rotate those passwords, and use Windows LAPS for local admin passwords instead. - Never put credentials in scripts; use gMSAs or scheduled tasks running as a managed identity.
- Restrict GPO edit rights to a Tier 0 group; link Tier 0 GPOs (Domain Controllers OU) only from Tier 0 administration (GPO Abuse).
Pitfalls
- Assuming the GPO on the OU is what applies. Enforcement, blocking, filtering and WMI filters change the outcome; check the result on the client.
- Removing Authenticated Users from security filtering without adding back Read for computers breaks user policy since MS16-072 (the GPO silently stops applying).
- Editing the Default Domain Policy for everything. Keep it to account policies and put the rest in separate, named GPOs.
- Forgetting the local policy: settings applied locally on a machine are overridden by domain GPOs, but only for values those GPOs set.
Practice
1. Remove the enforcement of Baseline-Hardening in the model. What do WS01 and SRV-TEST get for LocalAdmins?
WS01: helpdesk allowed (the OU GPO is processed later and wins). SRV-TEST: everyone, and LLMNR = on, because Block Inheritance now removes the baseline as well. Set enforced to False and run it.
2. A GPO is filtered to the group Finance-Users only (Authenticated Users removed). Users in Finance don't get the settings. Why?
Since MS16-072 user policy is retrieved with the computer's credentials; the computer accounts have no Read permission on the GPO any more. Add Domain Computers (or Authenticated Users) with Read only, not Apply.
3. You find a Groups.xml with cpassword dated 2013. Is deleting the file enough?
No. Every domain user could read it for years, so the password must be treated as known: change it everywhere it is used (likely the local admin password of many machines), deploy Windows LAPS, then delete the file.
Test yourself
In which order are GPOs applied?
- OU, Domain, Site, Local
- Local, Site, Domain, OU, with later ones winning
- Alphabetically
- Domain only
What does an Enforced link do?
- Nothing
- It applies even through Block Inheritance and wins over non-enforced GPOs
- It applies only to DCs
- It disables security filtering
Why are Group Policy Preferences cpassword values considered exposed?
- They are stored in plaintext in the registry
- They are encrypted with a key Microsoft published, in files every domain user can read
- They are sent by email
- They are only on DCs
Which permissions must a principal have for a GPO to apply to it?
- Write and Delete
- Read and Apply group policy
- Full control
- Only Read