# Host Cve Validator

> 主机安全CVE漏洞修复验证引擎。从主机漏扫报告(Excel)或CVE编号自动提取漏洞，查询威胁情报(NVD/EPSS/MSRC/OVAL)，生成修复脚本(fix.sh/fix.ps1)，SSH验证脚本可执行性，产出修复验证报告。覆盖 Linux(centos/ubuntu/debian/suse/amazon/fedora/alpine/arch) + Windows + Web-CMS 三类。触发关键词：主机漏扫、CVE验证、漏洞修复验证、host CVE、fix validation。

- Skill: `infometa/host-cve-validator` (Agent Skill, multi-file: 56 files)
- Install (CLI): `npx skillmds@latest add infometa/host-cve-validator`
- Raw SKILL.md: https://api.skillmd.com/api/skills/infometa/host-cve-validator/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Data & Analytics
- Author: infometa (https://skillmd.com/u/infometa)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/infometa/host-cve-validator

---


# 主机安全CVE漏洞修复验证

## 角色

资深主机安全修复工程师。精准定位漏洞修复路径，给出可验证的修复结论。

## 支持系统

| 家族 | 发行版 | 包管理器 | OVAL 离线 | SSH 实测 |
|---|---|---|---|---|
| RHEL 系 | CentOS/RHEL/TencentOS/Rocky/Alma/Anolis/openEuler/Oracle/Amazon/Fedora | yum/dnf | ✅ | ✅ |
| Debian 系 | Ubuntu/Debian/Kali | apt | ✅ (Ubuntu) | ✅ |
| SUSE 系 | SLES/openSUSE | zypper | ✅ | ✅ |
| Alpine 系 | Alpine Linux | apk | ❌ (降级 SSH) | ✅ |
| Arch 系 | Arch Linux | pacman | ❌ (降级 SSH) | ✅ |
| Windows | Windows Server | PowerShell/WinRM | ✅ (MSRC KB) | ✅ |
| Web-CMS | WordPress/Drupal 等 | — | ❌ | ❌ (纯情报) |

## 脚本白名单

仅使用以下 14 个脚本。CVE 信息采集、SSH 准备、数据预处理均由 `run_pipeline.py --batch` 内部自动完成。

| 脚本 | 用途 |
|---|---|
| `plan_gate.py` | 步骤0 门禁（清污 + run_dir 隔离） |
| `parse_host_report.py` | 步骤1.1 解析 Excel → raw_rows.json |
| `propose_extracted.py` | 步骤1.2 生成候选提议 → extracted.proposal.json |
| `adopt_proposal.py` | 步骤1.3 采纳候选 + 暴露 unresolved；--finalize 产 extracted.json |
| `patch_unresolved.py` | 步骤1.4 结构化批量编辑 unresolved.json |
| `merge_extracted.py` | 步骤1.5 合并校验 → vulns.json |
| `run_pipeline.py` | 步骤2-5 主流水线（--create-plan → --batch → --verify → --summary） |
| `recover_failed.py` | 失败任务二次回收（--apply 调度修复决策） |
| `apply_fix.py` | 修正数据 / 注入脚本 |
| `ssh_exec_commands.py` | SSH 执行命令 |
| `generate_word_report.py` | Word 报告生成 |
| `default_intel.py` | NVD+EPSS 情报查询与准确性检测 |
| `kb_query.py` | CVE 知识库查询（--cve / --list / --stats / --recommend） |
| `kb_save.py` | CVE 知识库写入（stage6 自动调用） |

## 工作流程

```
阶段一：解析漏扫
  步骤0  unset 环境变量 + plan_gate.py --init           → run_dir
  步骤1  parse_host_report → propose_extracted → adopt_proposal
         → patch_unresolved → adopt_proposal --finalize → merge_extracted  → vulns.json

阶段二：主流水线 (run_pipeline.py)
  步骤2  --create-plan vulns.json                        → execution_plan.json
  步骤3  --batch                                         → 单条 Task 自动流水线：
            Stage0 KB查询 → Stage1 CVE情报分析(NVD/CIRCL/OSV)
            → Stage2 OS确认(OVAL离线/SSH实测/MSRC KB/Win)
            → 组件分类 refine → 分流判定(auto / ai_required)
            → Stage3 脚本生成(fix.sh/fix.ps1) + 静态校验(bash -n)
            → 回写 plan.json
  步骤3.5 --verify                                        → 按主机分组并行 SSH/Win dry-run 验证
  步骤4  recover_failed.py --apply（可选）                → NEEDS_AI_FIX 二次回收
  步骤5  --summary                                        → 按 display_status 分桶汇总 + Word 报告 + 写入 KB

分流判定规则：
  auto:      来源=权威(OVAL/KB/主机仓库/fix_plan/厂商公告) → 直接生成脚本
  ai_required: 来源=推断(NVD上游/assess/不同源/unknown)  → 写入 needs_ai_fix 等待 Agent
  manual:    vuln_category=driver_manual               → NEEDS_MANUAL_REVIEW 不生成脚本

代码模块（scripts/pipeline/）：
  status.py     TaskOutcome 统一状态模型(emoji+label+category)
  diagnostics.py LinuxFixDiagnosis OVAL/SSH 诊断结构化
  routing.py    分流判定 + 来源推断
  handlers.py   CategoryHandler 策略模式(linux/windows/web_cms/driver_manual)
```

步骤 0→5 无缝衔接，跑完一步立刻跑下一步。仅在以下情况停止：`--init` 检测到环境污染、`--batch` 跑完后 NEEDS_AI_FIX > 0、stdout 出现 fail_fast/environment_mismatch 告警、用户主动喊停。

### 步骤 0 门禁初始化

```bash
unset HOST_CVE_RUN_DIR HOST_CVE_CACHE_DIR
python3 scripts/plan_gate.py --init --input-report "<报告路径>"
export HOST_CVE_RUN_DIR=$(python3 scripts/plan_gate.py --print-run-dir)
```

若 stdout 出现 `POLLUTION DETECTED`，按提示清污后再继续。

### 步骤 1 解析漏扫

```bash
python3 scripts/parse_host_report.py "<报告路径>"
python3 scripts/propose_extracted.py
python3 scripts/adopt_proposal.py
python3 scripts/patch_unresolved.py --list-pending --limit 30
python3 scripts/patch_unresolved.py --auto-fill-from-raw --also-resolved
# 仍有残留时逐条精修：patch_unresolved.py --cve CVE-XXXX --set component=xxx --set _resolution_status=RESOLVED
python3 scripts/adopt_proposal.py --finalize
python3 scripts/merge_extracted.py --validate-only
python3 scripts/merge_extracted.py
```

CVE 总数 ≥ 100 时，先跑 `--auto-fill-from-raw` 批量处理，仅当 PENDING < 30 条时才逐条 `--cve`。

### 步骤 2-5 主流水线

```bash
python3 scripts/run_pipeline.py --create-plan $HOST_CVE_RUN_DIR/vulns.json
python3 scripts/run_pipeline.py --batch          # 脚本自驱跑完所有 pending
python3 scripts/run_pipeline.py --verify          # 全量 dry-run 验证
# 可选：失败回收
python3 scripts/recover_failed.py --apply
python3 scripts/run_pipeline.py --summary         # 汇总报告 + Word + KB
```

`--batch` 是步骤3 唯一入口，脚本在同一进程内自驱循环跑完所有 pending（支持 Ctrl+C 断点续跑）。失败任务走 `recover_failed.py --apply` 或修改 vulns.json/KB 后 `plan_manager.py --reset-failed && run_pipeline.py --batch` 断点续跑。

## 关键规则

1. **stdout 汇报**：`--batch` / `--summary` stdout 完整粘贴到回复。从 stdout 获取全部汇报字段，不读取 `task_results.json` 等中间产物。需要按维度查询时用 `plan_manager.py --query <subtype>` 或 `jq -r '.字段' <file>`。

2. **硬事实原样输出**：`current_version`/`target_version`/`final_status` 等字段原样取自 JSON，不推测、不省略、不格式化。

3. **失败如实报告**：`SKIPPED`/`REVIEW_REQUIRED` 不等于"已验证"。`L3 情报已验证`不等于"已修复"，汇报时保留"情报已验证"字样。

4. **脚本白名单**：仅使用上述 14 个脚本。使用 `patch_unresolved.py` 编辑 unresolved.json，不写 ad-hoc python。

5. **全量跑完**：vulns.json 全量处理直到 `next_action=run_summary`。`--summary` 在 `completed<total` 时报 `SUMMARY GATE BLOCKED`。用户明说"提前收尾"时用 `--summary --force`。

## 验证档次

| 档次 | 状态 | 含义 |
|---|---|---|
| L1 | `SCRIPT_OK_VERIFIED` / `SCRIPT_OK_AI_VERIFIED` | 修复版本可信 + 脚本语法正确 + dry-run 通过 |
| L2 | `SCRIPT_OK` / `SCRIPT_OK_AI_CONFIRMED` | 修复版本同源可信 + 脚本语法正确，未环境验证 |
| — | `REVIEW_REQUIRED` | 待 AI 确认版本号 |
| — | `SKIPPED_OS_MISMATCH` | 跨家族非核心包，诚实降级 |

完整 display_status 映射表见 [references/report-constraints.md](references/report-constraints.md)。

## 退路机制

| 场景 | 动作 |
|---|---|
| 报告格式无法识别 | 告知用户「该文件未匹配已知漏扫报告格式」 |
| `--batch` 中单条 SSH 失败 | 脚本自动 ack 后继续下一条 |
| `--batch` Ctrl+C 中断 | 重新调 `--batch` 断点续跑 |
| NEEDS_AI_FIX > 0 | `recover_failed.py --apply` 回收 → 修 vulns.json/KB → `--reset-failed && --batch` |
| 连续 SSH 超时 | `CVE_BATCH_WORKERS=1` 退回串行 |
| SUMMARY GATE BLOCKED | 重调 `--batch` 跑完剩余；用户明说提前收尾时 `--force` |

完整退路机制见 [references/runtime-contract.md](references/runtime-contract.md)。

## 演示模式

默认以演示验证模式运行：修复目标为测试机（`HOST_CVE_DEMO_LINUX_HOST` 配置），仅验证脚本语法/CVE 情报/包管理器命令。详见 [references/demo-mode.md](references/demo-mode.md)。

## 资源索引

| 类别 | 文件 |
|---|---|
| 路径模块 | `scripts/paths.py` |
| 知识库模块 | `scripts/knowledge_base.py` |
| PLAN 模板 | `assets/PLAN.template.md` |
| 流水线详解 | [references/pipeline.md](references/pipeline.md) |
| run_dir 隔离 | [references/run-dir-isolation.md](references/run-dir-isolation.md) |
| 执行契约 | [references/runtime-contract.md](references/runtime-contract.md) |
| 反幻觉守则 | [references/hallucination-guards.md](references/hallucination-guards.md) |
| 演示模式 | [references/demo-mode.md](references/demo-mode.md) |
| 调用示例 | [references/usage-examples.md](references/usage-examples.md) |
| 汇报约束 | [references/report-constraints.md](references/report-constraints.md) |

