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

Commit 9f4e32e

Browse files
committed
Renamed Get-DomainPolicy to Get-DomainPolicyData and generalized the
function to accept any policy.
1 parent 92e17e5 commit 9f4e32e

File tree

1 file changed

+59
-57
lines changed

1 file changed

+59
-57
lines changed

Recon/PowerView.ps1

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -10451,7 +10451,9 @@ Ouputs a hashtable representing the parsed GptTmpl.inf file.
1045110451
}
1045210452

1045310453
Write-Verbose "[Get-GptTmpl] Parsing GptTmplPath: $TargetGptTmplPath"
10454-
Get-IniContent -Path $TargetGptTmplPath -ErrorAction Stop
10454+
$Contents = Get-IniContent -Path $TargetGptTmplPath -ErrorAction Stop
10455+
$Contents['Path'] = $TargetGptTmplPath
10456+
$Contents
1045510457
}
1045610458
catch {
1045710459
Write-Verbose "[Get-GptTmpl] Error parsing $TargetGptTmplPath : $_"
@@ -11862,7 +11864,7 @@ PowerView.GGPOComputerLocalGroupMember
1186211864
}
1186311865

1186411866

11865-
function Get-DomainPolicy {
11867+
function Get-DomainPolicyData {
1186611868
<#
1186711869
.SYNOPSIS
1186811870

@@ -11882,9 +11884,10 @@ domain or a specified domain/domain controller using Get-DomainGPO.
1188211884

1188311885
The domain to query for default policies, defaults to the current domain.
1188411886

11885-
.PARAMETER Source
11887+
.PARAMETER Policy
1188611888

11887-
Extract 'Domain' or 'DC' (domain controller) policies.
11889+
Extract 'Domain' or 'DC' (domain controller) policies, otherwise queries for the particular
11890+
GPO name or GUID.
1188811891

1188911892
.PARAMETER Server
1189011893

@@ -11905,27 +11908,33 @@ for connection to the target domain.
1190511908

1190611909
.EXAMPLE
1190711910

11908-
Get-DomainPolicy
11911+
Get-DomainPolicyData
1190911912

11910-
Returns the domain policy for the current domain.
11913+
Returns the default domain policy for the current domain.
1191111914

1191211915
.EXAMPLE
1191311916

11914-
Get-DomainPolicy -Domain dev.testlab.local
11917+
Get-DomainPolicyData -Domain dev.testlab.local
1191511918

11916-
Returns the domain policy for the dev.testlab.local domain.
11919+
Returns the default domain policy for the dev.testlab.local domain.
1191711920

1191811921
.EXAMPLE
1191911922

11920-
Get-DomainPolicy -Source DC -Domain dev.testlab.local
11923+
Get-DomainGPO | Get-DomainPolicy
11924+
11925+
Parses any GptTmpl.infs found for any policies.
11926+
11927+
.EXAMPLE
11928+
11929+
Get-DomainPolicyData -Policy DC -Domain dev.testlab.local
1192111930

1192211931
Returns the policy for the dev.testlab.local domain controller.
1192311932

1192411933
.EXAMPLE
1192511934

1192611935
$SecPassword = ConvertTo-SecureString 'Password123!' -AsPlainText -Force
1192711936
$Cred = New-Object System.Management.Automation.PSCredential('TESTLAB\dfm.a', $SecPassword)
11928-
Get-DomainPolicy -Credential $Cred
11937+
Get-DomainPolicyData -Credential $Cred
1192911938

1193011939
.OUTPUTS
1193111940

@@ -11939,14 +11948,13 @@ Ouputs a hashtable representing the parsed GptTmpl.inf file.
1193911948
[CmdletBinding()]
1194011949
Param(
1194111950
[Parameter(Position = 0, ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
11942-
[Alias('Name')]
11943-
[ValidateNotNullOrEmpty()]
11951+
[Alias('Source', 'Name')]
1194411952
[String]
11945-
$Domain,
11953+
$Policy = 'Domain',
1194611954

11947-
[ValidateSet('Domain', 'DC', 'DomainController')]
11955+
[ValidateNotNullOrEmpty()]
1194811956
[String]
11949-
$Source = 'Domain',
11957+
$Domain,
1195011958

1195111959
[ValidateNotNullOrEmpty()]
1195211960
[Alias('DomainController')]
@@ -11982,56 +11990,49 @@ Ouputs a hashtable representing the parsed GptTmpl.inf file.
1198211990
$ConvertArguments['Domain'] = $Domain
1198311991
}
1198411992

11985-
if ($Source -eq 'Domain') {
11986-
# query the given domain for the default domain policy object (name = {31B2F340-016D-11D2-945F-00C04FB984F9})
11993+
if ($Policy -eq 'Domain') {
1198711994
$SearcherArguments['Identity'] = '{31B2F340-016D-11D2-945F-00C04FB984F9}'
11988-
$GPO = Get-DomainGPO @SearcherArguments
11989-
11990-
if ($GPO) {
11991-
# grab the GptTmpl.inf file and parse it
11992-
$GptTmplPath = $GPO.gpcfilesyspath + '\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf'
11993-
$ParseArgs = @{'GptTmplPath' = $GptTmplPath}
11994-
if ($PSBoundParameters['Credential']) { $ParseArgs['Credential'] = $Credential }
11995-
Get-GptTmpl @ParseArgs
11996-
}
1199711995
}
11998-
else {
11999-
# query the given domain/dc for the default domain controller policy object (name = {6AC1786C-016F-11D2-945F-00C04FB984F9})
11996+
elseif (($Policy -eq 'DomainController') -or ($Policy -eq 'DC')) {
1200011997
$SearcherArguments['Identity'] = '{6AC1786C-016F-11D2-945F-00C04FB984F9}'
12001-
$GPO = Get-DomainGPO @SearcherArguments
12002-
12003-
if ($GPO) {
12004-
# grab the GptTmpl.inf file and parse it
12005-
$GptTmplPath = $GPO.gpcfilesyspath + "\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf"
12006-
12007-
$ParseArgs = @{'GptTmplPath' = $GptTmplPath}
12008-
if ($PSBoundParameters['Credential']) { $ParseArgs['Credential'] = $Credential }
12009-
12010-
# parse the GptTmpl.inf
12011-
Get-GptTmpl @ParseArgs | ForEach-Object {
12012-
if ($PSBoundParameters['ResolveSids']) {
12013-
$Root = $_
12014-
$PrivilegeRightsResovled = @{}
12015-
# if we're resolving sids in PrivilegeRights to names
12016-
if ($Root.'Privilege Rights') {
12017-
$PrivilegeRights = $Root.'Privilege Rights'
12018-
ForEach ($PrivilegeRight in $PrivilegeRights.Keys) {
12019-
$PrivilegeRightsResovled[$PrivilegeRight] = $PrivilegeRights."$PrivilegeRight" | ForEach-Object {
12020-
try {
12021-
$_ | ForEach-Object { ConvertFrom-SID -ObjectSid ($_.Trim('*')) @ConvertArguments }
12022-
}
12023-
catch {
12024-
Write-Verbose "[Get-DomainPolicy] Error resolving SID : $_"
12025-
$_
12026-
}
11998+
}
11999+
else {
12000+
$SearcherArguments['Identity'] = $Policy
12001+
}
12002+
12003+
$GPO = Get-DomainGPO @SearcherArguments
12004+
12005+
if ($GPO) {
12006+
# grab the GptTmpl.inf file and parse it
12007+
$GptTmplPath = $GPO.gpcfilesyspath + "\MACHINE\Microsoft\Windows NT\SecEdit\GptTmpl.inf"
12008+
12009+
$ParseArgs = @{'GptTmplPath' = $GptTmplPath}
12010+
if ($PSBoundParameters['Credential']) { $ParseArgs['Credential'] = $Credential }
12011+
12012+
# parse the GptTmpl.inf
12013+
Get-GptTmpl @ParseArgs | ForEach-Object {
12014+
if ($PSBoundParameters['ResolveSids']) {
12015+
$Root = $_
12016+
$PrivilegeRightsResovled = @{}
12017+
# if we're resolving sids in PrivilegeRights to names
12018+
if ($Root.'Privilege Rights') {
12019+
$PrivilegeRights = $Root.'Privilege Rights'
12020+
ForEach ($PrivilegeRight in $PrivilegeRights.Keys) {
12021+
$PrivilegeRightsResovled[$PrivilegeRight] = $PrivilegeRights."$PrivilegeRight" | ForEach-Object {
12022+
try {
12023+
$_ | ForEach-Object { ConvertFrom-SID -ObjectSid ($_.Trim('*')) @ConvertArguments }
12024+
}
12025+
catch {
12026+
Write-Verbose "[Get-DomainPolicy] Error resolving SID : $_"
12027+
$_
1202712028
}
1202812029
}
1202912030
}
12030-
$Root.'Privilege Rights' = $PrivilegeRightsResovled
12031-
$Root
1203212031
}
12033-
else { $_ }
12032+
$Root.'Privilege Rights' = $PrivilegeRightsResovled
12033+
$Root
1203412034
}
12035+
else { $_ }
1203512036
}
1203612037
}
1203712038
}
@@ -18663,3 +18664,4 @@ Set-Alias Get-NetForestTrust Get-ForestTrust
1866318664
Set-Alias Find-ForeignUser Get-DomainForeignUser
1866418665
Set-Alias Find-ForeignGroup Get-DomainForeignGroupMember
1866518666
Set-Alias Invoke-MapDomainTrust Get-DomainTrustMapping
18667+
Set-Alias Get-DomainPolicy Get-DomainPolicyData

0 commit comments

Comments
 (0)