Gamerboyi/identify-risk-intelligence-platform
GitHub: Gamerboyi/identify-risk-intelligence-platform
一个基于 Spring Boot 和 Python ML 微服务的企业安全平台,整合机器学习风险评分、入侵检测和防火墙管理,提供智能化的安全运维能力。
Stars: 1 | Forks: 0
# 🛡️ AI 驱动的企业安全平台
这是一个 AI 驱动的安全平台,将**机器学习风险评分**、**入侵检测**和**防火墙管理**整合到统一的 REST API 中 —— 基于 Spring Boot 3.2 和 Python ML 微服务构建。
## ✨ 功能特性
| 模块 | 功能 |
|---|---|
| **Authentication** | 基于 JWT 的认证,BCrypt 密码哈希,基于角色的访问控制 (Admin/Analyst/User),登录失败后自动锁定账户 |
| **ML Risk Scoring** | 针对每次登录的 7 个行为特征进行 Isolation Forest 异常检测,当 ML 服务不可用时有基于规则的回退机制 |
| **Intrusion Detection** | 速率限制 (每 IP 每分钟 30 次请求),暴力破解检测,恶意模式匹配 (SQLi, XSS, 目录遍历, 命令注入) |
| **Firewall Engine** | 防火墙规则的 CRUD 管理,基于优先级的实时流量评估匹配,支持通配符 |
| **Audit Trail** | 使用 JSONB 数据完整记录每个安全事件的日志 |
## 🏗️ 系统架构
```
┌──────────────┐ ┌──────────────────────────────────┐ ┌─────────────────┐
│ Client │─────▶│ Spring Boot 3.2 (Java 17) │─────▶│ PostgreSQL │
│ (REST API) │ │ │ │ (Supabase) │
│ │ │ ┌──────────┐ ┌──────────────┐ │ └─────────────────┘
│ │ │ │ Auth │ │ Feature │ │
│ │ │ │ Service │──│ Engineering │ │ ┌─────────────────┐
│ │ │ └──────────┘ └──────┬───────┘ │ │ Python Flask │
│ │ │ ┌──────────┐ │ │─────▶│ ML Service │
│ │ │ │ IDS │ ┌──────▼───────┐ │ │ (Isolation │
│ │ │ │ Service │ │ ML Service │ │ │ Forest) │
│ │ │ └──────────┘ │ Client │ │ └─────────────────┘
│ │ │ ┌──────────┐ └──────────────┘ │
│ │ │ │ Firewall │ │
│ │ │ │ Service │ │
│ │ │ └──────────┘ │
│ │ └──────────────────────────────────┘
└──────────────┘
```
## 🧠 ML 风险评分流水线
每次登录都会提取 **7 个行为特征** 并输入到 Isolation Forest 模型中:
| # | 特征 | 描述 |
|---|---|---|
| 1 | `loginFrequency24h` | 最近 24 小时内的登录次数 |
| 2 | `isNewIp` | 该 IP 是否从未被此用户使用过 |
| 3 | `isNewDevice` | 该 User-Agent 是否从未出现过 |
| 4 | `failedAttemptRatio` | 最近登录中失败次数与总次数的比例 |
| 5 | `hourOfDay` | 登录时间的小时数 (0–23) |
| 6 | `isWeekend` | 是否为周末标志 |
| 7 | `totalUniqueIps` | 历史唯一 IP 数量 |
**风险等级:** LOW (0–29), MEDIUM (30–69), HIGH (70–100)
## 🛠️ 技术栈
| 层级 | 技术 |
|---|---|
| Backend | Spring Boot 3.2, Java 17 |
| Security | Spring Security, JWT (jjwt), BCrypt-12 |
| Database | PostgreSQL, Spring Data JPA |
| ML Service | Python Flask, scikit-learn (Isolation Forest) |
| API Docs | SpringDoc OpenAPI / Swagger UI |
| Monitoring | Spring Actuator |
| Containers | Docker, Docker Compose |
## 🚀 快速开始
### 前置条件
- Java 17+
- Maven
- PostgreSQL 15+
- Python 3.11+ (用于 ML 服务)
### 选项 1:Docker Compose(推荐)
```
# 克隆 repo
git clone https://github.com/Gamerboyi/identify-risk-intelligence-platform.git
cd identify-risk-intelligence-platform
# 启动所有服务 (API + ML + PostgreSQL)
docker compose up --build
```
API 将在 `http://localhost:8080` 可用,Swagger UI 位于 `http://localhost:8080/swagger-ui.html`。
### 选项 2:本地运行
```
# 1. 设置数据库
psql -U postgres -c "CREATE DATABASE securitydb;"
psql -U postgres -d securitydb -f src/main/resources/schema.sql
# 2. 设置环境变量
export DB_USERNAME=postgres
export DB_PASSWORD=your_password
export JWT_SECRET=your_64_char_hex_secret
# 3. 启动 ML 服务
cd ml-service
pip install -r requirements.txt
python train.py # Train the model first
python app.py # Start on port 5000
# 4. 启动 Spring Boot API (新终端)
cd ..
./mvnw spring-boot:run
```
### 运行测试
```
./mvnw test
```
## 📡 API 端点
### Authentication(公开)
| Method | Endpoint | 描述 |
|---|---|---|
| POST | `/api/auth/register` | 注册新用户 |
| POST | `/api/auth/login` | 登录并获取 JWT + 风险评分 |
| GET | `/api/auth/health` | 健康检查 |
### Firewall(Admin/Analyst)
| Method | Endpoint | 描述 |
|---|---|---|
| POST | `/api/firewall/rules` | 添加防火墙规则 (Admin) |
| GET | `/api/firewall/rules` | 列出所有规则 |
| GET | `/api/firewall/rules/active` | 仅列出活跃规则 |
| PUT | `/api/firewall/rules/{id}/toggle` | 启用/禁用规则 (Admin) |
| DELETE | `/api/firewall/rules/{id}` | 删除规则 (Admin) |
| POST | `/api/firewall/evaluate` | 根据规则评估流量 |
### Intrusion Detection(Admin/Analyst)
| Method | Endpoint | 描述 |
|---|---|---|
| POST | `/api/ids/analyze` | 完整威胁分析 |
| GET | `/api/ids/check/ratelimit` | 检查 IP 是否被速率限制 |
| GET | `/api/ids/check/bruteforce` | 检查是否存在暴力破解攻击 |
| POST | `/api/ids/check/pattern` | 扫描恶意模式 |
## 📁 项目结构
```
eurds/
├── src/main/java/com/vedant/eurds/
│ ├── config/ # Swagger, CORS configuration
│ ├── controller/ # REST controllers (Auth, Firewall, IDS)
│ ├── dto/ # Request/Response DTOs
│ ├── exception/ # Global exception handler
│ ├── model/ # JPA entities
│ ├── repository/ # Spring Data repositories
│ ├── security/ # JWT filter, SecurityConfig
│ └── service/ # Business logic + ML integration
├── src/test/ # Unit tests (JUnit 5 + Mockito)
├── ml-service/ # Python Flask ML microservice
│ ├── app.py # Flask API (predict, train, health)
│ ├── train.py # Isolation Forest training script
│ └── model/ # Trained model artifacts (.pkl)
├── docker-compose.yml # One-command deployment
├── Dockerfile # Multi-stage Java build
└── .env.example # Environment variable template
```
## 🔒 安全设计
- **无状态 JWT 会话** —— 无服务端会话存储
- **BCrypt-12** 密码哈希 —— 企业级代价因子
- **账户自动锁定** —— 5 次登录失败后触发
- **锁定账户 JWT 拒绝** —— 被锁定的用户无法使用现有 Token
- **基于角色的访问控制** —— Admin, Analyst, User 角色,具有方法级安全性
- **审计追踪** —— 使用 JSONB 事件数据记录每个安全事件
- **请求验证** —— 所有端点使用 `@Valid`,并返回适当的错误响应
## 📄 许可证
MIT
标签:Apex, API安全, CISA项目, DNS 反向解析, JSON输出, JWT认证, PostgreSQL, Python, REST API, Spring Boot, SQL注入防护, Streamlit, Web安全, XSS防护, 企业安全, 免杀技术, 入侵检测系统, 域名枚举, 安全数据湖, 安全运营中心, 审计日志, 异常检测, 无后门, 暴力破解检测, 机器学习, 测试用例, 红队行动, 网络安全, 网络映射, 网络资产管理, 蓝队分析, 访问控制, 请求拦截, 逆向工具, 防火墙管理, 隐私保护, 风险评分