AntPatcher
自动化安全漏洞扫描与修复系统,利用多智能体协作实现代码安全漏洞的自动检测、验证和修复。
┌─────────────────────────────────────────────────────────────┐ │ 用户界面层 │ │ ┌─────────────────┐ ┌─────────────────────────────┐ │ │ │ Web 界面 │ │ 命令行接口 │ │ │ │ (launcher.py) │ │ (vul_fix.py) │ │ │ └─────────────────┘ └─────────────────────────────┘ │ └─────────────────────────────────────────────────────────────┘ │ ┌─────────────────────────────────────────────────────────────┐ │ 智能体协作层 (crewAI) │ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │ │ 安全侦察兵 │───▶│ 安全裁决官 │───▶│ 修复架构师 │ │ │ │ (Scout) │ │(Adjudicator)│ │(Remediation)│ │ │ └─────────────┘ └─────────────┘ └─────────────┘ │ └─────────────────────────────────────────────────────────────┘ │ ┌─────────────────────────────────────────────────────────────┐ │ 工具层 │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────┐ │ │ │ Bandit │ │ Semgrep │ │ CodeQL │ │ 补丁工具 │ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────────┘ │ └─────────────────────────────────────────────────────────────┘
python -m venv venv # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate
pip install -r requirements.txt
如需使用 CodeQL 深度扫描功能:
Queries/py/
编辑 config.yaml 文件:
config.yaml
# LLM 配置 llm: api_key: "your-api-key" # API 密钥 api_base: "https://api.xxx.com/v1" # API 地址 default: model: "gpt-4.1" # 默认模型 temperature: 0.5 # 温度系数 analysis: model: "gpt-4.1" # 分析模型 temperature: 0.2 remediation: model: "gpt-4.1" # 修复模型 temperature: 0.2 # 修复流程配置 fix_process: batch_size: 5 # 每批处理文件数 max_iterations: 1 # 最大迭代次数 # 扫描工具配置 scan_tools: bandit: enabled: true config_file: bandit.yaml semgrep: enabled: true config: p/security-audit codeql: enabled: true query_set: top25 # 智能体配置 agents: scout: verbose: true max_iter: 15 adjudicator: verbose: true max_iter: 20 remediation: verbose: true max_iter: 25
python launcher.py
启动后访问 http://localhost:5000
Web 界面功能:
python vul_fix.py <目标路径> [参数]
参数说明:
目标路径
--batch-size
--max-iterations
示例:
# 扫描单个文件 python vul_fix.py ./src/main.py # 扫描整个目录 python vul_fix.py ./src --batch-size 20 --max-iterations 5
1. 复制目标文件到 fixed 目录 ↓ 2. 安全侦察兵执行扫描(Bandit + Semgrep + CodeQL) ↓ 3. 安全裁决官验证漏洞、判定严重等级 ↓ 4. 修复架构师生成补丁并应用 ↓ 5. 重新扫描验证 ↓ 6. 重复步骤 2-5 直到无漏洞或达到最大迭代次数 ↓ 7. 输出修复报告
AntPather/ ├── Agent/ # 智能体定义 │ ├── __init__.py │ └── security_agents.py # 三个安全智能体配置 ├── SecTool/ # 安全扫描工具 │ ├── bandit_tool.py # Bandit 扫描工具 │ ├── semgrep_tool.py # Semgrep 扫描工具 │ ├── codeql_tool.py # CodeQL 扫描工具 │ └── secure_code_search_tool.py # 安全代码知识库 ├── SecurityTools/ # 协作工具 │ ├── file_reader.py # 文件读取工具 │ ├── patch_tool.py # 补丁生成与应用 │ ├── scan_result_reporter.py # 扫描结果报告 │ └── validated_vulnerability_reporter.py # 漏洞验证报告 ├── launcher/ # Web 界面模块 │ ├── config_manager.py # 配置管理 │ ├── git_integration.py # Git 集成 │ └── ... ├── Queries/ # CodeQL 查询规则 │ └── py/ ├── templates/ # Web 模板 │ └── index.html ├── fixed/ # 修复后的文件(自动生成) ├── fix_log/ # 扫描和修复日志(自动生成) ├── config.yaml # 配置文件 ├── requirements.txt # 依赖列表 ├── launcher.py # Web 界面入口 ├── vul_fix.py # 命令行入口 └── README.md # 本文档
fixed/
fix_log/
iter*_scan_*.json
iter*_validated_*.json
iter*_remediation_*.json
iter*_patch_apply_*.json
summary_*.json
补丁保存在 fixed/patch_{timestamp}/ 目录:
fixed/patch_{timestamp}/
*.patch
*.json
SecTool/bandit_tool.py
SecTool/semgrep_tool.py
vul_fix.py
Q: 扫描时提示找不到 Python 解释器?
A: 检查 SecTool/bandit_tool.py 和 SecTool/semgrep_tool.py 中的 venv_python 变量是否正确。
venv_python
Q: CodeQL 扫描失败?
A: 确保 CodeQL CLI 已正确安装并添加到 PATH,同时检查 Queries/py/ 目录是否存在。
Q: Web 界面无法访问?
A: 检查 5000 端口是否被占用,或修改 launcher.py 中的端口号。
launcher.py
MIT License
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802047560号
安全漏洞扫描修复系统
自动化安全漏洞扫描与修复系统,利用多智能体协作实现代码安全漏洞的自动检测、验证和修复。
功能特性
系统架构
智能体说明
环境要求
安装步骤
1. 创建虚拟环境
2. 安装依赖
3. 安装 CodeQL(可选)
如需使用 CodeQL 深度扫描功能:
Queries/py/目录存在配置说明
编辑
config.yaml文件:启动方式
方式一:Web 界面启动(推荐)
启动后访问 http://localhost:5000
Web 界面功能:
方式二:命令行启动
参数说明:
目标路径--batch-size--max-iterations示例:
工作流程
目录结构
输出说明
输出目录
fixed/fix_log/日志文件
iter*_scan_*.jsoniter*_validated_*.jsoniter*_remediation_*.jsoniter*_patch_apply_*.jsonsummary_*.json补丁文件
补丁保存在
fixed/patch_{timestamp}/目录:*.patch*.json支持的漏洞类型示例
注意事项
config.yaml提交到版本控制SecTool/bandit_tool.py第 13 行SecTool/semgrep_tool.py第 12 行vul_fix.py第 631 行--batch-size参数分批处理大量文件常见问题
Q: 扫描时提示找不到 Python 解释器?
A: 检查
SecTool/bandit_tool.py和SecTool/semgrep_tool.py中的venv_python变量是否正确。Q: CodeQL 扫描失败?
A: 确保 CodeQL CLI 已正确安装并添加到 PATH,同时检查
Queries/py/目录是否存在。Q: Web 界面无法访问?
A: 检查 5000 端口是否被占用,或修改
launcher.py中的端口号。许可证
MIT License