nayefsiddique-eng/siem-ai-guardian
GitHub: nayefsiddique-eng/siem-ai-guardian
集成实时日志接入、多规则威胁检测引擎和 Gemini AI 事件分析的企业级安全信息与事件管理平台。
Stars: 0 | Forks: 0
# AI 驱动的 SIEM — 设置指南
一个集成 Gemini AI 威胁分析的全栈安全信息与事件管理平台。
## 架构
```
Logs (API / Script)
│
▼
FastAPI Backend ─── Detection Engine (5 rules)
│ │
▼ ▼
SQLite DB Alert Table
│
▼
Gemini AI ──────── AI Analysis + Recommendations
│
▼
React Dashboard ─── Charts, Alerts, Log Stream
```
## 快速开始
### 1. 后端设置
```
cd siem-project\backend
# 创建虚拟环境
python -m venv venv
.\venv\Scripts\Activate.ps1
# 安装依赖
pip install -r requirements.txt
# 复制并配置 .env
Copy-Item .env.example .env
# 编辑 .env 并添加你的 GEMINI_API_KEY
# 在此获取免费密钥: https://aistudio.google.com/app/apikey
# 启动服务器
uvicorn main:app --reload --port 8000
```
API 将在 `http://localhost:8000` 提供
交互式文档位于 `http://localhost:8000/docs`
### 2. 前端设置
```
cd siem-project\frontend
npm install
npm run dev
```
仪表板位于 `http://localhost:5173`
### 3. 填充测试数据
```
# 在一个新的终端中,保持 backend 运行:
cd siem-project
.\scripts\seed_test_data.ps1
```
这将:
- 触发一个**暴力破解警报**(来自 185.220.101.45 的 6 次失败登录)
- 触发一个**端口扫描警报**(来自 10.0.0.88 的 12 个端口)
- 触发一个**权限提升警报**(sudo su root)
- 添加正常的基线活动
## 检测规则
| 规则 | 触发条件 | MITRE |
|------|---------|-------|
| 暴力破解 | 60秒内来自同一 IP 的 ≥5 次失败登录 | T1110 |
| 端口扫描 | 30秒内来自同一 IP 的 ≥10 个不同端口 | T1046 |
| 威胁情报 | 源 IP 位于黑名单中 | T1071 |
| 非工作时间登录 | UTC 时间 22:00–06:00 之间的成功登录 | T1078 |
| 权限提升 | 日志消息中包含 sudo/su root 关键字 | T1068 |
## API Endpoints
### 日志接入
```
POST /api/logs/ingest Single log event
POST /api/logs/ingest/bulk Up to 1000 events
GET /api/logs List logs (filterable)
```
### 警报
```
GET /api/alerts List alerts
GET /api/alerts/{id} Alert detail
PATCH /api/alerts/{id} Update status (open/investigating/resolved/false_positive)
POST /api/alerts/{id}/analyze Trigger AI analysis
```
### 仪表板
```
GET /api/dashboard/stats All dashboard statistics
```
### AI 分析
```
POST /api/analysis/freeform Plain English incident analysis
```
### 日志事件格式
```
{
"source_ip": "192.168.1.100",
"destination_ip": "10.0.0.1",
"source_port": 54321,
"destination_port": 22,
"event_type": "failed_login",
"severity": "medium",
"hostname": "server-01",
"username": "admin",
"log_source": "linux",
"raw_message": "Failed password for admin from 192.168.1.100"
}
```
用于检测的有效 `event_type` 值:`failed_login`, `authentication_failure`, `port_probe`, `connection_attempt`, `firewall_drop`, `successful_login`, `login_success`, `user_logon`, `privilege_event`
## 项目结构
```
siem-project/
├── backend/
│ ├── main.py FastAPI app entry point
│ ├── requirements.txt
│ ├── .env.example
│ └── app/
│ ├── api/
│ │ ├── logs.py Log ingestion routes
│ │ ├── alerts.py Alert management routes
│ │ ├── dashboard.py Stats routes
│ │ └── analysis.py AI analysis routes
│ ├── core/
│ │ ├── config.py Settings + .env loading
│ │ └── database.py SQLAlchemy async setup
│ ├── models/
│ │ ├── log_entry.py Log DB model
│ │ └── alert.py Alert DB model
│ └── services/
│ ├── detection_engine.py 5-rule threat detector
│ └── gemini_service.py Gemini AI integration
├── frontend/
│ ├── src/
│ │ ├── App.jsx
│ │ ├── hooks/useSiem.jsx Global state + API calls
│ │ └── components/
│ │ ├── dashboard/ Overview + charts
│ │ ├── alerts/ Alert cards + AI trigger
│ │ ├── logs/ Log stream + test injector
│ │ └── analysis/ Freeform AI analysis
│ ├── package.json
│ └── vite.config.js
└── scripts/
└── seed_test_data.ps1 Test data generator
```
## 添加新的检测规则
编辑 `backend/app/services/detection_engine.py`:
```
async def _check_your_rule(self, log: LogEntry, db: AsyncSession) -> Optional[Alert]:
if log.event_type != "your_event_type":
return None
# your logic
alert = Alert(
alert_type="your_rule",
severity="high",
title="...",
description="...",
source_ip=log.source_ip,
mitre_technique_id="T1234",
mitre_technique_name="Your Technique",
mitre_tactic="Your Tactic",
)
db.add(alert)
await db.flush()
return alert
```
然后将其添加到 `analyze_log` 方法链中。
## 生产环境升级(第 2-3 个月)
- [ ] 将 SQLite 替换为 PostgreSQL
- [ ] 添加 ML 异常检测(Isolation Forest)
- [ ] 接入真实的威胁情报源(AbuseIPDB, OpenPhish)
- [ ] 添加 Windows Event Log 转发器(Python 代理)
- [ ] 添加 Linux syslog UDP 监听器
- [ ] 生成 PDF 事件报告
- [ ] 用户身份验证(JWT)
- [ ] 使用 WebSocket 进行实时日志流传输
- [ ] Docker Compose 部署
标签:AMSI绕过, AV绕过, FastAPI, IP 地址批量处理, PB级数据处理, React, SIEM系统, Syscalls, Web报告查看器, 威胁检测, 安全运维, 插件系统, 自定义脚本, 逆向工具