From 095988269bfaafcb3cb0ab050cc782b98fd582ac Mon Sep 17 00:00:00 2001 From: HarmJ0y Date: Fri, 28 Apr 2017 00:56:52 -0400 Subject: Get-DomainGPO - fixed enumerations of 'enforced' GPOs, and bug fix for nested OUs with similar starting names. --- Recon/PowerView.ps1 | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'Recon') diff --git a/Recon/PowerView.ps1 b/Recon/PowerView.ps1 index b40989d..c6cb5ff 100755 --- a/Recon/PowerView.ps1 +++ b/Recon/PowerView.ps1 @@ -11164,7 +11164,7 @@ The raw DirectoryServices.SearchResult object, if -Raw is enabled. $ObjectOUs = @() $ObjectOUs += $ObjectDN.split(',') | ForEach-Object { if($_.startswith('OU=')) { - $ObjectDN.SubString($ObjectDN.IndexOf($_)) + $ObjectDN.SubString($ObjectDN.IndexOf("$($_),")) } } Write-Verbose "[Get-DomainGPO] object OUs: $ObjectOUs" @@ -11174,13 +11174,28 @@ The raw DirectoryServices.SearchResult object, if -Raw is enabled. $SearcherArguments.Remove('Properties') $InheritanceDisabled = $False ForEach($ObjectOU in $ObjectOUs) { - if ($InheritanceDisabled) { break } $SearcherArguments['Identity'] = $ObjectOU $GPOAdsPaths += Get-DomainOU @SearcherArguments | ForEach-Object { # extract any GPO links for this particular OU the computer is a part of - $_.gplink.split('][') | ForEach-Object { - if ($_.startswith('LDAP')) { - $_.split(';')[0] + if ($_.gplink) { + $_.gplink.split('][') | ForEach-Object { + if ($_.startswith('LDAP')) { + $Parts = $_.split(';') + $GpoDN = $Parts[0] + $Enforced = $Parts[1] + + if ($InheritanceDisabled) { + # if inheritance has already been disabled and this GPO is set as "enforced" + # then add it, otherwise ignore it + if ($Enforced -eq 2) { + $GpoDN + } + } + else { + # inheritance not marked as disabled yet + $GpoDN + } + } } } -- cgit v1.2.3