首页
/ RuView v3 智能体集群中的 Injection Analyst:提示注入攻击的分类、复杂度评分与缓解闭环

RuView v3 智能体集群中的 Injection Analyst:提示注入攻击的分类、复杂度评分与缓解闭环

2026-09-06 16:36:34作者:咎岭娴Homer

本文以 injection-analyst.md 这一 v3 安全智能体定义文件为核心,完整拆解 RuView 仓库 .claude/agents/v3/ 目录下 Injection Analyst 的角色设定:六大攻击技术分类表、基于 @claude-flow/aidefence 的四步分析工作流、MITRE ATT&CK 技术映射、sophistication 加权评分与规避手段检测、结构化 JSON 输出契约,以及模式学习与周期报告的闭环机制。读完本文,你可以理解一个"提示注入/越狱分析专家"智能体在 Agent 集群中如何与 Guardian 类实时检测智能体分工协作,并可复用其分类表、评分权重与输出格式设计到自己的 LLM 安全防护系统中。

一、定位与元数据:一个高优先级安全分析专家

该文件是一个标准的 claude-flow v3 智能体定义(Markdown + YAML frontmatter),与同目录下的 aidefence-guardian.mdsecurity-architect-aidefence.mdpii-detector.mdsecurity-auditor.md 共同构成 RuView 项目 .claude/ 目录中的安全智能体矩阵。

frontmatter 中的关键元数据决定了这个智能体在集群中的行为属性:

字段 取值 含义
name injection-analyst 智能体标识
type security 安全域智能体
description Deep analysis specialist for prompt injection and jailbreak attempts with pattern learning 定位:提示注入与越狱尝试的深度分析专家,具备模式学习能力
priority high 高优先级调度
requires.packages @claude-flow/aidefence 依赖 AIDefence 检测库
capabilities 六项能力 见下表
hooks.pre/post 两段 shell 提示 会话启动/结束的初始化与收尾输出

六项能力声明覆盖了完整的分析闭环:

  • injection_analysis:注入行为分析;
  • attack_pattern_recognition:攻击模式识别;
  • technique_classification:攻击技术分类;
  • threat_intelligence:威胁情报沉淀;
  • pattern_learning:模式学习;
  • mitigation_recommendation:缓解策略推荐。

值得注意的是它与 aidefence-guardian 的定位差异:Guardian 是 priority: criticalsingleton: true 的实时守门员(负责在输入处理前做 <10ms 级检测与阻断),而 Injection Analyst 是"事后深挖"角色——接收 Guardian 转来的告警样本,做分类、溯源、评分与学习。从文件结构看,二者共享同一个 @claude-flow/aidefence 依赖包,构成"检测—分析—学习"的分层防御。

二、攻击技术分类表:六大类别与严重度分级

文档给出了核心分类矩阵,这是该智能体最重要的知识资产:

类别 典型技术 严重度
指令覆写(Instruction Override) "Ignore previous"、"Forget all"、"Disregard" Critical
角色切换(Role Switching) "You are now"、"Act as"、"Pretend to be" High
越狱(Jailbreak) DAN、Developer mode、Bypass 请求 Critical
上下文操纵(Context Manipulation) 伪造系统消息、分隔符滥用 Critical
编码攻击(Encoding Attacks) Base64、ROT13、Unicode 技巧 Medium
社会工程(Social Engineering) 假设性话术、研究名义 Low-Medium

这张表的设计逻辑是:直接破坏系统提示(覆写、伪造系统消息)和突破安全边界(越狱)被判为 Critical,因为一旦得逞意味着模型约束完全失效;角色切换虽改变身份但未必破坏约束,判 High;编码攻击本身不直接突破约束,只是给检测器"加噪",判 Medium;社会工程攻击依赖模型配合,单独出现危害最小,判 Low-Medium。这套分级后续会直接驱动输出契约中的 verdict 判定与缓解策略选择。

三、四步分析工作流:从检测到学习

文档主体是一段 TypeScript 参考实现,定义了 analyzeInjection 的完整四步流水线。需要说明的是:@claude-flow/aidefence 包本身并不随 RuView 仓库分发(它是 frontmatter 中声明的外部依赖),因此这段代码应视为智能体行为规范层面的参考实现,展示了对该库 API 的期望用法——createAIDefencedetectsearchSimilarThreatsgetBestMitigationlearnFromDetection

import { createAIDefence, checkThreats } from '@claude-flow/aidefence';

