saipurumandla/ctip

GitHub: saipurumandla/ctip

一个基于事实、全程可审计的 AI 辅助网络威胁情报平台,能从非结构化报告中自动提取 IOC、实体和攻击技战术,并以极低幻觉率输出可追溯的结构化情报。

Stars: 0 | Forks: 0

# CTIP — 网络威胁情报平台 [![CI](https://img.shields.io/badge/CI-passing-green)](https://github.com/org/ctip) [![Grounding](https://img.shields.io/badge/grounding-94%25-brightgreen)](docs/EVALUATION.md) [![Python 3.11](https://img.shields.io/badge/python-3.11-blue)](https://python.org) 一个完全基于事实、可审计、AI 辅助的威胁情报平台。 每一个输出都可以从原始报告文本追溯到最终发现。 ## 设计原则 - **基于事实优先** — 没有来自源文本的证据就不产生发现 - **可审计性** — 每一次转换都记录在仅追加的审计日志中 - **Human in the loop** — 低置信度的输出始终交由人工审查 - **多模型** — 通过配置在 Claude、GPT-4o 或本地模型之间切换 ## 架构 ``` Raw Report │ ▼ ┌─────────────┐ │ Ingestion │ hash, dedup, encoding detection └──────┬──────┘ │ ▼ ┌─────────────┐ │ Parsing │ text cleaning, sentence splitting └──────┬──────┘ │ ▼ ┌───────────────────────────┐ │ Extraction │ │ ┌─────────────────────┐ │ │ │ Regex (rules) │ │ IPv4, domain, hash, CVE, URL, email │ ├─────────────────────┤ │ │ │ spaCy NER │ │ org, location, person │ ├─────────────────────┤ │ │ │ Fine-tuned NER │ │ malware, threat actor, tool, vulnerability │ ├─────────────────────┤ │ │ │ ATT&CK Mapper │ │ technique/tactic classification │ └─────────────────────┘ │ └──────┬────────────────────┘ │ ▼ ┌─────────────────────┐ │ Normalization │ lowercase domains, strip protocols, │ + Semantic Dedup │ cosine-similarity near-duplicate detection └──────┬──────────────┘ │ ▼ ┌─────────────┐ │ Validation │ per-type rules + confidence threshold └──────┬──────┘ │ ▼ ┌─────────────┐ │ Scoring │ composite: rule overlap + model probability └──────┬──────┘ │ ▼ ┌──────────────────────────┐ │ Retrieval (RAG) │ ChromaDB vector store, top-k similar reports └──────┬───────────────────┘ │ ▼ ┌──────────────────────────┐ │ Reasoning / Agents │ Grounded analyst agent (Claude / GPT-4o) │ + Structured Extraction │ OpenAI function calling (gpt-3.5-turbo-0613) └──────┬───────────────────┘ │ ▼ ┌──────────────────────────┐ │ Guardrails │ evidence grounding, NLI hallucination check, │ │ token budget, confidence threshold, prompt tracking └──────┬───────────────────┘ │ ▼ ┌──────────────────────────┐ │ Storage + Audit Log │ SQLite + append-only JSONL audit log └──────┬───────────────────┘ │ ▼ ┌──────────────────────────┐ │ Review Queue │ Human review for flagged findings (confidence < 0.7) └──────────────────────────┘ ``` ## AI 组件 | 组件 | 模型 | 版本 | Grounding 检查 | |----------------------|-----------------------------|---------|----------------------| | Grounded Analyst | claude-3-5-sonnet-20241022 | v1 | span match + NLI | | Grounded Analyst | gpt-4o (alt backend) | v1 | span match + NLI | | Structured Extract | gpt-3.5-turbo-0613 | v1 | span match | | IOC Summarizer | text-davinci-002 | v1 | span match | | NER (fine-tuned) | bert-base-cased (CTI) | 3.2.1 | confidence gate | | Embeddings (RAG) | all-MiniLM-L6-v2 | n/a | n/a | | NLI (hallucination) | nli-deberta-v3-small | n/a | n/a | 所有 LLM prompts 都在 `prompts/` 中进行版本控制。版本升级需要运行 prompt 回归测试。`tests/prompt_regression/` 中经过 Hash 锁定的测试可检测任何未进行版本控制的修改。 ## Guardrails 请参阅 GUARDRAILS.md 获取完整规范。关键门控: 1. **Evidence span match** — 每一个 LLM 声明都必须引用源文本的精确子串 2. **NLI 矛盾检查** — NLI 模型标记与源文本矛盾的声明 3. **置信度阈值** — 置信度 < 0.7 → 人工审查队列 4. **Token 预算** — 如果超出限制,prompts 将在句子边界处被截断 5. **Prompt 版本追踪** — 每次 LLM 调用都会记录 prompt 版本 6. **回归漂移** — 提取数量与基线相比变化 > 20% → 告警 ## 评估结果 在 500 份标记报告上进行了评估(留出测试集,上次运行时间 2025-01-10): | 指标 | 分数 | |-------------------------------|-------| | IOC 提取 F1 | 0.94 | | 实体提取 F1 | 0.88 | | Finding grounding 准确率 | 0.94 | | 幻觉率 (findings) | 1.2% | | 误报率 | 2.8% | 请参阅 EVALUATION.md 获取完整的方法论和结果。 ## 审计日志 所有 pipeline 操作都写入仅追加的 JSONL 审计日志中。 任何内容都不会被删除 —— 撤回被建模为一条新记录。 ``` GET /api/audit/report/{report_id} — full provenance chain for a report GET /api/audit/finding/{finding_id} — evidence chain for a finding ``` ## 人工审查队列 被任何 guardrail 标记或置信度 < 0.7 的 findings 将进入队列: ``` GET /api/review/queue POST /api/review/{item_id}/approve POST /api/review/{item_id}/reject ``` ## 项目结构 ``` ctip/ ingestion/ -- report loading and deduplication parsing/ -- text cleaning and encoding detection extraction/ regex_extractor.py -- IPv4, domain, hash, CVE, URL, email entity_extractor.py -- spaCy NER (org, location, person) ml_extractor.py -- fine-tuned NER (malware, threat actor, tool) attack_mapper.py -- MITRE ATT&CK technique mapping normalization/ normalizer.py -- value normalization semantic_dedup.py -- near-duplicate detection validation/ -- per-type validation rules scoring/ -- composite confidence scoring storage/ -- SQLite persistence layer retrieval/ vector_store.py -- ChromaDB vector store for RAG reasoning/ llm_summarizer.py -- LLM summarization (text-davinci-002) structured_extractor.py -- structured extraction (function calling) agents/ analyst.py -- grounded analyst agent (Claude / GPT-4o) guardrails/ evidence_checker.py -- span-match grounding check hallucination_guard.py -- NLI contradiction check review/ queue.py -- human review queue audit/ log.py -- append-only JSONL audit log evaluation/ -- precision/recall evaluation harness api/ main.py -- FastAPI application schemas.py -- Pydantic domain models pipeline.py -- stage orchestration prompts/ v1/ summarize.txt -- IOC summarization prompt extract.txt -- structured extraction prompt analyst.txt -- grounded analyst prompt config/ patterns.yml -- regex patterns settings.ini -- runtime configuration models/ ner_model/ -- fine-tuned NER model artifacts (not in git) tests/ unit/ -- per-module unit tests integration/ -- API integration tests evaluation/ -- NER evaluation harness regression/ -- IOC extraction regression suite prompt_regression/ -- prompt content and drift detection ``` ## 安装 ``` pip install -r requirements.txt python -m spacy download en_core_web_sm # API keys (仅对应的 LLM backends 需要) export ANTHROPIC_API_KEY=your_key_here export OPENAI_API_KEY=your_key_here ``` LLM 组件默认是禁用的。在 `config/settings.ini` 中设置 `LLM_ENABLED=true` 以启用它们。 ## 运行 ``` docker-compose up # full stack # 或: uvicorn ctip.api.main:app # API only, port 8000 ``` ## 测试 ``` pytest tests/ -v pytest tests/prompt_regression/ -v # prompt drift detection pytest tests/evaluation/ -v # NER evaluation suite pytest tests/regression/ -v # IOC regression suite ``` ## 文档 - ARCHITECTURE.md — 系统设计和数据流图 - GUARDRAILS.md — guardrail 规范和阈值 - MODEL_CARD.md — 模型版本、训练数据、评估 - EVALUATION.md — 评估方法论和完整结果 - SECURITY.md — 威胁模型和安全策略 - CHANGELOG.md — 版本历史 ## 系统要求 Python 3.11+,SQLite(默认)或 PostgreSQL 14+
标签:AI辅助分析, CISA项目, Clair, Claude, Cloudflare, CTIP, CVE提取, CVE检测, DLL 劫持, DNS 反向解析, DNS 解析, Go语言工具, GPT-4, HTTP工具, IP 地址批量处理, IP提取, masscan, MITRE ATT&CK, NER, NLP, Python, spaCy, Threat Intelligence, TTP映射, XSS, 人机协同, 可审计, 命名实体识别, 域名提取, 多模型, 大语言模型, 威胁情报平台, 威胁挖掘, 威胁行为者, 威胁追踪, 子域名变形, 实体抽取, 微调模型, 恶意软件识别, 报告解析, 插件系统, 攻击组织, 数据去重, 数据清洗, 文本分析, 无后门, 无线安全, 智能安全, 测试用例, 漏洞情报, 网络威胁情报, 网络安全, 网络安全审计, 自动化情报分析, 请求拦截, 逆向工具, 隐私保护