Reject unexplained descendant changes and unrelated WMI command arguments

This commit is contained in:
Shirofune-Security committed 2026-09-22 14:45:06 +09:00
1 parent ddcdd8e2b8
commit 8546d319eb
10 files changed
+42 -7

No files matched your search

@@ -0,0 +1,16 @@
$ErrorActionPreference='Stop';$repo=Split-Path $PSScriptRoot -Parent;$engine=(Get-Process -Id $PID).Path
$cases=@(
@{Args=@('wmi-auditing','-Help');Exit=0;Pattern='WmiIncludeChildren'},
@{Args=@('wmi-auditing','-WmiAction','Plan','-WmiNamespace','root\default','-WmiIncludeChildren','-Help');Exit=0;Pattern='Usage:'},
@{Args=@('wmi-auditing','-WmiAction','Configure','-WmiIncludeChildren','-DryRun','-Help');Exit=0;Pattern='Usage:'},
@{Args=@('wmi-auditing','-WmiAction','Audit','-WmiIncludeChildren','-DryRun','-Help');Exit=1;Pattern='DryRun'},
@{Args=@('configure','-WmiIncludeChildren','-Help');Exit=1;Pattern='require wmi-auditing'},
@{Args=@('wmi-auditing','unexpected','-WmiIncludeChildren','-Help');Exit=1;Pattern='positional|argument|Unrecognized'},
@{Args=@('wmi-auditing','-WmiNamespace','root\default','-FileProbeAction','Run','-Help');Exit=1;Pattern='require file-access-probe|dedicated'}
)
foreach($c in $cases){
$ErrorActionPreference='Continue';try{$text=@(& $engine -NoProfile -File (Join-Path $repo 'WELA.ps1') @($c.Args) 2>&1);$code=$LASTEXITCODE}finally{$ErrorActionPreference='Stop'}
if($code -ne $c.Exit -or ($text -join "`n") -notmatch $c.Pattern){throw "CLI mismatch: $($c.Args -join ' ') : $code / $text"}
}
Write-Host "PASS: $($cases.Count) WMI inheritance public CLI assertions."
$global:LASTEXITCODE=0
+13 -1
View File
@@ -58,6 +58,10 @@ try{
$c=New-WelaConfigurationContext -Auto -DryRun -BackupPath $temp
Set-WelaWmiAuditControls $c $p
Assert ($script:writes -eq 0 -and $c.Results[0].Status -eq 'Skipped' -and -not (Test-Path $temp)) 'DryRun no state or journal mutation.'
$script:context='changed token';$c=New-WelaConfigurationContext -Auto -BackupPath (Join-Path $temp token)
Set-WelaWmiAuditControls $c $p
Assert ($script:writes -eq 0 -and $c.Results[0].Status -eq 'Failed') 'Full context drift invalidates planned subtree.'
$script:context='caller/host/source'
$script:tree['root\default\New']=Descriptor
$c=New-WelaConfigurationContext -Auto -BackupPath (Join-Path $temp stale)
Set-WelaWmiAuditControls $c $p
@@ -80,17 +84,25 @@ try{
Assert ((Get-WelaWmiDescendantKey $journal.Before.Descendants) -ceq (Get-WelaWmiDescendantKey $p[0].Descendants)) 'Journal serialization does not truncate original child snapshots.'
$script:tree['root\default\A'].Opaque='drift'
Assert ((Complete-WelaConfiguration $c).ExitCode -eq 1) 'Final child drift propagates failure.'
Reset;$script:tree['root\default'].SACL+=Ace 66;$script:tree['root\default'].ControlFlags=32788
$unverified=@(Get-WelaWmiAuditPlan -Namespace 'root\default' -IncludeChildren)
Assert ($unverified[0].Status -eq 'Unknown' -and $unverified[0].Diagnostic -match 'descendants are unverified') 'Already-compliant parent cannot imply descendant compliance.'
$c=New-WelaConfigurationContext -Auto -BackupPath (Join-Path $temp unverified)
Set-WelaWmiAuditControls $c $unverified
Assert ($script:writes -eq 0 -and (Complete-WelaConfiguration $c).ExitCode -eq 1) 'Missing existing-child inheritance fails without an unnecessary parent rewrite.'
# Each unrelated mutation invalidates observed propagation, even when required ACE still exists.
foreach($kind in @('Owner','Dacl','Control','Unknown','Protected','Removed','Extra','Missing','New')){
foreach($kind in @('Owner','Dacl','Control','Unknown','NewProperty','Protected','Removed','Extra','Duplicate','Missing','New')){
Reset;$a=Get-WelaWmiStableDescendants 'root\default';$null=Set-WelaWmiNamespaceDescriptor 'root\default' $a.Root.DescriptorJson $defs
switch($kind){
Owner {$script:tree['root\default\A'].Owner='other'}
Dacl {$script:tree['root\default\A'].DACL=@('other')}
Control {$script:tree['root\default\A'].ControlFlags=$script:tree['root\default\A'].ControlFlags -bor 256}
Unknown {$script:tree['root\default\A'].Opaque='other'}
NewProperty {$script:tree['root\default\A']|Add-Member NoteProperty NewOpaque 1}
Protected {$script:tree['root\default\Protected\B'].SACL+=Ace}
Removed {$script:tree.Remove('root\default\A\B')}
Extra {$script:tree['root\default\A'].SACL+=Ace 64}
Duplicate {$script:tree['root\default\A'].SACL+=Ace}
Missing {$script:tree['root\default\A'].SACL=@()}
New {$script:tree['root\default\Unreviewed']=Descriptor}
}