Aman112211/DCTIN
GitHub: Aman112211/DCTIN
一个基于以太坊区块链和机器学习的去中心化网络威胁情报共享平台,支持组织间安全协作、情报奖励和智能威胁分析。
Stars: 0 | Forks: 2
# ⬡ DCTIN — 去中心化网络威胁情报网络
一个全栈协作安全平台,组织在此平台上共享由 Ethereum 区块链保护并由机器学习分析的网络威胁指标。
```
Organizations → React Dashboard → Flask API → PostgreSQL
↓
Ethereum (Ganache)
↓
ML Threat Engine (scikit-learn)
```
## 🗂 项目结构
```
dctin/
├── backend/
│ ├── app.py # Flask app factory + SocketIO
│ ├── database.py # PostgreSQL connection pool
│ ├── schema.sql # Database schema
│ ├── requirements.txt
│ ├── .env.example
│ ├── routes/
│ │ ├── auth.py # POST /register, POST /login
│ │ ├── threats.py # POST /submit-threat, GET /threats, POST /verify-threat
│ │ ├── alerts.py # GET /alerts
│ │ ├── reputation.py # GET /reputation, GET /reputation/leaderboard
│ │ └── analytics.py # GET /analytics/*
│ └── services/
│ ├── blockchain_service.py # Web3.py + smart contract interaction
│ ├── threat_service.py # Threat business logic
│ └── ml_engine.py # KMeans clustering + Isolation Forest
│
├── blockchain/
│ ├── ThreatIntel.sol # Solidity smart contract
│ ├── deploy_script.js # Deployment script (Node.js)
│ └── package.json
│
└── frontend/
├── package.json
├── public/index.html
└── src/
├── App.js # Root + auth context
├── index.js
├── services/api.js # API client
├── components/
│ └── Sidebar.js
└── pages/
├── LoginPage.js
├── ThreatFeed.js
├── ThreatSubmit.js
├── AlertsPage.js
├── ReputationPage.js
└── AnalyticsPage.js
```
## ⚙️ 前置条件
| 工具 | 版本 | 用途 |
|------|---------|---------|
| Python | 3.10+ | 后端 |
| Node.js | 18+ | 前端 + 部署脚本 |
| PostgreSQL | 14+ | 数据库 |
| Ganache | 最新版 | 本地 Ethereum 区块链 |
### 安装 Ganache CLI
```
npm install -g ganache
```
## 🚀 安装说明
### 步骤 1 — PostgreSQL 数据库
```
# 创建数据库和用户
psql -U postgres <`
- **速率限制** — 每个 IP 每小时 200 次请求,每分钟 50 次请求
- **输入验证** — 威胁类型白名单、长度限制、邮箱验证
- **密码哈希** — 使用 salt 的 Werkzeug PBKDF2
- **CORS** — 为 `localhost:3000` 配置 (生产环境请更新)
- **不可变记录** — 区块链哈希防止篡改
## 🤖 机器学习详情
### KMeans 聚类 (`/api/analytics/clusters`)
根据以下特征将威胁分组:
- 威胁类型编码
- 严重性评分
- 提交时间 (小时/天)
- 指标长度和字符熵
用于检测协同攻击活动。
### Isolation Forest 异常检测 (`/api/analytics/anomalies`)
标记统计上异常的威胁提交,可能指示:
- 虚假数据注入
- 协同垃圾信息
- 异常时间模式
### 钓鱼域名相似度
基于字符级 TF-IDF 和余弦相似度检测抢注域名活动
(例如,`paypa1-secure.com`, `paypa1-login.com`, `paypa1-verify.com`)。
### 自动严重性评分
当未提供严重性时,ML 引擎根据以下规则分配 1–10 分:
- 基于威胁类型的基础分 (malware hash = 9, phishing = 7, IP = 5)
- 来自现有类似威胁的佐证 (+1 或 +2)
- 指标值的香农熵 (高熵 = 可疑)
## 🔗 Smart Contract 函数
```
// Submit a threat hash
function submitThreat(bytes32 hash, string threatType, uint256 severity) returns (uint256 index)
// Retrieve threat by blockchain index
function getThreat(uint256 index) returns (bytes32, string, address, uint256, uint256, bool)
// Get total threat count
function getThreatCount() returns (uint256)
// Check for duplicate hash
function isDuplicate(bytes32 hash) returns (bool)
// Verify a threat (updates on-chain reputation)
function verifyThreat(uint256 index, bool isLegitimate)
// Get on-chain reputation for an address
function getReputation(address org) returns (int256)
```
## 🏆 声誉系统
| 操作 | 声誉 | Tokens |
|--------|-----------|--------|
| 提交已验证的威胁 | +10 | +5 |
| 确认他人的威胁 | +2 | +1 |
| 重复提交 | 0 | 0 |
| 提交误报 | -5 | 0 |
**等级分层:**
- `Newcomer` — 0–99 分
- `Member` — 100–149 分
- `Contributor` — 150–199 分
- `Security Analyst` — 200–299 分
- `Threat Hunter` — 300–499 分
- `Elite Defender` — 500+ 分
## 🌐 实时警报 (WebSocket)
后端会发送以下 SocketIO 事件:
- `new_high_severity_threat` — 严重性 ≥ 8
- ML 生成的警报 (钓鱼活动、集群、异常)
前端每 30 秒轮询一次警报。要启用真正的推送通知,
请连接到 `http://localhost:5000` 的 SocketIO 服务器。
## 🧪 使用 curl 快速测试
```
# 注册
curl -X POST http://localhost:5000/api/register \
-H "Content-Type: application/json" \
-d '{"name":"Test Org","email":"test@example.com","password":"password123"}'
# 登录 (保存 token)
TOKEN=$(curl -s -X POST http://localhost:5000/api/login \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password123"}' | python3 -c "import sys,json; print(json.load(sys.stdin)['access_token'])")
# 提交威胁
curl -X POST http://localhost:5000/api/submit-threat \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"threat_type":"malicious_ip","indicator_value":"10.0.0.99","description":"Active C2"}'
# 列出威胁
curl -H "Authorization: Bearer $TOKEN" http://localhost:5000/api/threats
# 获取分析
curl -H "Authorization: Bearer $TOKEN" http://localhost:5000/api/analytics/clusters
```
## 🐳 Docker Compose (可选)
在项目根目录创建 `docker-compose.yml`:
```
version: '3.8'
services:
postgres:
image: postgres:15
environment:
POSTGRES_DB: dctin_db
POSTGRES_USER: dctin_user
POSTGRES_PASSWORD: dctin_pass
ports: ["5432:5432"]
ganache:
image: trufflesuite/ganache:latest
ports: ["7545:7545"]
command: ["--port", "7545", "--deterministic", "--accounts", "10"]
backend:
build: ./backend
ports: ["5000:5000"]
environment:
DATABASE_URL: postgresql://dctin_user:dctin_pass@postgres:5432/dctin_db
GANACHE_URL: http://ganache:7545
depends_on: [postgres, ganache]
frontend:
build: ./frontend
ports: ["3000:80"]
depends_on: [backend]
```
## 📝 生产环境注意事项
1. **替换所有密钥** — 在 `.env` 中使用加密随机值
2. **使用 HTTPS** — 配置 TLS 证书
3. **设置 CORS** — 指向您的实际前端域名
4. **使用真实的 Ethereum 测试网** (Sepolia) 或主网代替 Ganache
5. **添加数据库备份** 和连接池调优
6. **按组织进行速率限制** (不仅是 IP) 以防止滥用
7. **添加 SIEM 集成** (例如,导出到 Splunk/ELK)
标签:AMSI绕过, Apex, Burp项目解析, DApp, Flask, PostgreSQL, React, Solidity, Syscalls, Web3, Web3.py, 代币经济, 以太坊, 众包安全, 区块链安全, 协作防御, 去中心化应用, 声誉系统, 威胁共享, 威胁情报, 威胁检测, 开发者工具, 异常检测, 智能合约, 机器学习, 测试用例, 网络安全, 聚类分析, 自定义脚本, 请求拦截, 逆向工具, 隐私保护, 隔离森林