rawqubit/yaraforge
GitHub: rawqubit/yaraforge
YARA 规则全生命周期管理工具,提供规则验证、编译、多线程扫描及远程部署的一站式自动化能力。
Stars: 1 | Forks: 0
# YaraForge 架构概述
## 系统架构
```
graph TB
subgraph Client["Client Layer"]
CLI["CLI Interface
(Command Line Tools)"] end subgraph Core["Core Processing Layer"] Engine["Engine Module
(YARA Rule Processing)"] Compiler["Rule Compiler"] Validator["Rule Validator"] end subgraph Execution["Execution Layer"] Scanner["Scanner
(Local & Remote)"] Deploy["Deployment Manager
(Distribution)"] end subgraph Output["Output Layer"] Report["Report Generator
(Results & Analytics)"] end subgraph Storage["Storage & Resources"] Rules["Rules Directory
(YARA Rule Files)"] Tests["Test Suite
(Unit & Integration Tests)"] end subgraph Targets["Target Systems"] LocalTarget["Local Targets"] RemoteTarget["Remote Targets"] end CLI -->|Commands| Engine CLI -->|Deploy Commands| Deploy CLI -->|Report Requests| Report Engine --> Compiler Engine --> Validator Engine -->|Compiled Rules| Scanner Scanner -->|Scan Rules| LocalTarget Scanner -->|Scan Rules| RemoteTarget Deploy -->|Distribute Rules| LocalTarget Deploy -->|Distribute Rules| RemoteTarget LocalTarget -->|Scan Results| Report RemoteTarget -->|Scan Results| Report Report -->|Generate Reports| CLI Rules -->|Rule Input| Engine Rules -->|Rule Input| Scanner Rules -->|Rule Input| Deploy Tests -->|Validate| Engine Tests -->|Validate| Scanner style Client fill:#e1f5ff style Core fill:#f3e5f5 style Execution fill:#e8f5e9 style Output fill:#fff3e0 style Storage fill:#f5f5f5 style Targets fill:#fce4ec ``` # yaraforge **YARA 规则部署与扫描自动化工具。** [](https://python.org) [](LICENSE) [](https://virustotal.github.io/yara/) [](https://github.com/rawqubit/yaraforge) `yaraforge` 是一个生产级的 CLI 工具,用于管理 YARA 规则的完整生命周期 —— 从加载和验证,到多线程扫描,再到跨本地和远程目标的部署。它专为需要可靠、可脚本化且适配 CI/CD 的 YARA 自动化层的安全工程师而设计。 ## 功能特性 - **规则管理** — 从本地目录、远程 URL 或 GitHub 仓库加载 `.yar`/`.yara` 文件,并自动进行语法验证。 - **快速多线程扫描** — 使用可配置的线程池扫描文件、目录(递归)及进程内存。 - **编译规则包** — 将规则编译为 `.yarc` 包,以便在生产流水线中实现近乎即时地重新加载。 - **灵活部署** — 通过 `rsync` 将规则集部署到本地路径或远程 SSH 主机;支持从公开/私有 GitHub 仓库同步。 - **版本化部署历史** — 每次部署都会记录 SHA-256 包哈希值,支持一键回滚。 - **多种报告格式** — 输出扫描结果为 JSON、SARIF 2.1.0 (GitHub Code Scanning)、HTML、CSV 或纯文本格式。 - **适配 CI/CD** — 匹配到结果时以代码 `1` 退出;SARIF 输出可直接与 GitHub Advanced Security 集成。 - **内置规则库** — 附带针对恶意软件、勒索软件、Web Shell 和网络威胁的检测规则。 ## 安装 ``` # 从 PyPI 安装(推荐) pip install yaraforge # 从源码安装 git clone https://github.com/rawqubit/yaraforge cd yaraforge pip install -e ".[dev]" ``` **系统依赖:** 系统中必须安装 YARA。 ``` # Ubuntu/Debian sudo apt install yara # macOS brew install yara ``` ## 快速入门 ### 验证规则 ``` yaraforge validate ./rules/ # ✓ generic_malware.yar (4 条规则) # ✓ ransomware_generic.yar (4 条规则) # ✓ webshell_generic.yar (4 条规则) # 3/3 文件有效。 ``` ### 扫描目录 ``` yaraforge scan /var/www/html --rules ./rules/ --format text ``` ### 扫描并输出用于 GitHub Code Scanning 的 SARIF ``` yaraforge scan ./src --rules ./rules/ --format sarif --output results.sarif ``` ### 编译规则为包 ``` yaraforge compile ./rules/ --output compiled.yarc # [✓] 已编译 12 条规则 → compiled.yarc (14.2 KB, 3.1ms) ``` ### 从 GitHub 同步规则 ``` yaraforge sync Yara-Rules/rules --dest ./rules/ --branch main # [✓] 已同步 847 个规则文件到 ./rules/ ``` ### 部署规则到远程主机 ``` yaraforge deploy ./rules/ \ --target-type ssh \ --target-path /opt/yara/rules \ --host scanner.internal \ --user deploy \ --key-file ~/.ssh/id_ed25519 ``` ### 扫描运行中的进程 ``` sudo yaraforge scan --rules ./rules/ --pid 1234 ``` ## CLI 参考 ``` Usage: yaraforge [OPTIONS] COMMAND [ARGS]... Options: --verbose, -v Enable debug logging. --version Show version and exit. Commands: scan Scan files, directories, or processes for YARA matches. validate Validate YARA rule syntax without scanning. compile Compile rules into a fast .yarc bundle. sync Pull rules from a GitHub repository. deploy Deploy rules to a local path or remote SSH host. report Convert an existing JSON scan report to another format. ``` ### `scan` 选项 | 标志 | 默认值 | 描述 | |------|---------|-------------| | `--rules, -r` | 必需 | 规则文件或目录(可重复指定) | | `--recursive` | `true` | 递归扫描目录 | | `--threads, -t` | `4` | 扫描器线程数 | | `--max-size` | `50` MB | 最大扫描文件大小 | | `--timeout` | `60` s | 单文件扫描超时时间 | | `--format, -f` | `text` | 输出格式:`json`、`sarif`、`html`、`csv`、`text` | | `--output, -o` | stdout | 将报告写入文件 | | `--pid` | — | 根据进程 PID 扫描运行中的进程 | | `--exit-code` | `true` | 如果发现匹配项则退出码为 1 | ## 报告格式 | 格式 | 适用场景 | |--------|----------| | `text` | 人类可读的终端摘要 | | `json` | 机器可读的完整详情,用于流水线集成 | | `sarif` | GitHub Code Scanning,VS Code SARIF 查看器 | | `html` | 独立的共享报告 | | `csv` | 电子表格分析 | ### GitHub Code Scanning 集成 添加到 `.github/workflows/yara-scan.yml`: ``` name: YARA Scan on: [push, pull_request] jobs: scan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: pip install yaraforge - run: | yaraforge scan . \ --rules rules/ \ --format sarif \ --output yara-results.sarif \ --no-exit-code - uses: github/codeql-action/upload-sarif@v3 with: sarif_file: yara-results.sarif ``` ## 内置规则 `yaraforge` 在 `rules/` 下附带了一个经过筛选的规则库: | 类别 | 规则数 | 描述 | |----------|-------|-------------| | `malware/` | 4 | 通用恶意软件模式、shellcode 存根、C2 信标 | | `ransomware/` | 4 | 勒索信、文件加密 API、WannaCry IoC | | `webshells/` | 4 | PHP、ASPX、JavaScript Web Shell 检测 | | `network/` | — | 网络级威胁指标 | ## 架构 ``` yaraforge/ ├── engine/ │ ├── loader.py # Rule loading, validation, compilation │ └── scanner.py # Multi-threaded file/process/memory scanning ├── deploy/ │ └── deployer.py # Rule deployment, versioning, rollback ├── report/ │ └── reporter.py # JSON, SARIF, HTML, CSV, text output └── cli/ └── main.py # Click CLI entrypoint ``` ## 开发 ``` # 安装开发依赖 pip install -e ".[dev]" # 运行测试 pytest tests/ -v --cov=yaraforge # Lint ruff check yaraforge/ # 类型检查 mypy yaraforge/ ``` ## 许可证 MIT — 详见 [LICENSE](LICENSE)。
(Command Line Tools)"] end subgraph Core["Core Processing Layer"] Engine["Engine Module
(YARA Rule Processing)"] Compiler["Rule Compiler"] Validator["Rule Validator"] end subgraph Execution["Execution Layer"] Scanner["Scanner
(Local & Remote)"] Deploy["Deployment Manager
(Distribution)"] end subgraph Output["Output Layer"] Report["Report Generator
(Results & Analytics)"] end subgraph Storage["Storage & Resources"] Rules["Rules Directory
(YARA Rule Files)"] Tests["Test Suite
(Unit & Integration Tests)"] end subgraph Targets["Target Systems"] LocalTarget["Local Targets"] RemoteTarget["Remote Targets"] end CLI -->|Commands| Engine CLI -->|Deploy Commands| Deploy CLI -->|Report Requests| Report Engine --> Compiler Engine --> Validator Engine -->|Compiled Rules| Scanner Scanner -->|Scan Rules| LocalTarget Scanner -->|Scan Rules| RemoteTarget Deploy -->|Distribute Rules| LocalTarget Deploy -->|Distribute Rules| RemoteTarget LocalTarget -->|Scan Results| Report RemoteTarget -->|Scan Results| Report Report -->|Generate Reports| CLI Rules -->|Rule Input| Engine Rules -->|Rule Input| Scanner Rules -->|Rule Input| Deploy Tests -->|Validate| Engine Tests -->|Validate| Scanner style Client fill:#e1f5ff style Core fill:#f3e5f5 style Execution fill:#e8f5e9 style Output fill:#fff3e0 style Storage fill:#f5f5f5 style Targets fill:#fce4ec ``` # yaraforge **YARA 规则部署与扫描自动化工具。** [](https://python.org) [](LICENSE) [](https://virustotal.github.io/yara/) [](https://github.com/rawqubit/yaraforge) `yaraforge` 是一个生产级的 CLI 工具,用于管理 YARA 规则的完整生命周期 —— 从加载和验证,到多线程扫描,再到跨本地和远程目标的部署。它专为需要可靠、可脚本化且适配 CI/CD 的 YARA 自动化层的安全工程师而设计。 ## 功能特性 - **规则管理** — 从本地目录、远程 URL 或 GitHub 仓库加载 `.yar`/`.yara` 文件,并自动进行语法验证。 - **快速多线程扫描** — 使用可配置的线程池扫描文件、目录(递归)及进程内存。 - **编译规则包** — 将规则编译为 `.yarc` 包,以便在生产流水线中实现近乎即时地重新加载。 - **灵活部署** — 通过 `rsync` 将规则集部署到本地路径或远程 SSH 主机;支持从公开/私有 GitHub 仓库同步。 - **版本化部署历史** — 每次部署都会记录 SHA-256 包哈希值,支持一键回滚。 - **多种报告格式** — 输出扫描结果为 JSON、SARIF 2.1.0 (GitHub Code Scanning)、HTML、CSV 或纯文本格式。 - **适配 CI/CD** — 匹配到结果时以代码 `1` 退出;SARIF 输出可直接与 GitHub Advanced Security 集成。 - **内置规则库** — 附带针对恶意软件、勒索软件、Web Shell 和网络威胁的检测规则。 ## 安装 ``` # 从 PyPI 安装(推荐) pip install yaraforge # 从源码安装 git clone https://github.com/rawqubit/yaraforge cd yaraforge pip install -e ".[dev]" ``` **系统依赖:** 系统中必须安装 YARA。 ``` # Ubuntu/Debian sudo apt install yara # macOS brew install yara ``` ## 快速入门 ### 验证规则 ``` yaraforge validate ./rules/ # ✓ generic_malware.yar (4 条规则) # ✓ ransomware_generic.yar (4 条规则) # ✓ webshell_generic.yar (4 条规则) # 3/3 文件有效。 ``` ### 扫描目录 ``` yaraforge scan /var/www/html --rules ./rules/ --format text ``` ### 扫描并输出用于 GitHub Code Scanning 的 SARIF ``` yaraforge scan ./src --rules ./rules/ --format sarif --output results.sarif ``` ### 编译规则为包 ``` yaraforge compile ./rules/ --output compiled.yarc # [✓] 已编译 12 条规则 → compiled.yarc (14.2 KB, 3.1ms) ``` ### 从 GitHub 同步规则 ``` yaraforge sync Yara-Rules/rules --dest ./rules/ --branch main # [✓] 已同步 847 个规则文件到 ./rules/ ``` ### 部署规则到远程主机 ``` yaraforge deploy ./rules/ \ --target-type ssh \ --target-path /opt/yara/rules \ --host scanner.internal \ --user deploy \ --key-file ~/.ssh/id_ed25519 ``` ### 扫描运行中的进程 ``` sudo yaraforge scan --rules ./rules/ --pid 1234 ``` ## CLI 参考 ``` Usage: yaraforge [OPTIONS] COMMAND [ARGS]... Options: --verbose, -v Enable debug logging. --version Show version and exit. Commands: scan Scan files, directories, or processes for YARA matches. validate Validate YARA rule syntax without scanning. compile Compile rules into a fast .yarc bundle. sync Pull rules from a GitHub repository. deploy Deploy rules to a local path or remote SSH host. report Convert an existing JSON scan report to another format. ``` ### `scan` 选项 | 标志 | 默认值 | 描述 | |------|---------|-------------| | `--rules, -r` | 必需 | 规则文件或目录(可重复指定) | | `--recursive` | `true` | 递归扫描目录 | | `--threads, -t` | `4` | 扫描器线程数 | | `--max-size` | `50` MB | 最大扫描文件大小 | | `--timeout` | `60` s | 单文件扫描超时时间 | | `--format, -f` | `text` | 输出格式:`json`、`sarif`、`html`、`csv`、`text` | | `--output, -o` | stdout | 将报告写入文件 | | `--pid` | — | 根据进程 PID 扫描运行中的进程 | | `--exit-code` | `true` | 如果发现匹配项则退出码为 1 | ## 报告格式 | 格式 | 适用场景 | |--------|----------| | `text` | 人类可读的终端摘要 | | `json` | 机器可读的完整详情,用于流水线集成 | | `sarif` | GitHub Code Scanning,VS Code SARIF 查看器 | | `html` | 独立的共享报告 | | `csv` | 电子表格分析 | ### GitHub Code Scanning 集成 添加到 `.github/workflows/yara-scan.yml`: ``` name: YARA Scan on: [push, pull_request] jobs: scan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - run: pip install yaraforge - run: | yaraforge scan . \ --rules rules/ \ --format sarif \ --output yara-results.sarif \ --no-exit-code - uses: github/codeql-action/upload-sarif@v3 with: sarif_file: yara-results.sarif ``` ## 内置规则 `yaraforge` 在 `rules/` 下附带了一个经过筛选的规则库: | 类别 | 规则数 | 描述 | |----------|-------|-------------| | `malware/` | 4 | 通用恶意软件模式、shellcode 存根、C2 信标 | | `ransomware/` | 4 | 勒索信、文件加密 API、WannaCry IoC | | `webshells/` | 4 | PHP、ASPX、JavaScript Web Shell 检测 | | `network/` | — | 网络级威胁指标 | ## 架构 ``` yaraforge/ ├── engine/ │ ├── loader.py # Rule loading, validation, compilation │ └── scanner.py # Multi-threaded file/process/memory scanning ├── deploy/ │ └── deployer.py # Rule deployment, versioning, rollback ├── report/ │ └── reporter.py # JSON, SARIF, HTML, CSV, text output └── cli/ └── main.py # Click CLI entrypoint ``` ## 开发 ``` # 安装开发依赖 pip install -e ".[dev]" # 运行测试 pytest tests/ -v --cov=yaraforge # Lint ruff check yaraforge/ # 类型检查 mypy yaraforge/ ``` ## 许可证 MIT — 详见 [LICENSE](LICENSE)。
标签:AMSI绕过, DAST, DNS 反向解析, FTP漏洞扫描, HTTP工具, Python, YARA, YARAForge, 云计算, 云资产可视化, 企业安全, 内存分配, 威胁情报, 威胁检测, 安全管理, 安全编排, 库, 应急响应, 开发者工具, 恶意软件分析, 文件分析, 无后门, 本地扫描, 网络安全, 网络资产管理, 自动化运维, 规则引擎, 规则编译, 规则验证, 远程部署, 逆向工具, 隐私保护