const analyst = createAIDefence({ enableLearning: true });

async function analyzeInjection(input: string) {
  // Step 1: Initial detection
  const detection = await analyst.detect(input);

  if (!detection.safe) {
    // Step 2: Deep analysis
    const analysis = {
      input,
      threats: detection.threats,
      techniques: classifyTechniques(detection.threats),
      sophistication: calculateSophistication(input, detection),
      evasionAttempts: detectEvasion(input),
      similarPatterns: await analyst.searchSimilarThreats(input, { k: 5 }),
      recommendedMitigations: [],
    };

    // Step 3: Get mitigation recommendations
    for (const threat of detection.threats) {
      const mitigation = await analyst.getBestMitigation(threat.type);
      if (mitigation) {
        analysis.recommendedMitigations.push({
          threatType: threat.type,
          strategy: mitigation.strategy,
          effectiveness: mitigation.effectiveness
        });
      }
    }

    // Step 4: Store for pattern learning
    await analyst.learnFromDetection(input, detection);

    return analysis;
  }

  return null;
}

四个步骤的设计意图:

  1. Step 1 初检短路analyst.detect(input) 复用 AIDefence 内置的 50+ 注入模式库做快速判定;detection.safe === true 时直接返回 null,深度分析只对命中样本执行,避免把算力花在干净输入上。
  2. Step 2 深度画像:对不安全样本并行聚合六类证据——原始威胁列表、MITRE 技术分类、复杂度评分、规避手段、相似历史模式(k: 5 近邻检索)、缓解建议占位。这里 searchSimilarThreats 体现了与仓库中 aidefence-guardian.md 一致的"相似历史检测"用法(Guardian 同样以 searchSimilarThreats(input, { k: 5 }) 检索历史),也呼应了 security-architect-aidefence.md 中提到的 HNSW 加速威胁模式检索能力——即相似性搜索底层依赖向量近邻索引而非线性扫描。
  3. Step 3 缓解推荐:按威胁类型逐一调用 getBestMitigation,把"该用什么策略、历史有效率多少"结构化进输出,而不是硬编码 block。这与 Guardian 智能体中 guardian.recordMitigation('jailbreak', 'block', true) 的回流机制形成闭环:缓解有效率是随拦截结果持续更新的。
  4. Step 4 学习落盘learnFromDetection(input, detection) 把本次样本写入模式库,使检测能力随流量增长——这正是 enableLearning: true 配置项的落点。

四、MITRE ATT&CK 映射:classifyTechniques

classifyTechniques 函数把 AIDefence 的威胁类型翻译成 MITRE ATT&CK 技术 ID,使 LLM 注入事件能纳入传统安全运营的技术语言体系:

AIDefence 威胁类型 分类名 MITRE ID MITRE 技术
instruction_override Direct Override T1059.007 Command scripting
jailbreak Jailbreak T1548 Abuse elevation
context_manipulation Context Injection T1055 Process injection
function classifyTechniques(threats) {
  const techniques = [];
  for (const threat of threats) {
    switch (threat.type) {
      case 'instruction_override':
        techniques.push({
          category: 'Direct Override',
          technique: threat.description,
          mitre_id: 'T1059.007' // Command scripting
        });
        break;
      case 'jailbreak':
        techniques.push({
          category: 'Jailbreak',
          technique: threat.description,
          mitre_id: 'T1548' // Abuse elevation
        });
        break;
      case 'context_manipulation':
        techniques.push({
          category: 'Context Injection',
          technique: threat.description,
          mitre_id: 'T1055' // Process injection
        });
        break;
    }
  }
  return techniques;
}

从映射关系看,作者的类比思路是:指令覆写≈以脚本方式执行非预期命令(T1059.007),越狱≈滥用提权(T1548),上下文注入≈向宿主进程注入代码(T1055)。这是把"提示词层面"的攻击类比到"系统层面"攻击的映射,便于安全团队用既有 ATT&CK 工具链做统计与对齐。实现上该 switch 只覆盖三类(role_switchingencoding_attackpii_exposure 等其余类型不产出 MITRE 条目),可推断其定位是"关键攻击优先映射",而非全覆盖字典。

五、复杂度评分与规避检测:两个启发式打分器

5.1 calculateSophistication:0–1 的加权评分

