Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
150bfc1
feat(defender): device security recommendations and exploitable vulne…
earbona23 Nov 6, 2026
1fb5b5c
fix(MT.1255): the per-instance severity goes on the instance
earbona23 Nov 7, 2026
2ef6908
fix(MT.1256): Severity is Medium, not High
earbona23 Nov 7, 2026
0b028cb
fix(MT.1255): no severity when the knowledge base publishes no impact
earbona23 Nov 7, 2026
cd60ccb
chore: save the new PowerShell files as UTF-8 with BOM
earbona23 Nov 7, 2026
cc9edd7
Merge remote-tracking branch 'origin/main' into resolver/2695
earbona23 Nov 8, 2026
2931d26
chore: renumber to the next free MT sequence (MT.1255/1256 -> MT.1269…
earbona23 Nov 8, 2026
c791969
fix(defender): drop the unsupported MITRE mapping and escape tenant n…
earbona23 Nov 8, 2026
5997ad8
fix(defender): T1203 for MT.1270, escape the KB text, and compare wit…
earbona23 Nov 8, 2026
a999886
fix: move the Mitre note above the attribute and keep the canonical o…
earbona23 Nov 8, 2026
5cd741e
Merge main and regenerate the golden selection fixture
earbona23 Nov 11, 2026
0a5df56
Merge branch 'main' into feat/2517-defender-vulnerability-management
earbona23 Nov 14, 2026
3ee0387
fix(defender): MT.1269 and MT.1270 probe advanced hunting before quer…
earbona23 Nov 16, 2026
b404241
test(defender): cover the advanced hunting probe, and MT.1270 states …
earbona23 Nov 16, 2026
92c1e39
test(defender): the probe's own tests move to their own file
earbona23 Nov 16, 2026
aef280e
test(defender): a query that cannot run must not read as a clean tenant
earbona23 Nov 16, 2026
c4f34b8
perf(defender): the advanced hunting probe is read once per run
earbona23 Nov 16, 2026
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
1 change: 1 addition & 0 deletions powershell/Maester.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ $__MtSession = @{
ExoCache = @{}
OrcaCache = @{}
AIAgentInfo = $null # Get-MtAIAgentInfo cache: @{ Agents; Error }, Error is why no agent data is available
DefenderHuntingTables = $null # Test-MtDefenderAdvancedHuntingAvailable cache: $true when the Defender for Endpoint tables answer
AzureDevOpsConnectionCache = $null
DataverseApiBase = $null # Resolved Dataverse OData API base URL (e.g. https://org123.api.crm.dynamics.com/api/data/v9.2)
DataverseResourceUrl = $null # Dataverse resource URL for token acquisition (e.g. https://org123.crm.dynamics.com)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
function Get-MtDefenderExploitableVulnerability {
<#
.SYNOPSIS
Returns a single summary of the devices that run software with a high or critical vulnerability for
which exploit code is publicly available.

.DESCRIPTION
Runs one advanced hunting query that joins DeviceTvmSoftwareVulnerabilities to
DeviceTvmSoftwareVulnerabilitiesKB and keeps the vulnerabilities whose IsExploitAvailable is true,
at high or critical severity.

The returned object always carries AssessedDeviceCount: the number of distinct devices Defender
Vulnerability Management has any vulnerability data for. That is the denominator, and it is what lets
the caller tell "no device is exposed" from "nothing has been assessed". A summarize without a by
clause returns exactly one row even over no input, so the denominator comes back either way.

Note on the signal: the advanced hunting schema exposes no CISA KEV flag. The closest first-party
signal is IsExploitAvailable in DeviceTvmSoftwareVulnerabilitiesKB, documented as "whether exploit
code for the vulnerability is publicly available", and that is what this uses. The check does not
claim CISA KEV membership.

Errors are deliberately not caught here. Invoke-MtGraphSecurityQuery throws on a query execution
error, and letting that surface keeps a broken query from being reported as a clean fleet.

.EXAMPLE
Get-MtDefenderExploitableVulnerability

Returns the exposed device count, the CVE count and the denominator of assessed devices.
#>
[CmdletBinding()]
[OutputType([pscustomobject])]
param()

# The denominator is computed first and attached to the single summary row, so an unassessed tenant
# is distinguishable from a clean one. Sets are capped: the result is a summary, not an inventory.
$query = @'
let assessed = toscalar(DeviceTvmSoftwareVulnerabilities | summarize dcount(DeviceId));
DeviceTvmSoftwareVulnerabilities
| where VulnerabilitySeverityLevel in ('High', 'Critical')
| join kind=inner (
DeviceTvmSoftwareVulnerabilitiesKB
| where IsExploitAvailable == true
| project CveId, CvssScore
) on CveId
| summarize ExposedDeviceCount = dcount(DeviceId),
CveCount = dcount(CveId),
TopDeviceList = make_set(DeviceName, 10),
TopCveList = make_set(CveId, 10),
TopSoftwareList = make_set(strcat(SoftwareVendor, ' ', SoftwareName), 10)
| extend AssessedDeviceCount = assessed
'@

Write-Verbose 'Querying Defender Vulnerability Management software vulnerabilities...'
$rows = @(Invoke-MtGraphSecurityQuery -Query $query -Timespan 'P1D')

# The query shape guarantees one row. If the call came back with nothing at all, Defender returned
# no result set and the caller must skip rather than read that as a clean fleet.
$row = $rows | Select-Object -First 1
if (-not $row) {
Write-Verbose 'No result set returned; the caller reports a skip.'
return $null
}

[pscustomobject]@{
AssessedDeviceCount = [int]($row.AssessedDeviceCount)
ExposedDeviceCount = [int]($row.ExposedDeviceCount)
CveCount = [int]($row.CveCount)
TopDeviceList = @($row.TopDeviceList)
TopCveList = @($row.TopCveList)
TopSoftwareList = @($row.TopSoftwareList)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
function Get-MtDefenderSecureConfigurationAssessment {
<#
.SYNOPSIS
Returns one row per Defender Vulnerability Management security configuration, with how many devices
it applies to and how many of those are not compliant with it.

.DESCRIPTION
Runs a single advanced hunting query over DeviceTvmSecureConfigurationAssessment, joined to
DeviceTvmSecureConfigurationAssessmentKB for the configuration's name, description, risk and impact.
The aggregation happens server side, so the result is one row per configuration rather than one row
per device and configuration.

Only configurations Defender reports as applicable to at least one device are returned. A
configuration that applies to nothing cannot be complied with or breached, so it has no outcome to
judge.

An empty result means Defender Vulnerability Management has no assessment data for this tenant,
typically because no device is onboarded to Defender for Endpoint. The caller must skip in that case:
"no configuration is non-compliant" over zero assessed configurations is not a pass.

Errors are deliberately not caught here. Invoke-MtGraphSecurityQuery throws on a query execution
error, and letting that surface keeps a broken query from being reported as a clean tenant.

.EXAMPLE
Get-MtDefenderSecureConfigurationAssessment

Returns the security configurations assessed in the tenant with their non-compliant device counts.
#>
[CmdletBinding()]
[OutputType([System.Collections.Generic.List[pscustomobject]])]
param()

# Aggregated server side: one row per configuration. make_set_if is capped so a configuration that
# is non-compliant on thousands of devices does not drag the whole result set back.
$query = @'
DeviceTvmSecureConfigurationAssessment
| where IsApplicable == true
| summarize ApplicableDeviceCount = dcount(DeviceId),
NonCompliantDeviceCount = dcountif(DeviceId, IsCompliant == false),
NonCompliantDeviceList = make_set_if(DeviceName, IsCompliant == false, 10),
ConfigurationCategory = any(ConfigurationCategory),
ConfigurationSubcategory = any(ConfigurationSubcategory)
by ConfigurationId
| join kind=leftouter (
DeviceTvmSecureConfigurationAssessmentKB
| project ConfigurationId, ConfigurationName, ConfigurationDescription, RiskDescription, ConfigurationImpact
) on ConfigurationId
| project-away ConfigurationId1
| sort by NonCompliantDeviceCount desc, ConfigurationImpact desc
'@

Write-Verbose 'Querying Defender Vulnerability Management secure configuration assessment...'
$rows = @(Invoke-MtGraphSecurityQuery -Query $query -Timespan 'P1D')

$result = [System.Collections.Generic.List[pscustomobject]]::new()
foreach ($row in $rows) {
if (-not $row -or [string]::IsNullOrWhiteSpace([string]$row.ConfigurationId)) { continue }
$result.Add([pscustomobject]@{
ConfigurationId = [string]$row.ConfigurationId
Name = [string]$row.ConfigurationName
Description = [string]$row.ConfigurationDescription
RiskDescription = [string]$row.RiskDescription
Category = [string]$row.ConfigurationCategory
Subcategory = [string]$row.ConfigurationSubcategory
# $null, not 0, when the knowledge base has no row for this configuration: the join
# above is a leftouter, and [double]$null is 0, which reads as "impact 1 to 10, the
# lowest" rather than "not known". The caller decides what to do with the absence.
Impact = if ($null -eq $row.ConfigurationImpact -or [string]::IsNullOrWhiteSpace([string]$row.ConfigurationImpact)) { $null } else { [double]$row.ConfigurationImpact }
ApplicableDeviceCount = [int]($row.ApplicableDeviceCount)
NonCompliantDeviceCount = [int]($row.NonCompliantDeviceCount)
NonCompliantDeviceList = @($row.NonCompliantDeviceList)
})
}

# -NoEnumerate keeps an empty list from collapsing to $null, so the caller can tell an empty
# assessment from a list it can iterate.
Write-Output $result -NoEnumerate
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function Test-MtDefenderAdvancedHuntingAvailable {
<#
.SYNOPSIS
Returns whether the Defender for Endpoint device tables answer advanced hunting on this tenant.

.DESCRIPTION
The Defender Vulnerability Management checks read DeviceTvm* tables through advanced hunting. On a
tenant where those tables are not served, the query comes back as an execution error and the check
ends in Error with the API's own text, which on some tenants is reduced to
". Fix semantic errors in your query." and does not even name the table. That reads as a defect in
the check rather than as a tenant that cannot answer the question.

A licence gate cannot tell the two apart. A tenant holding both Defender for Business (from Business
Premium) and Defender for Endpoint Plan 2 (for instance from an E5 trial) keeps the Defender for
Business experience until Support switches it, and advanced hunting belongs to Plan 2 only. Both
DEFENDER_XDR and a gate on Plan 2 pass on such a tenant while the tables stay silent.

So this probes instead of inferring. The query is a constant and minimal one over DeviceInfo, the
table every Defender for Endpoint device reports into. It cannot fail because of anything a caller
composed, which is what makes its failure attributable to the tenant rather than to the query.

An empty result is availability, not absence: a table that resolves and returns no row has answered.
The distinction matters, because a tenant with no onboarded device must still be skipped by the
caller's own no-data path, with its own reason.

The answer is a property of the tenant, not of the caller, so it is read once per run and kept in
$__MtSession.DefenderHuntingTables. Three checks depend on it and advanced hunting is rate limited;
asking the same question three times a run is a cost paid by every tenant, including the ones where
nothing is wrong. Invoke-Maester clears it between runs.

.OUTPUTS
[bool] - True when the Defender for Endpoint tables answer, false when they do not.

.EXAMPLE
Test-MtDefenderAdvancedHuntingAvailable

Returns $true on a tenant whose Defender for Endpoint tables are served by advanced hunting.
#>
[CmdletBinding()]
[OutputType([bool])]
param()

if ($null -ne $__MtSession.DefenderHuntingTables) {
return [bool]$__MtSession.DefenderHuntingTables
}

try {
$null = Invoke-MtGraphSecurityQuery -Query 'DeviceInfo | project DeviceId | take 1' -Timespan 'P1D'
$__MtSession.DefenderHuntingTables = $true
return $true
} catch {
# Deliberately broad. Invoke-MtGraphSecurityQuery surfaces the API's message, and that message is
# not reliable enough to match on: the same unavailability reaches us as
# "Failed to resolve table or column expression named ..." for some tables and as
# ". Fix semantic errors in your query." for others. Matching the text would make the probe fail
# open on the tenants it exists for. The query being a constant is what bounds this catch.
Write-Verbose "Defender for Endpoint tables did not answer advanced hunting: $($_.Exception.Message)"
$__MtSession.DefenderHuntingTables = $false
return $false
}
}
1 change: 1 addition & 0 deletions powershell/internal/session/Clear-ModuleVariable.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Clear-MtExoCache
Clear-MtADCache
$__MtSession.AIAgentInfo = $null
$__MtSession.DefenderHuntingTables = $null
$__MtSession.IncludeAffectedObjects = $false
$__MtSession.AffectedObjectFacts = $null
$__MtSession.AzureDevOpsConnectionCache = $null
Expand Down
12 changes: 9 additions & 3 deletions powershell/tests/fixtures/golden/selection.json
Original file line number Diff line number Diff line change
Expand Up @@ -1951,7 +1951,7 @@
"AD"
]
},
"SelectedCount": 609,
"SelectedCount": 611,
"SelectedFamilies": [
"MT.1024",
"MT.1059",
Expand Down Expand Up @@ -2500,6 +2500,8 @@
"MT.1259",
"MT.1260",
"MT.1265",
"MT.1269",
"MT.1270",
"ORCA.100",
"ORCA.101",
"ORCA.102",
Expand Down Expand Up @@ -2581,7 +2583,7 @@
"AD"
]
},
"SelectedCount": 639,
"SelectedCount": 641,
"SelectedFamilies": [
"MT.1024",
"MT.1033",
Expand Down Expand Up @@ -3162,6 +3164,8 @@
"MT.1259",
"MT.1260",
"MT.1265",
"MT.1269",
"MT.1270",
"ORCA.100",
"ORCA.101",
"ORCA.102",
Expand Down Expand Up @@ -4006,7 +4010,7 @@
"AD"
]
},
"SelectedCount": 595,
"SelectedCount": 597,
"SelectedFamilies": [
"MT.1024",
"MT.1033",
Expand Down Expand Up @@ -4543,6 +4547,8 @@
"MT.1259",
"MT.1260",
"MT.1265",
"MT.1269",
"MT.1270",
"ORCA.100",
"ORCA.101",
"ORCA.102",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
Describe 'Test-MtDefenderAdvancedHuntingAvailable' {
BeforeAll {
Import-Module $PSScriptRoot/../../Maester.psd1 -Force
. "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1"
# An internal helper, so it is not exported.
Use-MtModuleFunction -Name Test-MtDefenderAdvancedHuntingAvailable
}

BeforeEach {
# The answer is cached for the run. Without this each case would read the previous one's result
# and the probe would appear to work no matter what it was given.
InModuleScope Maester { $__MtSession.DefenderHuntingTables = $null }
}

It 'reports available when the probe query answers' {
Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { @([pscustomobject]@{ DeviceId = 'd1' }) }

Test-MtDefenderAdvancedHuntingAvailable | Should -BeTrue
}

It 'reports available when the table answers with no row' {
# A table that resolves and returns nothing has answered. Reading an empty result as
# unavailable would skip every tenant with no onboarded device for the wrong reason, and those
# tenants have their own skip with its own wording.
Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { @() }

Test-MtDefenderAdvancedHuntingAvailable | Should -BeTrue
}

It 'reports unavailable when the probe query throws' {
Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { throw '. Fix semantic errors in your query.' }

Test-MtDefenderAdvancedHuntingAvailable | Should -BeFalse
}

It 'reports unavailable on the message that names the table too' {
# The same unavailability reaches the caller as either message depending on the table, which is
# why the catch does not match on the text.
Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { throw "Failed to resolve table or column expression named 'DeviceInfo'" }

Test-MtDefenderAdvancedHuntingAvailable | Should -BeFalse
}

It 'asks only for what it needs, and only once per run' {
# Three checks depend on this and advanced hunting is rate limited, so the question is asked
# once and kept for the run. A probe that pulled rows, or asked again per check, would be a cost
# on every tenant, including the ones where nothing is wrong.
Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { @() }

$null = Test-MtDefenderAdvancedHuntingAvailable
$null = Test-MtDefenderAdvancedHuntingAvailable
$null = Test-MtDefenderAdvancedHuntingAvailable

Should -Invoke -ModuleName Maester Invoke-MtGraphSecurityQuery -Times 1 -Exactly
Should -Invoke -ModuleName Maester Invoke-MtGraphSecurityQuery -ParameterFilter {
$Query -eq 'DeviceInfo | project DeviceId | take 1'
} -Times 1 -Exactly
}

It 'caches the unavailable answer too, rather than retrying per check' {
# The expensive case is the one that fails: without this the tenant pays a failing query for
# every check that depends on the probe.
Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { throw 'Query execution has failed.' }

Test-MtDefenderAdvancedHuntingAvailable | Should -BeFalse
Test-MtDefenderAdvancedHuntingAvailable | Should -BeFalse

Should -Invoke -ModuleName Maester Invoke-MtGraphSecurityQuery -Times 1 -Exactly
}

It 'asks again once the run cache is cleared' {
# Invoke-Maester clears the per-run cache, so a second run on a tenant whose licensing changed
# must not be answered from the first.
Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { @() }

$null = Test-MtDefenderAdvancedHuntingAvailable
InModuleScope Maester { $__MtSession.DefenderHuntingTables = $null }
$null = Test-MtDefenderAdvancedHuntingAvailable

Should -Invoke -ModuleName Maester Invoke-MtGraphSecurityQuery -Times 2 -Exactly
}

It 'does not swallow the failure silently' {
Mock -ModuleName Maester Invoke-MtGraphSecurityQuery { throw 'boom' }

$verbose = Test-MtDefenderAdvancedHuntingAvailable -Verbose 4>&1 |
Where-Object { $_ -is [System.Management.Automation.VerboseRecord] }

($verbose -join ' ') | Should -Match 'did not answer advanced hunting'
}
}
Loading
Loading