使用 PowerShell 有效访问 Active Directory 对象
Effective Access Active Directory Object Using PowerShell
我正在尝试获取某些 Active Directory 用户对各种 Active Directory 对象的有效权限。我可以从 UI -
中看到这些权限
我正在尝试使用 Powershell 获取此信息。我已经尝试过 dsacls
和 Get-Acls
但这些都没有提供有效的权限。 这两个都给出了“谁有access/permissions”,这与“谁有什么有效权限”是不一样的。这些也没有列出提供有效访问上下文的所有详细信息。
任何关于如何以编程方式实现这一点的指示将不胜感激。
更新-
此处的有效权限是指现实中根据继承或其他设置在不同级别的规则允许对象的权限。
例如-
下例中的所有属性在 Get-ACL 中都不可见。
另一个 Get-Acl 显示的例子,而 UI 则不同,当我在解析 ObjectType 和 InheritedObjectType 中的值(使用Santiago Squarzon 提到的 get-effective 访问函数)我得到 -
虽然UI有效访问显示-
我的最终目标是使用powershell获得上面截图中的所有权限。
这与您要查找的内容非常接近。 Source 了解更多详情。 Get-ACL
的访问控制列表不像 Effective Access 上的 那样容易阅读安全设置 我认为没有办法解决这个问题。我确实认为,一旦习惯了,Get-ACL
会在您知道要查找什么时提供更多详细信息\过滤 ACL 以获得您要查找的内容。
代码
# requires -Modules ActiveDirectory
$ErrorActionPreference = 'Stop'
function Get-EffectiveAccess {
[CmdletBinding()]
param(
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName
)]
[ValidatePattern(
'(?:(CN=([^,]*)),)?(?:((?:(?:CN|OU)=[^,]+,?)+),)?((?:DC=[^,]+,?)+)$'
)]
[string]$DistinguishedName,
[switch]$IncludeOrphan
)
begin {
$GUIDMap = @{}
$domain = Get-ADRootDSE
$z = '00000000-0000-0000-0000-000000000000'
$hash = @{
SearchBase = $domain.schemaNamingContext
LDAPFilter = '(schemaIDGUID=*)'
Properties = 'name', 'schemaIDGUID'
ErrorAction = 'SilentlyContinue'
}
$schemaIDs = Get-ADObject @hash
$hash = @{
SearchBase = "CN=Extended-Rights,$($domain.configurationNamingContext)"
LDAPFilter = '(objectClass=controlAccessRight)'
Properties = 'name', 'rightsGUID'
ErrorAction = 'SilentlyContinue'
}
$extendedRigths = Get-ADObject @hash
foreach($i in $schemaIDs) {
if(-not $GUIDMap.ContainsKey([System.GUID]$i.schemaIDGUID)) {
$GUIDMap.add([System.GUID]$i.schemaIDGUID, $i.name)
}
}
foreach($i in $extendedRigths) {
if(-not $GUIDMap.ContainsKey([System.GUID]$i.rightsGUID)) {
$GUIDMap.add([System.GUID]$i.rightsGUID, $i.name)
}
}
}
process {
$object = Get-ADObject $DistinguishedName
$acls = (Get-ACL "AD:$object").Access
$result = foreach($acl in $acls) {
$objectType = (
$GUIDMap[$acl.ObjectType],
'All Objects (Full Control)'
)[$acl.ObjectType -eq $z]
$inheritedObjType = (
$GUIDMap[$acl.InheritedObjectType],
'Applied to Any Inherited Object'
)[$acl.InheritedObjectType -eq $z]
[PSCustomObject]@{
Name = $object.Name
IdentityReference = $acl.IdentityReference
AccessControlType = $acl.AccessControlType
ActiveDirectoryRights = $acl.ActiveDirectoryRights
ObjectType = $objectType
InheritedObjectType = $inheritedObjType
InheritanceType = $acl.InheritanceType
IsInherited = $acl.IsInherited
}
}
if($IncludeOrphan.IsPresent) {
return $result | Sort-Object IdentityReference
}
$result | Where-Object { -not $_.IdentityReference.StartsWith('S-1-5-21') } |
Sort-Object IdentityReference
}
}
用法
PS \> Get-ADOrganizationalUnit -Filter "Name -eq 'ExampleOU'" | Get-EffectiveAccess | Out-GridView
PS \> Get-EffectiveAccess -DistinguishedName 'OU=ExampleOU,DC=domainName,DC=com' | Out-GridView
PS \> $effectiveAccess = Get-ADGroup exampleGroup | Get-EffectiveAccess -IncludeOrphan
PS \> Get-ADOrganizationalUnit -Filter * | Select -First 10 | Get-EffectiveAccess | Out-GridView
默认情况下,该函数将过滤所有孤立的 ACL。使用 IncludeOrphan
开关包含所有以 S-1-*
开头的 IdentityReference
编辑
供参考,这就是 完全控制 与 Get-ACL
的样子
与 BUILTIN\Administrators 相比,后者对此 OU 具有写入权限但没有 完全控制
你可以试试PowerShellAccessControl module I think the details for this module are covered in this youtube video with the function Get-EffectiveAccess
. This should help you get the information. The module has been deleted from the Microsoft's PS Gallery。我不确定您如何从 Github 安装模块,我无法尝试,因为我正在使用 Mac.
我正在尝试获取某些 Active Directory 用户对各种 Active Directory 对象的有效权限。我可以从 UI -
我正在尝试使用 Powershell 获取此信息。我已经尝试过 dsacls
和 Get-Acls
但这些都没有提供有效的权限。 这两个都给出了“谁有access/permissions”,这与“谁有什么有效权限”是不一样的。这些也没有列出提供有效访问上下文的所有详细信息。
任何关于如何以编程方式实现这一点的指示将不胜感激。
更新-
此处的有效权限是指现实中根据继承或其他设置在不同级别的规则允许对象的权限。
例如-
下例中的所有属性在 Get-ACL 中都不可见。
另一个 Get-Acl 显示的例子,而 UI 则不同,当我在解析 ObjectType 和 InheritedObjectType 中的值(使用Santiago Squarzon 提到的 get-effective 访问函数)我得到 -
虽然UI有效访问显示-
我的最终目标是使用powershell获得上面截图中的所有权限。
这与您要查找的内容非常接近。 Source 了解更多详情。 Get-ACL
的访问控制列表不像 Effective Access 上的 那样容易阅读安全设置 我认为没有办法解决这个问题。我确实认为,一旦习惯了,Get-ACL
会在您知道要查找什么时提供更多详细信息\过滤 ACL 以获得您要查找的内容。
代码
# requires -Modules ActiveDirectory
$ErrorActionPreference = 'Stop'
function Get-EffectiveAccess {
[CmdletBinding()]
param(
[Parameter(
Mandatory,
ValueFromPipelineByPropertyName
)]
[ValidatePattern(
'(?:(CN=([^,]*)),)?(?:((?:(?:CN|OU)=[^,]+,?)+),)?((?:DC=[^,]+,?)+)$'
)]
[string]$DistinguishedName,
[switch]$IncludeOrphan
)
begin {
$GUIDMap = @{}
$domain = Get-ADRootDSE
$z = '00000000-0000-0000-0000-000000000000'
$hash = @{
SearchBase = $domain.schemaNamingContext
LDAPFilter = '(schemaIDGUID=*)'
Properties = 'name', 'schemaIDGUID'
ErrorAction = 'SilentlyContinue'
}
$schemaIDs = Get-ADObject @hash
$hash = @{
SearchBase = "CN=Extended-Rights,$($domain.configurationNamingContext)"
LDAPFilter = '(objectClass=controlAccessRight)'
Properties = 'name', 'rightsGUID'
ErrorAction = 'SilentlyContinue'
}
$extendedRigths = Get-ADObject @hash
foreach($i in $schemaIDs) {
if(-not $GUIDMap.ContainsKey([System.GUID]$i.schemaIDGUID)) {
$GUIDMap.add([System.GUID]$i.schemaIDGUID, $i.name)
}
}
foreach($i in $extendedRigths) {
if(-not $GUIDMap.ContainsKey([System.GUID]$i.rightsGUID)) {
$GUIDMap.add([System.GUID]$i.rightsGUID, $i.name)
}
}
}
process {
$object = Get-ADObject $DistinguishedName
$acls = (Get-ACL "AD:$object").Access
$result = foreach($acl in $acls) {
$objectType = (
$GUIDMap[$acl.ObjectType],
'All Objects (Full Control)'
)[$acl.ObjectType -eq $z]
$inheritedObjType = (
$GUIDMap[$acl.InheritedObjectType],
'Applied to Any Inherited Object'
)[$acl.InheritedObjectType -eq $z]
[PSCustomObject]@{
Name = $object.Name
IdentityReference = $acl.IdentityReference
AccessControlType = $acl.AccessControlType
ActiveDirectoryRights = $acl.ActiveDirectoryRights
ObjectType = $objectType
InheritedObjectType = $inheritedObjType
InheritanceType = $acl.InheritanceType
IsInherited = $acl.IsInherited
}
}
if($IncludeOrphan.IsPresent) {
return $result | Sort-Object IdentityReference
}
$result | Where-Object { -not $_.IdentityReference.StartsWith('S-1-5-21') } |
Sort-Object IdentityReference
}
}
用法
PS \> Get-ADOrganizationalUnit -Filter "Name -eq 'ExampleOU'" | Get-EffectiveAccess | Out-GridView
PS \> Get-EffectiveAccess -DistinguishedName 'OU=ExampleOU,DC=domainName,DC=com' | Out-GridView
PS \> $effectiveAccess = Get-ADGroup exampleGroup | Get-EffectiveAccess -IncludeOrphan
PS \> Get-ADOrganizationalUnit -Filter * | Select -First 10 | Get-EffectiveAccess | Out-GridView
默认情况下,该函数将过滤所有孤立的 ACL。使用 IncludeOrphan
开关包含所有以 S-1-*
编辑
供参考,这就是 完全控制 与 Get-ACL
与 BUILTIN\Administrators 相比,后者对此 OU 具有写入权限但没有 完全控制
你可以试试PowerShellAccessControl module I think the details for this module are covered in this youtube video with the function Get-EffectiveAccess
. This should help you get the information. The module has been deleted from the Microsoft's PS Gallery。我不确定您如何从 Github 安装模块,我无法尝试,因为我正在使用 Mac.