1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
| // 行为分析引擎
class BehaviorAnalyzer {
private baseline = new Map<string, UserBaseline>();
async analyzeActivity(
userId: string,
activity: UserActivity
): Promise<RiskScore> {
const baseline = this.getBaseline(userId);
const anomalies: Anomaly[] = [];
// 时间模式检查
if (!this.isNormalTime(baseline, activity.timestamp)) {
anomalies.push({
type: 'unusual_time',
severity: 'medium',
description: 'Access outside normal hours'
});
}
// 位置检查
if (!this.isNormalLocation(baseline, activity.location)) {
anomalies.push({
type: 'unusual_location',
severity: 'high',
description: 'Access from new location'
});
}
// 设备检查
if (!this.isKnownDevice(baseline, activity.deviceId)) {
anomalies.push({
type: 'unknown_device',
severity: 'high',
description: 'Access from unregistered device'
});
}
// 行为模式检查
if (!this.isNormalBehavior(baseline, activity.actions)) {
anomalies.push({
type: 'unusual_behavior',
severity: 'medium',
description: 'Deviation from normal behavior pattern'
});
}
// 计算风险分数
return this.calculateRiskScore(anomalies);
}
private calculateRiskScore(anomalies: Anomaly[]): RiskScore {
let score = 0;
for (const anomaly of anomalies) {
switch (anomaly.severity) {
case 'low':
score += 10;
break;
case 'medium':
score += 30;
break;
case 'high':
score += 50;
break;
}
}
return {
score: Math.min(score, 100),
level: this.getRiskLevel(score),
anomalies,
timestamp: Date.now()
};
}
}
// 实时威胁检测
class ThreatDetectionEngine {
async detectThreats(
events: SecurityEvent[]
): Promise<ThreatAlert[]> {
const alerts: ThreatAlert[] = [];
// 检测暴力破解
const failedLogins = this.groupEventsByUser(events, 'login_failed');
for (const [userId, attempts] of failedLogins) {
if (attempts.length > 5) {
alerts.push({
type: 'brute_force',
severity: 'high',
target: userId,
description: `Multiple failed login attempts: ${attempts.length}`,
recommendedActions: ['lock_account', 'notify_admin']
});
}
}
// 检测横向移动
const lateralMovement = this.detectLateralMovement(events);
if (lateralMovement) {
alerts.push({
type: 'lateral_movement',
severity: 'critical',
target: lateralMovement.source,
description: 'Potential lateral movement detected',
recommendedActions: ['isolate_host', 'investigate']
});
}
// 检测数据外泄
const dataExfiltration = this.detectDataExfiltration(events);
if (dataExfiltration) {
alerts.push({
type: 'data_exfiltration',
severity: 'critical',
target: dataExfiltration.user,
description: 'Unusual data transfer detected',
recommendedActions: ['block_transfer', 'investigate']
});
}
return alerts;
}
}
|