Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
function Get-MtCisaPhishingResistantPolicy {
<#
.SYNOPSIS
Returns Conditional Access policies that enforce phishing-resistant MFA for all users and applications.

.DESCRIPTION
User and group exclusions are counted only when they match configured emergency access accounts or groups.
Other exclusions are not counted because Maester has no matching SCuBA exclusion allowlists.
#>
[CmdletBinding()]
[OutputType([object[]])]
param(
[Parameter()]
[object[]] $EmergencyAccessAccounts = @()
)

$phishingResistantMethods = @('windowsHelloForBusiness', 'fido2', 'x509CertificateMultiFactor')
$emergencyAccessObjectIds = @(Get-MtEmergencyAccessAccount -Account $EmergencyAccessAccounts | ForEach-Object { $_.ObjectId })

$policies = Get-MtConditionalAccessPolicy | Where-Object {
$authenticationStrength = $_.grantControls.authenticationStrength
$allowedCombinations = @($authenticationStrength.allowedCombinations | Where-Object { $_ })
$userAndGroupExclusions = @(
$_.conditions.users.excludeUsers
$_.conditions.users.excludeGroups
) | Where-Object { $_ }
$unapprovedExclusions = @($userAndGroupExclusions | Where-Object { $_ -notin $emergencyAccessObjectIds })

$_.state -eq 'enabled' -and
$_.conditions.applications.includeApplications -contains 'All' -and
$_.conditions.users.includeUsers -contains 'All' -and
$unapprovedExclusions.Count -eq 0 -and
-not $_.conditions.users.excludeRoles -and
-not $_.conditions.applications.excludeApplications -and
$null -eq $_.conditions.users.excludeGuestsOrExternalUsers -and
$authenticationStrength -and (
$allowedCombinations.Count -gt 0 -and
@($allowedCombinations | Where-Object { $_ -notin $phishingResistantMethods }).Count -eq 0
)
}

return @($policies)
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,15 @@
role = $role.displayName
activationNotify = $false
}
$recipients = @(Get-MtRoleActivationNotificationRecipient -RoleDefinitionId $role.id)
try {
$recipients = @(Get-MtRoleActivationNotificationRecipient -RoleDefinitionId $role.id -ErrorAction Stop)
} catch {
if ($_.ErrorDetails.Message -match '"code"\s*:\s*"AadPremiumLicenseRequired"') {
Add-MtTestResultDetail -SkippedBecause NotLicensedEntraIDP2OrGovernance
return $null
}
throw
}
$rolePolicy.activationNotify = $recipients.Count -gt 0

$rolePolicies += $rolePolicy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Filter = "scopeId eq '/' and scopeType eq 'DirectoryRole' and roleDefinitionId eq '$RoleDefinitionId'"
QueryParameters = @{ expand = 'policy(expand=rules)' }
}
$assignment = Invoke-MtGraphRequest @policySplat
$assignment = Invoke-MtGraphRequest @policySplat -ErrorAction Stop
$rule = @($assignment.policy.rules) | Where-Object { $_.id -eq 'Notification_Admin_EndUser_Assignment' } | Select-Object -First 1
return [string[]]@($rule.notificationRecipients | Where-Object { $_ })
}
203 changes: 203 additions & 0 deletions powershell/tests/functions/Test-MtCisaAuthenticatorContext.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
BeforeAll {
. "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1"
Use-MtModuleFunction -Name @(
'Test-MtCisaAuthenticatorContext',
'Get-MtCisaPhishingResistantPolicy',
'Test-MtCisaPhishResistant'
)

function Get-TestPhishingResistantPolicy {
[pscustomobject]@{
state = 'enabled'
conditions = [pscustomobject]@{
applications = [pscustomobject]@{
includeApplications = @('All')
excludeApplications = @()
}
users = [pscustomobject]@{
includeUsers = @('All')
excludeUsers = @()
excludeGroups = @()
excludeRoles = @()
excludeGuestsOrExternalUsers = $null
}
}
grantControls = [pscustomobject]@{
authenticationStrength = [pscustomobject]@{
id = 'custom'
allowedCombinations = @('fido2', 'windowsHelloForBusiness')
}
}
}
}
}

