AllExtendedRights
Summary
Description
Identification
PowerShell
function Find-AllExtendedRights {
[CmdletBinding()]
param ( [string]$Target = $null, [string]$SearchBase = $null,[string]$OutputPath = "AllExtendedRights.csv",[switch]$ExcludeAdmins = $false)
Import-Module ActiveDirectory -ErrorAction Stop
Write-Host "Gathering Active Directory objects and inspecting ACLs for explicit 'All Extended Rights' permissions..."
$AccessControlType = [System.Security.AccessControl.AccessControlType]::Allow;
$ActiveDirectoryRights = [System.DirectoryServices.ActiveDirectoryRights]::ExtendedRight;
$AllExtendedRightsGuid = "00000000-0000-0000-0000-000000000000";
$ExcludedSIDs = @()
if ($ExcludeAdmins) {
Write-Host "Excluding default administrative groups and built-in accounts."
$ExcludedSIDs += (New-Object System.Security.Principal.NTAccount "NT AUTHORITY\SYSTEM").Translate([System.Security.Principal.SecurityIdentifier]), (New-Object System.Security.Principal.NTAccount "NT AUTHORITY\SELF").Translate([System.Security.Principal.SecurityIdentifier]), (New-Object System.Security.Principal.NTAccount "BUILTIN\Account Operators").Translate([System.Security.Principal.SecurityIdentifier]),(New-Object System.Security.Principal.NTAccount "BUILTIN\Administrators").Translate([System.Security.Principal.SecurityIdentifier]), (New-Object System.Security.Principal.NTAccount "BUILTIN\Terminal Server License Servers").Translate([System.Security.Principal.SecurityIdentifier]),(New-Object System.Security.Principal.NTAccount "NT AUTHORITY\ENTERPRISE DOMAIN CONTROLLERS").Translate([System.Security.Principal.SecurityIdentifier])
$ExcludedSIDs += [System.Security.Principal.SecurityIdentifier]::new("S-1-3-0");
try {
$ExcludedSIDs += (Get-ADGroup -Identity "Domain Admins").SID
$ExcludedSIDs += (Get-ADGroup -Identity "Enterprise Admins").SID ; $ExcludedSIDs += (Get-ADGroup -Identity "Schema Admins").SID
$ExcludedSIDs += (Get-ADGroup -Identity "Cert Publishers").SID; $ExcludedSIDs += (Get-ADGroup -Identity "Group Policy Creator Owners").SID
$ExcludedSIDs += (Get-ADGroup -Identity "Domain Controllers").SID ; $ExcludedSIDs += (Get-ADGroup -Identity "Key Admins").SID
$ExcludedSIDs += (Get-ADGroup -Identity "Enterprise Key Admins").SID ;$ExcludedSIDs += (Get-ADGroup -Identity "RAS and IAS Servers").SID
}
catch {
Write-Warning "Could not resolve one or more default domain admin groups. They might not be filtered from results."
}
}
$foundAcls = @()
$objectsToScan = @()
try {
if ($Target) {
Write-Host "Searching for permissions on specific object: '$Target'."
$specificObject = Get-ADObject -Identity $Target -Properties nTSecurityDescriptor -ErrorAction Stop
if ($specificObject) {
$objectsToScan += $specificObject
} else {
Write-Output "Object '$Target' not found."
return
}
} elseif ($SearchBase) {
Write-Host "Searching for objects within '$SearchBase'."
$objectsToScan = Get-ADObject -Filter "*" -SearchBase $SearchBase -Properties "nTSecurityDescriptor" -ErrorAction Stop
} else {
Write-Host "Searching for all objects in the domain."
$actualSearchBase = (Get-ADRootDSE).DefaultNamingContext
$objectsToScan = Get-ADObject -Filter "*" -SearchBase $actualSearchBase -Properties "nTSecurityDescriptor" -ErrorAction Stop
}
if (-not $objectsToScan) {
Write-Output "No Active Directory objects found matching the criteria."
return
}
foreach ($obj in $objectsToScan) {
$ObjectDistinguishedName = $obj.DistinguishedName;
try {
$acl = Get-Acl -Path "AD:$ObjectDistinguishedName"
foreach ($ace in $acl.Access) {
$isExcluded = $false
if ($ExcludeAdmins) {
try {
if ($ExcludedSIDs -contains $ace.IdentityReference.Translate([System.Security.Principal.SecurityIdentifier])) {
$isExcluded = $true
}
}
catch {
Write-Warning "Could not translate SID for exclusion check: $($ace.IdentityReference.Value). Error: $($_.Exception.Message)"
}
}
if ($ace.AccessControlType -eq $AccessControlType -and
($ace.ActiveDirectoryRights -band $ActiveDirectoryRights) -and
($ace.ObjectType -eq $AllExtendedRightsGuid) -and
-not $ace.IsInherited -and
-not $isExcluded) {
$foundAcls += [PSCustomObject]@{
'Object' = $ObjectDistinguishedName
'Trustee' = $ace.IdentityReference.Value # Get the string representation
}
}
}
}
catch {
Write-Warning "Could not retrieve ACL for '$ObjectDistinguishedName': $($_.Exception.Message)"
}
}
}
catch {
Write-Error "Failed to retrieve Active Directory objects: $($_.Exception.Message)"
return
}
if ($foundAcls.Count -gt 0) {
$exclusionMessage = if ($ExcludeAdmins) { " (excluding default admin groups and built-in accounts)" } else { "" }
Write-Host "Found $($foundAcls.Count) Active Directory object(s) with explicit 'All Extended Rights' permissions$exclusionMessage."
try {
$foundAcls | Sort-Object -Unique Object, Trustee | Export-Csv -Path $OutputPath -NoTypeInformation -Encoding UTF8
Write-Output "Results exported successfully to '$OutputPath'"
}
catch {
Write-Error "Failed to export results to CSV file '$OutputPath': $($_.Exception.Message)"
}
} else {
$exclusionMessage = if ($ExcludeAdmins) { " (excluding default admin groups and built-in accounts)" } else { "" }
Write-Output "No Active Directory objects found with explicit 'All Extended Rights' permissions$exclusionMessage."
}
}Active Directory Users and Computers

Exploitation
Mitigation

Detection
Event ID
Category
Description
Fields/Attributes
References
References
Last updated
Was this helpful?