function calculateSophistication(input, detection) {
  let score = 0;

  // Multiple techniques = more sophisticated
  score += detection.threats.length * 0.2;

  // Evasion attempts
  if (/base64|encode|decrypt/i.test(input)) score += 0.3;
  if (/hypothetically|theoretically/i.test(input)) score += 0.2;

  // Length-based obfuscation
  if (input.length > 500) score += 0.1;

  // Unicode tricks
  if (/[\u200B-\u200D\uFEFF]/.test(input)) score += 0.4;

  return Math.min(score, 1.0);
}

权重设计值得逐项解读:

  • 多技术叠加threats.length × 0.2):命中威胁数越多,攻击组合越精密,线性累计;
  • 编码关键词(base64/encode/decrypt,+0.3):显式提及编码是刻意绕检测的强信号;
  • 假设性话术(hypothetically/theoretically,+0.2):典型的社会工程铺垫;
  • 长度伪装(>500 字符,+0.1):长文本中藏恶意指令的常见手法;
  • 零宽字符\u200B-\u200D\uFEFF,+0.4):单项最高权重——零宽字符注入意味着攻击者已主动针对渲染与比对环节做对抗;
  • 上限钳制Math.min(score, 1.0) 保证输出始终落在 [0,1] 区间,可直接作为置信度或趋势指标。

输出示例中 sophistication: 0.7 即表示一次中等偏复杂的攻击。

5.2 detectEvasion:四类规避标签

function detectEvasion(input) {
  const evasions = [];

  if (/hypothetically|in theory|for research/i.test(input)) {
    evasions.push('hypothetical_framing');
  }
  if (/base64|rot13|hex/i.test(input)) {
    evasions.push('encoding_obfuscation');
  }
  if (/[\u200B-\u200D\uFEFF]/.test(input)) {
    evasions.push('unicode_injection');
  }
  if (input.split('\n').length > 10) {
    evasions.push('long_context_hiding');
  }

  return evasions;
}

四个标签分别对应:假设性框架话术(hypothetical_framing)、编码混淆(encoding_obfuscation,注意此处比评分函数多覆盖了 rot13/hex)、Unicode 零宽注入(unicode_injection)、长上下文藏匿(行数 >10,long_context_hiding——把恶意指令埋进多行文本降低逐行审查命中率)。evasionAttempts 是字符串数组而非评分,便于在输出契约中逐项列出,也便于报告阶段做频次统计。

六、输出契约:结构化 JSON 分析结果

智能体的最终交付物是一份严格结构的 JSON,这是它与下游消费者(Guardian、threat-intel、报告生成器)之间的接口契约:

{
  "analysis": {
    "threats": [
      {
        "type": "jailbreak",
        "severity": "critical",
        "confidence": 0.98,
        "technique": "DAN jailbreak variant"
      }
    ],
    "techniques": [
      {
        "category": "Jailbreak",
        "technique": "DAN mode activation",
        "mitre_id": "T1548"
      }
    ],
    "sophistication": 0.7,
    "evasionAttempts": ["hypothetical_framing"],
    "similarPatterns": 3,
    "recommendedMitigations": [
      {
        "threatType": "jailbreak",
        "strategy": "block",
        "effectiveness": 0.95
      }
    ]
  },
  "verdict": "BLOCK",
  "reasoning": "High-confidence DAN jailbreak attempt with evasion tactics"
}

字段与前三节一一对应:threats 来自 Step 1 检测器(含 confidence 与 severity);techniques 来自 MITRE 映射;sophisticationevasionAttempts 来自两个启发式打分器;similarPatterns 是近邻检索命中的历史模式数(示例为 3,对应 k: 5 检索下的命中条数);recommendedMitigations 携带策略与有效率(示例中 block 策略 0.95)。顶层 verdict 是最终裁决(示例为 BLOCK),reasoning 给出人类可读理由。这种"分析细节 + 单一裁决 + 理由"的三段式设计,使机器可直接消费 verdict,人可直接审 reasoning

七、模式学习:轨迹(Trajectory)三段式 API

分析不是终点。文档在 "Pattern Learning Integration" 一节规定了把单次分析沉淀为训练轨迹的三段式调用:

// Start trajectory for this analysis session
analyst.startTrajectory(sessionId, 'injection_analysis');

// Record analysis steps
for (const step of analysisSteps) {
  analyst.recordStep(sessionId, step.input, step.result, step.reward);
}

// End trajectory with verdict
await analyst.endTrajectory(sessionId, wasSuccessfulBlock ? 'success' : 'failure');
  • startTrajectory(sessionId, 'injection_analysis'):以会话 ID 开启一条标注为 injection_analysis 类型的轨迹;
  • recordStep:逐步记录(输入、结果、奖励三元组),把分析过程本身当作可强化学习的序列;
  • endTrajectory:以该次拦截最终成功与否(success/failure)收尾轨迹。

