Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 0e2daae

Browse files
authored
Merge pull request #236 from MrAnde7son/patch-3
Get-GPODelegation
2 parents f8d2a34 + 6a71a6e commit 0e2daae

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

Recon/PowerView.ps1

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18764,6 +18764,68 @@ Custom PSObject with translated domain API trust result fields.
1876418764
}
1876518765
}
1876618766

18767+
function Get-GPODelegation
18768+
{
18769+
<#
18770+
.SYNOPSIS
18771+
Finds users with write permissions on GPO objects which may allow privilege escalation within the domain.
18772+
18773+
Author: Itamar Mizrahi (@MrAnde7son)
18774+
License: GNU v3
18775+
Required Dependencies: None
18776+
Optional Dependencies: None
18777+
18778+
.DESCRIPTION
18779+
18780+
.PARAMETER GPOName
18781+
The GPO display name to query for, wildcards accepted.
18782+
18783+
.PARAMETER PageSize
18784+
18785+
.EXAMPLE
18786+
PS C:\> Get-GPODelegation
18787+
Returns all GPO delegations in current forest.
18788+
18789+
.EXAMPLE
18790+
PS C:\> Get-GPODelegation -GPOName
18791+
Returns all GPO delegations on a given GPO.
18792+
#>
18793+
[CmdletBinding()]
18794+
Param (
18795+
[String]
18796+
$GPOName = '*',
18797+
18798+
[ValidateRange(1,10000)]
18799+
[Int]
18800+
$PageSize = 200
18801+
)
18802+
18803+
$Exclusions = @("SYSTEM","Domain Admins","Enterprise Admins")
18804+
18805+
$Forest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
18806+
$DomainList = @($Forest.Domains)
18807+
$Domains = $DomainList | foreach { $_.GetDirectoryEntry() }
18808+
foreach ($Domain in $Domains) {
18809+
$Filter = "(&(objectCategory=groupPolicyContainer)(displayname=$GPOName))"
18810+
$Searcher = New-Object System.DirectoryServices.DirectorySearcher
18811+
$Searcher.SearchRoot = $Domain
18812+
$Searcher.Filter = $Filter
18813+
$Searcher.PageSize = $PageSize
18814+
$Searcher.SearchScope = "Subtree"
18815+
$listGPO = $Searcher.FindAll()
18816+
foreach ($gpo in $listGPO){
18817+
$ACL = ([ADSI]$gpo.path).ObjectSecurity.Access | ? {$_.ActiveDirectoryRights -match "Write" -and $_.AccessControlType -eq "Allow" -and $Exclusions -notcontains $_.IdentityReference.toString().split("\")[1] -and $_.IdentityReference -ne "CREATOR OWNER"}
18818+
if ($ACL -ne $null){
18819+
$GpoACL = New-Object psobject
18820+
$GpoACL | Add-Member Noteproperty 'ADSPath' $gpo.Properties.adspath
18821+
$GpoACL | Add-Member Noteproperty 'GPODisplayName' $gpo.Properties.displayname
18822+
$GpoACL | Add-Member Noteproperty 'IdentityReference' $ACL.IdentityReference
18823+
$GpoACL | Add-Member Noteproperty 'ActiveDirectoryRights' $ACL.ActiveDirectoryRights
18824+
$GpoACL
18825+
}
18826+
}
18827+
}
18828+
}
1876718829

1876818830
########################################################
1876918831
#

0 commit comments

Comments
 (0)