Describe 'CISA Microsoft Authenticator context and software OTP' {
BeforeEach {
$script:ResultMarkdown = $null
$script:SkippedBecause = $null
$script:ConditionalAccessPolicies = @()
$script:EmergencyAccessAccounts = @()
$script:AuthenticatorPolicy = [pscustomobject]@{
id = 'MicrosoftAuthenticator'
state = 'enabled'
includeTargets = @(@{ id = 'all_users' })
isSoftwareOathEnabled = $false
featureSettings = @{
displayAppInformationRequiredState = @{ state = 'enabled'; includeTarget = @{ id = 'all_users' } }
displayLocationInformationRequiredState = @{ state = 'enabled'; includeTarget = @{ id = 'all_users' } }
}
}
$script:AuthenticationMethodPolicyConfig = @(
$script:AuthenticatorPolicy
[pscustomobject]@{ id = 'Email'; state = 'enabled' }
)
Mock -ModuleName Maester Get-MtAuthenticationMethodPolicyConfig {
$script:AuthenticationMethodPolicyConfig
}
Mock -ModuleName Maester Get-MtConditionalAccessPolicy {
$script:ConditionalAccessPolicies
}
Mock -ModuleName Maester Get-MtEmergencyAccessAccount {
param($Account)
@($Account | ForEach-Object { [pscustomobject]@{ ObjectId = $_.Id } })
}
Mock -ModuleName Maester Add-MtTestResultDetail {
param($Result, $SkippedBecause)
$script:ResultMarkdown = $Result
$script:SkippedBecause = $SkippedBecause
}
}

It 'skips when the Microsoft Authenticator policy is disabled' {
$script:AuthenticatorPolicy.state = 'disabled'

Test-MtCisaAuthenticatorContext | Should -BeNull
$script:SkippedBecause | Should -Be 'NotApplicable'
}

It 'skips when no Microsoft Authenticator policy is returned' {
$script:AuthenticationMethodPolicyConfig = @(
[pscustomobject]@{ id = 'Email'; state = 'enabled' }
)

Test-MtCisaAuthenticatorContext | Should -BeNull
$script:SkippedBecause | Should -Be 'NotApplicable'
}

It 'errors when no authentication method configurations are returned' {
$script:AuthenticationMethodPolicyConfig = @()

{ Test-MtCisaAuthenticatorContext } | Should -Throw '*No authentication method configurations were returned*'
$script:SkippedBecause | Should -BeNullOrEmpty
}

It 'skips when ScubaGear would mark phishing-resistant MFA as enforced' {
$script:ConditionalAccessPolicies = @(Get-TestPhishingResistantPolicy)

Test-MtCisaAuthenticatorContext | Should -BeNull
$script:SkippedBecause | Should -Be 'NotApplicable'
Get-MtCisaPhishingResistantPolicy | Should -HaveCount 1
Test-MtCisaPhishResistant | Should -BeTrue
}

It 'allows phishing-resistant policies that exclude configured emergency access accounts' {
$policy = Get-TestPhishingResistantPolicy
$policy.conditions.users.excludeUsers = @('emergency-user')
$policy.conditions.users.excludeGroups = @('emergency-group')
$script:ConditionalAccessPolicies = @($policy)
$script:EmergencyAccessAccounts = @(
[pscustomobject]@{ Id = 'emergency-user'; Type = 'user' }
[pscustomobject]@{ Id = 'emergency-group'; Type = 'group' }
)

Test-MtCisaAuthenticatorContext -EmergencyAccessAccounts $script:EmergencyAccessAccounts | Should -BeNull
$script:SkippedBecause | Should -Be 'NotApplicable'
Get-MtCisaPhishingResistantPolicy -EmergencyAccessAccounts $script:EmergencyAccessAccounts | Should -HaveCount 1
Test-MtCisaPhishResistant -EmergencyAccessAccounts $script:EmergencyAccessAccounts | Should -BeTrue
}

It 'does not allow additional user exclusions beyond configured emergency access accounts' {
$policy = Get-TestPhishingResistantPolicy
$policy.conditions.users.excludeUsers = @('emergency-user', 'other-user')
$script:ConditionalAccessPolicies = @($policy)
$script:EmergencyAccessAccounts = @([pscustomobject]@{ Id = 'emergency-user'; Type = 'user' })

Test-MtCisaAuthenticatorContext -EmergencyAccessAccounts $script:EmergencyAccessAccounts | Should -BeTrue
$script:SkippedBecause | Should -BeNullOrEmpty
Get-MtCisaPhishingResistantPolicy -EmergencyAccessAccounts $script:EmergencyAccessAccounts | Should -BeNullOrEmpty
}

It 'does not skip when a phishing-resistant policy has role exclusions' {
$policy = Get-TestPhishingResistantPolicy
$policy.conditions.users.excludeRoles = @('Global Administrator')
$script:ConditionalAccessPolicies = @($policy)

Test-MtCisaAuthenticatorContext | Should -BeTrue
$script:SkippedBecause | Should -BeNullOrEmpty
Get-MtCisaPhishingResistantPolicy | Should -BeNullOrEmpty
}

It 'does not skip when a phishing-resistant policy excludes users, groups, apps, or guests' {
$policy = Get-TestPhishingResistantPolicy
$policy.conditions.users.excludeUsers = @('user-id')
$policy.conditions.users.excludeGroups = @('group-id')
$policy.conditions.applications.excludeApplications = @('app-id')
$policy.conditions.users.excludeGuestsOrExternalUsers = [pscustomobject]@{
guestOrExternalUserTypes = 'b2bCollaborationGuest'
}
$script:ConditionalAccessPolicies = @($policy)

Test-MtCisaAuthenticatorContext | Should -BeTrue
$script:SkippedBecause | Should -BeNullOrEmpty
Get-MtCisaPhishingResistantPolicy | Should -BeNullOrEmpty
}

It 'does not skip when an authentication strength allows a non-phishing-resistant method' {
$policy = Get-TestPhishingResistantPolicy
$policy.grantControls.authenticationStrength.allowedCombinations = @('fido2', 'password,sms')
$script:ConditionalAccessPolicies = @($policy)

Test-MtCisaAuthenticatorContext | Should -BeTrue
$script:SkippedBecause | Should -BeNullOrEmpty
Get-MtCisaPhishingResistantPolicy | Should -BeNullOrEmpty
}

It 'does not skip when a phishing-resistant policy does not include all users' {
$policy = Get-TestPhishingResistantPolicy
$policy.conditions.users.includeUsers = @('group-id')
$script:ConditionalAccessPolicies = @($policy)

Test-MtCisaAuthenticatorContext | Should -BeTrue
$script:SkippedBecause | Should -BeNullOrEmpty
Get-MtCisaPhishingResistantPolicy | Should -BeNullOrEmpty
}

It 'passes with Authenticator software OTP disabled even when Email OTP is enabled' {
Test-MtCisaAuthenticatorContext | Should -BeTrue
$script:ResultMarkdown | Should -Match 'software OTP \(not Email OTP\) disabled'
}

It 'fails with Authenticator software OTP enabled despite both context settings being enabled' {
$script:AuthenticatorPolicy.isSoftwareOathEnabled = $true

Test-MtCisaAuthenticatorContext | Should -BeFalse
$script:ResultMarkdown | Should -Match '\| Microsoft Authenticator software OTP \(not Email OTP\) disabled \| ❌ Fail \|'
}

It 'does not label missing Authenticator software OTP data as passing' {
$script:AuthenticatorPolicy.isSoftwareOathEnabled = $null

Test-MtCisaAuthenticatorContext | Should -BeFalse
$script:ResultMarkdown | Should -Match '\| Microsoft Authenticator software OTP \(not Email OTP\) disabled \| ❌ Fail \|'
}

It 'still fails when application or location context is disabled' -ForEach @(
@{ Setting = 'displayAppInformationRequiredState' }
@{ Setting = 'displayLocationInformationRequiredState' }
) {
$script:AuthenticatorPolicy.featureSettings[$Setting].state = 'disabled'

Test-MtCisaAuthenticatorContext | Should -BeFalse
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
BeforeAll {
. "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1"
Use-MtModuleFunction -Name @(
'Test-MtCisaDlpAlternate',
'Test-MtCheckCISAMSEXO92',
'Test-MtCisaEmailFilterAlternative',
'Test-MtCisaMailboxIntelligence'
)
}

Describe 'Deprecated CISA Exchange checks' {
BeforeEach {
$script:SkippedBecause = $null
$script:SkippedCustomReason = $null

Mock -ModuleName Maester Add-MtTestResultDetail {
param($SkippedBecause, $SkippedCustomReason)

$script:SkippedBecause = $SkippedBecause
$script:SkippedCustomReason = $SkippedCustomReason
}
}

It '<CheckName> skips the retired control' -ForEach @(
@{ CheckName = 'Test-MtCisaDlpAlternate' }
@{ CheckName = 'Test-MtCheckCISAMSEXO92' }
@{ CheckName = 'Test-MtCisaEmailFilterAlternative' }
@{ CheckName = 'Test-MtCisaMailboxIntelligence' }
) {
& $CheckName | Should -BeNull
$script:SkippedBecause | Should -Be 'Custom'
$script:SkippedCustomReason | Should -Match 'removed'
}
}
Loading
Loading