kidoz/vulners-cli

GitHub: kidoz/vulners-cli

一款由 Vulners 数据库驱动的命令行漏洞扫描与审计工具,支持主机、容器镜像、代码仓库及 SBOM 的多维度安全扫描。

Stars: 6 | Forks: 0

# vulners-cli [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/kidoz/vulners-cli/actions/workflows/ci.yml) [![Release](https://static.pigsec.cn/wp-content/uploads/repos/cas/42/42ba98a60a0bb3b0ad908f024db145f9c5b831eb7df822f56ac578ee7d7215b3.svg)](https://github.com/kidoz/vulners-cli/actions/workflows/release.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/kidoz/vulners-cli)](https://goreportcard.com/report/github.com/kidoz/vulners-cli) [![GitHub release](https://img.shields.io/github/v/release/kidoz/vulners-cli)](https://github.com/kidoz/vulners-cli/releases) [![License](https://img.shields.io/github/license/kidoz/vulners-cli)](LICENSE) 基于 Go 的 CLI 漏洞扫描器,由 [Vulners](https://vulners.com) 提供支持,使用 [go-vulners](https://github.com/kidoz/go-vulners) 作为情报后端。 专为安全工程师、CI/CD pipeline 以及需要确定性 JSON 输出的 AI agent 设计。 ## 安装 ### Homebrew (macOS) ``` brew install kidoz/vulners/vulners-cli ``` ### 从源码安装 ``` go install github.com/kidoz/vulners-cli/cmd/vulners@latest ``` ### 从发布版安装 从 [GitHub Releases](https://github.com/kidoz/vulners-cli/releases) 下载二进制文件。 ### Docker ``` docker build -t vulners . docker run --rm -e VULNERS_API_KEY vulners scan repo /src # 或者挂载本地项目: docker run --rm -e VULNERS_API_KEY -v "$(pwd):/src" vulners scan repo /src ``` ## 身份验证 将你的 Vulners API key 设置为环境变量: ``` export VULNERS_API_KEY=your-api-key-here ``` 有关模板,请参见 [`.env.example`](.env.example)。在 [vulners.com](https://vulners.com) 获取 API key。 ## 命令 ### Intel 命令 ``` # 搜索 Vulners 数据库 vulners search "apache log4j" vulners search "type:exploit AND apache" --limit 20 vulners search "log4j" --exploits # search exploits only # 查找特定 CVE vulners cve CVE-2021-44228 vulners cve CVE-2021-44228 --references # include external references vulners cve CVE-2021-44228 --history # include change history # 按 CPE 搜索 vulners cpe chrome --vendor google vulners cpe nginx --limit 20 # vendor defaults to product name # 导出 STIX bundle vulners stix CVE-2021-44228 # auto-detects CVE prefix vulners stix RHSA-2021:5137 # by bulletin ID vulners stix CVE-2021-44228 --by-cve # explicit CVE lookup # 自动补全和建议 vulners autocomplete "apache log" # search query autocomplete vulners suggest type # field value suggestions ``` ### Audit 命令 ``` # 审计 Linux packages vulners audit linux --distro ubuntu --version 22.04 --pkg openssl=3.0.2 --pkg curl=7.81.0 # 审计 Windows KB updates vulners audit windows --kb KB5034441 --kb KB5034439 # 主机审计(v4 API -- package 为 "name version" 格式) vulners audit host --os ubuntu --version 22.04 --packages "openssl 3.0.2" --packages "curl 7.81.0" # 完整 Windows 审计(KBs + 软件) vulners audit winaudit --os "Windows 10" --version "19045" --kb KB5034441 --software "Firefox 121.0" ``` ### Scan 命令 ``` # 扫描本地或远程主机(通过 SSH 或 WinRM 进行无代理扫描) vulners scan host local vulners scan host ssh://user@192.168.1.10 --ask-pass vulners scan host ssh://user@192.168.1.10 --identity-file ~/.ssh/id_rsa vulners scan host winrms://Administrator@192.168.1.20 --password-env WIN_PASS # 扫描 Go repository(通过 govulncheck 感知可达性) vulners scan repo . vulners scan repo /path/to/project # 扫描目录中的 package manifests vulners scan dir . # 扫描 CycloneDX SBOM vulners scan sbom sbom.json --format cyclonedx # 扫描 SPDX SBOM vulners scan sbom sbom.spdx.json --format spdx # 扫描容器镜像 vulners scan image alpine:3.18 vulners scan image ubuntu:22.04 --distro ubuntu/22.04 # override distro detection ``` 镜像扫描会自动检测 OS 发行版,并使用专用的 API 进行精确匹配: - **OS 包** (apk/deb/rpm) 通过 `LinuxAudit` API 进行匹配,并支持感知发行版的版本比较 - **应用程序包** 通过 `SBOMAudit` API 进行匹配,并附带 CVSS、EPSS、AIScore 和 exploit 扩展信息 - 输出包含 `imageMeta`,其中包括发行版信息、包分类和 audit 模式 ### VScanner (远程扫描) ``` # 管理项目 vulners vscan license vulners vscan project list vulners vscan project create --name "Production" --license vulners vscan project stats --stat total_hosts,unique_cve vulners vscan project update --name "Production" --license # 管理扫描任务 vulners vscan task list vulners vscan task create --name "Web Servers" --networks 10.0.0.0/24 --ports 1-1000 --timing normal vulners vscan task start vulners vscan task delete # 访问结果 vulners vscan result list vulners vscan result delete ``` ### Webhook 和订阅 ``` # Webhooks — 当有匹配查询的新通报时接收通知 vulners webhook list vulners webhook add "type:exploit AND apache" vulners webhook read vulners webhook enable vulners webhook disable vulners webhook delete # Subscriptions — 管理的告警规则 vulners subscription list vulners subscription create --name "Log4j alerts" --type email --query "log4j" vulners subscription get vulners subscription enable vulners subscription disable vulners subscription delete ``` ### 报告 ``` # 账户级别的漏洞报告 vulners report summary # aggregated vulnerability summary vulners report vulns --limit 50 # list known vulnerabilities vulners report hosts # host vulnerability status vulners report scans # scan history vulners report ips # IP-level summary ``` ### MCP 服务器 将 vulners-cli 作为 [Model Context Protocol](https://modelcontextprotocol.io/) 服务器运行,以便进行 AI agent 集成: ``` vulners mcp ``` 向兼容 MCP 的客户端(Claude Desktop、Cursor 等)暴露用于搜索、CVE 查找、CPE 搜索、SBOM audit 和健康检查的工具。 ### 离线模式 ``` # 同步漏洞数据以供离线使用 vulners offline sync --collections cve,exploit # 检查离线数据库状态 vulners offline status # 清除离线数据库 vulners offline purge # 在任何受支持的命令中使用离线数据 vulners scan repo . --offline vulners scan dir . --offline vulners cve CVE-2021-44228 --offline vulners search "log4j" --offline ``` ### 诊断 ``` # 检查环境健康状态 vulners doctor ``` 验证 API key、网络连接、离线缓存和 Go 安装。使用 `--output json` 获取机器可读的结果。 ## 输出格式 ``` # JSON(默认) vulners scan repo . --output json # 人类可读表格 vulners scan repo . --output table # SARIF(用于 GitHub Code Scanning 和 IDE 集成) vulners scan repo . --output sarif # HTML 报告 vulners scan repo . --output html # CycloneDX VEX vulners scan repo . --output cyclonedx # 写入文件而不是 stdout vulners scan repo . --output sarif --output-file results.sarif ``` ## Agent 和 CI/CD 模式 ``` # 机器友好模式:JSON、静默、确定性排序、无颜色 vulners scan repo . --agent # 选择特定的 JSON fields vulners scan repo . --fields findings.vulnID,findings.severity,summary # 仅显示摘要和前 5 项 findings(适用于 LLM 上下文的较小负载) vulners scan repo . --summary-only # 限制 findings 数量(在输出中保留总数) vulners scan repo . --max-findings 20 # Dry-run:显示扫描将执行的操作 vulners scan repo . --plan # 用于工具集成的命令规范 vulners spec vulners schema scan ``` ## 策略与退出码 ``` # 如果 findings 达到或超过指定 severity 则失败 vulners scan repo . --fail-on high vulners scan repo . --fail-on critical # 忽略特定的 CVE vulners scan repo . --ignore CVE-2021-44228 --ignore CVE-2023-0001 # 使用 OpenVEX document 抑制 findings vulners scan repo . --vex vex.json ``` | 退出码 | 含义 | |---|---| | 0 | 无超出门限的发现 | | 1 | 存在超出门限的发现 | | 2 | 用法或配置错误 | | 3 | 运行时错误 | ## 全局 flag | Flag | 描述 | |---|---| | `--output` | 输出格式:`json`、`table`、`sarif`、`html`、`cyclonedx`(默认:`json`) | | `--output-file` | 将输出写入文件而不是 stdout | | `--quiet` / `-q` | 抑制非错误输出 | | `--verbose` / `-v` | 启用调试输出 | | `--offline` | 仅使用离线数据库 | | `--agent` | 机器友好模式:JSON 输出、静默、确定性排序、无颜色 | | `--no-color` | 禁用彩色日志输出 | | `--fail-on` | 在达到指定严重程度时以退出码 1 失败:`low`、`medium`、`high`、`critical` | | `--ignore` | 要忽略的 CVE ID(可重复使用) | | `--vex` | 用于抑制发现的 OpenVEX 文档路径 | | `--fields` | 选择要包含在输出中的 JSON 字段(可重复使用,仅限 JSON) | | `--summary-only` | 仅输出摘要和首要发现 | | `--max-findings` | 输出中的最大发现数量;0 = 不限(默认:`0`) | | `--plan` | 显示扫描将要执行的操作而不实际执行 | ## 配置 可以通过位于 `~/.vulners/config.yaml` 的 YAML 文件配置 `vulners-cli`: ``` api_key: your-api-key-here verbose: false quiet: false offline: false ``` 配置优先级(最高优先级优先):CLI flag > 环境变量 > 配置文件 > 默认值。 环境变量使用 `VULNERS_` 前缀(例如 `VULNERS_API_KEY`、`VULNERS_VERBOSE`)。 ## 开发 ``` # 构建 just build # 运行测试(带有 race detector) just test # 运行集成测试(需要 VULNERS_API_KEY) just test-integration # 运行 linter just lint # 格式化代码 just fmt # 移除构建产物 just clean ``` ### 需求 - Go >= 1.26 - [just](https://github.com/casey/just) 任务运行器 - golangci-lint v2 - gofumpt ## 架构 ``` cmd/vulners/main.go Fx wiring, Kong parse, logger init internal/cmd/ Kong command structs internal/config/ Koanf v2 config loader internal/intel/ go-vulners wrapper + govulncheck + vscanner internal/cache/ SQLite offline cache (modernc.org/sqlite) internal/inventory/ go.mod, npm, pip, CycloneDX/SPDX, syft parsers internal/matcher/ Component normalization + vuln matching + enrichment internal/policy/ --fail-on / --ignore / VEX filtering + exit codes internal/report/ JSON, table, SARIF, HTML, CycloneDX output internal/model/ Component, Finding, ExitCode, SeverityLevel ``` ## 安全 有关漏洞披露策略,请参见 [SECURITY.md](SECURITY.md)。 ## 许可证 MIT -- 详情请见 [LICENSE](LICENSE)。
标签:AI应用开发, DevSecOps, EVTX分析, Go, Ruby工具, 上游代理, 加密, 威胁情报, 密码管理, 开发者工具, 日志审计, 漏洞扫描器, 请求拦截