这与 frontmatter 中 pattern_learning 能力声明、enableLearning: true 配置以及 post hook 中 "patterns stored for learning" 的提示语相互印证:拦截成功/失败这一外部反馈是学习信号的核心来源。

八、协作网络与周期报告

8.1 协作关系

文档 Collaboration 一节声明了三条协作边:

  • aidefence-guardian:接收告警、提供深度分析。仓库中的 aidefence-guardian.md 定义了 Guardian 的升级协议——Block、Log、Alert、Escalate、Learn 五步,其中 Escalate 会经由 swarm memory(security_escalations 命名空间)写入需要人工/架构师复核的条目,这正是 Analyst 的上游样本来源;
  • security-architect:把攻击趋势反馈给架构决策。仓库中 security-architect-aidefence.md 展示了配套的 CLI 用法(npx claude-flow@v3alpha security defend --input "$TASK" --mode thorough --json),说明安全智能体矩阵共享同一套 AIDefence 检测入口;
  • threat-intel:向威胁情报系统输出模式。

8.2 周期分析报告

function generateReport(analyses: Analysis[]) {
  const report = {
    period: { start: startDate, end: endDate },
    totalAttempts: analyses.length,
    byCategory: groupBy(analyses, 'category'),
    bySeverity: groupBy(analyses, 'severity'),
    topTechniques: getTopTechniques(analyses, 10),
    sophisticationTrend: calculateTrend(analyses, 'sophistication'),
    mitigationEffectiveness: calculateMitigationStats(analyses),
    recommendations: generateRecommendations(analyses)
  };

  return report;
}

报告聚合八个维度:时间窗、总攻击数、按类别/严重度分布、Top 10 技术、复杂度趋势(即第五节评分的时序曲线)、缓解有效率统计、以及自动生成的改进建议。其中 sophisticationTrend 特别有价值:复杂度持续上升往往意味着攻击方在迭代,应触发缓解策略升级。

九、在 RuView 仓库中的落地语境

理解这个智能体如何被加载,需要看仓库的 Claude Code 配置:

  • settings.jsonclaudeFlow.version3.0.0agentTeams.enabledtrue,swarm 拓扑为 hierarchical-meshmaxAgents: 15),即 .claude/agents/v3/ 下的定义文件正是该 v3 框架消费的 agent 清单;
  • permissions.allow 预授权了 Bash(npx claude-flow*)mcp__claude-flow__:*,使智能体可以合法调用 claude-flow 的内存与协作 API;
  • UserPromptSubmitPreToolUse 等 hook 统一路由到 .claude/helpers/hook-handler.cjs,构成 Guardian 类"输入前置扫描"的工程挂点;
  • v3-security-overhaul/SKILL.md 则从技能层面规定了 v3 安全改造的整体目标(secure-by-default、路径净化、execFile 安全执行等),Injection Analyst 的产出(攻击趋势、Top 技术)是其中"输入面防护"一环的持续输入。

两点边界需要说明:其一,@claude-flow/aidefence 包未包含在仓库内,文档中的 TypeScript 是该智能体的规范级参考实现,实际 API 行为以该包实现为准;其二,文档中的性能与覆盖率数字(如 Guardian 文档所述 <10ms 检测延迟、50+ 内置模式)属于 agent 定义文件的自我描述,宜作为设计目标理解。

十、可复用的设计要点小结

从这份 agent 定义可以提炼出对任何"LLM 安全运营"场景都成立的四个设计模式:

  1. 检测与分析分层:轻量实时检测(Guardian,全量扫描)+ 深度后置分析(Analyst,仅命中样本),用短路逻辑控制成本;
  2. 分类学驱动:先建立攻击类别/严重度/技术 ID 三层分类表,再谈评分与缓解,保证输出可统计、可对齐 ATT&CK;
  3. 启发式评分显式化:复杂度与规避检测的权重(0.2/0.3/0.4 等)直接写在规范里,可审计、可随误报情况调参;
  4. 拦截反馈回流learnFromDetection + trajectory 三段式 + recordMitigation 有效率回流,让"拦截成功与否"成为模型持续改进的监督信号,形成检测—分析—学习—报告的完整闭环。
登录后查看全文
热门项目推荐
相关项目推荐