robdinovil/nexus-dfir
GitHub: robdinovil/nexus-dfir
Nexus DFIR 是一个纯 CPU、气隙就绪的数字取证证据智能平台,支持自然语言查询、威胁狩猎和 IOC 关联分析。
Stars: 0 | Forks: 0
# Nexus DFIR
**用于数字取证的证据智能平台 — 纯 CPU 运行,支持气隙隔离,无需云端。**
使用自然语言询问有关取证证据的问题。Nexus 会自动将每个问题路由到合适的工具。
```
nexus shell lockbit2024
nexus [lockbit2024]> ¿hay malware?
[THREAT_HUNT] ⚠ 5 reglas disparadas — 20 hallazgos
[CRITICAL] T1078 — System Process Username Anomaly
[HIGH] T1071.001 — C2 over HTTPS → 152.236.2.63:443
... ↳ 0.0s
nexus [lockbit2024]> correlaciona 152.236.2.63
[IOC] ✓ 2 referencias en 1 tabla(s)
network_connections: TCP 152.236.2.63:443 ESTABLISHED pid=9052
... ↳ 0.0s
nexus [lockbit2024]> ¿cuántos logons fallidos por IP?
[SQL] SELECT source_ip, COUNT(*) as failed ...
10.1.1.45 45 intentos
10.1.1.20 42 intentos
... ↳ 87s
```
## 工作原理
三种路由 — 系统会自动选择:
| 路由 | 适用情况 | LLM | 延迟 |
|---|---|---|---|
| **Threat Hunt** | "hay malware", "hunting", "TTPs" | 否 | ~0s |
| **IOC Correlation** | IP/hash literal, "correlaciona", "pivot" | 否 | ~0s |
| **NL→SQL** | 其他所有情况 | 是 (本地 Ollama) | 纯 CPU ~60-90s |
Threat Hunt 会在安全事件、Sysmon、进程、网络连接、计划任务和注册表键中应用 19 条映射到 MITRE ATT&CK 的规则。
## 环境要求
- Python 3.10+
- 本地运行 [Ollama](https://ollama.ai) 并加载任意指令微调模型
- 无需 GPU — 仅在 i9 CPU 上测试过
```
ollama pull qwen2.5:7b-instruct # or any model
```
## 安装说明
```
git clone https://github.com/robdinovil/nexus-dfir
cd nexus-dfir
pip install -e .
```
## 使用说明
```
# 创建 case
nexus new lockbit2024
# Ingest evidence directory (EVTX, CSV tasklist/netstat, .reg, systeminfo)
nexus ingest lockbit2024 /path/to/evidence/
# 交互式 shell
nexus shell lockbit2024
# 单个问题
nexus ask lockbit2024 "¿qué procesos corren como SYSTEM?"
# 列出 cases
nexus cases
# 仅 Threat hunt
nexus ask lockbit2024 "¿hay malware?"
```
## 支持的证据格式
| 格式 | 解析器 | 示例文件 |
|---|---|---|
| Windows 事件日志 | EVTX | Security.evtx, System.evtx, Sysmon.evtx |
| 进程列表 | CSV | tasklist /v /fo csv, wmic process |
| 网络连接 | TXT | netstat -ano |
| 系统信息 | TXT | systeminfo |
| 注册表导出 | REG | reg export HKLM\...\Run |
## NL→SQL 基准测试 (qwen2.5:7b-instruct,纯 CPU)
| 轮次 | 问题数 | 得分 | 幻觉率 | 自我纠正率 |
|---|---|---|---|---|
| 第 1 轮 | 20 | 16/20 (80%) | 10% | — |
| 第 2 轮 | 20 | 18/20 (90%) | 5% | — |
| 第 3 轮 | 20 | 18/20 (90%) | 5% | — |
| 第 4 轮 | 20 | 19/20 (95%) | 5% | 已追踪 |
| 第 5 轮 | 25 | — | — | — |
准确率达到 100% 的类别:cross_table, enumeration, meta, persistence, anomaly, processes, network。
## 幻觉测量方法
Nexus 在执行前将 LLM 错误分为三类:
| 类型 | 描述 | 检测方法 |
|---|---|---|
| **结构型 (Structural)** | Schema 中不存在的列或表 | SQL 解析后进行 Schema 检查 |
| **引用型 (Referential)** | 当前数据库中不存在的 `event_id` 值 | 针对实时数据库执行 `events` 查询 |
| **语法型 (Syntax)** | 格式错误的 SQL(解析错误) | `EXPLAIN QUERY PLAN` |
### 三层验证器 pipeline
```
LLM generates SQL
│
[Layer 1] SELECT-only check (structural)
│
[Layer 2] Table + column existence (structural)
│
[Layer 3] event_id in DB check (referential)
│
valid? ── No ──→ inject error hint into prompt → RETRY once
│ │
Yes re-validate
│ │
execute SQL ←──────────────────────── valid? ──Yes──┘
│
No → execute anyway, log unresolved hallucination
```
### 指标
- **得分** — 在真实问题集上的 PASS 率(关键字检查 + 行数边界)
- **幻觉率** — 未解决的幻觉问题数 / 总问题数(越低越好)
- **自我纠正率** — (由验证器检测并修复)/ (所有触发的错误) — 衡量验证器的有效性
- **延迟** — 在纯 CPU 硬件上每个问题的平均和 p95 实际耗时
### 关键发现
验证器的自我纠正机制将许多结构性幻觉转化为顺利通过 (PASS) 的结果。一个出现“幻觉”但最终 PASS 的问题,意味着验证器捕获了错误并且重试取得了成功 — 这是一项功能,而不是失败。
SANS FIND EVIL 评估增加了 5 个攻击调查问题(B21–B25),涵盖:时间线锚定、进程归因、异常检测、暴力破解排名和非工作时间认证 — 与 CTF 挑战赛的问题风格保持一致。
## 架构
```
nexus/
├── router.py — intent detection + tool dispatch (no LLM for hunt/IOC)
├── analyst.py — NL→SQL with BM25 retrieval + Ollama
├── validator.py — 3-layer SQL validation (structural + referential + syntax)
├── vectorstore.py — BM25 over SQLite, zero external dependencies
├── ingestor.py — evidence parser orchestrator (idempotent)
├── detector.py — magic-byte file type detection
├── case.py — case management (~/.nexus/cases/)
└── parsers/ — EVTX, CSV, netstat, systeminfo, registry
```
案件存储在 `~/.nexus/cases//` — 可移植,无需服务器。
## 在 FIRST 2026 上发表
标签:AI风险缓解, IOC关联, LLM评估, Ollama, Python, 安全运营, 扫描框架, 数字取证, 无后门, 自动化脚本, 逆向工具