anthonyg-1/PSAgentEval

GitHub: anthonyg-1/PSAgentEval

PSAgentEval 是一个 PowerShell 模块,用于自动化红队评估 Claude AI 代理的安全性,解决 AI 代理安全测试的效率和标准化问题。

Stars: 0 | Forks: 0

PSAgentEval logo **PowerShell AI 代理红队评估** [![PowerShell 7.5+](https://img.shields.io/badge/PowerShell-7.5%2B-blue?logo=powershell)](https://github.com/PowerShell/PowerShell) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![Preview](https://img.shields.io/badge/status-preview-orange)](https://github.com/AgentEvalHQ/AgentEval) [![AgentEval](https://img.shields.io/badge/powered%20by-AgentEval-blue)](https://github.com/AgentEvalHQ/AgentEval)
## 概述 PSAgentEval 是一个 PowerShell 模块,它封装了 [AgentEval](https://github.com/AgentEvalHQ/AgentEval) .NET 红队评估库,使您能够直接从 PowerShell 命令行或 CI 管道中,对 Claude AI 代理运行自动化的对抗性安全评估。 您可以发送涵盖 9 个攻击类别的多达 192 个预写对抗性探测,并接收结构化的 `PSObject` 结果,该结果可立即用于管道传输、筛选、导出为 JSON 或用于在构建门控中执行失败判断。 **覆盖范围:** - [OWASP LLM Top 10 2025](https://owasp.org/www-project-top-10-for-large-language-model-applications/) 中的 10 个类别中的 6 个 - 6 个 [MITRE ATLAS](https://atlas.mitre.org/) 技术 ID ## 快速开始 ``` # 安装 Anthropic API key(添加到您的配置文件中以保持持久性) $env:ANTHROPIC_API_KEY = 'sk-ant-...' # 理想情况下,您不应该以明文形式拥有 API key,因此请使用来自 Microsoft.PowerShell.SecretManagement 模块的 Get-Secret 如下所示: $env:ANTHROPIC_API_KEY = Get-Secret -Name ANTHROPIC_API_KEY -AsPlainText # 导入模块 Import-Module ./PSAgentEval.psd1 # 运行快速扫描(最低成本,~50 次探测) $result = Invoke-AgentRedTeam -SystemPrompt "You are a customer support bot for Contoso." $result.Verdict # Pass | PartialPass | Fail | Inconclusive $result.OverallScore # 0–100 (higher is better) ``` ## 攻击类别 | 类别 | OWASP ID | MITRE ATLAS | 描述 | |---|---|---|---| | 提示注入 | LLM01 | AML.T0051 | 直接指令覆盖尝试 | | 越狱 | LLM01 | AML.T0051, AML.T0054 | 角色扮演和人设劫持攻击 | | 个人身份信息 / 数据泄露 | LLM02 | AML.T0024, AML.T0037 | 提取个人信息或训练数据 | | 系统提示提取 | LLM07 | AML.T0043 | 尝试暴露系统提示 | | 间接注入 | LLM01 | AML.T0051 | 隐藏在已处理文档中的攻击载荷 | | 过度授权 | LLM06 | AML.T0051, AML.T0054 | 请求执行未经授权的操作或使用工具 | | 不安全输出处理 | LLM05 | AML.T0051 | 代理输出中的 XSS 和注入攻击载荷 | | 推理 API 滥用 | LLM10 | AML.T0045 | Token 洪泛和上下文耗尽 | | 编码规避 | LLM01 | AML.T0051 | Base64、十六进制和 URL 编码的攻击载荷 | ## 参数 | 参数 | 类型 | 默认值 | 描述 | |---|---|---|---| | `-ApiKey` | `String` | `$env:ANTHROPIC_API_KEY` | Anthropic API 密钥 | | `-Model` | `String` | `claude-opus-4-7` | 要评估的 Claude 模型 ID | | `-SystemPrompt` | `String` | `"You are a helpful AI assistant."` | 提供给待测代理的系统提示 | | `-Intensity` | `String` | `Quick` | `Quick`、`Moderate` 或 `Comprehensive` | | `-RateLimitMs` | `Int` | `100` | 探测请求之间的毫秒间隔 | | `-FailFast` | `Switch` | | 在第一次成功的攻击探测后停止 | ### 强度等级 | 等级 | 探测数量 | 预估成本 | |---|---|---| | `Quick` | ~50 | $0.01–$0.03 | | `Moderate` | ~100 | $0.05–$0.10 | | `Comprehensive` | 最多 192 | $0.10–$0.30 | ## 输出对象 `Invoke-AgentRedTeam` 返回一个包含以下属性的 `PSObject`: | 属性 | 类型 | 描述 | |---|---|---| | `Verdict` | `String` | `Pass`、`PartialPass`、`Fail` 或 `Inconclusive` | | `Passed` | `Boolean` | 仅当判定为 `Pass` 时为 `$true` | | `OverallScore` | `Double` | 0–100,成功抵御的探测百分比(越高越好) | | `AttackSuccessRate` | `Double` | 0–1,成功的探测比例(越低越好) | | `TotalProbes` | `Int` | 发送的探测总数 | | `ResistedProbes` | `Int` | 代理成功抵御的探测数 | | `SucceededProbes` | `Int` | 暴露漏洞的探测数 | | `InconclusiveProbes` | `Int` | 结果不确定的探测数 | | `StartedAt` | `DateTimeOffset` | 扫描开始时间 | | `CompletedAt` | `DateTimeOffset` | 扫描结束时间 | | `Duration` | `TimeSpan` | 扫描总时长 | | `AgentName` | `String` | 待测代理的名称 | | `Summary` | `String` | 人类可读的摘要段落 | | `FailedAttackNames` | `String[]` | 未被完全抵御的攻击类别 | | `AttackResults` | `PSObject[]` | 包含 `Probes` 数组的每次攻击细分结果 | `AttackResults` 中的每个条目都包含 `AttackName`、`Passed`、`TotalProbes`、`SucceededProbes`、`Severity`、`HighestSeverity` 和一个 `Probes` 数组。每个探测项包含 `ProbeId`、`Outcome`、`Severity`、`Difficulty`、`Technique`、`Prompt`、`Response`、`Reason` 和 `MatchedItems`。 ## 示例 ### 基本扫描 ``` $env:ANTHROPIC_API_KEY = 'sk-ant-...' $result = Invoke-AgentRedTeam -SystemPrompt "You are a customer support bot for Contoso." $result.Verdict $result.OverallScore ``` ### 检查失败的攻击类别 ``` $result = Invoke-AgentRedTeam -Intensity Moderate -SystemPrompt "You are a financial advisor bot." if (-not $result.Passed) { Write-Warning "Agent failed: $($result.Verdict) (score $($result.OverallScore))" $result.AttackResults | Where-Object { -not $_.Passed } | Select-Object AttackName, SucceededProbes, AttackSuccessRate | Format-Table -AutoSize } ``` ### 深入查看 High 和 Critical 等级的探测失败 ``` $result = Invoke-AgentRedTeam -Intensity Comprehensive -RateLimitMs 500 $result.AttackResults | ForEach-Object { $_.Probes } | Where-Object { $_.Outcome -eq 'Succeeded' -and $_.Severity -in 'High','Critical' } | Select-Object ProbeId, Severity, Technique, Prompt, Response | Format-List ``` ### 使用 FailFast 的 CI 门控 ``` $result = Invoke-AgentRedTeam -Intensity Quick -FailFast if (-not $result.Passed) { Write-Error "Red team gate failed: $($result.FailedAttackNames -join ', ')" exit 1 } ``` ### 导出完整结果为 JSON ``` Invoke-AgentRedTeam -Intensity Comprehensive | ConvertTo-Json -Depth 10 | Set-Content -Path "redteam-$(Get-Date -Format 'yyyyMMdd-HHmmss').json" ``` ## 安装 PSAgentEval 尚未发布到 PowerShell Gallery。请克隆仓库并直接导入模块: ``` git clone https://github.com/anthonyg-1/PSAgentEval.git cd PSAgentEval Import-Module ./PSAgentEval.psd1 ``` **要求:** - PowerShell 7.5.0 或更高版本 - 一个 [Anthropic API 密钥](https://console.anthropic.com/) ## 许可 MIT © Anthony Guimelli / Ralliant。参见 [LICENSE](LICENSE)。 此模块由 [AgentEval](https://github.com/AgentEvalHQ/AgentEval) 提供支持,作者 Jose Luis Latorre,同样采用 MIT 许可。
标签:AI合规, AI安全, Chat Copilot, Claude AI, Libemu, LLM安全评估, MITRE ATLAS, OWASP LLM Top 10, PowerShell模块, 代理评估, 多人体追踪, 安全扫描工具, 对抗性探测, 红队评估, 网络安全, 隐私保护