目录

AgentVet - AI Agent 安全审计平台

License: MIT Python Version Test Coverage

AgentVet 是一个专门针对 AI Agent 项目的安全审计平台,集成了静态扫描、污点分析、对抗测试等多种安全检测技术,帮助开发者发现和修复 AI Agent 代码中的安全漏洞。


🌟 功能特性

核心功能

  • 🔍 安全扫描:自动识别 AI Agent 代码中的安全漏洞
  • ✅ 漏洞验证:确认漏洞的可利用性
  • ⚡ 自动修复:提供代码级的漏洞修复方案
  • 📊 安全评分:根据漏洞情况计算安全评分(A-F等级)
  • 📄 多格式报告:支持 JSON、CSV、Markdown、HTML、Word 等格式
  • 🩸 污点分析:追踪用户输入到危险函数的数据流
  • ⚔️ 对抗测试:自动生成攻击载荷验证漏洞

特色功能

  • 👤 普通人版报告:用大白话解释安全问题,非技术人员也能看懂
  • 🎨 可视化仪表盘:直观展示扫描结果和安全趋势
  • 🛡️ 安全保障:修复前自动备份,支持回滚操作

覆盖的安全问题类别

类别 规则数 说明
数据泄露(DL) 5 HTTP明文传输、敏感数据日志等
工具滥用(TA) 6 动态代码执行、无限制文件访问等
Prompt注入(PI) 6 输入未清理、越狱模式检测等
框架集成(FW) 6 AutoGen、LangChain等框架安全
MCP安全(MCP) 5 MCP服务器认证、CORS配置等
技能安全(SC) 5 插件验证、权限管理等
AI特有规则(AI) 8 记忆篡改、权限越界等
通用安全(SEC) 5 API密钥泄露、云凭证暴露等

📦 安装指南

环境要求

  • Python 3.10+
  • Git

安装步骤

# 1. 克隆项目
git clone https://gitlink.org.cn/tlyyxjz/agentvet.git
cd agentvet

# 2. 创建虚拟环境
python -m venv venv

# 3. 激活虚拟环境
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activate

# 4. 安装依赖
pip install -r requirements.txt

🚀 使用指南

方式一:可视化仪表盘

# 启动仪表盘
python cli.py dashboard --port 9090

然后在浏览器中访问 http://localhost:9090/

仪表盘功能

  1. 首页仪表盘:查看安全评分和漏洞统计
  2. 扫描项目:输入项目路径进行安全扫描
  3. 漏洞详情:查看漏洞详情和修复建议
  4. 扫描历史:查看历史扫描记录
  5. 规则管理:管理安全检测规则
  6. 报告中心:生成和下载安全报告
  7. API文档:查看API接口文档
  8. 用户设置:配置系统参数

方式二:命令行工具(CLI)

基础命令

# 扫描项目
python cli.py scan /path/to/your/agent-project -o reports

# 查看可用规则
python cli.py list-rules

# 验证漏洞
python cli.py verify reports/project.json

# 生成报告
python cli.py report reports/project.json -o reports -f all

# 启动仪表盘
python cli.py dashboard --port 9090

扫描命令详解

python cli.py scan <target> [选项]

参数:
  target              目标项目路径

选项:
  -o, --output        输出目录(默认: reports)
  -m, --mode          扫描模式:quick(快速)、full(完整)、custom(自定义)
  -r, --rules         指定规则文件(逗号分隔)
  -i, --include       包含的文件模式(逗号分隔)
  -e, --exclude       排除的文件模式(逗号分隔)
  -v, --verbose       详细输出
  --format            输出格式:json、csv、md、html

修复命令详解

python cli.py fix <rule-id> <file-path>

参数:
  rule-id             规则编号(如 DL-002)
  file-path           要修复的文件路径

示例:
python cli.py fix DL-002 location_service.py

污点分析命令

python cli.py taint <target>

参数:
  target              目标项目路径

示例:
python cli.py taint /path/to/project

对抗测试命令

python cli.py adversarial <target> <attack-type>

参数:
  target              目标项目路径
  attack-type         攻击类型:prompt_injection、command_injection、ssrf、xss、data_poisoning

示例:
python cli.py adversarial /path/to/project prompt_injection

完整审计命令

python cli.py full <target> -o reports

参数:
  target              目标项目路径
  -o, --output        输出目录

示例:
python cli.py full /path/to/project -o reports

批量扫描命令

python cli.py batch <config-file>

参数:
  config-file         配置文件路径(JSON格式)

配置文件示例:
{
  "projects": [
    "/path/to/project1",
    "/path/to/project2"
  ],
  "output": "reports",
  "format": ["json", "md"]
}

📁 项目结构

