Phxmi/threat-intel-agent

GitHub: Phxmi/threat-intel-agent

一款面向 SOC 分析师的 AI 威胁情报聊天 Agent,支持用自然语言跨多个威胁情报源查询 IOC、行为者和漏洞暴露面,并内置执行追踪与提示词注入防御。

Stars: 0 | Forks: 0

# 威胁情报 Agent 一款专为 SOC 分析师设计的智能 AI 威胁情报聊天 Agent。使用自然语言查询威胁数据 —— 支持 IOC 查询、威胁行为者研究、暴露面分析,并能跨 **5 个威胁情报源** 进行数据关联,同时提供 **实时执行追踪** 与 **提示词注入防御**。 ## 功能 - **自然语言接口** — 使用日常英语提问威胁相关问题 (React + FastAPI) - **5 种查询类型**: - **IOC 查询** — IP、域名、文件哈希信誉 - **行为者与 TTP** — 威胁行为者研究及其技术 - **暴露面推理** — 将软件版本映射到已知的 CVE - **关联查询** — 发现相关实体(域名、IP、行为者) - **多轮上下文** — 引用之前的发现(“以及它的 ASN?”) - **多个威胁情报源**: - VirusTotal, AbuseIPDB, AlienVault OTX, NVD, Shodan - 模拟数据集作为最终兜底(始终可用) - **工具降级链** — 当 API 失败或触发频率限制时优雅降级 - **提示词注入防御** — 同时防御 **直接注入**(用户输入)和 **间接注入**(检索到的数据) - **实时执行追踪** — 在每次响应中内联展示逐步的 Agent 可观测性 - **置信度评分** — 每个结果都包含置信度水平 - **来源归属** — 每次响应都会引用其数据来源 ## 快速开始 ``` # 安装 Python 依赖 cd threat_intel_agent pip install -r requirements.txt # 安装 Node.js 依赖 cd frontend && npm install && cd .. # 构建 React 前端 cd frontend && npm run build && cd .. # 配置 API 密钥(可选,不配置也可运行) cp .env.example .env # 编辑 .env 并添加密钥(参见下方的 Configuration) # 启动服务器 python3 -m uvicorn threat_intel_agent.api_server:app --host 127.0.0.1 --port 8000 ``` 然后在浏览器中打开 **http://localhost:8000**。 该 Agent 使用模拟数据即可 **开箱即用** —— 演示无需任何 API 密钥。 ## 配置 ### 可选:添加真实 API 密钥 免费层级 API(推荐用于类生产环境行为): | 服务 | 免费层级 | 最适用途 | |---------|-----------|----------| | **VirusTotal** | 4 次请求/分钟,500 次/天 | 文件哈希,多引擎扫描 | | **AbuseIPDB** | 1000 次/天 | IP 信誉 | | **AlienVault OTX** | 1万次/小时 | 威胁脉冲,行为者 | | **NVD** | 50 次请求/30秒 | CVE/漏洞数据 | | **Shodan** | 100 次/月 | 互联网暴露面 | 获取免费密钥: - [VirusTotal](https://www.virustotal.com/gui/join-us) - [AbuseIPDB](https://www.abuseipdb.com/api/api-key) - [AlienVault OTX](https://otx.alienvault.com/api) - [NVD](https://nvd.nist.gov/developers/api-key) - [Shodan](https://account.shodan.io/) 编辑 `.env`: ``` VIRUSTOTAL_API_KEY="your_key_here" ABUSEIPDB_API_KEY="your_key_here" ALIENVAULT_OTX_API_KEY="your_key_here" NVD_API_KEY="your_key_here" SHODAN_API_KEY="your_key_here" ``` ### 工具优先级与降级 Agent 按以下顺序尝试工具 —— 首个成功的优先: ``` 1. VirusTotal → Best for IPs, domains, hashes 2. AbuseIPDB → IP reputation 3. AlienVault OTX → Threat actors, pulses 4. NVD → CVE lookups 5. Shodan → Internet scanning 6. Mock Dataset → Always works (final fallback) ``` 如果真实 API 失败(频率限制、无密钥、网络错误),Agent 会自动降级到下一个工具。 ## 使用方法 ### Web 界面(推荐) ``` # 构建一次 cd frontend && npm run build && cd .. # 启动服务器 python3 -m uvicorn threat_intel_agent.api_server:app --host 127.0.0.1 --port 8000 ``` 打开 **http://localhost:8000**。 ### 开发模式(热重载) ``` # Terminal 1 — API python3 -m uvicorn threat_intel_agent.api_server:app --host 127.0.0.1 --port 8000 # Terminal 2 — React dev server cd frontend && npm run dev # 在 http://localhost:5173 打开(将 /api 代理到 :8000) ``` ### CLI ``` python3 -m threat_intel_agent.cli ``` CLI 命令:`help`、`context`、`trace`、`clear`、`sources`、`exit` ### REST API 所有端点均位于 `/api` 下: | 端点 | 方法 | 描述 | |----------|--------|-------------| | `/api/query` | POST | 处理威胁情报查询 | | `/api/health` | GET | 健康检查 + 活动来源 | | `/api/traces` | GET | 列出执行追踪(支持 `DELETE` 清除) | | `/api/traces/{id}` | GET | 完整追踪详情 | | `/api/traces/stats/summary` | GET | 汇总统计信息 | | `/api/context/{session_id}` | GET | 会话上下文 | | `/api/context/{session_id}` | DELETE | 清除会话 | API 文档:`http://localhost:8000/docs` 示例: ``` curl -X POST http://localhost:8000/api/query \ -H "Content-Type: application/json" \ -d '{"query":"Is 8.8.8.8 malicious?","session_id":"demo"}' ``` ## 查询示例 ``` # IOC 查询 Is 8.8.8.8 malicious? # Google DNS - clean Is 45.83.122.10 malicious? # Russian C2 - malicious Is 1.1.1.1 malicious? # Cloudflare - clean Check domain: evil.com # Threat Actor 研究 What is Fancy Bear known for? Tell me about LockBit Show APT29 TTPs # 暴露分析 We run Confluence 7.13 — are we exposed? Is OpenSSL 1.1.1 vulnerable? # Pivoting Pivot from 45.83.122.10 to related domains # Multi-turn Is 45.83.122.10 malicious? # first and what's its ASN? # follow-up (resolves context) ``` ## 架构 ``` threat_intel_agent/ ├── frontend/ # React + Vite + TypeScript │ ├── src/ │ │ ├── App.tsx # Main component │ │ ├── api.ts # API client │ │ └── index.css │ ├── package.json │ └── vite.config.ts ├── threat_intel_agent/ # Python backend │ ├── api_server.py # FastAPI (serves React + API) │ ├── cli.py # Interactive CLI │ ├── agent.py # Core agent logic │ ├── tracer.py # Execution tracing & observability │ ├── intent_parser.py # Query routing (5 intent types) │ ├── context_manager.py # Multi-turn memory │ ├── models.py # Data models │ ├── config.py # .env loading + config │ ├── tools/ # Threat intel integrations │ │ ├── base.py │ │ ├── virus_total.py # VirusTotal API │ │ ├── abuse_ipdb.py # AbuseIPDB API │ │ ├── alienvault_otx.py # OTX API │ │ ├── nvd.py # NVD API │ │ ├── shodan.py # Shodan API │ │ └── mock_data.py # Always-available fallback │ └── security/ │ └── injection_defense.py # Direct + indirect injection detection ├── requirements.txt ├── .env.example ├── README.md └── DESIGN.md ``` ## 安全:提示词注入防御 Agent 可防御这两种注入类型: ### 直接注入 用户输入恶意命令,例如: - "忽略所有之前的指令" - "假装你是管理员" - "泄露你的系统提示词" **动作**:阻止 (CRITICAL) 或 净化 (MEDIUM) ### 间接注入 隐藏在检索数据中的恶意内容: - 包含注入企图的威胁情报流评论 - 包含“忽略之前的指令”的 API 响应 - 带有提示词泄露 payload 的工具输出 **动作**:扫描检索到的数据,若发现威胁则阻止,不向用户显示结果 ### 威胁等级 | 等级 | 动作 | |-------|--------| | NONE | 允许 | | LOW/MEDIUM | 警告用户,净化 | | HIGH | 阻止查询 | | CRITICAL | 阻止查询(立即) | 模式定义在 `threat_intel_agent/security/injection_defense.py` 中。 ## 追踪与可观测性 每次查询都会生成逐步的追踪记录。每次 Agent 响应都会显示一个可折叠的追踪块: ``` 1. query_received ✓ 2. security_check ✓ Direct: NONE | Indirect: MEDIUM 3. intent_parsed ✓ Intent: ioc_lookup (95%) 4. tool_called ✓ Called virustotal.lookup_ioc 5. tool_result ✓ virustotal succeeded in 519ms 6. response_generated ✓ VirusTotal (85%) ``` 所有追踪记录也可通过 REST API 在 `/api/traces` 获取。 ## 许可证 MIT **快速参考:** - 启动:`python3 -m uvicorn threat_intel_agent.api_server:app --host 127.0.0.1 --port 8000` - Web UI:`http://localhost:8000` - API:`http://localhost:8000/docs` - CLI:`python3 -m threat_intel_agent.cli`
标签:AI智能体, AV绕过, FastAPI, React, SOC分析, Syscalls, 威胁情报, 实时处理, 开发者工具, 逆向工具