1

我正在编写 Pester 测试来验证 Windows 计算机的配置。我需要的测试之一是验证 PowerShell AMSI 是否正常工作。

有一个 AMSI 测试字符串可用于验证功能。我创建了以下测试。

It '"Antimalware Scan Interface" is working' {
    # AMSI test string 'AMSI Test Sample: 7e72c3ce-861b-4339-8740-0ac1484c1386'
    # (in the following as an obfuscated string)
    # must throw an error if executed (blocked by AMSI)
    $TestString = "FHJ+YHoTZ1ZARxNgUl5DX1YJEwRWBAFQAFBWHgsFAlEeBwAACh4LBAcDHgNSUAIHCwdQAgALBRQ="
    $Bytes = [Convert]::FromBase64String($TestString)
    $String = -join ($bytes | ForEach-Object { [char]($_ -bxor 0x33)})
    { Invoke-Expression -Command $String } | Should Throw
}

如果我运行测试,AMSI 运行良好,以至于没有执行完整的上下文块,即没有执行测试并且没有报告成功。

我收到"Error occurred in Context block" In Filename.Tests.ps1:420 Character:36 + Context 'Configure PowerShell' { + ~ The Script contains malicious data and was blocked by anti malware.(翻译文本。原文可能略有不同。)

取而代之的是错误,我希望执行上下文并返回“测试成功”以引发错误。

有什么想法可以处理这个问题或测试 AMSI 吗?

4

0 回答 0