Skip to content

Commit 563ae4a

Browse files
committed
Fix false CRITICAL on AMSI when PS.Security module fails to load
Made-with: Cursor
1 parent 362c6b6 commit 563ae4a

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

lib/Helpers.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,12 +378,14 @@ function Test-IsPrivateIP {
378378

379379
function Get-FileSignature {
380380
param([string]$FilePath)
381+
# Force-load the module; suppress TypeData-conflict errors that occur in some PS 5.1 sessions
382+
Import-Module Microsoft.PowerShell.Security -Force -ErrorAction SilentlyContinue -WarningAction SilentlyContinue 2>$null
381383
try {
382384
$sig = Get-AuthenticodeSignature $FilePath -ErrorAction SilentlyContinue
383-
return $sig
384-
} catch {
385-
return $null
386-
}
385+
if ($sig) { return $sig }
386+
} catch { }
387+
# If the module still couldn't load, return a sentinel so callers don't treat it as "unsigned"
388+
return [PSCustomObject]@{ Status = "CheckFailed"; StatusMessage = "Signature check unavailable (PS.Security module could not be loaded)." }
387389
}
388390

389391
function Get-FileVersionInfo {

modules/Check-DefenseEvasion.ps1

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ function Invoke-DefenseEvasionChecks {
6666
$amsiDll = "$env:SystemRoot\System32\amsi.dll"
6767
if (Test-Path $amsiDll) {
6868
$sig = Get-FileSignature -FilePath $amsiDll
69-
if (-not $sig -or $sig.Status -ne "Valid") {
69+
if ($sig -and $sig.Status -eq "CheckFailed") {
70+
Write-Status "AMSI signature check unavailable (PS.Security module could not be loaded)." -Color DarkGray
71+
} elseif (-not $sig -or $sig.Status -ne "Valid") {
7072
Add-Finding -Severity "CRITICAL" -Category "DefenseEvasion" `
7173
-Title "AMSI DLL Signature Invalid" `
7274
-Description "amsi.dll at '$amsiDll' does not have a valid digital signature (Status: $(if ($sig) { $sig.Status } else { 'Missing' })). This may indicate the AMSI interface has been tampered with to bypass script scanning." `

0 commit comments

Comments
 (0)