YaraFlux威胁分析服务

@ThreatFlux/YaraFlux
0 Stars 431 次浏览 ThreatFlux 更新于 2026-08-23

一种模型上下文协议服务器,使AI助手能够对文件和URL进行基于YARA规则的威胁分析,支持全面的规则管理和详细的扫描结果。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "yaraflux-mcp-server": {
      "args": [
        "run",
        "-i",
        "--rm",
        "--env",
        "JWT_SECRET_KEY=your-secret-key",
        "--env",
        "ADMIN_PASSWORD=your-admin-password",
        "--env",
        "DEBUG=true",
        "--env",
        "PYTHONUNBUFFERED=1",
        "threatflux/yaraflux-mcp-server:latest"
      ],
      "autoApprove": [
        "scan_url",
        "scan_data",
        "list_yara_rules",
        "get_yara_rule"
      ],
      "command": "docker",
      "disabled": false
    }
  }
}

该服务需要配置环境变量:ADMIN_PASSWORD、DEBUG、JWT_SECRET_KEY

服务介绍

YaraFlux MCP 服务器

GitHub release (latest by date)
CI
codecov
Codacy Badge

Python Version
FastAPI
MCP

一个用于YARA扫描的模型上下文协议(MCP)服务器,为大型语言模型提供基于YARA规则分析文件的能力。

📋 概述

YaraFlux MCP 服务器通过标准化的模型上下文协议接口,使AI助手能够执行基于YARA规则的威胁分析。该服务器将YARA扫描与现代AI助手集成在一起,通过模块化架构支持全面的规则管理、安全扫描和详细的结果分析。

🧩 架构概览

+------------------------------------------+
|              AI Assistant                |
+--------------------+---------------------+
                    |
                    | Model Context Protocol
                    |
+--------------------v---------------------+
|              YaraFlux MCP Server         |
|                                          |
|  +----------------+    +---------------+ |
|  | MCP Server     |    | Tool Registry | |
|  +-------+--------+    +-------+-------+ |
|          |                     |         |
|  +-------v--------+    +-------v-------+ |
|  | YARA Service   |    | Storage Layer | |
|  +----------------+    +---------------+ |
|                                          |
+------------------------------------------+
          |                   |
 +-----------------+  +---------------+
 | YARA Engine     |  | Storage       |
 | - Rule Compiling|  | - Local FS    |
 | - File Scanning |  | - MinIO/S3    |
 +-----------------+  +---------------+

YaraFlux 遵循一种模块化架构,将以下方面分离:

  • MCP集成层:处理与AI助手的通信
  • 工具实现层:实现YARA扫描和管理功能
  • 存储抽象层:提供灵活的存储选项
  • YARA引擎集成:利用YARA进行扫描和规则管理

有关详细的架构图,请参阅架构文档

✨ 特性

  • 🔄 模块化架构

    • MCP集成、工具实现和存储的清晰分离
    • 标准化的参数解析和错误处理
    • 灵活的存储后端,支持本地和S3/MinIO选项
  • 🤖 MCP集成

    • 集成了19个MCP工具,提供全面的功能
    • 优化了Claude Desktop集成
    • 可直接从对话中分析文件
    • 兼容最新的MCP协议规范
  • 🔍 YARA扫描

    • URL和文件内容扫描
    • 详细匹配信息及上下文
    • 扫描结果的存储和检索
    • 性能优化的扫描引擎
  • 📝 规则管理

    • 创建、读取、更新、删除YARA规则
    • 规则验证并提供详细的错误报告
    • 从ThreatFlux仓库导入规则
    • 按来源(自定义与社区)分类
  • 📊 文件分析

    • 用于二进制分析的十六进制视图
    • 可配置参数的字符串提取
    • 文件元数据和哈希信息
    • 安全的文件上传和存储
  • 🔐 安全特性

    • API访问的JWT认证
    • 非root容器执行
    • 安全的存储隔离
    • 可配置的访问控制

🚀 快速开始

使用Docker镜像

# Pull the latest Docker image
docker pull threatflux/yaraflux-mcp-server:latest
# Run the container
docker run -p 8000:8000 \
  -e JWT_SECRET_KEY=your-secret-key \
  -e ADMIN_PASSWORD=your-admin-password \
  -e DEBUG=true \
  threatflux/yaraflux-mcp-server:latest
### Using Docker building from source

