iamnikitakhare/Cybersecurity-RAG
GitHub: iamnikitakhare/Cybersecurity-RAG
基于 RAG 架构的网络安全知识助手,整合 CVE 数据、Nuclei 模板和内部安全报告,通过自然语言交互快速检索和回答安全相关问题。
Stars: 0 | Forks: 0
# 基于 RAG 的网络安全知识助手
一个 AI 驱动的助手,利用检索增强生成(RAG)技术在三种知识源上回答网络安全问题:CVE 数据库、Nuclei 模板和内部公司报告。
## 架构
```
User Query
│
▼
Embedder (sentence-transformers)
│
▼
FAISS Vector Search ←── [CVE Docs + Nuclei Docs + Report Docs]
│
▼
Top-K Retrieved Context
│
▼
GPT-4 (OpenAI)
│
▼
Answer
```
## 项目结构
```
rag_cybersec/
├── data/
│ ├── cve/ ← CVE List V5 JSON files (download separately)
│ ├── nuclei/ ← Nuclei templates (download separately)
│ └── reports/ ← Internal .txt / .md / .pdf reports
│
├── parsers/
│ ├── cve_parser.py ← Parses CVE JSON → Document
│ ├── nuclei_parser.py ← Parses Nuclei YAML → Document
│ └── report_parser.py ← Parses TXT/MD/PDF → Document
│
├── embeddings/
│ └── embedder.py ← Generates vector embeddings
│
├── vectordb/
│ └── faiss_store.py ← FAISS index (build, save, load, search)
│
├── retrieval/
│ └── retriever.py ← Query → top-K relevant documents
│
├── llm/
│ └── openai_llm.py ← GPT-4 response generation
│
├── interface/
│ └── assistant.py ← Interactive chat interface
│
├── utils/
│ └── document.py ← Unified Document schema
│
├── build_index.py ← Master index builder (run once)
├── requirements.txt
└── .env.example
```
## 设置
### 1. 安装依赖
```
pip install -r requirements.txt
```
如需支持 PDF 报告:
```
pip install pdfminer.six
```
### 2. 配置环境
```
cp .env.example .env
# 编辑 .env 并添加你的 OPENAI_API_KEY
```
### 3. 添加您的数据
**CVE 数据:**
- 从 https://github.com/CVEProject/cvelistV5 下载 CVE List V5
- 将 JSON 文件放入 `data/cve/` 目录下(支持子目录)
**Nuclei 模板:**
- 从 https://github.com/projectdiscovery/nuclei-templates 下载
- 放入 `data/nuclei/` 目录下
**内部报告:**
- 将 `.txt`、`.md` 或 `.pdf` 文件放入 `data/reports/` 目录
### 4. 构建索引
```
# 完整构建(所有 sources)
python build_index.py
# 使用有限数据进行快速测试
python build_index.py --cve-limit 1000 --nuclei-limit 500
# 跳过你还没有的 sources
python build_index.py --skip-reports
```
### 5. 运行助手
```
python interface/assistant.py
```
## 示例问题
```
> Explain CVE-2024-3400
> Show me Nuclei templates for Log4j vulnerabilities
> Which vulnerabilities affect Fortinet products?
> What is the CVSS score for CVE-2021-44228?
> Show me critical severity detections
> Which internal reports mention ransomware?
> What remediation steps exist for Apache vulnerabilities?
```
## 命令
| 命令 | 描述 |
|---------|-------------|
| `/sources` | 显示上一个回答中使用的来源 |
| `/filter cve` | 将查询限制为 CVE 文档 |
| `/filter nuclei` | 限制为 Nuclei 模板 |
| `/filter report` | 限制为内部报告 |
| `/filter off` | 取消过滤 |
| `/stats` | 显示索引统计信息 |
| `/clear` | 清除对话历史 |
| `/quit` | 退出 |
## 注意事项
- 索引只需在添加新数据时重新构建
- Embeddings 使用 `all-MiniLM-L6-v2`(384 维,速度快,无需 GPU)
- 为支持多轮对话,会保留最近 6 轮的聊天记录
- 来源过滤允许您直接查询特定的知识库
安装 sentence-transformers
pip install sentence-transformers
标签:AI助手, AI风险缓解, DLL 劫持, Ruby, 向量数据库, 大语言模型, 检索增强生成, 知识库, 网络安全, 逆向工具, 隐私保护