agentvet/
├── agentvet/              # 核心模块
│   ├── __init__.py
│   ├── scan_engine.py     # 扫描引擎
│   ├── verifier.py        # 漏洞验证器
│   ├── taint_analyzer.py  # 污点分析器
│   ├── adversarial_tester.py  # 对抗测试器
│   ├── fix_engine.py      # 修复引擎
│   ├── rule_loader.py     # 规则加载器
│   ├── noise_filter.py    # 噪声过滤器
│   └── rules/             # 规则库
│       ├── __init__.py
│       ├── dl_rules.py    # 数据泄露规则
│       ├── ta_rules.py    # 工具滥用规则
│       ├── pi_rules.py    # Prompt注入规则
│       ├── fw_rules.py    # 框架集成规则
│       ├── mcp_rules.py   # MCP安全规则
│       ├── sc_rules.py    # 技能安全规则
│       ├── ai_rules.py    # AI特有规则
│       └── sec_rules.py   # 通用安全规则
├── reporting/             # 报告生成模块
│   ├── __init__.py
│   ├── reporter.py        # 报告生成器
│   └── templates/         # 报告模板
├── dashboard/             # 可视化仪表盘
│   ├── index.html         # 主页面
│   ├── styles.css         # 样式文件
│   └── app.js             # 前端逻辑
├── cli.py                 # CLI命令行工具
├── run_tests.py           # 测试脚本
├── requirements.txt       # 依赖列表
└── README.md              # 项目说明

🧪 运行测试

# 运行所有测试
python run_tests.py

# 运行特定测试
python run_tests.py -t test_scan_file

测试覆盖模块:

  • NoiseFilter(噪声过滤)
  • Rule(规则匹配)
  • ScanEngine(扫描引擎)
  • RuleLoader(规则加载)
  • Score calculation(评分计算)
  • CLI commands(命令行命令)
  • FixEngine(修复引擎)
  • ReportGenerator(报告生成)
  • VulnerabilityVerifier(漏洞验证)
  • TaintAnalyzer(污点分析)
  • AdversarialTester(对抗测试)

🔌 API 接口

扫描接口

POST /api/scan
Content-Type: application/json

{
  "target": "/path/to/project",
  "mode": "full",
  "output_format": "json"
}

响应:
{
  "success": true,
  "score": "B",
  "summary": {
    "critical": 0,
    "high": 2,
    "medium": 3,
    "low": 1,
    "total": 6
  },
  "findings": [...],
  "duration_ms": 2340
}

修复接口

POST /api/fix
Content-Type: application/json

{
  "rule_id": "DL-002",
  "file_path": "/path/to/file.py"
}

响应:
{
  "success": true,
  "message": "修复成功",
  "backup_path": "backups/file.py_1783401033.bak"
}

报告接口

POST /api/report
Content-Type: application/json

{
  "scan_result": {...},
  "format": ["json", "md", "simple"]
}

响应:
{
  "success": true,
  "reports": [
    {"name": "report.json", "path": "reports/report.json"},
    {"name": "report.md", "path": "reports/report.md"},
    {"name": "report_simple.txt", "path": "reports/report_simple.txt"}
  ]
}

📊 扫描结果说明

安全评分

评分 说明
A 优秀,几乎没有安全问题
B 良好,有少量低风险问题
C 一般,需要关注中等风险问题
D 较差,存在高危漏洞
F 危险,存在严重漏洞

漏洞严重程度

等级 颜色 说明
critical 🔴 红色 严重漏洞,可能导致系统崩溃或数据泄露
high 🟠 橙色 高危漏洞,可能被攻击者利用
medium 🟡 黄色 中危漏洞,需要关注和修复
low 🔵 蓝色 低危漏洞,建议修复以提高安全性

📝 自定义规则

添加新规则

agentvet/rules/ 目录下创建新的规则文件,例如 custom_rules.py

from agentvet import Rule, Severity

rules = [
    Rule(
        rule_id="CUSTOM-001",
        title="自定义规则",
        severity=Severity.HIGH,
        category="自定义",
        pattern=r"custom_vulnerability_pattern",
        description="漏洞描述",
        fix_suggestion="修复建议",
        confidence=90,
        languages=["python"],
        skip_paths=["/tests/"]
    )
]

规则字段说明

字段 类型 说明
rule_id str 规则唯一标识
title str 规则名称
severity Severity 严重程度:CRITICAL/HIGH/MEDIUM/LOW
category str 规则类别
pattern regex 匹配模式(正则表达式)
description str 漏洞描述
fix_suggestion str 修复建议
confidence int 置信度(0-100)
languages list 适用语言列表
skip_paths list 跳过的路径列表

🤝 贡献指南

贡献流程

  1. Fork 项目
  2. 创建功能分支
  3. 提交代码
  4. 创建 Pull Request

代码规范

  • 遵循 PEP 8 代码规范
  • 使用类型注解
  • 添加单元测试
  • 编写清晰的文档

📄 许可证

本项目采用 MIT 许可证,详见 LICENSE 文件。


📞 联系方式


📚 参考资料

  1. “AI Agent Security: A Survey” - arXiv 2025
  2. “Prompt Injection Attacks on AI Agents” - USENIX Security 2025
  3. “Security Risks of AI-Powered Code Assistants” - IEEE S&P 2025

版本: v1.0.0
更新日期: 2026年7月7日

关于

AI Agent Security Audit Platform - 集成静态扫描、污点分析、对抗测试等多种安全检测技术,为AI Agent项目提供全方位安全审计能力

162.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号