```bash
# Clone the repository
git clone https://github.com/ThreatFlux/YaraFlux.git
cd YaraFlux/

# Build the Docker image
docker build -t yaraflux-mcp-server:latest .

# Run the container
docker run -p 8000:8000 \
  -e JWT_SECRET_KEY=your-secret-key \
  -e ADMIN_PASSWORD=your-admin-password \
  -e DEBUG=true \
  yaraflux-mcp-server:latest

从源代码安装

# Clone the repository
git clone https://github.com/ThreatFlux/YaraFlux.git
cd YaraFlux/

# Install dependencies (requires Python 3.13+)
make install

# Run the server
make run

🧩 Claude Desktop集成

YaraFlux设计为通过Model Context Protocol无缝集成到Claude Desktop。

  1. 构建Docker镜像:
docker build -t yaraflux-mcp-server:latest .
  1. 添加到Claude Desktop配置 (~/Library/Application Support/Claude/claude_desktop_config.json):
{
  "mcpServers": {
    "yaraflux-mcp-server": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "--env",
        "JWT_SECRET_KEY=your-secret-key",
        "--env",
        "ADMIN_PASSWORD=your-admin-password",
        "--env",
        "DEBUG=true",
        "--env",
        "PYTHONUNBUFFERED=1",
        "threatflux/yaraflux-mcp-server:latest"
      ],
      "disabled": false,
      "autoApprove": [
        "scan_url",
        "scan_data",
        "list_yara_rules",
        "get_yara_rule"
      ]
    }
  }
}
  1. 重启Claude Desktop以激活服务器。

🛠️ 可用的MCP工具

YaraFlux提供了19个集成的MCP工具:

规则管理工具

  • list_yara_rules: 列出可用的YARA规则,并提供过滤选项
  • get_yara_rule: 获取特定YARA规则的内容和元数据
  • validate_yara_rule: 验证YARA规则语法并提供详细的错误报告
  • add_yara_rule: 创建新的YARA规则
  • update_yara_rule: 更新现有的YARA规则
  • delete_yara_rule: 删除YARA规则
  • import_threatflux_rules: 从ThreatFlux GitHub仓库导入规则

扫描工具

  • scan_url: 使用指定的YARA规则扫描URL内容
  • scan_data: 使用指定规则扫描提供的数据(base64编码)
  • get_scan_result: 从之前的扫描中获取详细结果

文件管理工具

  • upload_file: 上传文件进行分析或扫描
  • get_file_info: 获取已上传文件的元数据
  • list_files: 分页和排序列出已上传文件
  • delete_file: 删除已上传的文件
  • extract_strings: 从文件中提取ASCII/Unicode字符串
  • get_hex_view: 获取文件内容的十六进制视图
  • download_file: 下载已上传的文件

存储管理工具

  • get_storage_info: 获取存储使用统计
  • clean_storage: 清除旧文件以释放存储空间

📚 文档

完整的文档可以在 docs/ 目录中找到:

🗂️ 项目结构

yaraflux_mcp_server/
├── src/
│   └── yaraflux_mcp_server/
│       ├── app.py                 # FastAPI application
│       ├── auth.py                # JWT authentication and user management
│       ├── config.py              # Configuration settings loader
│       ├── models.py              # Pydantic models for requests/responses
│       ├── mcp_server.py          # MCP server implementation
│       ├── utils/                 # Utility functions package
│       │   ├── __init__.py        # Package initialization
│       │   ├── error_handling.py  # Standardized error handling
│       │   ├── param_parsing.py   # Parameter parsing utilities
│       │   └── wrapper_generator.py # Tool wrapper generation
│       ├── mcp_tools/             # Modular MCP tools package
│       │   ├── __init__.py        # Package initialization
│       │   ├── base.py            # Base tool registration utilities
│       │   ├── file_tools.py      # File management tools
│       │   ├── rule_tools.py      # YARA rule management tools
│       │   ├── scan_tools.py      # Scanning tools
│       │   └── storage_tools.py   # Storage management tools
│       ├── storage/               # Storage implementation package
│       │   ├── __init__.py        # Package initialization
│       │   ├── base.py            # Base storage interface
│       │   ├── factory.py         # Storage client factory
│       │   ├── local.py           # Local filesystem storage
│       │   └── minio.py           # MinIO/S3 storage
│       ├── routers/               # API route definitions
│       │   ├── __init__.py        # Package initialization
│       │   ├── auth.py            # Authentication API routes
│       │   ├── files.py           # File management API routes
│       │   ├── rules.py           # YARA rule management API routes
│       │   └── scan.py            # YARA scanning API routes
│       ├── yara_service.py        # YARA rule management and scanning
│       ├── __init__.py            # Package initialization
│       └── __main__.py            # CLI entry point
├── docs/                          # Documentation
├── tests/                         # Test suite
├── Dockerfile                     # Docker configuration
├── entrypoint.sh                  # Container entrypoint script
├── Makefile                       # Build automation
├── pyproject.toml                 # Project metadata and dependencies
├── requirements.txt               # Core dependencies
└── requirements-dev.txt           # Development dependencies

🧪 开发

本地开发

# Set up development environment
make dev-setup

# Run tests
make test

# Code quality checks
make lint
make format
make security-check

# Generate test coverage report
make coverage

# Run development server
make run

CI/CD 工作流

此项目使用 GitHub Actions 进行持续集成和部署:

  • CI 测试:在每次推送到 main 和 develop 分支以及拉取请求时运行

    • 运行测试、格式化、代码检查和类型检查
    • 构建并测试 Docker 镜像
    • 将测试覆盖率报告上传到 Codecov
  • 版本自动递增:在推送到 main 分支时自动递增版本

    • 更新 pyproject.toml、setup.py 和 Dockerfile 中的版本
    • 为新版本创建 git 标签
  • 发布版本:在成功版本自动递增后触发

    • 为多个阶段构建 Docker 镜像
    • 从 git 提交生成发布说明
    • 创建带有附件的 GitHub 发布
    • 将 Docker 镜像发布到 Docker Hub

这些工作流确保了代码质量并自动化了发布过程。

状态检查

以下状态检查会在拉取请求上运行:

  • 格式验证:确保代码遵循 Black 和 isort 格式标准
  • 代码检查:验证代码质量和是否符合编码标准
  • 测试执行:运行完整的测试套件以验证功能
  • 覆盖率报告:确保代码库有足够的测试覆盖率

🌐 API 文档

交互式 API 文档可访问:

  • Swagger UI: http://localhost:8000/docs
  • ReDoc: http://localhost:8000/redoc

有关详细 API 文档,请参阅 API 参考

🤝 贡献

欢迎贡献!请随时提交 Pull Request。

  1. 叉仓库
  2. 创建你的功能分支 (git checkout -b feature/amazing-feature)
  3. 提交你的更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 打开一个 Pull Request

📄 许可证

此项目根据 MIT 许可证授权 - 详情见 LICENSE 文件。

💖 捐赠或请求功能

相关 MCP 服务