Skip to content

Commit 5583604

Browse files
committed
Corrected Get-NetGUIDOUs, fix for -TargetServerAdmins
1 parent f624c3d commit 5583604

File tree

1 file changed

+11
-29
lines changed

1 file changed

+11
-29
lines changed

PowerView/powerview.ps1

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ function Get-NetUser {
22632263
else{
22642264
# otherwise, use the current domain
22652265
if($UserName){
2266-
$UserSearcher = [adsisearcher]"(&(samAccountType=805306368)(samAccountName=*$UserName*))"
2266+
$UserSearcher = [adsisearcher]"(&(samAccountType=805306368)(samAccountName=$UserName))"
22672267
}
22682268
# if we're specifying an OU
22692269
elseif($OU){
@@ -2955,33 +2955,15 @@ function Get-NetGUIDOUs {
29552955
$FullData
29562956
)
29572957

2958-
# grab the OUs for this domain
2959-
$OUs = Get-NetOUs -FullData -Domain $Domain
2960-
2961-
$OUs | ForEach-Object {
2958+
# grab the OUs for this domain and process each
2959+
Get-NetOUs -FullData -Domain $Domain | % {
29622960
# grab all the GP links for this object and check for the target GUID
2963-
$a = $_.properties.gplink
2964-
$_ | %{
2965-
if($_.properties.gplink -match $GUID){
2966-
if ($FullData){
2967-
$properties = $_.Properties
2968-
$out = New-Object psobject
2969-
2970-
$properties.PropertyNames | % {
2971-
if($_ -eq "objectguid"){
2972-
# convert the GUID to a string
2973-
$out | Add-Member Noteproperty $_ (New-Object Guid (,$properties[$_][0])).Guid
2974-
}
2975-
else {
2976-
$out | Add-Member Noteproperty $_ $properties[$_][0]
2977-
}
2978-
}
2979-
$out
2980-
}
2981-
2982-
else{
2983-
$_.properties.distinguishedname
2984-
}
2961+
if($_.gplink -match $GUID) {
2962+
if ($FullData){
2963+
$_
2964+
}
2965+
else {
2966+
$_.distinguishedname
29852967
}
29862968
}
29872969
}
@@ -6118,7 +6100,7 @@ function Invoke-UserHunter {
61186100
if($ShowAll){}
61196101
# if we want to hunt for the effective domain users who can access a target server
61206102
elseif($TargetServerAdmins){
6121-
$TargetUsers = Get-NetLocalGroup WINDOWS4.dev.testlab.local -Recurse | ?{(-not $_.IsGroup) -and $_.IsDomain} | %{ ($_.AccountName).split("/")[1].toLower() }
6103+
$TargetUsers = Get-NetLocalGroup $TargetServerAdmins -Recurse | ?{(-not $_.IsGroup) -and $_.IsDomain} | %{ ($_.AccountName).split("/")[1].toLower() }
61226104
}
61236105
# if we get a specific username, only use that
61246106
elseif ($UserName){
@@ -6866,7 +6848,7 @@ function Invoke-StealthUserHunter {
68666848
if($ShowAll){}
68676849
# if we want to hunt for the effective domain users who can access a target server
68686850
elseif($TargetServerAdmins){
6869-
$TargetUsers = Get-NetLocalGroup WINDOWS4.dev.testlab.local -Recurse | ?{(-not $_.IsGroup) -and $_.IsDomain} | %{ ($_.AccountName).split("/")[1].toLower() }
6851+
$TargetUsers = Get-NetLocalGroup $TargetServerAdmins -Recurse | ?{(-not $_.IsGroup) -and $_.IsDomain} | %{ ($_.AccountName).split("/")[1].toLower() }
68706852
}
68716853
# if we get a specific username, only use that
68726854
elseif ($UserName){

0 commit comments

Comments
 (0)