From 4c1f6e60ea11257956d9de2771a81e309e7fd700 Mon Sep 17 00:00:00 2001 From: Snozz-Al Date: Sat, 21 Nov 2026 13:31:18 +0000 Subject: [PATCH 1/4] refactor(ad): consolidate computer checks and focus regression coverage --- build/golden/Export-MtLegacyTagTable.ps1 | 14 +- build/golden/native-test-replacements.psd1 | 9 + powershell/assets/Maester.LegacyTags.json | 51 +++-- .../ad/Test-MtAdDomainControllerAccount.ps1 | 38 ++++ .../ad/protocol/ConvertFrom-MtLdapValue.ps1 | 4 +- .../ad/queries/Get-MtLdapComputer.ps1 | 6 +- .../ad/queries/Get-MtLdapServiceAccount.ps1 | 16 +- .../functions/ADComputerChecks.Tests.ps1 | 193 ++++++++++++++++++ .../functions/ActiveDirectoryIssues.Tests.ps1 | 8 +- .../ActiveDirectoryThreshold.Tests.ps1 | 2 +- .../tests/functions/golden/Golden.Tests.ps1 | 9 +- tests/ad/computer/Test.AD-COMP-01.md | 2 +- tests/ad/computer/Test.AD-COMP-01.ps1 | 9 +- tests/ad/computer/Test.AD-COMP-02.md | 34 --- tests/ad/computer/Test.AD-COMP-02.ps1 | 111 ---------- tests/ad/computer/Test.AD-COMP-03.md | 2 +- tests/ad/computer/Test.AD-COMP-03.ps1 | 15 +- tests/ad/computer/Test.AD-COMP-04.md | 2 +- tests/ad/computer/Test.AD-COMP-04.ps1 | 53 +++-- tests/ad/computer/Test.AD-COMP-05.md | 2 +- tests/ad/computer/Test.AD-COMP-05.ps1 | 11 +- tests/ad/computer/Test.AD-COMP-06.md | 4 +- tests/ad/computer/Test.AD-COMP-06.ps1 | 26 ++- tests/ad/computer/Test.AD-COMP-07.ps1 | 9 +- tests/ad/computer/Test.AD-COMP-08.ps1 | 13 +- tests/ad/computer/Test.AD-COMP-09.md | 33 --- tests/ad/computer/Test.AD-COMP-09.ps1 | 102 --------- tests/ad/computer/Test.AD-COMP-10.md | 38 ---- tests/ad/computer/Test.AD-COMP-10.ps1 | 125 ------------ tests/ad/security/Test.AD-DCOMP-01.md | 14 +- tests/ad/security/Test.AD-DCOMP-01.ps1 | 76 +++++-- tests/ad/security/Test.AD-DCOMP-02.md | 53 ----- tests/ad/security/Test.AD-DCOMP-02.ps1 | 98 --------- tests/ad/security/Test.AD-DCOMP-03.md | 9 +- tests/ad/security/Test.AD-DCOMP-03.ps1 | 97 +++++---- tests/ad/security/Test.AD-DCOMP-04.md | 7 +- tests/ad/security/Test.AD-DCOMP-04.ps1 | 28 +-- tests/ad/security/Test.AD-DCOMP-05.md | 50 ----- tests/ad/security/Test.AD-DCOMP-05.ps1 | 98 --------- tests/ad/security/Test.AD-DCOMP-06.md | 4 +- tests/ad/security/Test.AD-DCOMP-06.ps1 | 23 +-- tests/ad/security/Test.AD-DCOMP-07.md | 2 +- tests/ad/security/Test.AD-DCOMP-07.ps1 | 9 +- tests/ad/security/Test.AD-DCOMP-08.md | 2 +- tests/ad/security/Test.AD-DCOMP-08.ps1 | 36 ++-- tests/ad/security/Test.AD-DCOMP-09.md | 51 ----- tests/ad/security/Test.AD-DCOMP-09.ps1 | 122 ----------- website/docs/advanced/active-directory.md | 6 +- 48 files changed, 578 insertions(+), 1148 deletions(-) create mode 100644 build/golden/native-test-replacements.psd1 create mode 100644 powershell/internal/services/ad/Test-MtAdDomainControllerAccount.ps1 create mode 100644 powershell/tests/functions/ADComputerChecks.Tests.ps1 delete mode 100644 tests/ad/computer/Test.AD-COMP-02.md delete mode 100644 tests/ad/computer/Test.AD-COMP-02.ps1 delete mode 100644 tests/ad/computer/Test.AD-COMP-09.md delete mode 100644 tests/ad/computer/Test.AD-COMP-09.ps1 delete mode 100644 tests/ad/computer/Test.AD-COMP-10.md delete mode 100644 tests/ad/computer/Test.AD-COMP-10.ps1 delete mode 100644 tests/ad/security/Test.AD-DCOMP-02.md delete mode 100644 tests/ad/security/Test.AD-DCOMP-02.ps1 delete mode 100644 tests/ad/security/Test.AD-DCOMP-05.md delete mode 100644 tests/ad/security/Test.AD-DCOMP-05.ps1 delete mode 100644 tests/ad/security/Test.AD-DCOMP-09.md delete mode 100644 tests/ad/security/Test.AD-DCOMP-09.ps1 diff --git a/build/golden/Export-MtLegacyTagTable.ps1 b/build/golden/Export-MtLegacyTagTable.ps1 index 33da8e4eff..4609761d1e 100644 --- a/build/golden/Export-MtLegacyTagTable.ps1 +++ b/build/golden/Export-MtLegacyTagTable.ps1 @@ -8,10 +8,11 @@ -Tag CA, -Tag CIS, -ExcludeTag MS.AAD.3.5 and every other 2.x tag keep selecting the same tests, the module ships a table that maps each 2.x tag to the IDs of the built-in tests that carried it. - The table is derived from two frozen files and nothing else, so the output never changes with tests/: + The table is derived from two frozen files and explicit native test replacements: powershell/tests/fixtures/golden/tags-and-blocks.json the tags of every built-in test in 2.x - powershell/tests/fixtures/golden/tags-3.0-preview.json tags the 3.0 previews added (for example AI) + powershell/tests/fixtures/golden/tags-3.0-preview.json tags the 3.0 previews added (for example AI) + build/golden/native-test-replacements.psd1 intentional renames and consolidations Rules: - A tag is matched case-insensitively; the table keeps the first spelling of the snapshot. @@ -22,7 +23,8 @@ obvious one ($Replacements below, and -Severity for Severity:). The engine names it in the warning it writes when a run selects through the tag. - Tests added after 3.0 are not in the table. The file is generated once and is not edited by hand; + Tests added after 3.0 are not in the table unless they explicitly replace a historical check. + The file is regenerated when native replacements change and is never edited by hand; powershell/tests/functions/golden/Golden.Tests.ps1 checks that it is what this script produces. .EXAMPLE @@ -49,10 +51,8 @@ $ErrorActionPreference = 'Stop' $RepoRoot = (Resolve-Path -Path $RepoRoot).Path $fixtures = Join-Path $RepoRoot 'powershell/tests/fixtures/golden' -# 2.x IDs that have another ID in 3.0. -$RenamedIds = @{ - 'MT1060' = 'MT.1060' # The drift family: four Its per folder in 2.x, one native family in 3.0. -} +# Explicit replacements, never a dynamic filter that could hide an accidental test deletion. +$RenamedIds = Import-PowerShellDataFile -LiteralPath (Join-Path $RepoRoot 'build/golden/native-test-replacements.psd1') # The typed selector that takes the place of a tag. Only tags with an obvious one are listed. $Replacements = [ordered]@{ diff --git a/build/golden/native-test-replacements.psd1 b/build/golden/native-test-replacements.psd1 new file mode 100644 index 0000000000..17192657dc --- /dev/null +++ b/build/golden/native-test-replacements.psd1 @@ -0,0 +1,9 @@ +@{ + 'MT1060' = 'MT.1060' + 'AD-COMP-02' = 'AD-DCOMP-06' + 'AD-COMP-09' = 'AD-DCOMP-01' + 'AD-COMP-10' = 'AD-DCOMP-03' + 'AD-DCOMP-02' = 'AD-DCOMP-01' + 'AD-DCOMP-05' = 'AD-DCOMP-04' + 'AD-DCOMP-09' = 'AD-DCOMP-08' +} diff --git a/powershell/assets/Maester.LegacyTags.json b/powershell/assets/Maester.LegacyTags.json index 2ba8db3c4b..2016ee1bdc 100644 --- a/powershell/assets/Maester.LegacyTags.json +++ b/powershell/assets/Maester.LegacyTags.json @@ -41,15 +41,12 @@ "AD-CFG-23", "AD-CFG-24", "AD-COMP-01", - "AD-COMP-02", "AD-COMP-03", "AD-COMP-04", "AD-COMP-05", "AD-COMP-06", "AD-COMP-07", "AD-COMP-08", - "AD-COMP-09", - "AD-COMP-10", "AD-DACL-01", "AD-DACL-02", "AD-DACL-03", @@ -81,14 +78,11 @@ "AD-DCD-03", "AD-DCD-04", "AD-DCOMP-01", - "AD-DCOMP-02", "AD-DCOMP-03", "AD-DCOMP-04", - "AD-DCOMP-05", "AD-DCOMP-06", "AD-DCOMP-07", "AD-DCOMP-08", - "AD-DCOMP-09", "AD-DFSR-01", "AD-DNS-01", "AD-DNS-02", @@ -288,19 +282,55 @@ "AD-USER-29" ] }, + { + "Tag": "AD-COMP-02", + "Tests": [ + "AD-DCOMP-06" + ] + }, + { + "Tag": "AD-COMP-09", + "Tests": [ + "AD-DCOMP-01" + ] + }, + { + "Tag": "AD-COMP-10", + "Tests": [ + "AD-DCOMP-03" + ] + }, + { + "Tag": "AD-DCOMP-02", + "Tests": [ + "AD-DCOMP-01" + ] + }, + { + "Tag": "AD-DCOMP-05", + "Tests": [ + "AD-DCOMP-04" + ] + }, + { + "Tag": "AD-DCOMP-09", + "Tests": [ + "AD-DCOMP-08" + ] + }, { "Tag": "AD.Computer", "Tests": [ "AD-COMP-01", - "AD-COMP-02", "AD-COMP-03", "AD-COMP-04", "AD-COMP-05", "AD-COMP-06", "AD-COMP-07", "AD-COMP-08", - "AD-COMP-09", - "AD-COMP-10" + "AD-DCOMP-01", + "AD-DCOMP-03", + "AD-DCOMP-06" ] }, { @@ -575,14 +605,11 @@ "Tag": "AD.Security", "Tests": [ "AD-DCOMP-01", - "AD-DCOMP-02", "AD-DCOMP-03", "AD-DCOMP-04", - "AD-DCOMP-05", "AD-DCOMP-06", "AD-DCOMP-07", "AD-DCOMP-08", - "AD-DCOMP-09", "AD-KRBTGT-01", "AD-KRBTGT-02", "AD-KRBTGT-03", diff --git a/powershell/internal/services/ad/Test-MtAdDomainControllerAccount.ps1 b/powershell/internal/services/ad/Test-MtAdDomainControllerAccount.ps1 new file mode 100644 index 0000000000..9648e13ac3 --- /dev/null +++ b/powershell/internal/services/ad/Test-MtAdDomainControllerAccount.ps1 @@ -0,0 +1,38 @@ +function Test-MtAdDomainControllerAccount { + <# + .SYNOPSIS + Identifies a DC account from the collected directory server inventory. + + .DESCRIPTION + Uses serverReference distinguished names, with DNS fallback only for inventory + entries lacking serverReference. A claimed DC primary group is not DC evidence. + #> + [CmdletBinding()] + [OutputType([bool])] + param( + [Parameter(Mandatory)] + [object] $Account, + + [Parameter(Mandatory)] + [object[]] $DomainControllers + ) + + if ([string]::IsNullOrWhiteSpace([string]$Account.DistinguishedName)) { + throw 'Account distinguished name is unavailable; DC identity cannot be verified.' + } + if (@($Account.ObjectClass | Where-Object { $_ -in 'msDS-ManagedServiceAccount', 'msDS-GroupManagedServiceAccount', 'msDS-DelegatedManagedServiceAccount' }).Count -gt 0) { + return $false + } + foreach ($dc in $DomainControllers) { + if (-not $dc.ServerReference -and -not $dc.DnsHostName) { + throw 'DC inventory lacks serverReference and DNS identity; DC exclusions cannot be verified.' + } + if ($dc.ServerReference) { + if ([string]$dc.ServerReference -eq [string]$Account.DistinguishedName) { return $true } + } + elseif ($Account.DnsHostName -and ([string]$dc.DnsHostName).TrimEnd('.') -eq ([string]$Account.DnsHostName).TrimEnd('.')) { + return $true + } + } + return $false +} diff --git a/powershell/internal/services/ad/protocol/ConvertFrom-MtLdapValue.ps1 b/powershell/internal/services/ad/protocol/ConvertFrom-MtLdapValue.ps1 index 92192b89c0..3384d6305f 100644 --- a/powershell/internal/services/ad/protocol/ConvertFrom-MtLdapValue.ps1 +++ b/powershell/internal/services/ad/protocol/ConvertFrom-MtLdapValue.ps1 @@ -162,7 +162,7 @@ if ($Value -is [byte[]]) { switch ($normalizedAttributeName) { - { $_ -in @('objectsid', 'sidhistory', 'securityidentifier') } { + { $_ -in @('objectsid', 'sidhistory', 'securityidentifier', 'ms-ds-creatorsid') } { try { return New-Object System.Security.Principal.SecurityIdentifier -ArgumentList $Value, 0 } @@ -206,7 +206,7 @@ } if ($Value -is [System.Security.Principal.SecurityIdentifier]) { - if ($normalizedAttributeName -in @('objectsid', 'sidhistory', 'securityidentifier')) { + if ($normalizedAttributeName -in @('objectsid', 'sidhistory', 'securityidentifier', 'ms-ds-creatorsid')) { return $Value } diff --git a/powershell/internal/services/ad/queries/Get-MtLdapComputer.ps1 b/powershell/internal/services/ad/queries/Get-MtLdapComputer.ps1 index 8b6b46a2e3..c3a2c6dbe0 100644 --- a/powershell/internal/services/ad/queries/Get-MtLdapComputer.ps1 +++ b/powershell/internal/services/ad/queries/Get-MtLdapComputer.ps1 @@ -9,7 +9,7 @@ ) if ([string]::IsNullOrWhiteSpace($SearchBase)) { $SearchBase = (Get-MtLdapRootDse -Connection $Connection).DefaultNamingContext } - $attributes = @('distinguishedName', 'name', 'sAMAccountName', 'userAccountControl', 'operatingSystem', 'operatingSystemVersion', 'dNSHostName', 'whenCreated', 'whenChanged', 'lastLogonTimestamp', 'pwdLastSet', 'servicePrincipalName', 'primaryGroupID', 'objectSid', 'isCriticalSystemObject', 'managedBy', 'sIDHistory') + $attributes = @('distinguishedName', 'name', 'sAMAccountName', 'userAccountControl', 'operatingSystem', 'operatingSystemVersion', 'dNSHostName', 'whenCreated', 'whenChanged', 'lastLogonTimestamp', 'pwdLastSet', 'servicePrincipalName', 'primaryGroupID', 'objectSid', 'isCriticalSystemObject', 'managedBy', 'sIDHistory', 'objectClass', 'msDS-AllowedToDelegateTo', 'msDS-AllowedToActOnBehalfOfOtherIdentity', 'mS-DS-CreatorSID') $entries = @(Invoke-MtLdapSearch -Connection $Connection -SearchBase $SearchBase -Scope Subtree -Filter '(objectClass=computer)' -Attributes $attributes) return @($entries | ForEach-Object { $uac = if ($null -ne $_.userAccountControl) { ConvertFrom-MtLdapUserAccountControl -UserAccountControl ([int]$_.userAccountControl) } else { $null } @@ -20,6 +20,10 @@ PasswordLastSet = $_.pwdLastSet; PasswordExpired = if ($null -ne $uac) { $uac.PasswordExpired } else { $null }; PasswordNeverExpires = if ($null -ne $uac) { $uac.DontExpirePassword } else { $null } PasswordNotRequired = if ($null -ne $uac) { $uac.PasswordNotRequired } else { $null }; TrustedForDelegation = if ($null -ne $uac) { $uac.TrustedForDelegation } else { $null } TrustedToAuthForDelegation = if ($null -ne $uac) { $uac.TrustedToAuthForDelegation } else { $null }; ServicePrincipalName = [string[]]@($_.servicePrincipalName | Where-Object { $null -ne $_ }) + ObjectClass = @($_.objectClass) + AllowedToDelegateTo = [string[]]@($_.'msDS-AllowedToDelegateTo' | Where-Object { $null -ne $_ }) + HasResourceBasedConstrainedDelegation = $null -ne $_.'msDS-AllowedToActOnBehalfOfOtherIdentity' + CreatorSid = $_.'mS-DS-CreatorSID' PrimaryGroupId = $_.primaryGroupID; Sid = $_.objectSid; UserAccountControl = [int]$_.userAccountControl IsCriticalSystemObject = if ($null -ne $_.isCriticalSystemObject) { [bool]$_.isCriticalSystemObject } else { $null }; ManagedBy = [string]$_.managedBy; SidHistory = @($_.sIDHistory | Where-Object { $null -ne $_ }) } diff --git a/powershell/internal/services/ad/queries/Get-MtLdapServiceAccount.ps1 b/powershell/internal/services/ad/queries/Get-MtLdapServiceAccount.ps1 index 4a60f57a4a..01870d6947 100644 --- a/powershell/internal/services/ad/queries/Get-MtLdapServiceAccount.ps1 +++ b/powershell/internal/services/ad/queries/Get-MtLdapServiceAccount.ps1 @@ -9,7 +9,17 @@ ) if ([string]::IsNullOrWhiteSpace($SearchBase)) { $SearchBase = (Get-MtLdapRootDse -Connection $Connection).DefaultNamingContext } - $attributes = @('distinguishedName', 'name', 'sAMAccountName', 'dNSHostName', 'whenCreated', 'whenChanged', 'objectSid') - $entries = @(Invoke-MtLdapSearch -Connection $Connection -SearchBase $SearchBase -Scope Subtree -Filter '(objectClass=msDS-GroupManagedServiceAccount)' -Attributes $attributes) - return @($entries | ForEach-Object { [PSCustomObject]@{ DistinguishedName = [string]$_.DistinguishedName; Name = [string]$_.name; SamAccountName = [string]$_.sAMAccountName; DnsHostName = [string]$_.dNSHostName; Created = $_.whenCreated; Modified = $_.whenChanged; Sid = $_.objectSid } }) + $attributes = @('distinguishedName', 'name', 'sAMAccountName', 'dNSHostName', 'whenCreated', 'whenChanged', 'objectSid', 'objectClass', 'msDS-DelegatedMSAState', 'userAccountControl', 'msDS-AllowedToDelegateTo', 'msDS-AllowedToActOnBehalfOfOtherIdentity') + $entries = @(Invoke-MtLdapSearch -Connection $Connection -SearchBase $SearchBase -Scope Subtree -Filter '(|(objectClass=msDS-ManagedServiceAccount)(objectClass=msDS-GroupManagedServiceAccount)(objectClass=msDS-DelegatedManagedServiceAccount))' -Attributes $attributes) + return @($entries | ForEach-Object { + $uac = if ($null -ne $_.userAccountControl) { ConvertFrom-MtLdapUserAccountControl -UserAccountControl ([int]$_.userAccountControl) } else { $null } + [PSCustomObject]@{ + DistinguishedName = [string]$_.DistinguishedName; Name = [string]$_.name; SamAccountName = [string]$_.sAMAccountName; DnsHostName = [string]$_.dNSHostName + Created = $_.whenCreated; Modified = $_.whenChanged; Sid = $_.objectSid; ObjectClass = @($_.objectClass); DelegatedMsaState = $_.'msDS-DelegatedMSAState' + TrustedForDelegation = if ($null -ne $uac) { $uac.TrustedForDelegation } else { $null } + TrustedToAuthForDelegation = if ($null -ne $uac) { $uac.TrustedToAuthForDelegation } else { $null } + AllowedToDelegateTo = [string[]]@($_.'msDS-AllowedToDelegateTo' | Where-Object { $null -ne $_ }) + HasResourceBasedConstrainedDelegation = $null -ne $_.'msDS-AllowedToActOnBehalfOfOtherIdentity' + } + }) } diff --git a/powershell/tests/functions/ADComputerChecks.Tests.ps1 b/powershell/tests/functions/ADComputerChecks.Tests.ps1 new file mode 100644 index 0000000000..51ae5bdc04 --- /dev/null +++ b/powershell/tests/functions/ADComputerChecks.Tests.ps1 @@ -0,0 +1,193 @@ +Describe 'Active Directory computer cleanup regressions' { + BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force + . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" + Use-MtModuleFunction -Name @( + 'Test-MtAdComputerUnconstrainedDelegationCount', 'Test-MtAdComputerNonDcConstrainedDelegationCount' + 'Test-MtAdComputerOperatingSystemCount', 'Test-MtAdComputerPerOUAverage', 'Test-MtAdComputerOUCount' + 'Test-MtAdComputerCreatorSidCount', 'Test-MtAdComputerInDefaultContainer', 'Test-MtAdComputerNonStandardGroup' + ) + } + + BeforeEach { + $script:Details = $null + $script:AdComputerState = [PSCustomObject]@{ + Computers = @( + [PSCustomObject]@{ Name = 'dc1'; DistinguishedName = 'CN=dc1,OU=Domain Controllers,DC=example,DC=com'; DnsHostName = 'dc1.example.com'; PrimaryGroupId = 516; Enabled = $true; TrustedForDelegation = $true; TrustedToAuthForDelegation = $false; AllowedToDelegateTo = @(); HasResourceBasedConstrainedDelegation = $false; OperatingSystem = 'Server' } + [PSCustomObject]@{ Name = 'app|one'; DistinguishedName = 'CN=app\,one,OU=Servers|Prod,DC=example,DC=com'; DnsHostName = 'app.example.com'; PrimaryGroupId = 515; Enabled = $true; TrustedForDelegation = $false; TrustedToAuthForDelegation = $true; AllowedToDelegateTo = @('HTTP/backend|one'); HasResourceBasedConstrainedDelegation = $true; OperatingSystem = '' } + [PSCustomObject]@{ Name = 'client'; DistinguishedName = 'CN=client,OU=Clients,DC=example,DC=com'; DnsHostName = 'client.example.com'; PrimaryGroupId = 515; Enabled = $true; TrustedForDelegation = $false; TrustedToAuthForDelegation = $false; AllowedToDelegateTo = @(); HasResourceBasedConstrainedDelegation = $false; OperatingSystem = 'Client' } + ) + DomainControllers = @([PSCustomObject]@{ ServerReference = 'CN=dc1,OU=Domain Controllers,DC=example,DC=com'; DnsHostName = 'dc1.example.com' }) + ServiceAccounts = @() + } + Mock -ModuleName Maester Get-MtADDomainState { $script:AdComputerState } + Mock -ModuleName Maester Add-MtTestResultDetail { param($Result, [switch] $Investigate) $script:Details = [PSCustomObject]@{ Text = $Result; Investigate = $Investigate.IsPresent } } + } + + It 'fails only for non-DC unconstrained delegation and uses the non-DC denominator' { + Test-MtAdComputerUnconstrainedDelegationCount | Should -BeTrue + $script:Details.Investigate | Should -BeFalse + $script:Details.Text | Should -BeLike '*| Non-DC Percentage with Unconstrained Delegation | 0% |*' + $script:AdComputerState.Computers[1].TrustedForDelegation = $true + Test-MtAdComputerUnconstrainedDelegationCount | Should -BeFalse + $script:Details.Text | Should -BeLike '*| Total Non-DC Computers | 2 |*' + $script:Details.Text | Should -BeLike '*| Non-DC Percentage with Unconstrained Delegation | 50% |*' + $script:Details.Text | Should -Match 'app\\\|one' + } + + It 'reports overlapping KCD, protocol-transition and RBCD indicators independently' { + Test-MtAdComputerNonDcConstrainedDelegationCount | Should -BeTrue + $script:Details.Investigate | Should -BeTrue + $script:Details.Text | Should -BeLike '*| Distinct Non-DC Accounts with One or More Indicators | 1 |*' + $script:AdComputerState.Computers[1].TrustedToAuthForDelegation = $false + $script:AdComputerState.Computers[2].HasResourceBasedConstrainedDelegation = $true + Test-MtAdComputerNonDcConstrainedDelegationCount | Should -BeTrue + $script:Details.Text | Should -BeLike '*| Non-DC Accounts with Classic KCD Target SPNs | 1 |*' + $script:Details.Text | Should -BeLike '*| Non-DC Accounts with Protocol Transition Flag | 0 |*' + $script:Details.Text | Should -BeLike '*| Non-DC Accounts with RBCD Descriptor Present | 2 |*' + $script:Details.Text | Should -BeLike '*| Distinct Non-DC Accounts with One or More Indicators | 2 |*' + $script:Details.Text | Should -Match 'HTTP/backend\\\|one' + } + + It 'requires DC inventory evidence, including RODCs and DNS-only inventory entries' { + $script:AdComputerState.Computers += [PSCustomObject]@{ Name = 'rodc'; DistinguishedName = 'CN=rodc,DC=example,DC=com'; DnsHostName = 'rodc.example.com'; PrimaryGroupId = 521; TrustedForDelegation = $true } + $script:AdComputerState.Computers += [PSCustomObject]@{ Name = 'dc-alias'; DistinguishedName = 'CN=dc-alias,DC=example,DC=com'; DnsHostName = 'SECOND.example.com'; TrustedForDelegation = $true } + $script:AdComputerState.DomainControllers += [PSCustomObject]@{ ServerReference = 'CN=rodc,DC=example,DC=com'; DnsHostName = 'rodc.example.com' } + $script:AdComputerState.DomainControllers += [PSCustomObject]@{ ServerReference = ''; DnsHostName = 'second.EXAMPLE.com' } + Test-MtAdComputerUnconstrainedDelegationCount | Should -BeTrue + Test-MtAdComputerNonDcConstrainedDelegationCount | Should -BeTrue + $script:Details.Text | Should -BeLike '*| Total Non-DC Computers | 2 |*' + + $script:AdComputerState.Computers[2].DnsHostName = 'dc1.example.com' + $script:AdComputerState.Computers[2].TrustedForDelegation = $true + foreach ($group in 516, 521) { + $script:AdComputerState.Computers[2].PrimaryGroupId = $group + Test-MtAdComputerUnconstrainedDelegationCount | Should -BeFalse + $script:Details.Text | Should -BeLike '*| Non-DC Computers Claiming DC Primary Groups | 1 |*' + $script:Details.Text | Should -BeLike '*| Total Non-DC Computers | 2 |*' + } + } + + It 'assesses managed accounts once without inflating device percentages' { + foreach ($class in 'msDS-ManagedServiceAccount', 'msDS-GroupManagedServiceAccount', 'msDS-DelegatedManagedServiceAccount') { + $managed = [PSCustomObject]@{ Name = 'Managed'; DistinguishedName = 'CN=Managed,DC=example,DC=com'; ObjectClass = @('computer', $class); TrustedForDelegation = $true; TrustedToAuthForDelegation = $true; AllowedToDelegateTo = @('HTTP/managed'); HasResourceBasedConstrainedDelegation = $true } + $script:AdComputerState.ServiceAccounts = @($managed) + $script:AdComputerState.Computers = @($script:AdComputerState.Computers | Select-Object -First 3) + @($managed) + Test-MtAdComputerUnconstrainedDelegationCount | Should -BeFalse + $script:Details.Text | Should -BeLike '*| Managed Service Accounts with Unconstrained Delegation | 1 |*' + $script:Details.Text | Should -BeLike '*| Non-DC Percentage with Unconstrained Delegation | 0% |*' + Test-MtAdComputerNonDcConstrainedDelegationCount | Should -BeTrue + $script:Details.Text | Should -BeLike '*| Total Non-DC Computers | 2 |*' + $script:Details.Text | Should -BeLike '*| Non-DC Accounts with Classic KCD Target SPNs | 2 |*' + } + } + + It 'does not turn missing delegation fields or inventories into clean results' { + foreach ($field in 'AllowedToDelegateTo', 'TrustedToAuthForDelegation', 'HasResourceBasedConstrainedDelegation') { + $saved = $script:AdComputerState.Computers[1].$field + $script:AdComputerState.Computers[1].$field = $null + { Test-MtAdComputerNonDcConstrainedDelegationCount } | Should -Throw '*Required delegation fields*' + $script:AdComputerState.Computers[1].$field = $saved + } + $script:AdComputerState.Computers[1].PSObject.Properties.Remove('AllowedToDelegateTo') + { Test-MtAdComputerNonDcConstrainedDelegationCount } | Should -Throw '*Required delegation fields*' + $script:AdComputerState.Computers[1].TrustedForDelegation = $null + { Test-MtAdComputerUnconstrainedDelegationCount } | Should -Throw '*flag is missing*' + $script:AdComputerState.ServiceAccounts = $null + { Test-MtAdComputerUnconstrainedDelegationCount } | Should -Throw '*inventories*' + $script:AdComputerState.ServiceAccounts = @([PSCustomObject]@{ TrustedForDelegation = $null }) + { Test-MtAdComputerUnconstrainedDelegationCount } | Should -Throw '*flag is missing*' + } + + It 'uses all computers for OS percentages and escapes known OS names' { + $script:AdComputerState.Computers[0].PSObject.Properties.Remove('OperatingSystem') + $script:AdComputerState.Computers[1].OperatingSystem = "Server|Core`nEdition" + Test-MtAdComputerOperatingSystemCount | Should -BeTrue + $script:Details.Investigate | Should -BeTrue + $script:Details.Text | Should -BeLike '*| Server\|Core Edition | 1 | 33.33% |*' + $script:Details.Text | Should -BeLike '*| Client | 1 | 33.33% |*' + $script:Details.Text | Should -BeLike '*| Unknown OS | 1 | 33.33% |*' + } + + It 'renders an all-undefined OS table and handles an empty inventory' { + $script:AdComputerState.Computers[0].OperatingSystem = $null + $script:AdComputerState.Computers[1].OperatingSystem = '' + $script:AdComputerState.Computers[2].OperatingSystem = " `t " + Test-MtAdComputerOperatingSystemCount | Should -BeTrue + $script:Details.Text | Should -BeLike '*| Distinct Operating Systems | 0 |*' + $script:Details.Text | Should -Match '(?s)\*\*Operating Systems in Use:\*\*\s+\| Operating System \| Count \| Percentage of All Computers \|\s+\| --- \| --- \| --- \|\s+\| Unknown OS \| 3 \| 100% \|' + $script:AdComputerState.Computers = @() + Test-MtAdComputerOperatingSystemCount | Should -BeTrue + $script:Details.Text | Should -BeLike '*| Total Computers | 0 |*' + $script:Details.Text | Should -Not -Match 'Operating Systems in Use|\| Unknown OS \|' + } + + It 'counts optional CreatorSid data for review without reporting uncollected fields as zero' { + Test-MtAdComputerCreatorSidCount | Should -BeFalse + $script:Details.Investigate | Should -BeTrue + $script:Details.Text | Should -BeLike '*CreatorSid is not collected*' + foreach ($computer in $script:AdComputerState.Computers) { $computer | Add-Member -NotePropertyName CreatorSid -NotePropertyValue $null } + $script:AdComputerState.Computers[1].CreatorSid = 'S-1-5-21-1-2-3-1100' + Test-MtAdComputerCreatorSidCount | Should -BeTrue + $script:Details.Investigate | Should -BeTrue + $script:Details.Text | Should -BeLike '*| Computers with CreatorSid | 1 |*' + } + + It 'enforces primary groups using verified DC identity, not a claimed group' { + Test-MtAdComputerNonStandardGroup | Should -BeTrue + $script:Details.Investigate | Should -BeFalse + foreach ($group in 516, 521) { + $script:AdComputerState.Computers[2].PrimaryGroupId = $group + Test-MtAdComputerNonStandardGroup | Should -BeFalse + $script:Details.Text | Should -Match 'client' + } + } + + It 'distinguishes the default container from an OU and handles escaped computer names' { + Test-MtAdComputerInDefaultContainer | Should -BeTrue + $script:Details.Investigate | Should -BeFalse + $script:AdComputerState.Computers[1].DistinguishedName = 'CN=app\,one,CN=Computers,DC=example,DC=com' + $script:AdComputerState.Computers[2].DistinguishedName = 'CN=client,OU=Computers,DC=example,DC=com' + Test-MtAdComputerInDefaultContainer | Should -BeFalse + $script:Details.Text | Should -BeLike '*| In Default Computers Container | 1 |*' + $script:AdComputerState.Computers[1].Enabled = $false + Test-MtAdComputerInDefaultContainer | Should -BeTrue + } + + It 'groups escaped names under their actual parent and escapes the top-five table' { + Test-MtAdComputerOUCount | Should -BeTrue + $script:Details.Investigate | Should -BeTrue + Test-MtAdComputerPerOUAverage | Should -BeTrue + $script:Details.Investigate | Should -BeTrue + $script:Details.Text | Should -BeLike '*| Container | Computer Count |*' + $script:Details.Text | Should -BeLike '*| OU=Servers\|Prod,DC=example,DC=com | 1 |*' + } + + It 'collects delegation and CreatorSid metadata without changing the shared computer population' { + Mock -ModuleName Maester Invoke-MtLdapSearch -RemoveParameterType Connection { + [PSCustomObject]@{ name = 'Managed'; objectClass = @('computer', 'msDS-DelegatedManagedServiceAccount'); userAccountControl = 17301504; 'msDS-AllowedToDelegateTo' = @('HTTP/service'); 'msDS-AllowedToActOnBehalfOfOtherIdentity' = [byte[]]@(1, 2, 3) } + } + InModuleScope Maester { + $connection = [System.DirectoryServices.Protocols.LdapConnection]::new('localhost') + try { + $computer = @(Get-MtLdapComputer -Connection $connection -SearchBase 'DC=example,DC=com')[0] + $account = @(Get-MtLdapServiceAccount -Connection $connection -SearchBase 'DC=example,DC=com')[0] + foreach ($object in $computer, $account) { + $object.ObjectClass | Should -Contain 'msDS-DelegatedManagedServiceAccount' + $object.TrustedForDelegation | Should -BeTrue + $object.TrustedToAuthForDelegation | Should -BeTrue + $object.AllowedToDelegateTo | Should -Contain 'HTTP/service' + $object.HasResourceBasedConstrainedDelegation | Should -BeTrue + $object.PSObject.Properties.Name | Should -Not -Contain 'msDS-AllowedToActOnBehalfOfOtherIdentity' + } + (ConvertFrom-MtLdapValue -AttributeName 'mS-DS-CreatorSID' -Value ([byte[]]@(1, 1, 0, 0, 0, 0, 0, 5, 11, 0, 0, 0))).Value | Should -Be 'S-1-5-11' + } + finally { $connection.Dispose() } + } + Should -Invoke Invoke-MtLdapSearch -ModuleName Maester -Times 1 -Exactly -ParameterFilter { $Filter -eq '(objectClass=computer)' -and $Attributes -contains 'objectClass' -and $Attributes -contains 'mS-DS-CreatorSID' } + Should -Invoke Invoke-MtLdapSearch -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Filter -match 'msDS-ManagedServiceAccount' -and $Filter -match 'msDS-GroupManagedServiceAccount' -and $Filter -match 'msDS-DelegatedManagedServiceAccount' -and + @($Attributes | Where-Object { $_ -match '^msDS-ManagedPassword' }).Count -eq 0 + } + } +} diff --git a/powershell/tests/functions/ActiveDirectoryIssues.Tests.ps1 b/powershell/tests/functions/ActiveDirectoryIssues.Tests.ps1 index eb336f1315..e78f35bf48 100644 --- a/powershell/tests/functions/ActiveDirectoryIssues.Tests.ps1 +++ b/powershell/tests/functions/ActiveDirectoryIssues.Tests.ps1 @@ -157,7 +157,7 @@ Describe 'AD-DCOMP-06: Stale enabled computers' { } } - It 'Returns Investigate when stale enabled computers exist' { + It 'Returns a false Boolean with Investigate when stale enabled computers exist' { InModuleScope Maester { Mock Get-MtADDomainState -ModuleName Maester { return [ordered]@{ @@ -172,8 +172,10 @@ Describe 'AD-DCOMP-06: Stale enabled computers' { } } - $result = Test-MtAdComputerStaleEnabledCount - $result | Should -Be $null + Mock Add-MtTestResultDetail -ModuleName Maester { } + $result = Test-MtAdComputerStaleEnabledCount -MaximumInactiveDays 180 + $result | Should -BeFalse + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Exactly -Times 1 -ParameterFilter { $Investigate } } } } diff --git a/powershell/tests/functions/ActiveDirectoryThreshold.Tests.ps1 b/powershell/tests/functions/ActiveDirectoryThreshold.Tests.ps1 index fda169187d..6c4227ed0b 100644 --- a/powershell/tests/functions/ActiveDirectoryThreshold.Tests.ps1 +++ b/powershell/tests/functions/ActiveDirectoryThreshold.Tests.ps1 @@ -91,7 +91,7 @@ Describe 'Active Directory Threshold Validation' -Tag 'LabOnly', 'ActiveDirector # Invoke the test through its supported entrypoint and assert investigate outcome $testResult = Test-MtAdComputerStaleEnabledCount -MaximumInactiveDays 1 - $testResult | Should -Be $null -Because 'AD-DCOMP-06 should investigate when stale enabled computers exist' + $testResult | Should -BeFalse -Because 'AD-DCOMP-06 returns a false Boolean and reports Investigate when stale enabled computers exist' # With a 1-day threshold in a fresh lab, most or all computers appear stale $staleCount | Should -BeGreaterThan 0 -Because 'a 1-day threshold in a fresh lab should flag at least one computer as stale' diff --git a/powershell/tests/functions/golden/Golden.Tests.ps1 b/powershell/tests/functions/golden/Golden.Tests.ps1 index 744d5aebe5..eeb60326ba 100644 --- a/powershell/tests/functions/golden/Golden.Tests.ps1 +++ b/powershell/tests/functions/golden/Golden.Tests.ps1 @@ -56,10 +56,9 @@ Describe 'Maester 2.x golden fixtures' -Tag 'Golden' { BeforeAll { # tags-and-blocks.json is the frozen 2.x snapshot. In 3.0 the built-in tests carry no taxonomy # tags, and Block and the tags on a result row changed on purpose, so neither is compared any - # more. What must hold is that every 2.x tag still selects exactly the tests it selected: not - # fewer, and not more, so a new test must not take a 2.x tag as one of its own tags. - # MT1060 (drift) became the native family MT.1060: its four 2.x Its are one test. - $script:renamedIds = @{ 'MT1060' = 'MT.1060' } + # more. Every 2.x tag selects the same tests, except for explicit native replacements. + # This registry preserves consolidation intent without filtering out accidental deletions. + $script:renamedIds = Import-PowerShellDataFile -LiteralPath (Join-Path $repoRoot 'build/golden/native-test-replacements.psd1') $toSet = { param($entries) $byTag = [System.Collections.Generic.Dictionary[string, System.Collections.Generic.SortedSet[string]]]::new([System.StringComparer]::OrdinalIgnoreCase) @@ -125,6 +124,8 @@ Describe 'Maester 2.x golden fixtures' -Tag 'Golden' { $ids = [System.Collections.Generic.HashSet[string]]::new([string[]]@($script:fresh | ForEach-Object { $_.Id }), [System.StringComparer]::OrdinalIgnoreCase) $missing = @($table.Tags | ForEach-Object { $_.Tests } | Where-Object { -not $ids.Contains($_) } | Select-Object -Unique) $missing | Should -BeNullOrEmpty + @($script:renamedIds.Values | Where-Object { -not $ids.Contains($_) }) | Should -BeNullOrEmpty -Because 'each explicit replacement must have a surviving native test' + @($script:renamedIds.Keys | Where-Object { $ids.Contains($_) }) | Should -BeNullOrEmpty -Because 'a replaced ID must no longer have its own test' $replacement = @{} foreach ($entry in $table.Tags) { if ($entry.PSObject.Properties['Replacement']) { $replacement[$entry.Tag] = $entry.Replacement } } $replacement['CA'] | Should -Be '-Feature conditional-access' diff --git a/tests/ad/computer/Test.AD-COMP-01.md b/tests/ad/computer/Test.AD-COMP-01.md index 1222663687..a97f2a4a1c 100644 --- a/tests/ad/computer/Test.AD-COMP-01.md +++ b/tests/ad/computer/Test.AD-COMP-01.md @@ -24,7 +24,7 @@ The test returns informational results to help you assess the scope of disabled #### Related Tests -- `Test-MtAdComputerDormantCount` - Identifies enabled computers that haven't logged on recently +- `AD-DCOMP-06` - Identifies enabled computers that haven't logged on recently - `Test-MtAdComputerInDefaultContainer` - Finds computers in the default container (another hygiene indicator) diff --git a/tests/ad/computer/Test.AD-COMP-01.ps1 b/tests/ad/computer/Test.AD-COMP-01.ps1 index 9d38d1b29d..09e164eeec 100644 --- a/tests/ad/computer/Test.AD-COMP-01.ps1 +++ b/tests/ad/computer/Test.AD-COMP-01.ps1 @@ -39,10 +39,8 @@ # Get AD domain state data (uses cached data if available) $adState = Get-MtADDomainState -Categories @('Computers') - # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null + if ($null -eq $adState -or $null -eq $adState.Computers) { + throw 'Computer inventory is required to review disabled accounts.' } $computers = $adState.Computers @@ -53,7 +51,6 @@ $totalCount = ($computers | Measure-Object).Count $enabledCount = $totalCount - $disabledCount - # Test passes if we successfully retrieved computer data $testResult = $totalCount -gt 0 # Generate markdown results @@ -77,7 +74,7 @@ $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." } - Add-MtTestResultDetail -Result $testResultMarkdown + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate return $testResult } diff --git a/tests/ad/computer/Test.AD-COMP-02.md b/tests/ad/computer/Test.AD-COMP-02.md deleted file mode 100644 index b4b569e262..0000000000 --- a/tests/ad/computer/Test.AD-COMP-02.md +++ /dev/null @@ -1,34 +0,0 @@ -Dormant (stale) computer accounts—enabled accounts that haven't authenticated for more than the configured threshold (default 90 days)—pose significant security risks: - -- **Attack vector**: Attackers can exploit dormant accounts that may have weak or unchanged passwords -- **Shadow IT**: These may represent forgotten test systems, VMs, or decommissioned hardware still in the directory -- **Lateral movement**: Compromised dormant accounts can be used to move laterally within the network -- **Compliance issues**: Many security frameworks require identification and remediation of stale accounts - -#### Control Type - -**Detective** - -#### Security Recommendation - -Establish a process to: -1. Identify dormant computers (this test) -2. Investigate whether they represent legitimate systems -3. Disable accounts for systems that are truly decommissioned -4. Delete disabled accounts after a verification period - -#### How the Test Works - -This test examines all enabled computer accounts and identifies those where: -- The `lastLogonDate` property is older than `MaximumInactiveDays` (default 90 days) -- The account remains enabled - -The default 90-day threshold is a common security baseline. Set `MaximumInactiveDays` to adjust it based on your organization's requirements (e.g., seasonal systems, remote workstations). - -#### Related Tests - -- `Test-MtAdComputerDisabledCount` - Counts already-disabled computer accounts -- `Test-MtAdComputerInDefaultContainer` - Identifies computers that may be unmanaged - - -%TestResult% diff --git a/tests/ad/computer/Test.AD-COMP-02.ps1 b/tests/ad/computer/Test.AD-COMP-02.ps1 deleted file mode 100644 index e013675ac9..0000000000 --- a/tests/ad/computer/Test.AD-COMP-02.ps1 +++ /dev/null @@ -1,111 +0,0 @@ -function Test-MtAdComputerDormantCount { - <# - .SYNOPSIS - Counts the number of dormant computer objects in Active Directory. - - .DESCRIPTION - This test identifies computer objects that have not logged on for more than the configured threshold. - Dormant computers can represent security risks if they are still enabled and can be - used for unauthorized access. This test provides visibility into stale computer accounts. - - .EXAMPLE - Test-MtAdComputerDormantCount - - Returns $true if computer object data is accessible, $false otherwise. - The test result includes counts of dormant computers since the configured threshold. - - .LINK - https://maester.dev/docs/commands/Test-MtAdComputerDormantCount - #> - [MaesterTest( - Id = 'AD-COMP-02', - Title = 'Computer dormant count should be retrievable', - Product = 'ad', - Feature = 'computers', - Area = 'identity-lifecycle', - ResourceType = 'Computer', - Severity = 'Info', - Mitre = 'T1078.002', - Service = 'ActiveDirectory', - Permission = ('ActiveDirectory:Ldap:computer:ReadProperty'), - Author = 'soulemike' - )] - [CmdletBinding()] - [OutputType([bool])] - param( - # Number of days without a logon before an enabled computer is considered dormant. - [ValidateRange(1, 3650)] - [int] $MaximumInactiveDays = 90 - ) - - Write-Verbose "Starting Test-MtAdComputerDormantCount" - - # Get AD domain state data (uses cached data if available) - $adState = Get-MtADDomainState -Categories @('Computers') - - # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } - - $computers = $adState.Computers - $thresholdDays = $MaximumInactiveDays - $thresholdDate = (Get-Date).AddDays(-$thresholdDays) - - # Count dormant computers (last logon older than the configured threshold and still enabled) - $dormantComputers = $computers | Where-Object { - $_.Enabled -eq $true -and - $_.lastLogonDate -and - $_.lastLogonDate -lt $thresholdDate - } - - $dormantCount = ($dormantComputers | Measure-Object).Count - $enabledCount = ($computers | Where-Object { $_.Enabled -eq $true } | Measure-Object).Count - $totalCount = ($computers | Measure-Object).Count - - # Test passes if we successfully retrieved computer data - $testResult = $totalCount -gt 0 - - # Generate markdown results - if ($testResult) { - $percentage = if ($enabledCount -gt 0) { - [Math]::Round(($dormantCount / $enabledCount) * 100, 2) - } else { - 0 - } - - $result = "| Metric | Value |" + "`n" - $result += "| --- | --- |" + "`n" - $result += "| Total Computers | $totalCount |" + "`n" - $result += "| Enabled Computers | $enabledCount |" + "`n" - $result += "| Dormant Computers (>$thresholdDays days) | $dormantCount |" + "`n" - $result += "| Dormant Percentage (of enabled) | $percentage% |" + "`n" + "`n" - - $testResultMarkdown = "Active Directory computer objects have been analyzed. $dormantCount out of $enabledCount enabled computers ($percentage%) have not logged on for more than $thresholdDays days.`n`n%TestResult%" - if ($dormantCount -eq 0) { - $datedEnabledComputers = $computers | Where-Object { $_.Enabled -eq $true -and $null -ne $_.lastLogonDate } - $undatedEnabledCount = $enabledCount - $datedEnabledComputers.Count - $oldestLastLogonDate = $datedEnabledComputers | - Sort-Object -Property lastLogonDate | - Select-Object -First 1 -ExpandProperty lastLogonDate - - if ($null -eq $oldestLastLogonDate) { - $testResultMarkdown += "`n`nThere are $enabledCount enabled computers. None have a recorded last logon date, so dormant status cannot be determined from available data." - } else { - $oldestLastLogonDate = [datetime]$oldestLastLogonDate - $oldestLastLogon = $oldestLastLogonDate.ToString('yyyy-MM-dd') - $daysUntilThreshold = [Math]::Max(1, [Math]::Ceiling(($oldestLastLogonDate.AddDays($thresholdDays) - (Get-Date)).TotalDays)) - $undatedNote = if ($undatedEnabledCount -gt 0) { " $undatedEnabledCount enabled computer(s) have no recorded logon date and are not counted in this analysis." } else { "" } - $testResultMarkdown += "`n`nThere are $enabledCount enabled computers. The oldest last logon date is $oldestLastLogon. No computers currently exceed the dormant threshold of $thresholdDays days. The oldest computer would reach the threshold in $daysUntilThreshold days.$undatedNote" - } - } - $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result - } else { - $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." - } - - Add-MtTestResultDetail -Result $testResultMarkdown - - return $testResult -} diff --git a/tests/ad/computer/Test.AD-COMP-03.md b/tests/ad/computer/Test.AD-COMP-03.md index bfd313bed6..259240ee1c 100644 --- a/tests/ad/computer/Test.AD-COMP-03.md +++ b/tests/ad/computer/Test.AD-COMP-03.md @@ -19,7 +19,7 @@ Computer account creation should be tightly controlled: #### How the Test Works -This test counts computer objects that have the `ms-ds-CreatorSid` attribute populated. This attribute is typically set when: +The cached LDAP computer collector retrieves `mS-DS-CreatorSID` as `CreatorSid`. This check reports **Investigate** because a recorded creator is not proof of an unauthorized join. It does not report a zero count when the field was not collected. This test counts enabled computer objects that have the attribute populated. This attribute is typically set when: - A user or service account explicitly creates a computer account - The creating principal has been captured in the directory diff --git a/tests/ad/computer/Test.AD-COMP-03.ps1 b/tests/ad/computer/Test.AD-COMP-03.ps1 index 730ec182ff..bf42b360b7 100644 --- a/tests/ad/computer/Test.AD-COMP-03.ps1 +++ b/tests/ad/computer/Test.AD-COMP-03.ps1 @@ -39,20 +39,21 @@ # Get AD domain state data (uses cached data if available) $adState = Get-MtADDomainState -Categories @('Computers') - # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null + if ($null -eq $adState -or $null -eq $adState.Computers) { + throw 'Computer inventory is required to review CreatorSid.' } $computers = $adState.Computers + if (@($computers).Count -eq 0 -or @($computers | Where-Object { -not $_.PSObject.Properties['CreatorSid'] }).Count -gt 0) { + Add-MtTestResultDetail -Result 'CreatorSid is not collected in the cached computer inventory. This test cannot determine how many accounts have it.' -Investigate + return $false + } # Count enabled computers with CreatorSid attribute # CreatorSid is optional in the collected computer contract, so check whether it exists. $computersWithCreatorSid = $computers | Where-Object { $_.Enabled -eq $true -and - $_.PSObject.Properties['ms-ds-CreatorSid'] -and - $_.'ms-ds-CreatorSid' + $_.CreatorSid } $creatorSidCount = ($computersWithCreatorSid | Measure-Object).Count @@ -83,7 +84,7 @@ $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." } - Add-MtTestResultDetail -Result $testResultMarkdown + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate return $testResult } diff --git a/tests/ad/computer/Test.AD-COMP-04.md b/tests/ad/computer/Test.AD-COMP-04.md index 5a4738eaf3..b48a0d61f4 100644 --- a/tests/ad/computer/Test.AD-COMP-04.md +++ b/tests/ad/computer/Test.AD-COMP-04.md @@ -23,7 +23,7 @@ The standard primary groups for computers are: #### How the Test Works -This test examines the `primaryGroupId` attribute of all enabled computer accounts and identifies those where the value is not 515, 516, or 521. +This test examines the `primaryGroupId` attribute of all enabled computer accounts. Non-DC devices must use 515. Groups 516 and 521 are accepted only for accounts identified in the collected DC server inventory, never because the account claims that group. A non-DC device claiming a DC group is listed as a finding; missing inventory or primary-group data produces Error. #### Related Tests diff --git a/tests/ad/computer/Test.AD-COMP-04.ps1 b/tests/ad/computer/Test.AD-COMP-04.ps1 index 7f2377e563..a8088994e6 100644 --- a/tests/ad/computer/Test.AD-COMP-04.ps1 +++ b/tests/ad/computer/Test.AD-COMP-04.ps1 @@ -10,7 +10,8 @@ - 516: Domain Controllers - 521: Read-only Domain Controllers - Computers with non-standard primary groups may indicate misconfiguration or + Only accounts verified in the DC inventory may use primary group 516 or 521. + Other enabled computer accounts must use 515. Computers with non-standard primary groups may indicate misconfiguration or custom security configurations that should be reviewed. .EXAMPLE @@ -24,15 +25,17 @@ #> [MaesterTest( Id = 'AD-COMP-04', - Title = 'Computer non-standard primary group count should be retrievable', + Title = 'Enabled computers should use standard primary groups', Product = 'ad', Feature = 'computers', Area = 'identity-lifecycle', ResourceType = 'Computer', - Severity = 'Info', + Severity = 'Low', + UserImpact = 'Low', + ImplementationCost = 'Medium', Mitre = 'None', Service = 'ActiveDirectory', - Permission = ('ActiveDirectory:Ldap:computer:ReadProperty'), + Permission = ('ActiveDirectory:Ldap:computer:ReadProperty', 'ActiveDirectory:Ldap:nTDSDSA:ReadProperty'), Author = 'soulemike' )] [CmdletBinding()] @@ -41,25 +44,27 @@ Write-Verbose "Starting Test-MtAdComputerNonStandardGroup" - # Standard computer primary group IDs - $standardGroupIds = @(515, 516, 521) - # Get AD domain state data (uses cached data if available) - $adState = Get-MtADDomainState -Categories @('Computers') + $adState = Get-MtADDomainState -Categories @('Computers', 'DomainControllers') # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } + if ($null -eq $adState -or $null -eq $adState.Computers -or $null -eq $adState.DomainControllers) { throw 'Computer and DC inventories are required to assess primary groups.' } + $domainControllers = @($adState.DomainControllers) + if ($domainControllers.Count -eq 0) { throw 'DC inventory is empty; primary group assignments cannot be verified.' } $computers = $adState.Computers + if (@($computers).Count -eq 0) { throw 'Computer inventory is empty; primary groups cannot be assessed.' } + if (@($computers | Where-Object { $null -eq $_.Enabled }).Count -gt 0) { + throw 'Enabled state is missing for computers; primary groups cannot be assessed completely.' + } # Count enabled computers with non-standard primary group $nonStandardGroupComputers = $computers | Where-Object { - $_.Enabled -eq $true -and - $_.primaryGroupId -and - $_.primaryGroupId -notin $standardGroupIds + if ($_.Enabled -eq $true -and $null -ne $_.PrimaryGroupId) { + $isDc = Test-MtAdDomainControllerAccount -Account $_ -DomainControllers $domainControllers + if ($isDc) { $_.PrimaryGroupId -notin 516, 521 } + else { $_.PrimaryGroupId -ne 515 } + } } $nonStandardCount = ($nonStandardGroupComputers | Measure-Object).Count @@ -67,10 +72,13 @@ $totalCount = ($computers | Measure-Object).Count # Test passes if we successfully retrieved computer data - $testResult = $totalCount -gt 0 + if (@($computers | Where-Object { $_.Enabled -eq $true -and $null -eq $_.PrimaryGroupId }).Count -gt 0) { + throw 'PrimaryGroupId is missing for enabled computers; cannot assess all primary groups.' + } + $testResult = $nonStandardCount -eq 0 # Generate markdown results - if ($testResult) { + if ($totalCount -gt 0) { $percentage = if ($enabledCount -gt 0) { [Math]::Round(($nonStandardCount / $enabledCount) * 100, 2) } else { @@ -84,6 +92,12 @@ $result += "| Non-Standard Primary Group | $nonStandardCount |" + "`n" $result += "| Non-Standard Percentage | $percentage% |" + "`n" + "`n" $result += "**Standard Primary Group IDs:** 515 (Domain Computers), 516 (Domain Controllers), 521 (Read-only Domain Controllers)" + "`n" + "`n" + $result += "DC groups are accepted only for accounts verified in the DC inventory.`n`n| Computer | Primary group | Distinguished name |`n| --- | --- | --- |`n" + foreach ($computer in $nonStandardGroupComputers) { + $name = ([string]$computer.Name).Replace('|', '|') -replace '[\r\n]+', ' ' + $dn = ([string]$computer.DistinguishedName).Replace('|', '|') -replace '[\r\n]+', ' ' + $result += "| $name | $($computer.PrimaryGroupId) | $dn |`n" + } $testResultMarkdown = "Active Directory computer objects have been analyzed. $nonStandardCount out of $enabledCount enabled computers ($percentage%) have non-standard primary group IDs.`n`n%TestResult%" $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result @@ -91,6 +105,11 @@ $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." } + if ($testResult) { + $testResultMarkdown = "Well done. No enabled computers have a non-standard primary group.`n`n$result" + } else { + $testResultMarkdown = "Enabled computers have non-standard primary groups. Review and restore standard group assignments where appropriate.`n`n$result" + } Add-MtTestResultDetail -Result $testResultMarkdown return $testResult diff --git a/tests/ad/computer/Test.AD-COMP-05.md b/tests/ad/computer/Test.AD-COMP-05.md index 45afc8938e..25830e2cd8 100644 --- a/tests/ad/computer/Test.AD-COMP-05.md +++ b/tests/ad/computer/Test.AD-COMP-05.md @@ -23,7 +23,7 @@ This test counts computer objects where the `SIDHistory` attribute is populated. #### Related Tests - `Test-MtAdComputerNonStandardGroup` - Identifies other migration or configuration anomalies -- `Test-MtAdComputerDormantCount` - Finds stale accounts that may be migration remnants +- `AD-DCOMP-06` - Finds stale accounts that may be migration remnants #### Related links diff --git a/tests/ad/computer/Test.AD-COMP-05.ps1 b/tests/ad/computer/Test.AD-COMP-05.ps1 index a1c3f98036..066c82421f 100644 --- a/tests/ad/computer/Test.AD-COMP-05.ps1 +++ b/tests/ad/computer/Test.AD-COMP-05.ps1 @@ -43,10 +43,7 @@ $adState = Get-MtADDomainState -Categories @('Computers') # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } + if ($null -eq $adState -or $null -eq $adState.Computers) { throw 'Computer inventory is required to review SID history.' } $computers = $adState.Computers @@ -60,10 +57,10 @@ $totalCount = ($computers | Measure-Object).Count # Test passes if we successfully retrieved computer data - $testResult = $totalCount -gt 0 + $testResult = $sidHistoryCount -eq 0 # Generate markdown results - if ($testResult) { + if ($totalCount -gt 0) { $percentage = if ($totalCount -gt 0) { [Math]::Round(($sidHistoryCount / $totalCount) * 100, 2) } else { @@ -82,7 +79,7 @@ $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." } - Add-MtTestResultDetail -Result $testResultMarkdown + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate return $testResult } diff --git a/tests/ad/computer/Test.AD-COMP-06.md b/tests/ad/computer/Test.AD-COMP-06.md index 76794963a8..28a82902aa 100644 --- a/tests/ad/computer/Test.AD-COMP-06.md +++ b/tests/ad/computer/Test.AD-COMP-06.md @@ -1,6 +1,6 @@ Computers located in the default `CN=Computers` container represent a security and management concern: -- **No Group Policy inheritance**: The Computers container is not an OU, so it doesn't support Group Policy inheritance +- **Limited Group Policy targeting**: The Computers container is not an OU, so GPOs cannot be linked directly to it; applicable domain- and site-linked GPOs can still apply - **Management gaps**: Computers in the default container may not receive security policies, software updates, or configurations - **Provisioning issues**: Indicates the domain join process hasn't been customized or automated provisioning is failing - **Shadow IT**: May represent unauthorized systems joined to the domain @@ -21,7 +21,7 @@ Computers located in the default `CN=Computers` container represent a security a #### How the Test Works -This test identifies enabled computer accounts where the Distinguished Name contains `CN=Computers,` indicating they are in the default Computers container rather than a proper organizational unit. +This test fails when an enabled computer is an immediate child of the domain's default `CN=Computers` container. Escaped commas in computer names are handled, and an OU named Computers is not treated as the default container. #### Related Tests diff --git a/tests/ad/computer/Test.AD-COMP-06.ps1 b/tests/ad/computer/Test.AD-COMP-06.ps1 index c67be42be8..6a1e721715 100644 --- a/tests/ad/computer/Test.AD-COMP-06.ps1 +++ b/tests/ad/computer/Test.AD-COMP-06.ps1 @@ -23,12 +23,14 @@ #> [MaesterTest( Id = 'AD-COMP-06', - Title = 'Computer default container count should be retrievable', + Title = 'Enabled computers should be moved out of the default Computers container', Product = 'ad', Feature = 'computers', Area = 'infrastructure', ResourceType = 'Computer', - Severity = 'Info', + Severity = 'Low', + UserImpact = 'Low', + ImplementationCost = 'Medium', Mitre = 'None', Service = 'ActiveDirectory', Permission = ('ActiveDirectory:Ldap:computer:ReadProperty'), @@ -44,18 +46,19 @@ $adState = Get-MtADDomainState -Categories @('Computers') # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } + if ($null -eq $adState -or $null -eq $adState.Computers) { throw 'Computer inventory is required to review the default container.' } $computers = $adState.Computers + if (@($computers).Count -eq 0) { throw 'Computer inventory is empty; default container placement cannot be assessed.' } + if (@($computers | Where-Object { $null -eq $_.Enabled -or ($_.Enabled -eq $true -and -not $_.DistinguishedName) }).Count -gt 0) { + throw 'Computer enabled state or distinguished name is missing; container placement cannot be assessed completely.' + } # Count enabled computers in the default Computers container $defaultContainerComputers = $computers | Where-Object { $_.Enabled -eq $true -and $_.DistinguishedName -and - $_.DistinguishedName -like "CN=Computers,*" + $_.DistinguishedName -match '^CN=(?:\\.|[^,])+,CN=Computers,DC=' } $defaultContainerCount = ($defaultContainerComputers | Measure-Object).Count @@ -63,10 +66,10 @@ $totalCount = ($computers | Measure-Object).Count # Test passes if we successfully retrieved computer data - $testResult = $totalCount -gt 0 + $testResult = $defaultContainerCount -eq 0 # Generate markdown results - if ($testResult) { + if ($totalCount -gt 0) { $percentage = if ($enabledCount -gt 0) { [Math]::Round(($defaultContainerCount / $enabledCount) * 100, 2) } else { @@ -86,6 +89,11 @@ $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." } + if ($testResult) { + $testResultMarkdown = "Well done. No enabled computers are in the default Computers container.`n`n$result" + } else { + $testResultMarkdown = "Enabled computers remain in the default Computers container. Move them to managed OUs so intended Group Policy applies.`n`n$result" + } Add-MtTestResultDetail -Result $testResultMarkdown return $testResult diff --git a/tests/ad/computer/Test.AD-COMP-07.ps1 b/tests/ad/computer/Test.AD-COMP-07.ps1 index 11036c2d29..8e20c0381e 100644 --- a/tests/ad/computer/Test.AD-COMP-07.ps1 +++ b/tests/ad/computer/Test.AD-COMP-07.ps1 @@ -42,10 +42,7 @@ $adState = Get-MtADDomainState -Categories @('Computers') # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } + if ($null -eq $adState -or $null -eq $adState.Computers) { throw 'Computer inventory is required to review containers.' } $computers = $adState.Computers @@ -56,7 +53,7 @@ $computerContainers = $enabledComputers | ForEach-Object { $dn = $_.DistinguishedName # Extract the container by removing the CN=ComputerName prefix - if ($dn -match '^CN=[^,]+,(.+)$') { + if ($dn -match '^CN=(?:\\.|[^,\\])+,(.+)$') { $matches[1] } } | Select-Object -Unique @@ -92,7 +89,7 @@ $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." } - Add-MtTestResultDetail -Result $testResultMarkdown + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate return $testResult } diff --git a/tests/ad/computer/Test.AD-COMP-08.ps1 b/tests/ad/computer/Test.AD-COMP-08.ps1 index e4c022ed7a..47de9a4e66 100644 --- a/tests/ad/computer/Test.AD-COMP-08.ps1 +++ b/tests/ad/computer/Test.AD-COMP-08.ps1 @@ -41,10 +41,7 @@ $adState = Get-MtADDomainState -Categories @('Computers') # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } + if ($null -eq $adState -or $null -eq $adState.Computers) { throw 'Computer inventory is required to review container distribution.' } $computers = $adState.Computers @@ -55,7 +52,7 @@ $computersByContainer = $enabledComputers | Group-Object -Property { $dn = $_.DistinguishedName # Extract the container by removing the CN=ComputerName prefix - if ($dn -match '^CN=[^,]+,(.+)$') { + if ($dn -match '^CN=(?:\\.|[^,\\])+,(.+)$') { $matches[1] } } @@ -99,11 +96,13 @@ if ($distinctOUCount -gt 0) { $result += "**Top 5 Containers by Computer Count:**" + "`n" + "`n" + $result += "| Container | Computer Count |`n| --- | --- |`n" $computersByContainer | Sort-Object -Property Count -Descending | Select-Object -First 5 | ForEach-Object { - $result += "| $($_.Name) | $($_.Count) |" + "`n" + $name = [string]$_.Name -replace '\|', '\|' -replace '[\r\n]', ' ' + $result += "| $name | $($_.Count) |" + "`n" } } @@ -113,7 +112,7 @@ $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." } - Add-MtTestResultDetail -Result $testResultMarkdown + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate return $testResult } diff --git a/tests/ad/computer/Test.AD-COMP-09.md b/tests/ad/computer/Test.AD-COMP-09.md deleted file mode 100644 index e30fd80139..0000000000 --- a/tests/ad/computer/Test.AD-COMP-09.md +++ /dev/null @@ -1,33 +0,0 @@ -Kerberos delegation allows a service to impersonate users when accessing other resources. While necessary for some applications, delegation—especially unconstrained delegation—creates significant security risks: - -- **Unconstrained delegation**: The service can impersonate users to ANY service on ANY system (highest risk) -- **Constrained delegation**: Limited to specific services, but still requires careful management -- **Protocol transition**: Allows S4U2Self/S4U2Proxy operations that can be exploited -- **Lateral movement**: Attackers can abuse delegation for privilege escalation and lateral movement - -#### Control Type - -**Detective** - -#### Security Recommendation - -- **Minimize unconstrained delegation**: Use it only when absolutely necessary, and never on tier 0 systems -- **Prefer constrained delegation**: Limit services to only those they need to access -- **Use resource-based constrained delegation**: More secure alternative in modern environments -- **Regular audits**: Periodically review which computers have delegation enabled -- **Remove unused delegation**: Disable delegation on systems that no longer require it -- **Consider Group Managed Service Accounts (gMSA)**: These provide better security for service accounts - -#### How the Test Works - -This test counts computers with different delegation configurations: -- `TrustedForDelegation` (unconstrained delegation) -- `TrustedToAuthForDelegation` (constrained delegation with protocol transition) - -#### Related Tests - -- `Test-MtAdComputerDelegationDetails` - Provides detailed breakdown of delegation per computer -- `Test-MtAdComputerDormantCount` - Identifies stale accounts that may have delegation enabled - - -%TestResult% diff --git a/tests/ad/computer/Test.AD-COMP-09.ps1 b/tests/ad/computer/Test.AD-COMP-09.ps1 deleted file mode 100644 index da55631a85..0000000000 --- a/tests/ad/computer/Test.AD-COMP-09.ps1 +++ /dev/null @@ -1,102 +0,0 @@ -function Test-MtAdComputerDelegationCount { - <# - .SYNOPSIS - Counts computers with delegation configured. - - .DESCRIPTION - This test identifies computer objects that have Kerberos delegation configured. - Delegation allows a service to impersonate users when accessing resources, which - can be a security risk if not properly configured. This test counts: - - Unconstrained delegation (most risky) - - Constrained delegation - - Protocol transition delegation - - .EXAMPLE - Test-MtAdComputerDelegationCount - - Returns $true if computer object data is accessible, $false otherwise. - The test result includes the count of computers with various delegation types. - - .LINK - https://maester.dev/docs/commands/Test-MtAdComputerDelegationCount - #> - [MaesterTest( - Id = 'AD-COMP-09', - Title = 'Computer delegation count should be retrievable', - Product = 'ad', - Feature = 'computers', - Area = 'authentication', - ResourceType = 'Computer', - Severity = 'Info', - Mitre = ('T1558', 'T1550.003'), - Service = 'ActiveDirectory', - Permission = ('ActiveDirectory:Ldap:computer:ReadProperty'), - Author = 'soulemike' - )] - [CmdletBinding()] - [OutputType([bool])] - param() - - Write-Verbose "Starting Test-MtAdComputerDelegationCount" - - # Get AD domain state data (uses cached data if available) - $adState = Get-MtADDomainState -Categories @('Computers') - - # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } - if ($null -eq $adState.Computers) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } - - $computers = $adState.Computers - - # Count computers with different delegation types - $unconstrainedDelegation = $computers | Where-Object { - $_.TrustedForDelegation -eq $true - } - - $constrainedDelegation = $computers | Where-Object { - $_.TrustedToAuthForDelegation -eq $true - } - - $unconstrainedCount = ($unconstrainedDelegation | Measure-Object).Count - $constrainedCount = ($constrainedDelegation | Measure-Object).Count - $totalDelegationCount = $unconstrainedCount + $constrainedCount - - $enabledCount = ($computers | Where-Object { $_.Enabled -eq $true } | Measure-Object).Count - $totalCount = ($computers | Measure-Object).Count - - # Test passes if we successfully retrieved computer data - $testResult = $totalCount -gt 0 - - # Generate markdown results - if ($testResult) { - $delegationPercentage = if ($enabledCount -gt 0) { - [Math]::Round(($totalDelegationCount / $enabledCount) * 100, 2) - } else { - 0 - } - - $result = "| Metric | Value |" + "`n" - $result += "| --- | --- |" + "`n" - $result += "| Total Computers | $totalCount |" + "`n" - $result += "| Enabled Computers | $enabledCount |" + "`n" - $result += "| Computers with Any Delegation | $totalDelegationCount |" + "`n" - $result += "| Unconstrained Delegation | $unconstrainedCount |" + "`n" - $result += "| Constrained/Protocol Transition | $constrainedCount |" + "`n" - $result += "| Delegation Percentage | $delegationPercentage% |" + "`n" + "`n" - - $testResultMarkdown = "Active Directory computer objects have been analyzed. $totalDelegationCount out of $enabledCount enabled computers ($delegationPercentage%) have delegation configured.`n`n%TestResult%" - $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result - } else { - $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." - } - - Add-MtTestResultDetail -Result $testResultMarkdown - - return $testResult -} diff --git a/tests/ad/computer/Test.AD-COMP-10.md b/tests/ad/computer/Test.AD-COMP-10.md deleted file mode 100644 index f6f39b59a9..0000000000 --- a/tests/ad/computer/Test.AD-COMP-10.md +++ /dev/null @@ -1,38 +0,0 @@ -Detailed visibility into Kerberos delegation configurations is essential for security because: - -- **Risk prioritization**: Unconstrained delegation poses significantly higher risk than constrained delegation -- **Attack path analysis**: Understanding delegation relationships helps identify potential lateral movement paths -- **Compliance requirements**: Many security frameworks require documentation of delegation configurations -- **Incident response**: Knowing which systems have delegation helps during security investigations - -Computers with unconstrained delegation should be treated as high-value targets requiring enhanced monitoring and protection. - -#### Control Type - -**Detective** - -#### Security Recommendation - -For each computer with delegation enabled: - -1. **Verify necessity**: Confirm the delegation is required for business operations -2. **Minimize scope**: Replace unconstrained with constrained delegation where possible -3. **Implement tiering**: Ensure tier 0 systems (Domain Controllers) never have unconstrained delegation -4. **Monitor closely**: Systems with delegation should have enhanced logging and monitoring -5. **Document exceptions**: Maintain a registry of systems requiring delegation with business justifications -6. **Regular review**: Quarterly review of delegation configurations - -#### How the Test Works - -This test provides a detailed breakdown of: -- Computers with unconstrained delegation (highest risk) -- Computers with constrained delegation and protocol transition -- Per-computer details including name, enabled status, and distinguished name - -#### Related Tests - -- `Test-MtAdComputerDelegationCount` - Provides summary counts of delegation -- `Test-MtAdComputerDormantCount` - Identifies stale accounts that may have delegation - - -%TestResult% diff --git a/tests/ad/computer/Test.AD-COMP-10.ps1 b/tests/ad/computer/Test.AD-COMP-10.ps1 deleted file mode 100644 index 53ad07d2b6..0000000000 --- a/tests/ad/computer/Test.AD-COMP-10.ps1 +++ /dev/null @@ -1,125 +0,0 @@ -function Test-MtAdComputerDelegationDetails { - <# - .SYNOPSIS - Provides detailed breakdown of delegation configuration per computer. - - .DESCRIPTION - This test provides a detailed analysis of Kerberos delegation configuration - across computer objects in Active Directory. It identifies: - - Computers with unconstrained delegation (full trust) - - Computers with constrained delegation (limited to specific services) - - Computers with protocol transition (S4U2Proxy) - - This detailed view helps security teams identify high-risk delegation - configurations that may need review or remediation. - - .EXAMPLE - Test-MtAdComputerDelegationDetails - - Returns $true if computer object data is accessible, $false otherwise. - The test result includes a detailed breakdown of delegation by computer. - - .LINK - https://maester.dev/docs/commands/Test-MtAdComputerDelegationDetails - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Clarity in using Details')] - [MaesterTest( - Id = 'AD-COMP-10', - Title = 'Computer delegation details should be retrievable', - Product = 'ad', - Feature = 'computers', - Area = 'authentication', - ResourceType = 'Computer', - Severity = 'Info', - Mitre = ('T1558', 'T1550.003'), - Service = 'ActiveDirectory', - Permission = ('ActiveDirectory:Ldap:computer:ReadProperty'), - Author = 'soulemike' - )] - [CmdletBinding()] - [OutputType([bool])] - param() - - Write-Verbose "Starting Test-MtAdComputerDelegationDetails" - - # Get AD domain state data (uses cached data if available) - $adState = Get-MtADDomainState -Categories @('Computers') - - # If unable to retrieve AD data, skip the test - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } - - $computers = $adState.Computers - - # Get computers with delegation - $computersWithUnconstrained = $computers | Where-Object { - $_.TrustedForDelegation -eq $true - } | Select-Object Name, DistinguishedName, Enabled, @{N = 'DelegationType'; E = { 'Unconstrained' } } - - $computersWithConstrained = $computers | Where-Object { - $_.TrustedToAuthForDelegation -eq $true - } | Select-Object Name, DistinguishedName, Enabled, @{N = 'DelegationType'; E = { 'Constrained/Protocol Transition' } } - - $allDelegationComputers = @($computersWithUnconstrained) + @($computersWithConstrained) - - $unconstrainedCount = ($computersWithUnconstrained | Measure-Object).Count - $constrainedCount = ($computersWithConstrained | Measure-Object).Count - $totalDelegationCount = $allDelegationComputers.Count - - $enabledCount = ($computers | Where-Object { $_.Enabled -eq $true } | Measure-Object).Count - $totalCount = ($computers | Measure-Object).Count - - # Test passes if we successfully retrieved computer data - $testResult = $totalCount -gt 0 - - # Generate markdown results - if ($testResult) { - $result = "| Metric | Value |" + "`n" - $result += "| --- | --- |" + "`n" - $result += "| Total Computers | $totalCount |" + "`n" - $result += "| Enabled Computers | $enabledCount |" + "`n" - $result += "| Computers with Any Delegation | $totalDelegationCount |" + "`n" - $result += "| Unconstrained Delegation | $unconstrainedCount |" + "`n" - $result += "| Constrained/Protocol Transition | $constrainedCount |" + "`n" + "`n" - - if ($unconstrainedCount -gt 0) { - $result += "**Computers with Unconstrained Delegation (High Risk):**" + "`n" + "`n" - $result += "| Computer Name | Enabled | Distinguished Name |" + "`n" - $result += "| --- | --- | --- |" + "`n" - $computersWithUnconstrained | Select-Object -First 20 | ForEach-Object { - $result += "| $($_.Name) | $($_.Enabled) | $($_.DistinguishedName) |" + "`n" - } - if ($unconstrainedCount -gt 20) { - $result += "| ... | ... | ... ($($unconstrainedCount - 20) more) |" + "`n" - } - $result += "" + "`n" - } - - if ($constrainedCount -gt 0) { - $result += "**Computers with Constrained Delegation:**" + "`n" + "`n" - $result += "| Computer Name | Enabled | Distinguished Name |" + "`n" - $result += "| --- | --- | --- |" + "`n" - $computersWithConstrained | Select-Object -First 20 | ForEach-Object { - $result += "| $($_.Name) | $($_.Enabled) | $($_.DistinguishedName) |" + "`n" - } - if ($constrainedCount -gt 20) { - $result += "| ... | ... | ... ($($constrainedCount - 20) more) |" + "`n" - } - } - - $testResultMarkdown = "Active Directory computer delegation configuration has been analyzed. $totalDelegationCount computers have delegation configured.`n`n%TestResult%" - if ($totalCount -gt 0) { - $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result - } else { - $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", "" - } - } else { - $testResultMarkdown = "Unable to retrieve Active Directory computer objects. Ensure you have appropriate permissions and the Active Directory module is installed." - } - - Add-MtTestResultDetail -Result $testResultMarkdown - - return $testResult -} diff --git a/tests/ad/security/Test.AD-DCOMP-01.md b/tests/ad/security/Test.AD-DCOMP-01.md index 75f394737b..5a276bc10a 100644 --- a/tests/ad/security/Test.AD-DCOMP-01.md +++ b/tests/ad/security/Test.AD-DCOMP-01.md @@ -1,4 +1,6 @@ -- Unconstrained delegation is one of the most dangerous configurations in Active Directory. When enabled on a computer, it allows services on that computer to impersonate authenticated users to ANY service on ANY computer in the domain. +Unconstrained delegation on non-domain-controller computers or managed service accounts exposes users' Kerberos tickets. This check fails when a non-DC computer, sMSA, gMSA or dMSA has the `TrustedForDelegation` flag. Managed accounts are reported separately; the device percentage still uses only non-DC computers as its denominator. + +Only the collected DC server inventory establishes DC identity: `serverReference` DN, or DNS fallback when that reference is unavailable. Primary groups 516 and 521 alone never exclude a computer. Unexpected DC primary-group claims are counted for review under AD-COMP-04. **Security Risks:** - **Complete Impersonation**: Attackers can impersonate any user who authenticates to the computer @@ -29,14 +31,14 @@ #### How the Test Works -This test counts computers with the `TrustedForDelegation` flag enabled and categorizes them by: -- Domain Controllers vs. non-DC computers -- Total count and percentage +This test counts accounts with the `TrustedForDelegation` flag enabled and reports: +- Verified domain controllers separately from non-DC computers +- Managed service accounts separately, without double-counting them as devices +- The percentage of non-DC computers with unconstrained delegation, using only that device population as the denominator #### Related Tests -- `Test-MtAdComputerNonDcUnconstrainedDelegationCount` - Focuses on non-DC computers (critical risk) -- `Test-MtAdComputerNonDcConstrainedDelegationCount` - Reviews constrained delegation +- `AD-DCOMP-03` - Reviews KCD, protocol transition and RBCD descriptor presence on non-DC computers and managed accounts - `Test-MtAdUserDelegationConfiguredCount` - Reviews user account delegation #### Related links diff --git a/tests/ad/security/Test.AD-DCOMP-01.ps1 b/tests/ad/security/Test.AD-DCOMP-01.ps1 index e8c8533af8..d2388419fe 100644 --- a/tests/ad/security/Test.AD-DCOMP-01.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-01.ps1 @@ -5,8 +5,9 @@ .DESCRIPTION Unconstrained delegation allows a service to impersonate a user to any other service. - This is a high-risk configuration that should be minimized. This test counts all - computers (including domain controllers) that have unconstrained delegation enabled. + This is a high-risk configuration on non-domain-controller computers. Domain + controllers are reported separately but excluded from the assessed population. + Managed service accounts are also assessed and reported separately from device percentages. Security Risk: - Unconstrained delegation allows full impersonation of authenticated users @@ -24,15 +25,18 @@ #> [MaesterTest( Id = 'AD-DCOMP-01', - Title = 'Computers with unconstrained delegation count should be investigated', + Title = 'Non-DC computers and managed service accounts should not have unconstrained delegation', Product = 'ad', Feature = 'computers', Area = 'authentication', ResourceType = 'Computer', - Severity = 'Info', + Severity = 'High', + UserImpact = 'Low', + ImplementationCost = 'Medium', Mitre = ('T1558', 'T1550.003'), + Control = 'nist-800-53-r5:AC-6', Service = 'ActiveDirectory', - Permission = ('ActiveDirectory:Ldap:computer:ReadProperty', 'ActiveDirectory:Ldap:nTDSDSA:ReadProperty'), + Permission = ('ActiveDirectory:Ldap:computer:ReadProperty', 'ActiveDirectory:Ldap:nTDSDSA:ReadProperty', 'ActiveDirectory:Ldap:msDS-ManagedServiceAccount:ReadProperty', 'ActiveDirectory:Ldap:msDS-GroupManagedServiceAccount:ReadProperty', 'ActiveDirectory:Ldap:msDS-DelegatedManagedServiceAccount:ReadProperty'), Author = 'soulemike' )] [CmdletBinding()] @@ -40,31 +44,43 @@ param() Write-Verbose "Starting Test-MtAdComputerUnconstrainedDelegationCount" - $adState = Get-MtADDomainState -Categories @('Computers', 'DomainControllers') + $adState = Get-MtADDomainState -Categories @('Computers', 'DomainControllers', 'ServiceAccounts') Write-Verbose "Retrieved AD state" - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null + if ($null -eq $adState -or $null -eq $adState.Computers -or $null -eq $adState.DomainControllers -or $null -eq $adState.ServiceAccounts) { + throw 'Computer and domain controller inventories are required to assess unconstrained delegation.' } Write-Verbose "Filtering/counting computer unconstrained delegation count" - $computers = $adState.Computers + $computers = @($adState.Computers | Where-Object { -not (@($_.ObjectClass | Where-Object { $_ -in 'msDS-ManagedServiceAccount', 'msDS-GroupManagedServiceAccount', 'msDS-DelegatedManagedServiceAccount' }).Count -gt 0) }) $domainControllers = $adState.DomainControllers + if (@($computers).Count -eq 0 -or @($domainControllers).Count -eq 0) { + throw 'Computer and domain controller inventories must not be empty when assessing delegation.' + } - # Get list of DC names for reference - $dcNames = $domainControllers | ForEach-Object { $_.Name } + # Only the collected server inventory establishes DC identity, never a claimed primary group. + $nonDcComputers = @($computers | Where-Object { + -not (Test-MtAdDomainControllerAccount -Account $_ -DomainControllers $domainControllers) + }) + $managedAccounts = @($adState.ServiceAccounts) + if (@(@($nonDcComputers) + @($managedAccounts) | Where-Object { $null -eq $_.TrustedForDelegation }).Count -gt 0) { + throw 'Unconstrained delegation flag is missing for non-DC computers.' + } # Find computers with unconstrained delegation $unconstrainedComputers = $computers | Where-Object { $_.TrustedForDelegation -eq $true } $unconstrainedCount = ($unconstrainedComputers | Measure-Object).Count # Count DCs vs non-DCs with unconstrained delegation - $dcUnconstrainedCount = ($unconstrainedComputers | Where-Object { $dcNames -contains $_.Name } | Measure-Object).Count - $nonDcUnconstrainedCount = $unconstrainedCount - $dcUnconstrainedCount + $nonDcUnconstrained = @($nonDcComputers | Where-Object { $_.TrustedForDelegation -eq $true }) + $dcUnconstrainedCount = $unconstrainedCount - $nonDcUnconstrained.Count + $nonDcUnconstrainedCount = $nonDcUnconstrained.Count + $managedUnconstrained = @($managedAccounts | Where-Object { $_.TrustedForDelegation -eq $true }) + $unverifiedDcGroups = @($nonDcComputers | Where-Object { $_.PrimaryGroupId -in 516, 521 }) - $totalComputers = ($computers | Measure-Object).Count - $testResult = $true + $totalComputers = @($computers).Count + $totalNonDcComputers = $nonDcComputers.Count + $testResult = $nonDcUnconstrainedCount -eq 0 -and $managedUnconstrained.Count -eq 0 $result = "| Metric | Value |" + "`n" $result += "| --- | --- |" + "`n" @@ -72,17 +88,33 @@ $result += "| Computers with Unconstrained Delegation | $unconstrainedCount |" + "`n" $result += "| Domain Controllers with Unconstrained Delegation | $dcUnconstrainedCount |" + "`n" $result += "| Non-DC Computers with Unconstrained Delegation | $nonDcUnconstrainedCount |" + "`n" - - if ($unconstrainedCount -gt 0) { - $percentage = [Math]::Round(($unconstrainedCount / $totalComputers) * 100, 2) - $result += "| Percentage with Unconstrained Delegation | $percentage% |" + "`n" + $result += "| Total Non-DC Computers | $totalNonDcComputers |" + "`n" + $result += "| Managed Service Accounts | $($managedAccounts.Count) |`n" + $result += "| Managed Service Accounts with Unconstrained Delegation | $($managedUnconstrained.Count) |`n" + $result += "| Non-DC Computers Claiming DC Primary Groups | $($unverifiedDcGroups.Count) |`n" + $percentage = if ($totalNonDcComputers -gt 0) { [Math]::Round(($nonDcUnconstrainedCount / $totalNonDcComputers) * 100, 2) } else { 0 } + $result += "| Non-DC Percentage with Unconstrained Delegation | $percentage% |" + "`n" + if (-not $testResult) { + $result += "`n| Non-DC Computer | Operating System |`n| --- | --- |`n" + foreach ($computer in @($nonDcUnconstrained | Select-Object -First 10)) { + $name = [string]$computer.Name -replace '\|', '\|' -replace '[\r\n]', ' ' + $os = [string]$computer.OperatingSystem -replace '\|', '\|' -replace '[\r\n]', ' ' + $result += "| $name | $os |`n" + } + $result += "`n| Managed Account with Unconstrained Delegation |`n| --- |`n" + foreach ($account in $managedUnconstrained) { + $name = ([string]$account.Name).Replace('|', '|') -replace '[\r\n]+', ' ' + $result += "| $name |`n" + } } Write-Verbose "Counts computed" - $testResultMarkdown = "Computers with unconstrained delegation have been identified. This configuration allows services to impersonate users to any service.`n`n%TestResult%" + $summary = if ($testResult) { 'Well done. No non-DC computers or managed service accounts have unconstrained delegation.' } else { 'Non-DC computers or managed service accounts with unconstrained delegation were found. Migrate their services to constrained delegation and remove unconstrained delegation.' } + if ($unverifiedDcGroups.Count -gt 0) { $summary += " $($unverifiedDcGroups.Count) computer(s) claim a DC primary group without inventory evidence; review AD-COMP-04. They were not excluded." } + $testResultMarkdown = "$summary`n`n%TestResult%" $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result - Add-MtTestResultDetail -Result $testResultMarkdown -Investigate + Add-MtTestResultDetail -Result $testResultMarkdown Write-Verbose "Completed Test-MtAdComputerUnconstrainedDelegationCount" return $testResult diff --git a/tests/ad/security/Test.AD-DCOMP-02.md b/tests/ad/security/Test.AD-DCOMP-02.md deleted file mode 100644 index 921198ffbf..0000000000 --- a/tests/ad/security/Test.AD-DCOMP-02.md +++ /dev/null @@ -1,53 +0,0 @@ -- Non-domain controller computers with unconstrained delegation represent a **CRITICAL** security vulnerability. While domain controllers may have legitimate reasons for unconstrained delegation in certain legacy scenarios, regular computers should **NEVER** have this configuration. - -**Critical Security Risks:** -- **Domain Compromise**: A single compromised computer with unconstrained delegation can lead to full domain compromise -- **Unrestricted Impersonation**: Any service on the computer can impersonate any domain user to any service -- **Attack Vector**: Common target for attackers seeking to escalate privileges -- **Stealthy Access**: Can be exploited without triggering typical security alerts - -**The target count for this test should ALWAYS be ZERO.** - -#### Control Type - -**Detective** - -#### Security Recommendation - -1. **Immediate Action Required**: - - Identify all non-DC computers with unconstrained delegation - - Remove unconstrained delegation immediately - - Investigate why it was configured - -2. **Replace with secure alternatives**: - - **Constrained Delegation**: Limit to specific required services - - **Resource-Based Constrained Delegation**: Modern, flexible approach - - **Managed Service Accounts**: Use gMSAs where possible - -3. **Audit and Monitor**: - - Regular audits of delegation settings - - Alert on any new unconstrained delegation configurations - - Review applications requiring delegation - -#### How the Test Works - -This test specifically identifies non-DC computers with the `TrustedForDelegation` flag enabled and reports: -- Count of affected computers -- Computer names and operating systems -- Compliance status (should be zero) - -**Pass Criteria**: Zero non-DC computers with unconstrained delegation - -#### Related Tests - -- `Test-MtAdComputerUnconstrainedDelegationCount` - Overall unconstrained delegation count -- `Test-MtAdComputerNonDcConstrainedDelegationCount` - Reviews constrained delegation on non-DCs -- `Test-MtAdComputerDelegationCount` - General delegation overview - -#### Related links - -- [Microsoft Defender for Identity: Unsecure Kerberos delegation](https://learn.microsoft.com/defender-for-identity/security-posture-assessments/accounts#unsecure-kerberos-delegation) -- [ANSSI Active Directory checkpoints: Unconstrained authentication delegation](https://www.cert.ssi.gouv.fr/uploads/ad_checklist.html#vuln_delegation_t4d) - - -%TestResult% diff --git a/tests/ad/security/Test.AD-DCOMP-02.ps1 b/tests/ad/security/Test.AD-DCOMP-02.ps1 deleted file mode 100644 index 52d41c13ee..0000000000 --- a/tests/ad/security/Test.AD-DCOMP-02.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -function Test-MtAdComputerNonDcUnconstrainedDelegationCount { - <# - .SYNOPSIS - Counts non-domain controller computers with unconstrained delegation. - - .DESCRIPTION - Non-DC computers with unconstrained delegation represent a significant security risk. - While domain controllers may require unconstrained delegation for certain scenarios, - regular computers should never have this configuration. This test specifically - identifies non-DC computers with unconstrained delegation enabled. - - Security Risk: - - Non-DC computers with unconstrained delegation are a critical vulnerability - - Compromise of such a computer allows attackers to impersonate any domain user - - This configuration should be eliminated in favor of constrained delegation - - Zero non-DC computers should have unconstrained delegation - - .EXAMPLE - Test-MtAdComputerNonDcUnconstrainedDelegationCount - - Returns $true if no non-DC computers have unconstrained delegation (or if data is accessible). - - .LINK - https://maester.dev/docs/commands/Test-MtAdComputerNonDcUnconstrainedDelegationCount - #> - [MaesterTest( - Id = 'AD-DCOMP-02', - Title = 'Non-DC computers should not have unconstrained delegation', - Product = 'ad', - Feature = 'computers', - Area = 'authentication', - ResourceType = 'Computer', - Severity = 'High', - UserImpact = 'Low', - ImplementationCost = 'Medium', - Mitre = ('T1558', 'T1550.003'), - Control = 'nist-800-53-r5:AC-6', - Service = 'ActiveDirectory', - Permission = ('ActiveDirectory:Ldap:computer:ReadProperty', 'ActiveDirectory:Ldap:nTDSDSA:ReadProperty'), - Author = 'soulemike' - )] - [CmdletBinding()] - [OutputType([bool])] - param() - - Write-Verbose "Starting Test-MtAdComputerNonDcUnconstrainedDelegationCount" - $adState = Get-MtADDomainState -Categories @('Computers', 'DomainControllers') - Write-Verbose "Retrieved AD state" - - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } - Write-Verbose "Filtering/counting computer non dc unconstrained delegation count" - - $computers = $adState.Computers - $domainControllers = $adState.DomainControllers - - # Get list of DC names - $dcNames = $domainControllers | ForEach-Object { $_.Name } - - # Find non-DC computers with unconstrained delegation - $nonDcComputers = $computers | Where-Object { $dcNames -notcontains $_.Name } - $nonDcUnconstrained = $nonDcComputers | Where-Object { $_.TrustedForDelegation -eq $true } - $nonDcUnconstrainedCount = ($nonDcUnconstrained | Measure-Object).Count - - $totalNonDcComputers = ($nonDcComputers | Measure-Object).Count - - # Test passes if no non-DC computers have unconstrained delegation - $testResult = ($nonDcUnconstrainedCount -eq 0) - - $result = "| Metric | Value |" + "`n" - $result += "| --- | --- |" + "`n" - $result += "| Total Non-DC Computers | $totalNonDcComputers |" + "`n" - $result += "| Non-DC Computers with Unconstrained Delegation | $nonDcUnconstrainedCount |" + "`n" - $result += "| Status | $(if ($testResult) { 'PASS - No non-DC computers with unconstrained delegation' } else { 'FAIL - Non-DC computers have unconstrained delegation' }) |" + "`n" - - if ($nonDcUnconstrainedCount -gt 0) { - $result += "`n**Non-DC Computers with Unconstrained Delegation:**" + "`n" + "`n" - $result += "| Computer Name | Operating System |" + "`n" - $result += "| --- | --- |" + "`n" - foreach ($comp in $nonDcUnconstrained | Select-Object -First 10) { - $result += "| $($comp.Name) | $($comp.operatingSystem) |" + "`n" - } - if ($nonDcUnconstrainedCount -gt 10) { - $result += "| ... and $($nonDcUnconstrainedCount - 10) more | |" + "`n" - } - } - Write-Verbose "Counts computed" - - $testResultMarkdown = "Non-DC computers with unconstrained delegation represent a critical security risk and should be eliminated.`n`n%TestResult%" - $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result - - Add-MtTestResultDetail -Result $testResultMarkdown - Write-Verbose "Completed Test-MtAdComputerNonDcUnconstrainedDelegationCount" - - return $testResult -} diff --git a/tests/ad/security/Test.AD-DCOMP-03.md b/tests/ad/security/Test.AD-DCOMP-03.md index 045ef63a51..f8a47dac79 100644 --- a/tests/ad/security/Test.AD-DCOMP-03.md +++ b/tests/ad/security/Test.AD-DCOMP-03.md @@ -1,4 +1,6 @@ -- Constrained delegation (also known as "protocol transition" or S4U2Proxy) is safer than unconstrained delegation but still carries security risks. It allows a service to impersonate a user to specific services only, rather than any service in the domain. +This check inventories three separate indicators on non-domain-controller computers and sMSA, gMSA and dMSA accounts: classic Kerberos constrained delegation (KCD) target SPNs from `msDS-AllowedToDelegateTo`, the `TrustedToAuthForDelegation` protocol-transition flag, and **presence** of an `msDS-AllowedToActOnBehalfOfOtherIdentity` resource-based constrained delegation (RBCD) descriptor. One account can have multiple indicators. Descriptor presence neither identifies allowed principals nor proves effective delegation permissions. + +LDAP attributes that cannot be read may be indistinguishable from unset attributes; adequate ReadProperty access is needed for a reliable inventory. **Security Considerations:** - **Limited Scope**: Safer than unconstrained but still enables impersonation @@ -29,14 +31,11 @@ #### How the Test Works -This test counts non-DC computers with the `TrustedToAuthForDelegation` flag enabled, which indicates: -- Constrained delegation is configured -- Protocol transition may be enabled +The test reports device and managed-account populations separately, then combined non-DC account counts for KCD targets, protocol transition and RBCD descriptor presence. Indicator percentages use this combined population. DC identity comes from the DC inventory, not a claimed primary group. A present RBCD descriptor needs a separate permissions review; this test cannot resolve principals or effective access. Delegation on ordinary user accounts remains outside this inventory. #### Related Tests - `Test-MtAdComputerUnconstrainedDelegationCount` - Overall unconstrained delegation -- `Test-MtAdComputerNonDcUnconstrainedDelegationCount` - Critical non-DC unconstrained delegation - `Test-MtAdUserDelegationConfiguredCount` - User account delegation settings #### Related links diff --git a/tests/ad/security/Test.AD-DCOMP-03.ps1 b/tests/ad/security/Test.AD-DCOMP-03.ps1 index e96f4ff665..21c3245947 100644 --- a/tests/ad/security/Test.AD-DCOMP-03.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-03.ps1 @@ -4,10 +4,11 @@ Counts non-domain controller computers with constrained delegation configured. .DESCRIPTION - Constrained delegation (also known as "protocol transition" or "S4U2Proxy") - allows a service to impersonate a user to specific services only. While safer - than unconstrained delegation, it should still be carefully reviewed and minimized. - This test identifies non-DC computers with constrained delegation enabled. + Inventories classic Kerberos constrained delegation target SPNs, the + TrustedToAuthForDelegation protocol-transition flag, and presence of an RBCD + security descriptor on non-DC computers and sMSA, gMSA and dMSA objects. RBCD presence does not + identify allowed principals or establish effective access. These categories + can overlap and do not include delegation configured on user accounts. Security Considerations: - Constrained delegation is safer than unconstrained but still carries risk @@ -18,14 +19,14 @@ .EXAMPLE Test-MtAdComputerNonDcConstrainedDelegationCount - Returns $true if computer data is accessible. + Reports an Investigate inventory when the required computer fields are available. .LINK https://maester.dev/docs/commands/Test-MtAdComputerNonDcConstrainedDelegationCount #> [MaesterTest( Id = 'AD-DCOMP-03', - Title = 'Non-DC computers with constrained delegation count should be investigated', + Title = 'Non-DC computer and managed account constrained delegation should be investigated', Product = 'ad', Feature = 'computers', Area = 'authentication', @@ -33,7 +34,7 @@ Severity = 'Info', Mitre = ('T1558', 'T1550.003'), Service = 'ActiveDirectory', - Permission = ('ActiveDirectory:Ldap:computer:ReadProperty', 'ActiveDirectory:Ldap:nTDSDSA:ReadProperty'), + Permission = ('ActiveDirectory:Ldap:computer:ReadProperty', 'ActiveDirectory:Ldap:nTDSDSA:ReadProperty', 'ActiveDirectory:Ldap:msDS-ManagedServiceAccount:ReadProperty', 'ActiveDirectory:Ldap:msDS-GroupManagedServiceAccount:ReadProperty', 'ActiveDirectory:Ldap:msDS-DelegatedManagedServiceAccount:ReadProperty'), Author = 'soulemike' )] [CmdletBinding()] @@ -41,62 +42,76 @@ param() Write-Verbose "Starting Test-MtAdComputerNonDcConstrainedDelegationCount" - $adState = Get-MtADDomainState -Categories @('Computers', 'DomainControllers') + $adState = Get-MtADDomainState -Categories @('Computers', 'DomainControllers', 'ServiceAccounts') Write-Verbose "Retrieved AD state" - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null + if ($null -eq $adState -or $null -eq $adState.Computers -or $null -eq $adState.DomainControllers -or $null -eq $adState.ServiceAccounts) { + throw 'Computer and domain controller inventories are required to review constrained delegation.' } Write-Verbose "Filtering/counting computer non dc constrained delegation count" - $computers = $adState.Computers + $computers = @($adState.Computers | Where-Object { -not (@($_.ObjectClass | Where-Object { $_ -in 'msDS-ManagedServiceAccount', 'msDS-GroupManagedServiceAccount', 'msDS-DelegatedManagedServiceAccount' }).Count -gt 0) }) $domainControllers = $adState.DomainControllers + if (@($computers).Count -eq 0 -or @($domainControllers).Count -eq 0) { + throw 'Computer and domain controller inventories must not be empty when reviewing constrained delegation.' + } - # Get list of DC names - $dcNames = $domainControllers | ForEach-Object { $_.Name } - - # Find non-DC computers with constrained delegation - $nonDcComputers = $computers | Where-Object { $dcNames -notcontains $_.Name } - $nonDcConstrained = $nonDcComputers | Where-Object { $_.TrustedToAuthForDelegation -eq $true } - $nonDcConstrainedCount = ($nonDcConstrained | Measure-Object).Count - - # Also check for computers with both types of delegation - $nonDcBoth = $nonDcComputers | Where-Object { $_.TrustedToAuthForDelegation -eq $true -and $_.TrustedForDelegation -eq $true } - $nonDcBothCount = ($nonDcBoth | Measure-Object).Count + # Device inventory stays separate from managed accounts; both are assessed for delegation. + $nonDcComputers = @($computers | Where-Object { + -not (Test-MtAdDomainControllerAccount -Account $_ -DomainControllers $domainControllers) + }) + $managedAccounts = @($adState.ServiceAccounts) + $nonDcAccounts = @($nonDcComputers) + @($managedAccounts) + if (@($nonDcAccounts | Where-Object { + -not $_.PSObject.Properties['AllowedToDelegateTo'] -or $null -eq $_.AllowedToDelegateTo -or + -not $_.PSObject.Properties['HasResourceBasedConstrainedDelegation'] -or $null -eq $_.HasResourceBasedConstrainedDelegation -or + -not $_.PSObject.Properties['TrustedToAuthForDelegation'] -or $null -eq $_.TrustedToAuthForDelegation + }).Count -gt 0) { + throw 'Required delegation fields are missing from the non-DC computer inventory; a zero count cannot be trusted.' + } - $totalNonDcComputers = ($nonDcComputers | Measure-Object).Count - $testResult = $true + $classicKcd = @($nonDcAccounts | Where-Object { @($_.AllowedToDelegateTo).Count -gt 0 }) + $protocolTransition = @($nonDcAccounts | Where-Object { $_.TrustedToAuthForDelegation -eq $true }) + $rbcdPresent = @($nonDcAccounts | Where-Object { $_.HasResourceBasedConstrainedDelegation -eq $true }) + $reviewComputers = @($nonDcAccounts | Where-Object { + @($_.AllowedToDelegateTo).Count -gt 0 -or $_.TrustedToAuthForDelegation -eq $true -or $_.HasResourceBasedConstrainedDelegation -eq $true + }) + $totalNonDcComputers = $nonDcComputers.Count + $totalNonDcAccounts = $nonDcAccounts.Count $result = "| Metric | Value |" + "`n" $result += "| --- | --- |" + "`n" $result += "| Total Non-DC Computers | $totalNonDcComputers |" + "`n" - $result += "| Non-DC Computers with Constrained Delegation | $nonDcConstrainedCount |" + "`n" - $result += "| Non-DC Computers with Both Delegation Types | $nonDcBothCount |" + "`n" - - if ($nonDcConstrainedCount -gt 0) { - $percentage = [Math]::Round(($nonDcConstrainedCount / $totalNonDcComputers) * 100, 2) - $result += "| Percentage with Constrained Delegation | $percentage% |" + "`n" + $result += "| Managed Service Accounts | $($managedAccounts.Count) |`n" + $result += "| Non-DC Accounts with Classic KCD Target SPNs | $($classicKcd.Count) |`n" + $result += "| Non-DC Accounts with Protocol Transition Flag | $($protocolTransition.Count) |`n" + $result += "| Non-DC Accounts with RBCD Descriptor Present | $($rbcdPresent.Count) |`n" + $result += "| Distinct Non-DC Accounts with One or More Indicators | $($reviewComputers.Count) |`n" + if ($totalNonDcAccounts -gt 0) { + $percentage = [Math]::Round(($reviewComputers.Count / $totalNonDcAccounts) * 100, 2) + $result += "| Percentage of Non-DC Accounts with an Indicator | $percentage% |`n" } - if ($nonDcConstrainedCount -gt 0) { - $result += "`n**Non-DC Computers with Constrained Delegation:**" + "`n" + "`n" - $result += "| Computer Name | Operating System |" + "`n" - $result += "| --- | --- |" + "`n" - foreach ($comp in $nonDcConstrained | Select-Object -First 10) { - $result += "| $($comp.Name) | $($comp.operatingSystem) |" + "`n" + if ($reviewComputers.Count -gt 0) { + $result += "`n**Non-DC Accounts to Review (Top 10):**`n`n" + $result += "| Account | Classic KCD Target SPNs | Protocol Transition Flag | RBCD Descriptor Present |`n| --- | --- | --- | --- |`n" + foreach ($computer in $reviewComputers | Select-Object -First 10) { + $name = [string]$computer.Name -replace '\|', '\|' -replace '[\r\n]', ' ' + $spns = [string](@($computer.AllowedToDelegateTo) -join ', ') -replace '\|', '\|' -replace '[\r\n]', ' ' + if (-not $spns) { $spns = 'None' } + $result += "| $name | $spns | $($computer.TrustedToAuthForDelegation) | $($computer.HasResourceBasedConstrainedDelegation) |`n" } - if ($nonDcConstrainedCount -gt 10) { - $result += "| ... and $($nonDcConstrainedCount - 10) more | |" + "`n" + if ($reviewComputers.Count -gt 10) { + $result += "| ... and $($reviewComputers.Count - 10) more | | | |`n" } } Write-Verbose "Counts computed" - $testResultMarkdown = "Non-DC computers with constrained delegation have been identified. These should be reviewed to ensure they are necessary and properly configured.`n`n%TestResult%" + $testResultMarkdown = "Review non-DC computer and managed service account classic KCD target SPNs, protocol transition and RBCD descriptor presence. RBCD presence does not identify allowed principals or prove effective access; categories can overlap.`n`n%TestResult%" $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result Add-MtTestResultDetail -Result $testResultMarkdown -Investigate Write-Verbose "Completed Test-MtAdComputerNonDcConstrainedDelegationCount" - return $testResult + return $true } diff --git a/tests/ad/security/Test.AD-DCOMP-04.md b/tests/ad/security/Test.AD-DCOMP-04.md index ab61c58f05..766ee6bbed 100644 --- a/tests/ad/security/Test.AD-DCOMP-04.md +++ b/tests/ad/security/Test.AD-DCOMP-04.md @@ -36,12 +36,13 @@ This test analyzes computer objects in Active Directory and: - Counts distinct operating systems -- Shows distribution percentages -- Identifies computers without OS data +- Shows distribution percentages using all collected computers, including domain controllers, as the denominator +- Includes an **Unknown OS** row in the **Operating Systems in Use** table for absent, empty, or whitespace-only OS values; these do not increase the distinct operating system count + +OS service pack and patch state are not available in the current collector. This inventory does not determine whether an operating system is supported or patched. #### Related Tests -- `Test-MtAdComputerOperatingSystemDetails` - Detailed OS and service pack information - `Test-MtAdComputerStaleEnabledCount` - Identifies stale computer accounts - `Test-MtAdDcOperatingSystemDetails` - Domain Controller OS distribution diff --git a/tests/ad/security/Test.AD-DCOMP-04.ps1 b/tests/ad/security/Test.AD-DCOMP-04.ps1 index dc1853d19f..cff3a7df95 100644 --- a/tests/ad/security/Test.AD-DCOMP-04.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-04.ps1 @@ -44,19 +44,18 @@ $adState = Get-MtADDomainState -Categories @('Computers') Write-Verbose "Retrieved AD state" - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null + if ($null -eq $adState -or $null -eq $adState.Computers) { + throw 'Computer inventory is required to review operating systems.' } Write-Verbose "Filtering/counting computer operating system count" $computers = $adState.Computers - # Group by operating system - $osGroups = $computers | Where-Object { $_.operatingSystem } | Group-Object -Property operatingSystem + # Blank and whitespace-only values are undefined, not distinct operating systems. + $osGroups = $computers | Where-Object { -not [string]::IsNullOrWhiteSpace($_.operatingSystem) } | Group-Object -Property operatingSystem $osCount = ($osGroups | Measure-Object).Count $totalComputers = ($computers | Measure-Object).Count - $computersWithOs = ($computers | Where-Object { $_.operatingSystem } | Measure-Object).Count + $computersWithOs = ($computers | Where-Object { -not [string]::IsNullOrWhiteSpace($_.operatingSystem) } | Measure-Object).Count $computersWithoutOs = $totalComputers - $computersWithOs $testResult = $true @@ -66,22 +65,27 @@ $result += "| Total Computers | $totalComputers |" + "`n" $result += "| Distinct Operating Systems | $osCount |" + "`n" $result += "| Computers with OS Data | $computersWithOs |" + "`n" - $result += "| Computers without OS Data | $computersWithoutOs |" + "`n" + $result += "| Computers with Unknown OS | $computersWithoutOs |" + "`n" - if ($osCount -gt 0) { + if ($totalComputers -gt 0) { $result += "`n**Operating Systems in Use:**" + "`n" + "`n" - $result += "| Operating System | Count | Percentage |" + "`n" + $result += "| Operating System | Count | Percentage of All Computers |" + "`n" $result += "| --- | --- | --- |" + "`n" $sortedGroups = $osGroups | Sort-Object -Property Count -Descending foreach ($group in $sortedGroups) { - $percentage = if ($computersWithOs -gt 0) { [Math]::Round(($group.Count / $computersWithOs) * 100, 2) } else { 0 } - $result += "| $($group.Name) | $($group.Count) | $percentage% |" + "`n" + $percentage = [Math]::Round(($group.Count / $totalComputers) * 100, 2) + $osName = [string]$group.Name -replace '\|', '\|' -replace '[\r\n]', ' ' + $result += "| $osName | $($group.Count) | $percentage% |" + "`n" + } + if ($computersWithoutOs -gt 0) { + $unknownPercentage = [Math]::Round(($computersWithoutOs / $totalComputers) * 100, 2) + $result += "| Unknown OS | $computersWithoutOs | $unknownPercentage% |`n" } } Write-Verbose "Counts computed" - $testResultMarkdown = "Domain computer operating system diversity has been analyzed.`n`n%TestResult%" + $testResultMarkdown = "Review the operating system inventory, including computers with unknown OS. OS service pack is not collected; this inventory cannot determine patch or support status.`n`n%TestResult%" $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result Add-MtTestResultDetail -Result $testResultMarkdown -Investigate diff --git a/tests/ad/security/Test.AD-DCOMP-05.md b/tests/ad/security/Test.AD-DCOMP-05.md deleted file mode 100644 index 6187f608a1..0000000000 --- a/tests/ad/security/Test.AD-DCOMP-05.md +++ /dev/null @@ -1,50 +0,0 @@ -- Detailed knowledge of operating system versions and service pack levels is essential for effective vulnerability management and security compliance. This information helps identify: - -**Security Risks:** -- **Missing Service Packs**: Systems without critical updates -- **End-of-Life Versions**: Operating systems no longer receiving security patches -- **Version Fragmentation**: Inconsistent patch levels across the environment -- **Unsupported Configurations**: OS versions that violate security policies - -**Compliance Requirements:** -- Many frameworks require specific OS versions -- Service pack levels may be mandated -- Documentation of OS landscape is often required - -#### Control Type - -**Operational** - -#### Security Recommendation - -1. **Maintain Current Service Packs**: - - Apply latest service packs and cumulative updates - - Test before deployment to production - - Maintain rollback procedures - -2. **Upgrade End-of-Life Systems**: - - Prioritize systems running unsupported OS versions - - Develop migration plans for legacy applications - - Consider virtualization for legacy requirements - -3. **Standardize Configurations**: - - Use standard OS images for new deployments - - Implement configuration management - - Regular compliance scanning - -#### How the Test Works - -This test provides detailed analysis including: -- Operating system names and versions -- Service pack levels -- Distribution counts and percentages -- Identification of systems without OS information - -#### Related Tests - -- `Test-MtAdComputerOperatingSystemCount` - Summary OS count -- `Test-MtAdComputerStaleEnabledCount` - Stale computer identification -- `Test-MtAdDcOperatingSystemDetails` - Domain Controller OS details - - -%TestResult% diff --git a/tests/ad/security/Test.AD-DCOMP-05.ps1 b/tests/ad/security/Test.AD-DCOMP-05.ps1 deleted file mode 100644 index dad3aff23a..0000000000 --- a/tests/ad/security/Test.AD-DCOMP-05.ps1 +++ /dev/null @@ -1,98 +0,0 @@ -function Test-MtAdComputerOperatingSystemDetails { - <# - .SYNOPSIS - Provides detailed breakdown of computers by operating system and service pack. - - .DESCRIPTION - This test provides a comprehensive view of the operating system landscape in the - domain, including OS versions and service pack levels. This helps identify - outdated systems, unsupported versions, and systems requiring security updates. - - Security Value: - - Identifies end-of-life operating systems - - Reveals systems missing critical service packs - - Supports vulnerability management programs - - Helps plan OS upgrade and standardization efforts - - .EXAMPLE - Test-MtAdComputerOperatingSystemDetails - - Returns $true if computer data is accessible. - - .LINK - https://maester.dev/docs/commands/Test-MtAdComputerOperatingSystemDetails - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Clarity in using plural')] - [MaesterTest( - Id = 'AD-DCOMP-05', - Title = 'Computer operating system details should be investigated', - Product = 'ad', - Feature = 'computers', - Area = 'devices', - ResourceType = 'Computer', - Severity = 'Info', - Mitre = 'None', - Control = 'nist-800-53-r5:CM-8', - Service = 'ActiveDirectory', - Permission = ('ActiveDirectory:Ldap:computer:ReadProperty'), - Author = 'soulemike' - )] - [CmdletBinding()] - [OutputType([bool])] - param() - - Write-Verbose "Starting Test-MtAdComputerOperatingSystemDetails" - $adState = Get-MtADDomainState -Categories @('Computers') - Write-Verbose "Retrieved AD state" - - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } - Write-Verbose "Filtering/counting computer operating system details" - - $computers = $adState.Computers - - # Create detailed OS breakdown including service pack - $osDetails = $computers | Where-Object { $_.operatingSystem } | ForEach-Object { - $osName = $_.operatingSystem - $osServicePack = if ($_.operatingSystemServicePack) { $_.operatingSystemServicePack } else { "No Service Pack" } - "$osName $osServicePack" - } | Group-Object - - $totalComputers = ($computers | Measure-Object).Count - $computersWithOs = ($computers | Where-Object { $_.operatingSystem } | Measure-Object).Count - - $testResult = $true - - $result = "| Metric | Value |" + "`n" - $result += "| --- | --- |" + "`n" - $result += "| Total Computers | $totalComputers |" + "`n" - $result += "| Computers with OS Data | $computersWithOs |" + "`n" - $result += "| Distinct OS/Service Pack Combinations | $(($osDetails | Measure-Object).Count) |" + "`n" - - if ($osDetails.Count -gt 0) { - $result += "`n**Operating System Details (Top 15):**" + "`n" + "`n" - $result += "| Operating System | Count | Percentage |" + "`n" - $result += "| --- | --- | --- |" + "`n" - - $sortedDetails = $osDetails | Sort-Object -Property Count -Descending | Select-Object -First 15 - foreach ($detail in $sortedDetails) { - $percentage = if ($computersWithOs -gt 0) { [Math]::Round(($detail.Count / $computersWithOs) * 100, 2) } else { 0 } - $result += "| $($detail.Name) | $($detail.Count) | $percentage% |" + "`n" - } - - if ($osDetails.Count -gt 15) { - $result += "| ... and $($osDetails.Count - 15) more combinations | | |" + "`n" - } - } - Write-Verbose "Counts computed" - - $testResultMarkdown = "Detailed operating system distribution has been analyzed. Review for unsupported or end-of-life systems.`n`n%TestResult%" - $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result - - Add-MtTestResultDetail -Result $testResultMarkdown -Investigate - Write-Verbose "Completed Test-MtAdComputerOperatingSystemDetails" - - return $testResult -} diff --git a/tests/ad/security/Test.AD-DCOMP-06.md b/tests/ad/security/Test.AD-DCOMP-06.md index 3c2c0341e4..f02a5710c4 100644 --- a/tests/ad/security/Test.AD-DCOMP-06.md +++ b/tests/ad/security/Test.AD-DCOMP-06.md @@ -42,9 +42,11 @@ This test identifies enabled computers that: Provides counts and lists affected computers. +AD-COMP-02 is consolidated into this check. Its former default was 90 days; set `MaximumInactiveDays` to `90` on AD-DCOMP-06 to retain that threshold. The canonical default remains 180 days. + #### Related Tests -- `Test-MtAdComputerDormantCount` - Dormant computer identification +- This is the canonical stale enabled computer inventory; findings report Investigate, while no findings return Passed. - `Test-MtAdComputerDisabledCount` - Disabled computer analysis - `Test-MtAdUserDormantEnabledCount` - Stale user account check diff --git a/tests/ad/security/Test.AD-DCOMP-06.ps1 b/tests/ad/security/Test.AD-DCOMP-06.ps1 index 3fbf48b57d..2cee1dd87b 100644 --- a/tests/ad/security/Test.AD-DCOMP-06.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-06.ps1 @@ -8,9 +8,9 @@ compromised and reactivated by attackers. This test identifies enabled computers that have not authenticated to the domain for the configured threshold or more. - Because nearly every domain has at least one stale enabled computer, this - test returns an Investigate result (rather than Pass/Fail) so the count - and details are surfaced for review without causing a failing audit. + An enabled computer with no recorded logon or a last logon before the threshold + is flagged for review. The result is Investigate when such computers exist; + a clean inventory returns Passed. Security Risk: - Stale enabled accounts can be reactivated and used for lateral movement @@ -53,17 +53,12 @@ $adState = Get-MtADDomainState -Categories @('Computers') Write-Verbose "Retrieved AD state" - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } + if ($null -eq $adState) { throw 'Computer inventory is required to assess stale accounts.' } Write-Verbose "Filtering/counting computer stale enabled count" $computers = $adState.Computers - if ($null -eq $computers) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } + if ($null -eq $computers) { throw 'Computer inventory is required to assess stale accounts.' } + if (@($computers).Count -eq 0) { throw 'Computer inventory is empty; stale accounts cannot be assessed.' } $staleThreshold = (Get-Date).AddDays(-$MaximumInactiveDays) # Find enabled computers that haven't logged on for the configured threshold or more. @@ -105,7 +100,9 @@ $sortedStale = $staleEnabledComputers | Sort-Object -Property lastLogonDate | Select-Object -First 10 foreach ($comp in $sortedStale) { $lastLogon = if ($comp.lastLogonDate) { $comp.lastLogonDate.ToString('yyyy-MM-dd') } else { 'Never' } - $result += "| $($comp.Name) | $lastLogon | $($comp.operatingSystem) |" + "`n" + $name = [string]$comp.Name -replace '\|', '\|' -replace '[\r\n]', ' ' + $os = [string]$comp.OperatingSystem -replace '\|', '\|' -replace '[\r\n]', ' ' + $result += "| $name | $lastLogon | $os |" + "`n" } if ($staleCount -gt 10) { @@ -126,6 +123,6 @@ $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result Add-MtTestResultDetail -Result $testResultMarkdown -Investigate Write-Verbose "Completed Test-MtAdComputerStaleEnabledCount" - return $null + return $false } } diff --git a/tests/ad/security/Test.AD-DCOMP-07.md b/tests/ad/security/Test.AD-DCOMP-07.md index 0177ee703d..2b8a816c7b 100644 --- a/tests/ad/security/Test.AD-DCOMP-07.md +++ b/tests/ad/security/Test.AD-DCOMP-07.md @@ -44,7 +44,7 @@ This test counts computers with and without the `dNSHostName` attribute populate #### Related Tests - `Test-MtAdComputerDnsZoneCount` - DNS zone distribution -- `Test-MtAdComputerDnsZoneDetails` - Detailed DNS zone analysis +- `AD-DCOMP-08` - DNS suffix distribution and per-zone computer counts - `Test-MtAdComputerSpnSetCount` - SPN configuration check diff --git a/tests/ad/security/Test.AD-DCOMP-07.ps1 b/tests/ad/security/Test.AD-DCOMP-07.ps1 index 342b785915..d85ae9de82 100644 --- a/tests/ad/security/Test.AD-DCOMP-07.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-07.ps1 @@ -43,9 +43,8 @@ $adState = Get-MtADDomainState -Categories @('Computers') Write-Verbose "Retrieved AD state" - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null + if ($null -eq $adState -or $null -eq $adState.Computers) { + throw 'Computer inventory is required to review DNS host names.' } Write-Verbose "Filtering/counting computer dns host name count" @@ -78,7 +77,9 @@ $result += "| --- | --- |" + "`n" foreach ($comp in $computersWithoutDns | Select-Object -First 10) { - $result += "| $($comp.Name) | $($comp.operatingSystem) |" + "`n" + $name = [string]$comp.Name -replace '\|', '\|' -replace '[\r\n]', ' ' + $os = [string]$comp.OperatingSystem -replace '\|', '\|' -replace '[\r\n]', ' ' + $result += "| $name | $os |`n" } if ($withoutDnsCount -gt 10) { diff --git a/tests/ad/security/Test.AD-DCOMP-08.md b/tests/ad/security/Test.AD-DCOMP-08.md index 4ed9d289bf..a5a666b65a 100644 --- a/tests/ad/security/Test.AD-DCOMP-08.md +++ b/tests/ad/security/Test.AD-DCOMP-08.md @@ -43,7 +43,7 @@ This test extracts DNS zones from computer `dNSHostName` attributes and: #### Related Tests - `Test-MtAdComputerDnsHostNameCount` - DNS host name coverage -- `Test-MtAdComputerDnsZoneDetails` - Detailed zone breakdown +- Zone counts and percentages are shown in this check; host names with no DNS suffix are counted separately. - `Test-MtAdDnsZoneCount` - DNS server zone analysis diff --git a/tests/ad/security/Test.AD-DCOMP-08.ps1 b/tests/ad/security/Test.AD-DCOMP-08.ps1 index c27dcb2e34..becce97ea5 100644 --- a/tests/ad/security/Test.AD-DCOMP-08.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-08.ps1 @@ -43,30 +43,17 @@ $adState = Get-MtADDomainState -Categories @('Computers') Write-Verbose "Retrieved AD state" - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null + if ($null -eq $adState -or $null -eq $adState.Computers) { + throw 'Computer inventory is required to review DNS zones.' } Write-Verbose "Filtering/counting computer dns zone count" $computers = $adState.Computers - # Extract DNS zones from dNSHostName - $dnsZones = @() - foreach ($computer in $computers) { - if ($computer.dNSHostName) { - $dnsName = $computer.dNSHostName.ToString() - # Extract zone (everything after first dot) - if ($dnsName -match '\.') { - $zone = $dnsName.Substring($dnsName.IndexOf('.') + 1) - if ($zone -and $dnsZones -notcontains $zone) { - $dnsZones += $zone - } - } - } - } - - $zoneCount = $dnsZones.Count + # A host name without a suffix is not a DNS zone; report it separately. + $zoneGroups = @($computers | Where-Object { $_.dNSHostName -match '^[^.]+\..+' } | + Group-Object -Property { $_.dNSHostName.Substring($_.dNSHostName.IndexOf('.') + 1).TrimEnd('.').ToLowerInvariant() }) + $zoneCount = $zoneGroups.Count $computersWithDns = ($computers | Where-Object { $_.dNSHostName } | Measure-Object).Count $totalComputers = ($computers | Measure-Object).Count @@ -77,14 +64,17 @@ $result += "| Total Computers | $totalComputers |" + "`n" $result += "| Computers with DNS Host Name | $computersWithDns |" + "`n" $result += "| Unique DNS Zones | $zoneCount |" + "`n" + $result += "| Computers without DNS Host Name | $(@($computers | Where-Object { -not $_.dNSHostName }).Count) |`n" + $result += "| Host Names without DNS Suffix | $(@($computers | Where-Object { $_.dNSHostName -and $_.dNSHostName -notmatch '^[^.]+\..+' }).Count) |`n" if ($zoneCount -gt 0) { $result += "`n**DNS Zones in Use:**" + "`n" + "`n" - $result += "| DNS Zone |" + "`n" - $result += "| --- |" + "`n" + $result += "| DNS Zone | Computer Count | Percentage of Hosts with Zone |`n| --- | --- | --- |`n" - foreach ($zone in ($dnsZones | Sort-Object)) { - $result += "| $zone |" + "`n" + foreach ($group in ($zoneGroups | Sort-Object -Property Count -Descending)) { + $zone = [string]$group.Name -replace '\|', '\|' -replace '[\r\n]', ' ' + $percentage = [Math]::Round(100 * $group.Count / @($computers | Where-Object { $_.dNSHostName -match '^[^.]+\..+' }).Count, 2) + $result += "| $zone | $($group.Count) | $percentage% |`n" } } Write-Verbose "Counts computed" diff --git a/tests/ad/security/Test.AD-DCOMP-09.md b/tests/ad/security/Test.AD-DCOMP-09.md deleted file mode 100644 index 80dc50f15b..0000000000 --- a/tests/ad/security/Test.AD-DCOMP-09.md +++ /dev/null @@ -1,51 +0,0 @@ -- Detailed analysis of DNS zone distribution provides visibility into Active Directory topology and helps identify potential configuration issues or security concerns related to DNS. - -**Security and Operational Value:** -- **Topology Mapping**: Understand how computers are distributed across DNS domains -- **Disjoint Namespace Detection**: Identify computers in unexpected DNS zones -- **Configuration Validation**: Verify computers are in appropriate zones -- **Compliance Verification**: Ensure DNS configuration meets organizational standards - -**Potential Issues Identified:** -- Computers in incorrect DNS zones -- Disjoint namespace misconfigurations -- Orphaned computer accounts -- DNS registration failures - -#### Control Type - -**Operational** - -#### Security Recommendation - -1. **Zone Assignment Review**: - - Verify computers are in appropriate DNS zones - - Investigate computers in unexpected zones - - Document legitimate multi-zone scenarios - -2. **DNS Configuration Audit**: - - Regular review of DNS zone configuration - - Validate DNS delegation settings - - Check for stale or orphaned records - -3. **Remediation**: - - Move computers to correct zones if misconfigured - - Delete stale computer accounts - - Fix DNS registration issues - -#### How the Test Works - -This test provides detailed analysis: -- Breakdown of computers by DNS zone -- Counts per zone with percentages -- List of computers without DNS host names -- Distribution statistics - -#### Related Tests - -- `Test-MtAdComputerDnsZoneCount` - DNS zone count summary -- `Test-MtAdComputerDnsHostNameCount` - DNS host name coverage -- `Test-MtAdAllowedDnsSuffixesCount` - DNS suffix configuration - - -%TestResult% diff --git a/tests/ad/security/Test.AD-DCOMP-09.ps1 b/tests/ad/security/Test.AD-DCOMP-09.ps1 deleted file mode 100644 index ced5f6dc65..0000000000 --- a/tests/ad/security/Test.AD-DCOMP-09.ps1 +++ /dev/null @@ -1,122 +0,0 @@ -function Test-MtAdComputerDnsZoneDetails { - <# - .SYNOPSIS - Provides detailed breakdown of computers by DNS zone. - - .DESCRIPTION - This test provides a comprehensive view of how computers are distributed - across DNS zones in the domain. This helps identify disjoint namespaces, - multi-domain scenarios, and potential DNS configuration issues. - - Security Value: - - Identifies computers in unexpected DNS zones - - Supports disjoint namespace assessment - - Helps detect DNS misconfigurations - - Important for Kerberos realm configuration - - .EXAMPLE - Test-MtAdComputerDnsZoneDetails - - Returns $true if computer data is accessible. - - .LINK - https://maester.dev/docs/commands/Test-MtAdComputerDnsZoneDetails - #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseSingularNouns', '', Justification = 'Clarity in using plural')] - [MaesterTest( - Id = 'AD-DCOMP-09', - Title = 'Computer DNS zone details should be investigated', - Product = 'ad', - Feature = 'computers', - Area = 'infrastructure', - ResourceType = 'DnsZone', - Severity = 'Info', - Mitre = 'None', - Service = 'ActiveDirectory', - Permission = ('ActiveDirectory:Ldap:computer:ReadProperty'), - Author = 'soulemike' - )] - [CmdletBinding()] - [OutputType([bool])] - param() - - Write-Verbose "Starting Test-MtAdComputerDnsZoneDetails" - $adState = Get-MtADDomainState -Categories @('Computers') - Write-Verbose "Retrieved AD state" - - if ($null -eq $adState) { - Add-MtTestResultDetail -SkippedBecause NotConnectedActiveDirectory - return $null - } - Write-Verbose "Filtering/counting computer dns zone details" - - $computers = $adState.Computers - - # Group computers by DNS zone - $zoneGroups = $computers | Where-Object { $_.dNSHostName } | ForEach-Object { - $dnsName = $_.dNSHostName.ToString() - if ($dnsName -match '\.') { - $zone = $dnsName.Substring($dnsName.IndexOf('.') + 1) - [PSCustomObject]@{ - Computer = $_ - Zone = $zone - } - } else { - [PSCustomObject]@{ - Computer = $_ - Zone = "(No Zone)" - } - } - } | Group-Object -Property Zone - - $computersWithDns = ($computers | Where-Object { $_.dNSHostName } | Measure-Object).Count - $totalComputers = ($computers | Measure-Object).Count - $zoneCount = ($zoneGroups | Measure-Object).Count - - $testResult = $true - - $result = "| Metric | Value |" + "`n" - $result += "| --- | --- |" + "`n" - $result += "| Total Computers | $totalComputers |" + "`n" - $result += "| Computers with DNS Host Name | $computersWithDns |" + "`n" - $result += "| Unique DNS Zones | $zoneCount |" + "`n" - - if ($zoneCount -gt 0) { - $result += "`n**Computers by DNS Zone:**" + "`n" + "`n" - $result += "| DNS Zone | Computer Count | Percentage |" + "`n" - $result += "| --- | --- | --- |" + "`n" - - $sortedGroups = $zoneGroups | Sort-Object -Property Count -Descending - foreach ($group in $sortedGroups) { - $percentage = if ($computersWithDns -gt 0) { [Math]::Round(($group.Count / $computersWithDns) * 100, 2) } else { 0 } - $result += "| $($group.Name) | $($group.Count) | $percentage% |" + "`n" - } - } - - # List computers without DNS host name - $computersWithoutDns = $computers | Where-Object { -not $_.dNSHostName } - $withoutDnsCount = ($computersWithoutDns | Measure-Object).Count - - if ($withoutDnsCount -gt 0) { - $result += "`n**Computers without DNS Host Name:** $withoutDnsCount**" + "`n" + "`n" - $result += "| Computer Name | Operating System |" + "`n" - $result += "| --- | --- |" + "`n" - - foreach ($comp in $computersWithoutDns | Select-Object -First 10) { - $result += "| $($comp.Name) | $($comp.operatingSystem) |" + "`n" - } - - if ($withoutDnsCount -gt 10) { - $result += "| ... and $($withoutDnsCount - 10) more | |" + "`n" - } - } - Write-Verbose "Counts computed" - - $testResultMarkdown = "Detailed DNS zone distribution has been analyzed.`n`n%TestResult%" - $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result - - Add-MtTestResultDetail -Result $testResultMarkdown -Investigate - Write-Verbose "Completed Test-MtAdComputerDnsZoneDetails" - - return $testResult -} diff --git a/website/docs/advanced/active-directory.md b/website/docs/advanced/active-directory.md index 234ff2d34e..490376af38 100644 --- a/website/docs/advanced/active-directory.md +++ b/website/docs/advanced/active-directory.md @@ -129,18 +129,18 @@ A standard **authenticated user** (Domain User) can read most LDAP attributes on |---|---|---| | AD-GPO-01 through AD-GPO-05, AD-GPOL-01 through AD-GPOL-06, AD-GPOREP-01 through AD-GPOREP-20, AD-GPOS-01 through AD-GPOS-09 | `ActiveDirectory:File:SYSVOL:Read` | Reading files from the `\\domain\SYSVOL` share. While Authenticated Users typically receive read access to SYSVOL, this is filesystem access separate from LDAP and may be restricted in hardened environments. | -**Summary:** 80 of 270 AD tests (30%) require privileges beyond a standard authenticated user. The remaining 190 tests can run with standard Domain User LDAP read access. +**Summary:** 80 of 264 AD tests (30%) require privileges beyond a standard authenticated user. The remaining 184 tests can run with standard Domain User LDAP read access. ## Category Summary | Category | Tests | Required permissions | |---|---|---| | `cfg` | AD-CFG-01 through AD-CFG-24 | `ActiveDirectory:Ldap:Configuration/*:ReadProperty` | -| `comp` | AD-COMP-01 through AD-COMP-10 | `ActiveDirectory:Ldap:computer:ReadProperty` | +| `comp` | AD-COMP-01, AD-COMP-03 through AD-COMP-08 | `ActiveDirectory:Ldap:computer:ReadProperty`; COMP-04 also needs `ActiveDirectory:Ldap:nTDSDSA:ReadProperty` | | `dacl` | AD-DACL-01 through AD-DACL-18 | `ActiveDirectory:Ldap:*.ntSecurityDescriptor:ReadControl` | | `dc` | AD-DC-01 through AD-DC-08 | `ActiveDirectory:Ldap:nTDSDSA:ReadProperty`; AD-DC-02 through AD-DC-04 also need `ActiveDirectory:Cim:root\Microsoft\Windows\SMB:MSFT_SmbServerConfiguration:Read` and `ActiveDirectory:Remoting:Microsoft.PowerShell` | | `dcd` | AD-DCD-01 through AD-DCD-04 | `ActiveDirectory:Ldap:nTDSDSA:ReadProperty` | -| `dcomp` | AD-DCOMP-01 through AD-DCOMP-09 | `ActiveDirectory:Ldap:computer:ReadProperty` | +| `dcomp` | AD-DCOMP-01, AD-DCOMP-03, AD-DCOMP-04, AD-DCOMP-06 through AD-DCOMP-08 | `ActiveDirectory:Ldap:computer:ReadProperty`; DCOMP-01/03 also read `nTDSDSA` and the three managed service account classes | | `dfsr` | AD-DFSR-01 | `ActiveDirectory:Ldap:domainDNS.distinguishedName:ReadProperty` | | `dns` | AD-DNS-01 through AD-DNS-19 | `ActiveDirectory:Cim:root\MicrosoftDNS:MicrosoftDNS_Zone:Read`, `ActiveDirectory:Remoting:Microsoft.PowerShell` | | `dom` | AD-DOM-01 through AD-DOM-08 | `ActiveDirectory:Ldap:domainDNS:ReadProperty` | From b22c2f36bbb85a02751620559a222d8bb0ce9295 Mon Sep 17 00:00:00 2001 From: Snozz-Al Date: Sat, 21 Nov 2026 17:07:08 +0000 Subject: [PATCH 2/4] fix(ad): clarify computer check references and hide empty findings --- .../functions/ADComputerChecks.Tests.ps1 | 3 +++ tests/ad/computer/Test.AD-COMP-01.md | 4 +-- tests/ad/computer/Test.AD-COMP-01.ps1 | 2 +- tests/ad/computer/Test.AD-COMP-03.md | 4 +-- tests/ad/computer/Test.AD-COMP-03.ps1 | 2 +- tests/ad/computer/Test.AD-COMP-04.md | 4 +-- tests/ad/computer/Test.AD-COMP-04.ps1 | 15 ++++++----- tests/ad/computer/Test.AD-COMP-05.md | 4 +-- tests/ad/computer/Test.AD-COMP-05.ps1 | 2 +- tests/ad/computer/Test.AD-COMP-06.md | 4 +-- tests/ad/computer/Test.AD-COMP-06.ps1 | 2 +- tests/ad/computer/Test.AD-COMP-07.md | 4 +-- tests/ad/computer/Test.AD-COMP-07.ps1 | 2 +- tests/ad/computer/Test.AD-COMP-08.md | 4 +-- tests/ad/computer/Test.AD-COMP-08.ps1 | 2 +- tests/ad/security/Test.AD-DCOMP-01.md | 6 ++--- tests/ad/security/Test.AD-DCOMP-01.ps1 | 4 +-- tests/ad/security/Test.AD-DCOMP-03.md | 4 +-- tests/ad/security/Test.AD-DCOMP-03.ps1 | 2 +- tests/ad/security/Test.AD-DCOMP-04.md | 4 +-- tests/ad/security/Test.AD-DCOMP-04.ps1 | 2 +- tests/ad/security/Test.AD-DCOMP-06.md | 26 ++++++++++++++++--- tests/ad/security/Test.AD-DCOMP-06.ps1 | 2 +- tests/ad/security/Test.AD-DCOMP-07.md | 5 ++-- tests/ad/security/Test.AD-DCOMP-07.ps1 | 2 +- tests/ad/security/Test.AD-DCOMP-08.md | 6 ++--- tests/ad/security/Test.AD-DCOMP-08.ps1 | 2 +- 27 files changed, 73 insertions(+), 50 deletions(-) diff --git a/powershell/tests/functions/ADComputerChecks.Tests.ps1 b/powershell/tests/functions/ADComputerChecks.Tests.ps1 index 51ae5bdc04..1beee75153 100644 --- a/powershell/tests/functions/ADComputerChecks.Tests.ps1 +++ b/powershell/tests/functions/ADComputerChecks.Tests.ps1 @@ -65,6 +65,7 @@ Test-MtAdComputerUnconstrainedDelegationCount | Should -BeFalse $script:Details.Text | Should -BeLike '*| Non-DC Computers Claiming DC Primary Groups | 1 |*' $script:Details.Text | Should -BeLike '*| Total Non-DC Computers | 2 |*' + $script:Details.Text | Should -BeLike '*AD-COMP-04: Enabled computers should use standard primary groups*assess unexpected primary-group assignments*' } } @@ -136,9 +137,11 @@ It 'enforces primary groups using verified DC identity, not a claimed group' { Test-MtAdComputerNonStandardGroup | Should -BeTrue $script:Details.Investigate | Should -BeFalse + $script:Details.Text | Should -Not -Match '\| Computer \| Primary group \| Distinguished name \|' foreach ($group in 516, 521) { $script:AdComputerState.Computers[2].PrimaryGroupId = $group Test-MtAdComputerNonStandardGroup | Should -BeFalse + $script:Details.Text | Should -Match '\| Computer \| Primary group \| Distinguished name \|' $script:Details.Text | Should -Match 'client' } } diff --git a/tests/ad/computer/Test.AD-COMP-01.md b/tests/ad/computer/Test.AD-COMP-01.md index a97f2a4a1c..6f166c6e3e 100644 --- a/tests/ad/computer/Test.AD-COMP-01.md +++ b/tests/ad/computer/Test.AD-COMP-01.md @@ -24,8 +24,8 @@ The test returns informational results to help you assess the scope of disabled #### Related Tests -- `AD-DCOMP-06` - Identifies enabled computers that haven't logged on recently -- `Test-MtAdComputerInDefaultContainer` - Finds computers in the default container (another hygiene indicator) +- [AD-DCOMP-06 — No enabled computers should be stale beyond the configured threshold](https://maester.dev/docs/tests/AD-DCOMP-06): Complements this disabled-account count by identifying enabled computer accounts that have not logged on recently. +- [AD-COMP-06 — Enabled computers should be moved out of the default Computers container](https://maester.dev/docs/tests/AD-COMP-06): Adds context on computer-account hygiene by identifying enabled computers left in the default container. %TestResult% diff --git a/tests/ad/computer/Test.AD-COMP-01.ps1 b/tests/ad/computer/Test.AD-COMP-01.ps1 index 09e164eeec..2f242576a8 100644 --- a/tests/ad/computer/Test.AD-COMP-01.ps1 +++ b/tests/ad/computer/Test.AD-COMP-01.ps1 @@ -15,7 +15,7 @@ The test result includes counts of disabled and total computers. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerDisabledCount + https://maester.dev/docs/tests/AD-COMP-01 #> [MaesterTest( Id = 'AD-COMP-01', diff --git a/tests/ad/computer/Test.AD-COMP-03.md b/tests/ad/computer/Test.AD-COMP-03.md index 259240ee1c..6523de1215 100644 --- a/tests/ad/computer/Test.AD-COMP-03.md +++ b/tests/ad/computer/Test.AD-COMP-03.md @@ -27,8 +27,8 @@ Note: Not all computer accounts will have this attribute, depending on how they #### Related Tests -- `Test-MtAdComputerNonStandardGroup` - Identifies computers with unusual primary group assignments -- `Test-MtAdComputerInDefaultContainer` - Finds computers that may have been auto-created +- [AD-COMP-04 — Enabled computers should use standard primary groups](https://maester.dev/docs/tests/AD-COMP-04): Reviews a separate computer-account attribute that can reveal unexpected configuration. +- [AD-COMP-06 — Enabled computers should be moved out of the default Computers container](https://maester.dev/docs/tests/AD-COMP-06): Identifies computers left in the default container, which can provide context when reviewing how accounts were provisioned. %TestResult% diff --git a/tests/ad/computer/Test.AD-COMP-03.ps1 b/tests/ad/computer/Test.AD-COMP-03.ps1 index bf42b360b7..8ab623409d 100644 --- a/tests/ad/computer/Test.AD-COMP-03.ps1 +++ b/tests/ad/computer/Test.AD-COMP-03.ps1 @@ -15,7 +15,7 @@ The test result includes the count of computers with CreatorSid set. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerCreatorSidCount + https://maester.dev/docs/tests/AD-COMP-03 #> [MaesterTest( Id = 'AD-COMP-03', diff --git a/tests/ad/computer/Test.AD-COMP-04.md b/tests/ad/computer/Test.AD-COMP-04.md index b48a0d61f4..46d6ac4de2 100644 --- a/tests/ad/computer/Test.AD-COMP-04.md +++ b/tests/ad/computer/Test.AD-COMP-04.md @@ -27,8 +27,8 @@ This test examines the `primaryGroupId` attribute of all enabled computer accoun #### Related Tests -- `Test-MtAdComputerSidHistoryCount` - Identifies computers with migration artifacts -- `Test-MtAdComputerOUCount` - Shows the distribution of computers across OUs +- [AD-COMP-05 — Computer SID History count should be retrievable](https://maester.dev/docs/tests/AD-COMP-05): Reviews SID History as a separate computer-account security attribute. +- [AD-COMP-07 — Computer OU count should be retrievable](https://maester.dev/docs/tests/AD-COMP-07): Shows where enabled computers are organized, complementing this check of their primary-group assignments. %TestResult% diff --git a/tests/ad/computer/Test.AD-COMP-04.ps1 b/tests/ad/computer/Test.AD-COMP-04.ps1 index a8088994e6..f7aaeb2e36 100644 --- a/tests/ad/computer/Test.AD-COMP-04.ps1 +++ b/tests/ad/computer/Test.AD-COMP-04.ps1 @@ -21,7 +21,7 @@ The test result includes the count of computers with non-standard primary groups. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerNonStandardGroup + https://maester.dev/docs/tests/AD-COMP-04 #> [MaesterTest( Id = 'AD-COMP-04', @@ -92,11 +92,14 @@ $result += "| Non-Standard Primary Group | $nonStandardCount |" + "`n" $result += "| Non-Standard Percentage | $percentage% |" + "`n" + "`n" $result += "**Standard Primary Group IDs:** 515 (Domain Computers), 516 (Domain Controllers), 521 (Read-only Domain Controllers)" + "`n" + "`n" - $result += "DC groups are accepted only for accounts verified in the DC inventory.`n`n| Computer | Primary group | Distinguished name |`n| --- | --- | --- |`n" - foreach ($computer in $nonStandardGroupComputers) { - $name = ([string]$computer.Name).Replace('|', '|') -replace '[\r\n]+', ' ' - $dn = ([string]$computer.DistinguishedName).Replace('|', '|') -replace '[\r\n]+', ' ' - $result += "| $name | $($computer.PrimaryGroupId) | $dn |`n" + $result += "DC groups are accepted only for accounts verified in the DC inventory.`n" + if ($nonStandardCount -gt 0) { + $result += "`n| Computer | Primary group | Distinguished name |`n| --- | --- | --- |`n" + foreach ($computer in $nonStandardGroupComputers) { + $name = ([string]$computer.Name).Replace('|', '|') -replace '[\r\n]+', ' ' + $dn = ([string]$computer.DistinguishedName).Replace('|', '|') -replace '[\r\n]+', ' ' + $result += "| $name | $($computer.PrimaryGroupId) | $dn |`n" + } } $testResultMarkdown = "Active Directory computer objects have been analyzed. $nonStandardCount out of $enabledCount enabled computers ($percentage%) have non-standard primary group IDs.`n`n%TestResult%" diff --git a/tests/ad/computer/Test.AD-COMP-05.md b/tests/ad/computer/Test.AD-COMP-05.md index 25830e2cd8..6ccafae403 100644 --- a/tests/ad/computer/Test.AD-COMP-05.md +++ b/tests/ad/computer/Test.AD-COMP-05.md @@ -22,8 +22,8 @@ This test counts computer objects where the `SIDHistory` attribute is populated. #### Related Tests -- `Test-MtAdComputerNonStandardGroup` - Identifies other migration or configuration anomalies -- `AD-DCOMP-06` - Finds stale accounts that may be migration remnants +- [AD-COMP-04 — Enabled computers should use standard primary groups](https://maester.dev/docs/tests/AD-COMP-04): Reviews primary-group assignments as a separate computer-account configuration check. +- [AD-DCOMP-06 — No enabled computers should be stale beyond the configured threshold](https://maester.dev/docs/tests/AD-DCOMP-06): Identifies stale enabled accounts that may warrant lifecycle review, including possible migration remnants. #### Related links diff --git a/tests/ad/computer/Test.AD-COMP-05.ps1 b/tests/ad/computer/Test.AD-COMP-05.ps1 index 066c82421f..cd995562b3 100644 --- a/tests/ad/computer/Test.AD-COMP-05.ps1 +++ b/tests/ad/computer/Test.AD-COMP-05.ps1 @@ -18,7 +18,7 @@ The test result includes the count of computers with SID History. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerSidHistoryCount + https://maester.dev/docs/tests/AD-COMP-05 #> [MaesterTest( Id = 'AD-COMP-05', diff --git a/tests/ad/computer/Test.AD-COMP-06.md b/tests/ad/computer/Test.AD-COMP-06.md index 28a82902aa..07c6beafee 100644 --- a/tests/ad/computer/Test.AD-COMP-06.md +++ b/tests/ad/computer/Test.AD-COMP-06.md @@ -25,8 +25,8 @@ This test fails when an enabled computer is an immediate child of the domain's d #### Related Tests -- `Test-MtAdComputerOUCount` - Shows the distribution of computers across OUs -- `Test-MtAdComputerPerOUAverage` - Analyzes OU structure effectiveness +- [AD-COMP-07 — Computer OU count should be retrievable](https://maester.dev/docs/tests/AD-COMP-07): Counts containers with enabled computers, giving broader context for this check of the default container. +- [AD-COMP-08 — Computer per OU average should be retrievable](https://maester.dev/docs/tests/AD-COMP-08): Shows computer distribution across containers and complements this check for computers in the default container. %TestResult% diff --git a/tests/ad/computer/Test.AD-COMP-06.ps1 b/tests/ad/computer/Test.AD-COMP-06.ps1 index 6a1e721715..8fee637a8a 100644 --- a/tests/ad/computer/Test.AD-COMP-06.ps1 +++ b/tests/ad/computer/Test.AD-COMP-06.ps1 @@ -19,7 +19,7 @@ The test result includes the count of computers in the default Computers container. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerInDefaultContainer + https://maester.dev/docs/tests/AD-COMP-06 #> [MaesterTest( Id = 'AD-COMP-06', diff --git a/tests/ad/computer/Test.AD-COMP-07.md b/tests/ad/computer/Test.AD-COMP-07.md index 05b426548e..c101ffac9b 100644 --- a/tests/ad/computer/Test.AD-COMP-07.md +++ b/tests/ad/computer/Test.AD-COMP-07.md @@ -27,8 +27,8 @@ This test analyzes all enabled computer accounts and counts the distinct organiz #### Related Tests -- `Test-MtAdComputerPerOUAverage` - Calculates the average computers per OU -- `Test-MtAdComputerInDefaultContainer` - Identifies computers in the unmanaged default container +- [AD-COMP-08 — Computer per OU average should be retrievable](https://maester.dev/docs/tests/AD-COMP-08): Measures computer density across containers, complementing this count of containers in use. +- [AD-COMP-06 — Enabled computers should be moved out of the default Computers container](https://maester.dev/docs/tests/AD-COMP-06): Identifies enabled computers in the default container, one specific placement issue within the broader OU inventory. %TestResult% diff --git a/tests/ad/computer/Test.AD-COMP-07.ps1 b/tests/ad/computer/Test.AD-COMP-07.ps1 index 8e20c0381e..12665141fc 100644 --- a/tests/ad/computer/Test.AD-COMP-07.ps1 +++ b/tests/ad/computer/Test.AD-COMP-07.ps1 @@ -17,7 +17,7 @@ The test result includes the count of distinct OUs with computers. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerOUCount + https://maester.dev/docs/tests/AD-COMP-07 #> [MaesterTest( Id = 'AD-COMP-07', diff --git a/tests/ad/computer/Test.AD-COMP-08.md b/tests/ad/computer/Test.AD-COMP-08.md index 21993583fd..296c33ca63 100644 --- a/tests/ad/computer/Test.AD-COMP-08.md +++ b/tests/ad/computer/Test.AD-COMP-08.md @@ -31,8 +31,8 @@ This test groups all enabled computers by their parent container and calculates: #### Related Tests -- `Test-MtAdComputerOUCount` - Counts the total number of OUs with computers -- `Test-MtAdComputerInDefaultContainer` - Identifies potential OU structure gaps +- [AD-COMP-07 — Computer OU count should be retrievable](https://maester.dev/docs/tests/AD-COMP-07): Counts containers with computers and complements this check's average, minimum, and maximum distribution measures. +- [AD-COMP-06 — Enabled computers should be moved out of the default Computers container](https://maester.dev/docs/tests/AD-COMP-06): Identifies enabled computers in the default container, a specific placement issue that can inform review of the overall distribution. %TestResult% diff --git a/tests/ad/computer/Test.AD-COMP-08.ps1 b/tests/ad/computer/Test.AD-COMP-08.ps1 index 47de9a4e66..0f47a45a51 100644 --- a/tests/ad/computer/Test.AD-COMP-08.ps1 +++ b/tests/ad/computer/Test.AD-COMP-08.ps1 @@ -16,7 +16,7 @@ The test result includes the average computers per OU and distribution details. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerPerOUAverage + https://maester.dev/docs/tests/AD-COMP-08 #> [MaesterTest( Id = 'AD-COMP-08', diff --git a/tests/ad/security/Test.AD-DCOMP-01.md b/tests/ad/security/Test.AD-DCOMP-01.md index 5a276bc10a..cf19a2bb03 100644 --- a/tests/ad/security/Test.AD-DCOMP-01.md +++ b/tests/ad/security/Test.AD-DCOMP-01.md @@ -1,6 +1,6 @@ Unconstrained delegation on non-domain-controller computers or managed service accounts exposes users' Kerberos tickets. This check fails when a non-DC computer, sMSA, gMSA or dMSA has the `TrustedForDelegation` flag. Managed accounts are reported separately; the device percentage still uses only non-DC computers as its denominator. -Only the collected DC server inventory establishes DC identity: `serverReference` DN, or DNS fallback when that reference is unavailable. Primary groups 516 and 521 alone never exclude a computer. Unexpected DC primary-group claims are counted for review under AD-COMP-04. +Only the collected DC server inventory establishes DC identity: `serverReference` DN, or DNS fallback when that reference is unavailable. Primary groups 516 and 521 alone never exclude a computer. Unexpected DC primary-group claims are counted for review by [AD-COMP-04 — Enabled computers should use standard primary groups](https://maester.dev/docs/tests/AD-COMP-04), which flags non-DC computers claiming a DC primary group. **Security Risks:** - **Complete Impersonation**: Attackers can impersonate any user who authenticates to the computer @@ -38,8 +38,8 @@ This test counts accounts with the `TrustedForDelegation` flag enabled and repor #### Related Tests -- `AD-DCOMP-03` - Reviews KCD, protocol transition and RBCD descriptor presence on non-DC computers and managed accounts -- `Test-MtAdUserDelegationConfiguredCount` - Reviews user account delegation +- [AD-DCOMP-03 — Non-DC computer and managed account constrained delegation should be investigated](https://maester.dev/docs/tests/AD-DCOMP-03): Reviews constrained delegation indicators on non-DC computers and managed accounts, distinct from this check of unconstrained delegation. +- [AD-USER-28 — User delegation configured count should be investigated](https://maester.dev/docs/tests/AD-USER-28): Reviews delegation settings on user accounts, which this computer and managed-account check does not cover. #### Related links diff --git a/tests/ad/security/Test.AD-DCOMP-01.ps1 b/tests/ad/security/Test.AD-DCOMP-01.ps1 index d2388419fe..b9d9fc6e5f 100644 --- a/tests/ad/security/Test.AD-DCOMP-01.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-01.ps1 @@ -21,7 +21,7 @@ Returns $true if computer data is accessible. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerUnconstrainedDelegationCount + https://maester.dev/docs/tests/AD-DCOMP-01 #> [MaesterTest( Id = 'AD-DCOMP-01', @@ -110,7 +110,7 @@ Write-Verbose "Counts computed" $summary = if ($testResult) { 'Well done. No non-DC computers or managed service accounts have unconstrained delegation.' } else { 'Non-DC computers or managed service accounts with unconstrained delegation were found. Migrate their services to constrained delegation and remove unconstrained delegation.' } - if ($unverifiedDcGroups.Count -gt 0) { $summary += " $($unverifiedDcGroups.Count) computer(s) claim a DC primary group without inventory evidence; review AD-COMP-04. They were not excluded." } + if ($unverifiedDcGroups.Count -gt 0) { $summary += " $($unverifiedDcGroups.Count) computer(s) claim a DC primary group without inventory evidence; review [AD-COMP-04: Enabled computers should use standard primary groups](https://maester.dev/docs/tests/AD-COMP-04) to assess unexpected primary-group assignments. They were not excluded." } $testResultMarkdown = "$summary`n`n%TestResult%" $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result diff --git a/tests/ad/security/Test.AD-DCOMP-03.md b/tests/ad/security/Test.AD-DCOMP-03.md index f8a47dac79..ad1a771c92 100644 --- a/tests/ad/security/Test.AD-DCOMP-03.md +++ b/tests/ad/security/Test.AD-DCOMP-03.md @@ -35,8 +35,8 @@ The test reports device and managed-account populations separately, then combine #### Related Tests -- `Test-MtAdComputerUnconstrainedDelegationCount` - Overall unconstrained delegation -- `Test-MtAdUserDelegationConfiguredCount` - User account delegation settings +- [AD-DCOMP-01 — Non-DC computers and managed service accounts should not have unconstrained delegation](https://maester.dev/docs/tests/AD-DCOMP-01): Checks the distinct risk of unconstrained delegation on non-DC computers and managed accounts. +- [AD-USER-28 — User delegation configured count should be investigated](https://maester.dev/docs/tests/AD-USER-28): Covers delegation settings on user accounts, outside this check's computer and managed-account inventory. #### Related links diff --git a/tests/ad/security/Test.AD-DCOMP-03.ps1 b/tests/ad/security/Test.AD-DCOMP-03.ps1 index 21c3245947..943dff9e92 100644 --- a/tests/ad/security/Test.AD-DCOMP-03.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-03.ps1 @@ -22,7 +22,7 @@ Reports an Investigate inventory when the required computer fields are available. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerNonDcConstrainedDelegationCount + https://maester.dev/docs/tests/AD-DCOMP-03 #> [MaesterTest( Id = 'AD-DCOMP-03', diff --git a/tests/ad/security/Test.AD-DCOMP-04.md b/tests/ad/security/Test.AD-DCOMP-04.md index 766ee6bbed..138b0d2e30 100644 --- a/tests/ad/security/Test.AD-DCOMP-04.md +++ b/tests/ad/security/Test.AD-DCOMP-04.md @@ -43,8 +43,8 @@ OS service pack and patch state are not available in the current collector. This #### Related Tests -- `Test-MtAdComputerStaleEnabledCount` - Identifies stale computer accounts -- `Test-MtAdDcOperatingSystemDetails` - Domain Controller OS distribution +- [AD-DCOMP-06 — No enabled computers should be stale beyond the configured threshold](https://maester.dev/docs/tests/AD-DCOMP-06): Identifies enabled computer accounts with old or missing logon data for lifecycle review alongside this OS inventory. +- [AD-DC-08 — DC operating system details should be retrievable](https://maester.dev/docs/tests/AD-DC-08): Provides OS details specifically for domain controllers, whereas this check inventories computers across the domain. %TestResult% diff --git a/tests/ad/security/Test.AD-DCOMP-04.ps1 b/tests/ad/security/Test.AD-DCOMP-04.ps1 index cff3a7df95..2aa65375ee 100644 --- a/tests/ad/security/Test.AD-DCOMP-04.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-04.ps1 @@ -20,7 +20,7 @@ Returns $true if computer data is accessible. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerOperatingSystemCount + https://maester.dev/docs/tests/AD-DCOMP-04 #> [MaesterTest( Id = 'AD-DCOMP-04', diff --git a/tests/ad/security/Test.AD-DCOMP-06.md b/tests/ad/security/Test.AD-DCOMP-06.md index f02a5710c4..027db4b091 100644 --- a/tests/ad/security/Test.AD-DCOMP-06.md +++ b/tests/ad/security/Test.AD-DCOMP-06.md @@ -42,13 +42,31 @@ This test identifies enabled computers that: Provides counts and lists affected computers. -AD-COMP-02 is consolidated into this check. Its former default was 90 days; set `MaximumInactiveDays` to `90` on AD-DCOMP-06 to retain that threshold. The canonical default remains 180 days. +The retired **AD-COMP-02 — Computer dormant count should be retrievable** is consolidated into [AD-DCOMP-06 — No enabled computers should be stale beyond the configured threshold](https://maester.dev/docs/tests/AD-DCOMP-06). Its former default was 90 days; set `MaximumInactiveDays` to `90` to retain that threshold. The canonical default remains 180 days. + +#### Configure the Inactivity Threshold + +The default threshold is 180 days. Set `MaximumInactiveDays` in `maester-config.json` to use another value from 1 to 3650 days. Maester reuses this test setting on `Invoke-Maester` runs. + +```json +{ + "TestSettings": [ + { + "Id": "AD-DCOMP-06", + "Parameters": { + "MaximumInactiveDays": 90 + } + } + ] +} +``` + +This check is the canonical inventory of stale enabled computer accounts. Findings return **Investigate**; a clean inventory returns **Passed**. #### Related Tests -- This is the canonical stale enabled computer inventory; findings report Investigate, while no findings return Passed. -- `Test-MtAdComputerDisabledCount` - Disabled computer analysis -- `Test-MtAdUserDormantEnabledCount` - Stale user account check +- [AD-COMP-01 — Computer disabled count should be retrievable](https://maester.dev/docs/tests/AD-COMP-01): Counts disabled computer accounts, complementing this check of enabled accounts with stale or missing logon data. +- [AD-USER-02 — Dormant enabled user count should be retrievable](https://maester.dev/docs/tests/AD-USER-02): Reviews stale enabled user accounts, a separate account population with a similar lifecycle concern. #### Related links diff --git a/tests/ad/security/Test.AD-DCOMP-06.ps1 b/tests/ad/security/Test.AD-DCOMP-06.ps1 index 2cee1dd87b..9645a52f09 100644 --- a/tests/ad/security/Test.AD-DCOMP-06.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-06.ps1 @@ -24,7 +24,7 @@ Returns the count of stale enabled computers and lists details for review. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerStaleEnabledCount + https://maester.dev/docs/tests/AD-DCOMP-06 #> [MaesterTest( Id = 'AD-DCOMP-06', diff --git a/tests/ad/security/Test.AD-DCOMP-07.md b/tests/ad/security/Test.AD-DCOMP-07.md index 2b8a816c7b..641f68ed69 100644 --- a/tests/ad/security/Test.AD-DCOMP-07.md +++ b/tests/ad/security/Test.AD-DCOMP-07.md @@ -43,9 +43,8 @@ This test counts computers with and without the `dNSHostName` attribute populate #### Related Tests -- `Test-MtAdComputerDnsZoneCount` - DNS zone distribution -- `AD-DCOMP-08` - DNS suffix distribution and per-zone computer counts -- `Test-MtAdComputerSpnSetCount` - SPN configuration check +- [AD-DCOMP-08 — Computer DNS zone count should be investigated](https://maester.dev/docs/tests/AD-DCOMP-08): Groups computer host names by DNS suffix, adding zone-level context to this check's host-name coverage count. +- [AD-SPN-01 — Computer SPN service class count should be retrievable](https://maester.dev/docs/tests/AD-SPN-01): Counts computer SPN service classes, providing a complementary view of service identities rather than checking the same DNS host-name setting. %TestResult% diff --git a/tests/ad/security/Test.AD-DCOMP-07.ps1 b/tests/ad/security/Test.AD-DCOMP-07.ps1 index d85ae9de82..1828ef79e9 100644 --- a/tests/ad/security/Test.AD-DCOMP-07.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-07.ps1 @@ -20,7 +20,7 @@ Returns $true if computer data is accessible. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerDnsHostNameCount + https://maester.dev/docs/tests/AD-DCOMP-07 #> [MaesterTest( Id = 'AD-DCOMP-07', diff --git a/tests/ad/security/Test.AD-DCOMP-08.md b/tests/ad/security/Test.AD-DCOMP-08.md index a5a666b65a..f3e148b35f 100644 --- a/tests/ad/security/Test.AD-DCOMP-08.md +++ b/tests/ad/security/Test.AD-DCOMP-08.md @@ -39,12 +39,12 @@ This test extracts DNS zones from computer `dNSHostName` attributes and: - Counts unique DNS zones - Lists all zones in use - Identifies computers without DNS host names +- Reports zone counts and percentages; host names without a DNS suffix are counted separately. #### Related Tests -- `Test-MtAdComputerDnsHostNameCount` - DNS host name coverage -- Zone counts and percentages are shown in this check; host names with no DNS suffix are counted separately. -- `Test-MtAdDnsZoneCount` - DNS server zone analysis +- [AD-DCOMP-07 — Computer DNS host name count should be investigated](https://maester.dev/docs/tests/AD-DCOMP-07): Counts computers with and without a DNS host name, complementing this check's grouping of host names by DNS suffix. +- [AD-DNS-01 — DNS zone count should be retrievable](https://maester.dev/docs/tests/AD-DNS-01): Inventories DNS server zones, a separate view from the zones inferred from computer host names in this check. %TestResult% diff --git a/tests/ad/security/Test.AD-DCOMP-08.ps1 b/tests/ad/security/Test.AD-DCOMP-08.ps1 index becce97ea5..24257456ee 100644 --- a/tests/ad/security/Test.AD-DCOMP-08.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-08.ps1 @@ -20,7 +20,7 @@ Returns $true if computer data is accessible. .LINK - https://maester.dev/docs/commands/Test-MtAdComputerDnsZoneCount + https://maester.dev/docs/tests/AD-DCOMP-08 #> [MaesterTest( Id = 'AD-DCOMP-08', From cb5a9aa48665c1074aab4288998fd7c246853c5a Mon Sep 17 00:00:00 2001 From: Michael <431932+soulemike@users.noreply.github.com> Date: Sat, 21 Nov 2026 10:21:55 -0700 Subject: [PATCH 3/4] Update tests/ad/computer/Test.AD-COMP-06.ps1 Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- tests/ad/computer/Test.AD-COMP-06.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ad/computer/Test.AD-COMP-06.ps1 b/tests/ad/computer/Test.AD-COMP-06.ps1 index 8fee637a8a..c883db5cda 100644 --- a/tests/ad/computer/Test.AD-COMP-06.ps1 +++ b/tests/ad/computer/Test.AD-COMP-06.ps1 @@ -58,7 +58,7 @@ $defaultContainerComputers = $computers | Where-Object { $_.Enabled -eq $true -and $_.DistinguishedName -and - $_.DistinguishedName -match '^CN=(?:\\.|[^,])+,CN=Computers,DC=' + $_.DistinguishedName -match '^CN=(?:\\.|[^,\\])+,CN=Computers,DC=' } $defaultContainerCount = ($defaultContainerComputers | Measure-Object).Count From 8d0a50738107c4488c35ab0bea6459e6c0aa6646 Mon Sep 17 00:00:00 2001 From: Snozz-Al Date: Sat, 21 Nov 2026 17:23:12 +0000 Subject: [PATCH 4/4] fix(ad): preserve dollar sequences in delegation result details --- powershell/tests/functions/ADComputerChecks.Tests.ps1 | 2 ++ tests/ad/security/Test.AD-DCOMP-01.ps1 | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/powershell/tests/functions/ADComputerChecks.Tests.ps1 b/powershell/tests/functions/ADComputerChecks.Tests.ps1 index 1beee75153..e7caefaa41 100644 --- a/powershell/tests/functions/ADComputerChecks.Tests.ps1 +++ b/powershell/tests/functions/ADComputerChecks.Tests.ps1 @@ -29,10 +29,12 @@ $script:Details.Investigate | Should -BeFalse $script:Details.Text | Should -BeLike '*| Non-DC Percentage with Unconstrained Delegation | 0% |*' $script:AdComputerState.Computers[1].TrustedForDelegation = $true + $script:AdComputerState.Computers[1].Name = 'app|one$$$&$1' Test-MtAdComputerUnconstrainedDelegationCount | Should -BeFalse $script:Details.Text | Should -BeLike '*| Total Non-DC Computers | 2 |*' $script:Details.Text | Should -BeLike '*| Non-DC Percentage with Unconstrained Delegation | 50% |*' $script:Details.Text | Should -Match 'app\\\|one' + $script:Details.Text | Should -BeLike '*| app\|one$$$&$1 |*' } It 'reports overlapping KCD, protocol-transition and RBCD indicators independently' { diff --git a/tests/ad/security/Test.AD-DCOMP-01.ps1 b/tests/ad/security/Test.AD-DCOMP-01.ps1 index b9d9fc6e5f..4131bdc78e 100644 --- a/tests/ad/security/Test.AD-DCOMP-01.ps1 +++ b/tests/ad/security/Test.AD-DCOMP-01.ps1 @@ -112,7 +112,7 @@ $summary = if ($testResult) { 'Well done. No non-DC computers or managed service accounts have unconstrained delegation.' } else { 'Non-DC computers or managed service accounts with unconstrained delegation were found. Migrate their services to constrained delegation and remove unconstrained delegation.' } if ($unverifiedDcGroups.Count -gt 0) { $summary += " $($unverifiedDcGroups.Count) computer(s) claim a DC primary group without inventory evidence; review [AD-COMP-04: Enabled computers should use standard primary groups](https://maester.dev/docs/tests/AD-COMP-04) to assess unexpected primary-group assignments. They were not excluded." } $testResultMarkdown = "$summary`n`n%TestResult%" - $testResultMarkdown = $testResultMarkdown -replace "%TestResult%", $result + $testResultMarkdown = $testResultMarkdown.Replace('%TestResult%', $result) Add-MtTestResultDetail -Result $testResultMarkdown Write-Verbose "Completed Test-MtAdComputerUnconstrainedDelegationCount"