From cc19499e15688881ebcbaf27bff78dc1b9047b1e Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Tue, 10 Nov 2026 15:36:39 +1300 Subject: [PATCH 01/12] feat(cisa): migrate Security Suite impersonation and alert checks 2.1-2.4 and 4.1-4.2 (Part 2) Move EXO 11.1, 11.2, 16.1 and 16.2 to SECURITYSUITE 2.1, 2.4, 4.1 and 4.2, and add 2.2 and 2.3 with an effective anti-phishing policy helper that follows ScubaGear. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Get-MtCisaEffectiveAntiPhishPolicy.ps1 | 71 ++++++++++++ ...MtCisaSecuritySuiteImpersonation.Tests.ps1 | 109 ++++++++++++++++++ .../functions/engine/Frameworks.Tests.ps1 | 8 +- .../engine/NativeLicenseGates.Tests.ps1 | 4 +- ...1.md => Test.CISA.MS.SECURITYSUITE.2.1.md} | 7 +- ...ps1 => Test.CISA.MS.SECURITYSUITE.2.1.ps1} | 28 ++--- .../Test.CISA.MS.SECURITYSUITE.2.2.md | 18 +++ .../Test.CISA.MS.SECURITYSUITE.2.2.ps1 | 65 +++++++++++ .../Test.CISA.MS.SECURITYSUITE.2.3.md | 18 +++ .../Test.CISA.MS.SECURITYSUITE.2.3.ps1 | 85 ++++++++++++++ ...2.md => Test.CISA.MS.SECURITYSUITE.2.4.md} | 4 +- ...ps1 => Test.CISA.MS.SECURITYSUITE.2.4.ps1} | 4 +- ...1.md => Test.CISA.MS.SECURITYSUITE.4.1.md} | 6 +- ...ps1 => Test.CISA.MS.SECURITYSUITE.4.1.ps1} | 6 +- ...2.md => Test.CISA.MS.SECURITYSUITE.4.2.md} | 6 +- ...ps1 => Test.CISA.MS.SECURITYSUITE.4.2.ps1} | 6 +- tests/cisa/frameworks/cisa-scuba.json | 24 ++++ 17 files changed, 431 insertions(+), 38 deletions(-) create mode 100644 powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiPhishPolicy.ps1 create mode 100644 powershell/tests/functions/Test-MtCisaSecuritySuiteImpersonation.Tests.ps1 rename tests/cisa/exchange/{Test.CISA.MS.EXO.11.1.md => Test.CISA.MS.SECURITYSUITE.2.1.md} (70%) rename tests/cisa/exchange/{Test.CISA.MS.EXO.11.1.ps1 => Test.CISA.MS.SECURITYSUITE.2.1.ps1} (61%) create mode 100644 tests/cisa/exchange/Test.CISA.MS.SECURITYSUITE.2.2.md create mode 100644 tests/cisa/exchange/Test.CISA.MS.SECURITYSUITE.2.2.ps1 create mode 100644 tests/cisa/exchange/Test.CISA.MS.SECURITYSUITE.2.3.md create mode 100644 tests/cisa/exchange/Test.CISA.MS.SECURITYSUITE.2.3.ps1 rename tests/cisa/exchange/{Test.CISA.MS.EXO.11.2.md => Test.CISA.MS.SECURITYSUITE.2.4.md} (82%) rename tests/cisa/exchange/{Test.CISA.MS.EXO.11.2.ps1 => Test.CISA.MS.SECURITYSUITE.2.4.ps1} (96%) rename tests/cisa/exchange/{Test.CISA.MS.EXO.16.1.md => Test.CISA.MS.SECURITYSUITE.4.1.md} (69%) rename tests/cisa/exchange/{Test.CISA.MS.EXO.16.1.ps1 => Test.CISA.MS.SECURITYSUITE.4.1.ps1} (94%) rename tests/cisa/exchange/{Test.CISA.MS.EXO.16.2.md => Test.CISA.MS.SECURITYSUITE.4.2.md} (68%) rename tests/cisa/exchange/{Test.CISA.MS.EXO.16.2.ps1 => Test.CISA.MS.SECURITYSUITE.4.2.ps1} (80%) diff --git a/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiPhishPolicy.ps1 b/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiPhishPolicy.ps1 new file mode 100644 index 0000000000..8ce7ab991a --- /dev/null +++ b/powershell/internal/checks/cisa/exchange/Get-MtCisaEffectiveAntiPhishPolicy.ps1 @@ -0,0 +1,71 @@ +function Get-MtCisaEffectiveAntiPhishPolicy { + [CmdletBinding()] + [OutputType([object[]])] + param() + + $policies = @(Get-MtExo -Request AntiPhishPolicy) + $antiPhishRules = @(Get-MtExo -Request AntiPhishRule) + $presetRules = @(Get-MtExo -Request EOPProtectionPolicyRule) + $tenantDomains = @( + Get-MtExo -Request AcceptedDomain | + ForEach-Object { + $domain = if ($_.DomainName) { $_.DomainName } else { $_.Name } + ([string]$domain).Trim().ToLowerInvariant() + } | + Where-Object { -not [string]::IsNullOrWhiteSpace($_) } + ) + + $isEmpty = { + param($Value) + $null -eq $Value -or + ($Value -is [string] -and [string]::IsNullOrWhiteSpace($Value)) -or + @($Value).Count -eq 0 + } + + $coversAllTenantDomains = { + param($Rule) + foreach ($field in @('SentTo', 'SentToMemberOf', 'ExceptIfSentTo', 'ExceptIfSentToMemberOf', 'ExceptIfRecipientDomainIs')) { + if (-not (& $isEmpty $Rule.$field)) { + return $false + } + } + + if (& $isEmpty $Rule.RecipientDomainIs) { + return $tenantDomains.Count -gt 0 + } + + $recipientDomains = @($Rule.RecipientDomainIs | ForEach-Object { ([string]$_).Trim().ToLowerInvariant() }) + $tenantDomains.Count -gt 0 -and @($tenantDomains | Where-Object { $_ -notin $recipientDomains }).Count -eq 0 + } + + $effectivePolicies = foreach ($policy in $policies | Where-Object { $_.Enabled -eq $true }) { + $coversAllRecipients = $policy.IsDefault -eq $true + + if (-not $coversAllRecipients -and $policy.Identity -match '(?i)(Standard|Strict) Preset Security Policy') { + $coversAllRecipients = @( + $presetRules | Where-Object { + $_.State -eq 'Enabled' -and + $_.Identity -match [regex]::Escape($policy.RecommendedPolicyType) -and + (& $isEmpty $_.SentTo) -and + (& $isEmpty $_.SentToMemberOf) -and + (& $isEmpty $_.RecipientDomainIs) + } + ).Count -gt 0 + } elseif (-not $coversAllRecipients) { + $policyRules = @( + $antiPhishRules | Where-Object { + $_.State -eq 'Enabled' -and + ($_.AntiPhishPolicy -eq $policy.Name -or $_.AntiPhishPolicy -eq $policy.Identity) -and + (& $coversAllTenantDomains $_) + } + ) + $coversAllRecipients = $tenantDomains.Count -gt 0 -and $policyRules.Count -gt 0 + } + + if ($coversAllRecipients) { + $policy + } + } + + return @($effectivePolicies) +} diff --git a/powershell/tests/functions/Test-MtCisaSecuritySuiteImpersonation.Tests.ps1 b/powershell/tests/functions/Test-MtCisaSecuritySuiteImpersonation.Tests.ps1 new file mode 100644 index 0000000000..405de80f09 --- /dev/null +++ b/powershell/tests/functions/Test-MtCisaSecuritySuiteImpersonation.Tests.ps1 @@ -0,0 +1,109 @@ +BeforeAll { + $testRoot = Resolve-Path (Join-Path $PSScriptRoot '..\..\..') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.2.1.ps1') + . (Join-Path $testRoot 'powershell\internal\checks\cisa\exchange\Get-MtCisaEffectiveAntiPhishPolicy.ps1') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.2.2.ps1') + . (Join-Path $testRoot 'tests\cisa\exchange\Test.CISA.MS.SECURITYSUITE.2.3.ps1') +} +Describe 'CISA Security Suite impersonation protection checks' { + BeforeEach { + Mock Add-MtTestResultDetail {} + } + + It 'requires at least one protected sensitive user for user impersonation protection' { + $script:policies = @( + [pscustomobject]@{ + Identity = 'Standard'; Guid = 'standard'; RecommendedPolicyType = 'Standard'; Enabled = $true + ImpersonationProtectionState = 'Automatic'; EnableOrganizationDomainsProtection = $true + EnableTargetedDomainsProtection = $true; EnableTargetedUserProtection = $true + TargetedUsersToProtect = @('sensitive@example.com') + }, + [pscustomobject]@{ + Identity = 'Strict'; Guid = 'strict'; RecommendedPolicyType = 'Strict'; Enabled = $true + ImpersonationProtectionState = 'Automatic'; EnableOrganizationDomainsProtection = $true + EnableTargetedDomainsProtection = $true; EnableTargetedUserProtection = $true + TargetedUsersToProtect = @() + } + ) + Mock Get-MtExo { $script:policies } + + Test-MtCisaImpersonation | Should -BeTrue + + $script:policies[0].TargetedUsersToProtect = @() + Test-MtCisaImpersonation | Should -BeFalse + } + + It 'checks owned-domain impersonation protection on an effective all-recipient policy' { + $script:exoResponses = @{ + AntiPhishPolicy = @( + [pscustomobject]@{ + Name = 'Default'; Identity = 'Default'; Enabled = $true; IsDefault = $true + EnableOrganizationDomainsProtection = $true; TargetedDomainProtectionAction = 'Quarantine' + } + ) + AntiPhishRule = @() + EOPProtectionPolicyRule = @() + AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeTrue + + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'BccMessage' + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeFalse + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'MoveToJmf' + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeTrue + + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'Quarantine' + $script:exoResponses.AntiPhishPolicy[0].EnableOrganizationDomainsProtection = $false + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeFalse + } + + It 'does not treat a scoped custom anti-phish rule as covering all recipients' { + $script:exoResponses = @{ + AntiPhishPolicy = @( + [pscustomobject]@{ + Name = 'Custom'; Identity = 'Custom'; Enabled = $true; IsDefault = $false + RecommendedPolicyType = 'Custom'; EnableOrganizationDomainsProtection = $true + TargetedDomainProtectionAction = 'Quarantine' + } + ) + AntiPhishRule = @( + [pscustomobject]@{ + State = 'Enabled'; AntiPhishPolicy = 'Custom'; SentTo = @('user@contoso.com') + SentToMemberOf = @(); RecipientDomainIs = @(); ExceptIfSentTo = @() + ExceptIfSentToMemberOf = @(); ExceptIfRecipientDomainIs = @() + } + ) + EOPProtectionPolicyRule = @() + AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaOwnedDomainImpersonationProtection | Should -BeFalse + } + + It 'requires configured partner domains and protection for every configured domain' { + $script:exoResponses = @{ + AntiPhishPolicy = @( + [pscustomobject]@{ + Name = 'Default'; Identity = 'Default'; Enabled = $true; IsDefault = $true + EnableTargetedDomainsProtection = $true; TargetedDomainProtectionAction = 'Quarantine' + TargetedDomainsToProtect = @('partner.example') + } + ) + AntiPhishRule = @() + EOPProtectionPolicyRule = @() + AcceptedDomain = @([pscustomobject]@{ DomainName = 'contoso.com' }) + } + Mock Get-MtExo { $script:exoResponses[$Request] } + + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains 'partner.example' | Should -BeTrue + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'BccMessage' + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains 'partner.example' | Should -BeFalse + $script:exoResponses.AntiPhishPolicy[0].TargetedDomainProtectionAction = 'MoveToJmf' + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains 'partner.example' | Should -BeTrue + Test-MtCisaPartnerDomainImpersonationProtection | Should -BeFalse + Test-MtCisaPartnerDomainImpersonationProtection -PartnerDomains @('partner.example', 'supplier.example') | Should -BeFalse + } +} diff --git a/powershell/tests/functions/engine/Frameworks.Tests.ps1 b/powershell/tests/functions/engine/Frameworks.Tests.ps1 index 06a6372fd8..057cb0921f 100644 --- a/powershell/tests/functions/engine/Frameworks.Tests.ps1 +++ b/powershell/tests/functions/engine/Frameworks.Tests.ps1 @@ -336,7 +336,7 @@ Describe 'Benchmark of the tests shipped with Maester' { It 'Gives every test a Benchmark of