@panguard-ai/manager 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/agent-registry.d.ts +88 -0
- package/dist/agent-registry.d.ts.map +1 -0
- package/dist/agent-registry.js +202 -0
- package/dist/agent-registry.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/manager.d.ts +153 -0
- package/dist/manager.d.ts.map +1 -0
- package/dist/manager.js +303 -0
- package/dist/manager.js.map +1 -0
- package/dist/policy-engine.d.ts +94 -0
- package/dist/policy-engine.d.ts.map +1 -0
- package/dist/policy-engine.js +171 -0
- package/dist/policy-engine.js.map +1 -0
- package/dist/threat-aggregator.d.ts +89 -0
- package/dist/threat-aggregator.d.ts.map +1 -0
- package/dist/threat-aggregator.js +344 -0
- package/dist/threat-aggregator.js.map +1 -0
- package/dist/types.d.ts +141 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +46 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +87 -0
- package/dist/utils.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ThreatAggregator - Collects and correlates threats from multiple Guard agents
|
|
3
|
+
* ThreatAggregator - 從多個 Guard 代理收集並關聯威脅
|
|
4
|
+
*
|
|
5
|
+
* Performs cross-agent correlation to detect coordinated attacks:
|
|
6
|
+
* - Same source IP appearing across different agents
|
|
7
|
+
* - Same malware hash detected on different endpoints
|
|
8
|
+
* - Same MITRE ATT&CK technique from same source
|
|
9
|
+
*
|
|
10
|
+
* @module @panguard-ai/manager/threat-aggregator
|
|
11
|
+
*/
|
|
12
|
+
import { createLogger } from '@panguard-ai/core';
|
|
13
|
+
import { generateThreatId, extractSourceIP, extractFileHash } from './utils.js';
|
|
14
|
+
const logger = createLogger('panguard-manager:aggregator');
|
|
15
|
+
/**
|
|
16
|
+
* Aggregates threats from multiple agents and performs cross-agent correlation.
|
|
17
|
+
*
|
|
18
|
+
* Uses secondary indexes (IP index, hash index) for O(1) correlation lookups
|
|
19
|
+
* instead of O(n^2) pairwise comparison.
|
|
20
|
+
*/
|
|
21
|
+
export class ThreatAggregator {
|
|
22
|
+
threats;
|
|
23
|
+
correlations;
|
|
24
|
+
// Secondary indexes for fast correlation / 快速關聯的二級索引
|
|
25
|
+
ipIndex;
|
|
26
|
+
hashIndex;
|
|
27
|
+
categoryIndex;
|
|
28
|
+
// Configuration / 配置
|
|
29
|
+
correlationWindowMs;
|
|
30
|
+
retentionMs;
|
|
31
|
+
constructor(correlationWindowMs, retentionMs) {
|
|
32
|
+
this.threats = new Map();
|
|
33
|
+
this.correlations = [];
|
|
34
|
+
this.ipIndex = new Map();
|
|
35
|
+
this.hashIndex = new Map();
|
|
36
|
+
this.categoryIndex = new Map();
|
|
37
|
+
this.correlationWindowMs = correlationWindowMs;
|
|
38
|
+
this.retentionMs = retentionMs;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Ingest a threat report from a Guard agent.
|
|
42
|
+
* Each threat event is stored as an AggregatedThreat and indexed
|
|
43
|
+
* for correlation. Cross-agent matches are detected during ingestion.
|
|
44
|
+
*
|
|
45
|
+
* @param report - The threat report containing one or more events
|
|
46
|
+
* @param hostname - The hostname of the reporting agent
|
|
47
|
+
* @returns Array of newly created AggregatedThreats
|
|
48
|
+
*/
|
|
49
|
+
ingestReport(report, hostname) {
|
|
50
|
+
const newThreats = [];
|
|
51
|
+
for (const threat of report.threats) {
|
|
52
|
+
const threatId = generateThreatId();
|
|
53
|
+
const now = new Date().toISOString();
|
|
54
|
+
const aggregated = {
|
|
55
|
+
id: threatId,
|
|
56
|
+
originalThreat: {
|
|
57
|
+
event: { ...threat.event, metadata: { ...threat.event.metadata } },
|
|
58
|
+
verdict: { ...threat.verdict },
|
|
59
|
+
},
|
|
60
|
+
sourceAgentId: report.agentId,
|
|
61
|
+
sourceHostname: hostname,
|
|
62
|
+
receivedAt: now,
|
|
63
|
+
correlatedWith: [],
|
|
64
|
+
};
|
|
65
|
+
this.threats.set(threatId, aggregated);
|
|
66
|
+
// Index for correlation / 索引以供關聯
|
|
67
|
+
const indexEntry = {
|
|
68
|
+
threatId,
|
|
69
|
+
agentId: report.agentId,
|
|
70
|
+
};
|
|
71
|
+
this.indexThreat(indexEntry, threat);
|
|
72
|
+
// Find correlations for this new threat / 為此新威脅尋找關聯
|
|
73
|
+
const correlatedIds = this.findCorrelations(indexEntry, threat, report.agentId);
|
|
74
|
+
if (correlatedIds.length > 0) {
|
|
75
|
+
// Update the new threat with correlation data (immutable)
|
|
76
|
+
const withCorrelation = {
|
|
77
|
+
...aggregated,
|
|
78
|
+
correlatedWith: correlatedIds,
|
|
79
|
+
};
|
|
80
|
+
this.threats.set(threatId, withCorrelation);
|
|
81
|
+
// Update each correlated threat to reference back
|
|
82
|
+
for (const correlatedId of correlatedIds) {
|
|
83
|
+
const existing = this.threats.get(correlatedId);
|
|
84
|
+
if (existing) {
|
|
85
|
+
const updated = {
|
|
86
|
+
...existing,
|
|
87
|
+
correlatedWith: [...existing.correlatedWith, threatId],
|
|
88
|
+
};
|
|
89
|
+
this.threats.set(correlatedId, updated);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
newThreats.push(withCorrelation);
|
|
93
|
+
logger.warn(`Cross-agent correlation detected: threat ${threatId} correlates with ` +
|
|
94
|
+
`[${correlatedIds.join(', ')}] / ` +
|
|
95
|
+
`跨代理關聯偵測: 威脅 ${threatId} 與 [${correlatedIds.join(', ')}] 相關`);
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
newThreats.push(aggregated);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return newThreats;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Index a threat for correlation lookups.
|
|
105
|
+
*/
|
|
106
|
+
indexThreat(entry, threat) {
|
|
107
|
+
const metadata = threat.event.metadata;
|
|
108
|
+
// Index by source IP / 依來源 IP 索引
|
|
109
|
+
const sourceIP = extractSourceIP(metadata);
|
|
110
|
+
if (sourceIP) {
|
|
111
|
+
const existing = this.ipIndex.get(sourceIP) ?? [];
|
|
112
|
+
this.ipIndex.set(sourceIP, [...existing, entry]);
|
|
113
|
+
}
|
|
114
|
+
// Index by file hash / 依檔案雜湊索引
|
|
115
|
+
const fileHash = extractFileHash(metadata);
|
|
116
|
+
if (fileHash) {
|
|
117
|
+
const existing = this.hashIndex.get(fileHash) ?? [];
|
|
118
|
+
this.hashIndex.set(fileHash, [...existing, entry]);
|
|
119
|
+
}
|
|
120
|
+
// Index by attack category / 依攻擊類別索引
|
|
121
|
+
const category = threat.event.category;
|
|
122
|
+
if (category) {
|
|
123
|
+
const key = `${category}:${sourceIP ?? 'unknown'}`;
|
|
124
|
+
const existing = this.categoryIndex.get(key) ?? [];
|
|
125
|
+
this.categoryIndex.set(key, [...existing, entry]);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Find existing threats that correlate with a new threat.
|
|
130
|
+
* Only matches threats from DIFFERENT agents within the correlation window.
|
|
131
|
+
*/
|
|
132
|
+
findCorrelations(newEntry, threat, agentId) {
|
|
133
|
+
const correlatedIds = new Set();
|
|
134
|
+
const metadata = threat.event.metadata;
|
|
135
|
+
const now = Date.now();
|
|
136
|
+
// Check IP correlation / 檢查 IP 關聯
|
|
137
|
+
const sourceIP = extractSourceIP(metadata);
|
|
138
|
+
if (sourceIP) {
|
|
139
|
+
const ipEntries = this.ipIndex.get(sourceIP) ?? [];
|
|
140
|
+
for (const entry of ipEntries) {
|
|
141
|
+
if (entry.threatId === newEntry.threatId)
|
|
142
|
+
continue;
|
|
143
|
+
if (entry.agentId === agentId)
|
|
144
|
+
continue; // Same agent, skip
|
|
145
|
+
const existing = this.threats.get(entry.threatId);
|
|
146
|
+
if (!existing)
|
|
147
|
+
continue;
|
|
148
|
+
const elapsed = now - new Date(existing.receivedAt).getTime();
|
|
149
|
+
if (elapsed > this.correlationWindowMs)
|
|
150
|
+
continue;
|
|
151
|
+
correlatedIds.add(entry.threatId);
|
|
152
|
+
this.correlations.push({
|
|
153
|
+
threatIdA: newEntry.threatId,
|
|
154
|
+
threatIdB: entry.threatId,
|
|
155
|
+
correlationType: 'same_source_ip',
|
|
156
|
+
sharedIndicator: sourceIP,
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
// Check hash correlation / 檢查雜湊關聯
|
|
161
|
+
const fileHash = extractFileHash(metadata);
|
|
162
|
+
if (fileHash) {
|
|
163
|
+
const hashEntries = this.hashIndex.get(fileHash) ?? [];
|
|
164
|
+
for (const entry of hashEntries) {
|
|
165
|
+
if (entry.threatId === newEntry.threatId)
|
|
166
|
+
continue;
|
|
167
|
+
if (entry.agentId === agentId)
|
|
168
|
+
continue;
|
|
169
|
+
const existing = this.threats.get(entry.threatId);
|
|
170
|
+
if (!existing)
|
|
171
|
+
continue;
|
|
172
|
+
const elapsed = now - new Date(existing.receivedAt).getTime();
|
|
173
|
+
if (elapsed > this.correlationWindowMs)
|
|
174
|
+
continue;
|
|
175
|
+
if (!correlatedIds.has(entry.threatId)) {
|
|
176
|
+
correlatedIds.add(entry.threatId);
|
|
177
|
+
this.correlations.push({
|
|
178
|
+
threatIdA: newEntry.threatId,
|
|
179
|
+
threatIdB: entry.threatId,
|
|
180
|
+
correlationType: 'same_malware_hash',
|
|
181
|
+
sharedIndicator: fileHash,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
// Check attack pattern correlation (same category + same source IP from different agents)
|
|
187
|
+
// 檢查攻擊模式關聯(相同類別 + 相同來源 IP 來自不同代理)
|
|
188
|
+
const category = threat.event.category;
|
|
189
|
+
if (category && sourceIP) {
|
|
190
|
+
const key = `${category}:${sourceIP}`;
|
|
191
|
+
const catEntries = this.categoryIndex.get(key) ?? [];
|
|
192
|
+
for (const entry of catEntries) {
|
|
193
|
+
if (entry.threatId === newEntry.threatId)
|
|
194
|
+
continue;
|
|
195
|
+
if (entry.agentId === agentId)
|
|
196
|
+
continue;
|
|
197
|
+
const existing = this.threats.get(entry.threatId);
|
|
198
|
+
if (!existing)
|
|
199
|
+
continue;
|
|
200
|
+
const elapsed = now - new Date(existing.receivedAt).getTime();
|
|
201
|
+
if (elapsed > this.correlationWindowMs)
|
|
202
|
+
continue;
|
|
203
|
+
if (!correlatedIds.has(entry.threatId)) {
|
|
204
|
+
correlatedIds.add(entry.threatId);
|
|
205
|
+
this.correlations.push({
|
|
206
|
+
threatIdA: newEntry.threatId,
|
|
207
|
+
threatIdB: entry.threatId,
|
|
208
|
+
correlationType: 'same_attack_pattern',
|
|
209
|
+
sharedIndicator: key,
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return Array.from(correlatedIds);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get all threats received since a given timestamp.
|
|
218
|
+
*
|
|
219
|
+
* @param since - Date threshold for filtering
|
|
220
|
+
* @returns Array of immutable AggregatedThreat copies
|
|
221
|
+
*/
|
|
222
|
+
getRecentThreats(since) {
|
|
223
|
+
const sinceMs = since.getTime();
|
|
224
|
+
return Array.from(this.threats.values())
|
|
225
|
+
.filter((t) => new Date(t.receivedAt).getTime() >= sinceMs)
|
|
226
|
+
.map((t) => ({
|
|
227
|
+
...t,
|
|
228
|
+
correlatedWith: [...t.correlatedWith],
|
|
229
|
+
}));
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Get all threats reported by a specific agent.
|
|
233
|
+
*
|
|
234
|
+
* @param agentId - The agent's unique identifier
|
|
235
|
+
* @returns Array of immutable AggregatedThreat copies
|
|
236
|
+
*/
|
|
237
|
+
getThreatsByAgent(agentId) {
|
|
238
|
+
return Array.from(this.threats.values())
|
|
239
|
+
.filter((t) => t.sourceAgentId === agentId)
|
|
240
|
+
.map((t) => ({
|
|
241
|
+
...t,
|
|
242
|
+
correlatedWith: [...t.correlatedWith],
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get all correlation matches.
|
|
247
|
+
*
|
|
248
|
+
* @returns Immutable array of correlation match records
|
|
249
|
+
*/
|
|
250
|
+
getCorrelations() {
|
|
251
|
+
return this.correlations.map((c) => ({ ...c }));
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Generate a summary of the current threat landscape.
|
|
255
|
+
*
|
|
256
|
+
* @returns Immutable threat summary object
|
|
257
|
+
*/
|
|
258
|
+
getSummary() {
|
|
259
|
+
let criticalCount = 0;
|
|
260
|
+
let highCount = 0;
|
|
261
|
+
let suspiciousCount = 0;
|
|
262
|
+
const uniqueAttackers = new Set();
|
|
263
|
+
const affectedAgentIds = new Set();
|
|
264
|
+
const correlatedGroups = new Set();
|
|
265
|
+
for (const threat of this.threats.values()) {
|
|
266
|
+
const verdict = threat.originalThreat.verdict;
|
|
267
|
+
const severity = threat.originalThreat.event.severity;
|
|
268
|
+
if (severity === 'critical')
|
|
269
|
+
criticalCount++;
|
|
270
|
+
if (severity === 'high')
|
|
271
|
+
highCount++;
|
|
272
|
+
if (verdict.conclusion === 'suspicious')
|
|
273
|
+
suspiciousCount++;
|
|
274
|
+
const sourceIP = extractSourceIP(threat.originalThreat.event.metadata);
|
|
275
|
+
if (sourceIP) {
|
|
276
|
+
uniqueAttackers.add(sourceIP);
|
|
277
|
+
}
|
|
278
|
+
affectedAgentIds.add(threat.sourceAgentId);
|
|
279
|
+
// Track correlated groups (use sorted pair as key)
|
|
280
|
+
for (const correlatedId of threat.correlatedWith) {
|
|
281
|
+
const groupKey = [threat.id, correlatedId].sort().join(':');
|
|
282
|
+
correlatedGroups.add(groupKey);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
return {
|
|
286
|
+
totalThreats: this.threats.size,
|
|
287
|
+
criticalCount,
|
|
288
|
+
highCount,
|
|
289
|
+
suspiciousCount,
|
|
290
|
+
uniqueAttackers: uniqueAttackers.size,
|
|
291
|
+
affectedAgents: affectedAgentIds.size,
|
|
292
|
+
correlatedGroups: correlatedGroups.size,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Purge threats older than the retention period.
|
|
297
|
+
* Also cleans up corresponding index entries.
|
|
298
|
+
*
|
|
299
|
+
* @returns Number of threats purged
|
|
300
|
+
*/
|
|
301
|
+
purgeExpired() {
|
|
302
|
+
const cutoff = Date.now() - this.retentionMs;
|
|
303
|
+
const toRemove = [];
|
|
304
|
+
for (const [id, threat] of this.threats.entries()) {
|
|
305
|
+
if (new Date(threat.receivedAt).getTime() <= cutoff) {
|
|
306
|
+
toRemove.push(id);
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
for (const id of toRemove) {
|
|
310
|
+
this.threats.delete(id);
|
|
311
|
+
}
|
|
312
|
+
// Rebuild indexes after purge if significant portion removed
|
|
313
|
+
if (toRemove.length > 0) {
|
|
314
|
+
this.rebuildIndexes();
|
|
315
|
+
}
|
|
316
|
+
if (toRemove.length > 0) {
|
|
317
|
+
logger.info(`Purged ${toRemove.length} expired threats / ` +
|
|
318
|
+
`清除了 ${toRemove.length} 個過期威脅`);
|
|
319
|
+
}
|
|
320
|
+
return toRemove.length;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Rebuild all secondary indexes from the current threat data.
|
|
324
|
+
*/
|
|
325
|
+
rebuildIndexes() {
|
|
326
|
+
this.ipIndex.clear();
|
|
327
|
+
this.hashIndex.clear();
|
|
328
|
+
this.categoryIndex.clear();
|
|
329
|
+
for (const [, threat] of this.threats.entries()) {
|
|
330
|
+
const entry = {
|
|
331
|
+
threatId: threat.id,
|
|
332
|
+
agentId: threat.sourceAgentId,
|
|
333
|
+
};
|
|
334
|
+
this.indexThreat(entry, threat.originalThreat);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Get the total number of tracked threats.
|
|
339
|
+
*/
|
|
340
|
+
get size() {
|
|
341
|
+
return this.threats.size;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
//# sourceMappingURL=threat-aggregator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threat-aggregator.js","sourceRoot":"","sources":["../src/threat-aggregator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAShF,MAAM,MAAM,GAAG,YAAY,CAAC,6BAA6B,CAAC,CAAC;AAU3D;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IACV,OAAO,CAAgC;IACvC,YAAY,CAAqB;IAElD,qDAAqD;IACpC,OAAO,CAA4B;IACnC,SAAS,CAA4B;IACrC,aAAa,CAA4B;IAE1D,qBAAqB;IACJ,mBAAmB,CAAS;IAC5B,WAAW,CAAS;IAErC,YAAY,mBAA2B,EAAE,WAAmB;QAC1D,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;QACzB,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,EAAE,CAAC;QAC/B,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;;;;;;;OAQG;IACH,YAAY,CACV,MAAoB,EACpB,QAAgB;QAEhB,MAAM,UAAU,GAAuB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I,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QACrB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;QAE3B,KAAK,MAAM,CAAC,EAAE,MAAM,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAChD,MAAM,KAAK,GAAe;gBACxB,QAAQ,EAAE,MAAM,CAAC,EAAE;gBACnB,OAAO,EAAE,MAAM,CAAC,aAAa;aAC9B,CAAC;YACF,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;IAED;;OAEG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC3B,CAAC;CACF"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manager type definitions for distributed Guard agent orchestration
|
|
3
|
+
* Manager 分散式 Guard 代理協調型別定義
|
|
4
|
+
*
|
|
5
|
+
* @module @panguard-ai/manager/types
|
|
6
|
+
*/
|
|
7
|
+
import type { SecurityEvent, Severity } from '@panguard-ai/core';
|
|
8
|
+
/** Agent status in the registry / 代理在登錄簿中的狀態 */
|
|
9
|
+
export type AgentStatus = 'online' | 'offline' | 'stale';
|
|
10
|
+
/** Agent platform information / 代理平台資訊 */
|
|
11
|
+
export interface AgentPlatformInfo {
|
|
12
|
+
readonly os: string;
|
|
13
|
+
readonly arch: string;
|
|
14
|
+
readonly ip?: string;
|
|
15
|
+
}
|
|
16
|
+
/** Agent registration record / 代理登錄紀錄 */
|
|
17
|
+
export interface AgentRegistration {
|
|
18
|
+
readonly agentId: string;
|
|
19
|
+
readonly hostname: string;
|
|
20
|
+
readonly platform: AgentPlatformInfo;
|
|
21
|
+
readonly version: string;
|
|
22
|
+
readonly registeredAt: string;
|
|
23
|
+
readonly lastHeartbeat: string;
|
|
24
|
+
readonly status: AgentStatus;
|
|
25
|
+
}
|
|
26
|
+
/** Incoming registration request from a Guard agent / 來自 Guard 代理的登錄請求 */
|
|
27
|
+
export interface AgentRegistrationRequest {
|
|
28
|
+
readonly hostname: string;
|
|
29
|
+
readonly os: string;
|
|
30
|
+
readonly arch: string;
|
|
31
|
+
readonly version: string;
|
|
32
|
+
readonly ip?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Heartbeat data sent by a Guard agent / Guard 代理發送的心跳資料 */
|
|
35
|
+
export interface AgentHeartbeat {
|
|
36
|
+
readonly agentId: string;
|
|
37
|
+
readonly timestamp: string;
|
|
38
|
+
readonly cpuUsage: number;
|
|
39
|
+
readonly memUsage: number;
|
|
40
|
+
readonly activeMonitors: number;
|
|
41
|
+
readonly threatCount: number;
|
|
42
|
+
readonly eventsProcessed: number;
|
|
43
|
+
readonly mode: string;
|
|
44
|
+
readonly uptime: number;
|
|
45
|
+
}
|
|
46
|
+
/** Threat event from a Guard agent / 來自 Guard 代理的威脅事件 */
|
|
47
|
+
export interface ThreatEvent {
|
|
48
|
+
readonly event: SecurityEvent;
|
|
49
|
+
readonly verdict: {
|
|
50
|
+
readonly conclusion: 'benign' | 'suspicious' | 'malicious';
|
|
51
|
+
readonly confidence: number;
|
|
52
|
+
readonly action: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Threat report containing one or more threat events / 包含一或多個威脅事件的威脅報告 */
|
|
56
|
+
export interface ThreatReport {
|
|
57
|
+
readonly agentId: string;
|
|
58
|
+
readonly threats: readonly ThreatEvent[];
|
|
59
|
+
readonly reportedAt: string;
|
|
60
|
+
}
|
|
61
|
+
/** Aggregated threat with source attribution and optional correlation / 帶有來源歸屬和可選關聯的聚合威脅 */
|
|
62
|
+
export interface AggregatedThreat {
|
|
63
|
+
readonly id: string;
|
|
64
|
+
readonly originalThreat: ThreatEvent;
|
|
65
|
+
readonly sourceAgentId: string;
|
|
66
|
+
readonly sourceHostname: string;
|
|
67
|
+
readonly receivedAt: string;
|
|
68
|
+
readonly correlatedWith: readonly string[];
|
|
69
|
+
}
|
|
70
|
+
/** Correlation match indicating related threats / 表示相關威脅的關聯比對 */
|
|
71
|
+
export interface CorrelationMatch {
|
|
72
|
+
readonly threatIdA: string;
|
|
73
|
+
readonly threatIdB: string;
|
|
74
|
+
readonly correlationType: 'same_source_ip' | 'same_malware_hash' | 'same_attack_pattern';
|
|
75
|
+
readonly sharedIndicator: string;
|
|
76
|
+
}
|
|
77
|
+
/** Threat summary for dashboard / 儀表板用威脅摘要 */
|
|
78
|
+
export interface ThreatSummary {
|
|
79
|
+
readonly totalThreats: number;
|
|
80
|
+
readonly criticalCount: number;
|
|
81
|
+
readonly highCount: number;
|
|
82
|
+
readonly suspiciousCount: number;
|
|
83
|
+
readonly uniqueAttackers: number;
|
|
84
|
+
readonly affectedAgents: number;
|
|
85
|
+
readonly correlatedGroups: number;
|
|
86
|
+
}
|
|
87
|
+
/** Policy rule definition / 策略規則定義 */
|
|
88
|
+
export interface PolicyRule {
|
|
89
|
+
readonly ruleId: string;
|
|
90
|
+
readonly type: 'block_ip' | 'alert_threshold' | 'auto_respond' | 'custom';
|
|
91
|
+
readonly condition: Record<string, unknown>;
|
|
92
|
+
readonly action: string;
|
|
93
|
+
readonly severity: Severity;
|
|
94
|
+
readonly description: string;
|
|
95
|
+
}
|
|
96
|
+
/** Policy update payload / 策略更新內容 */
|
|
97
|
+
export interface PolicyUpdate {
|
|
98
|
+
readonly policyId: string;
|
|
99
|
+
readonly version: number;
|
|
100
|
+
readonly rules: readonly PolicyRule[];
|
|
101
|
+
readonly updatedAt: string;
|
|
102
|
+
readonly appliedTo: readonly string[];
|
|
103
|
+
}
|
|
104
|
+
/** Manager server configuration / Manager 伺服器配置 */
|
|
105
|
+
export interface ManagerConfig {
|
|
106
|
+
readonly port: number;
|
|
107
|
+
readonly authToken: string;
|
|
108
|
+
readonly heartbeatIntervalMs: number;
|
|
109
|
+
readonly heartbeatTimeoutMs: number;
|
|
110
|
+
readonly maxAgents: number;
|
|
111
|
+
readonly correlationWindowMs: number;
|
|
112
|
+
readonly threatRetentionMs: number;
|
|
113
|
+
}
|
|
114
|
+
/** Default manager configuration / 預設 Manager 配置 */
|
|
115
|
+
export declare const DEFAULT_MANAGER_CONFIG: ManagerConfig;
|
|
116
|
+
/** Agent summary for overview display / 代理概覽摘要 */
|
|
117
|
+
export interface AgentOverview {
|
|
118
|
+
readonly agentId: string;
|
|
119
|
+
readonly hostname: string;
|
|
120
|
+
readonly status: AgentStatus;
|
|
121
|
+
readonly lastHeartbeat: string;
|
|
122
|
+
readonly threatCount: number;
|
|
123
|
+
}
|
|
124
|
+
/** Full manager overview for dashboard / 儀表板用完整 Manager 概覽 */
|
|
125
|
+
export interface ManagerOverview {
|
|
126
|
+
readonly totalAgents: number;
|
|
127
|
+
readonly onlineAgents: number;
|
|
128
|
+
readonly staleAgents: number;
|
|
129
|
+
readonly offlineAgents: number;
|
|
130
|
+
readonly agents: readonly AgentOverview[];
|
|
131
|
+
readonly threatSummary: ThreatSummary;
|
|
132
|
+
readonly activePolicyVersion: number;
|
|
133
|
+
readonly uptimeMs: number;
|
|
134
|
+
}
|
|
135
|
+
/** Policy broadcast result / 策略廣播結果 */
|
|
136
|
+
export interface PolicyBroadcastResult {
|
|
137
|
+
readonly policyId: string;
|
|
138
|
+
readonly targetAgents: readonly string[];
|
|
139
|
+
readonly queuedAt: string;
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAIjE,gDAAgD;AAChD,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;AAEzD,0CAA0C;A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pD,eAAO,MAAM,sBAAsB,EAAE,aAQpC,CAAC;AAIF,kDAAkD;AAClD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,8DAA8D;AAC9D,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,SAAS,aAAa,EAAE,CAAC;IAC1C,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACrC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,uCAAuC;AACvC,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manager type definitions for distributed Guard agent orchestration
|
|
3
|
+
* Manager 分散式 Guard 代理協調型別定義
|
|
4
|
+
*
|
|
5
|
+
* @module @panguard-ai/manager/types
|
|
6
|
+
*/
|
|
7
|
+
/** Default manager configuration / 預設 Manager 配置 */
|
|
8
|
+
export const DEFAULT_MANAGER_CONFIG = {
|
|
9
|
+
port: 8443,
|
|
10
|
+
authToken: '',
|
|
11
|
+
heartbeatIntervalMs: 30_000,
|
|
12
|
+
heartbeatTimeoutMs: 90_000,
|
|
13
|
+
maxAgents: 500,
|
|
14
|
+
correlationWindowMs: 300_000, // 5 minutes
|
|
15
|
+
threatRetentionMs: 86_400_000, // 24 hours
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAqIH,oDAAoD;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,IAAI,EAAE,IAAI;IACV,SAAS,EAAE,EAAE;IACb,mBAAmB,EAAE,MAAM;IAC3B,kBAAkB,EAAE,MAAM;IAC1B,SAAS,EAAE,GAAG;IACd,mBAAmB,EAAE,OAAO,EAAE,YAAY;IAC1C,iBAAiB,EAAE,UAAU,EAAE,WAAW;CAC3C,CAAC"}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manager utility functions
|
|
3
|
+
* Manager 工具函式
|
|
4
|
+
*
|
|
5
|
+
* @module @panguard-ai/manager/utils
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Generate a unique agent ID with a 'ag-' prefix.
|
|
9
|
+
*
|
|
10
|
+
* @returns A unique identifier string (e.g., 'ag-a1b2c3d4e5f6')
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateAgentId(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Generate a unique threat ID with a 'th-' prefix.
|
|
15
|
+
*
|
|
16
|
+
* @returns A unique identifier string (e.g., 'th-a1b2c3d4e5f6')
|
|
17
|
+
*/
|
|
18
|
+
export declare function generateThreatId(): string;
|
|
19
|
+
/**
|
|
20
|
+
* Generate a unique policy ID with a 'pol-' prefix.
|
|
21
|
+
*
|
|
22
|
+
* @returns A unique identifier string (e.g., 'pol-a1b2c3d4')
|
|
23
|
+
*/
|
|
24
|
+
export declare function generatePolicyId(): string;
|
|
25
|
+
/**
|
|
26
|
+
* Generate a secure authentication token.
|
|
27
|
+
*
|
|
28
|
+
* @returns A 32-byte hex token string
|
|
29
|
+
*/
|
|
30
|
+
export declare function generateAuthToken(): string;
|
|
31
|
+
/**
|
|
32
|
+
* Extract source IP from a SecurityEvent's metadata.
|
|
33
|
+
* Looks for common field names used across different event sources.
|
|
34
|
+
*
|
|
35
|
+
* @param metadata - The event metadata record
|
|
36
|
+
* @returns The source IP string, or undefined if not found
|
|
37
|
+
*/
|
|
38
|
+
export declare function extractSourceIP(metadata: Record<string, unknown>): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Extract a file hash from a SecurityEvent's metadata.
|
|
41
|
+
*
|
|
42
|
+
* @param metadata - The event metadata record
|
|
43
|
+
* @returns The hash string, or undefined if not found
|
|
44
|
+
*/
|
|
45
|
+
export declare function extractFileHash(metadata: Record<string, unknown>): string | undefined;
|
|
46
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,GAAG,SAAS,CAkBpB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,MAAM,GAAG,SAAS,CAkBpB"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Manager utility functions
|
|
3
|
+
* Manager 工具函式
|
|
4
|
+
*
|
|
5
|
+
* @module @panguard-ai/manager/utils
|
|
6
|
+
*/
|
|
7
|
+
import { randomBytes } from 'node:crypto';
|
|
8
|
+
/**
|
|
9
|
+
* Generate a unique agent ID with a 'ag-' prefix.
|
|
10
|
+
*
|
|
11
|
+
* @returns A unique identifier string (e.g., 'ag-a1b2c3d4e5f6')
|
|
12
|
+
*/
|
|
13
|
+
export function generateAgentId() {
|
|
14
|
+
return `ag-${randomBytes(6).toString('hex')}`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate a unique threat ID with a 'th-' prefix.
|
|
18
|
+
*
|
|
19
|
+
* @returns A unique identifier string (e.g., 'th-a1b2c3d4e5f6')
|
|
20
|
+
*/
|
|
21
|
+
export function generateThreatId() {
|
|
22
|
+
return `th-${randomBytes(6).toString('hex')}`;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Generate a unique policy ID with a 'pol-' prefix.
|
|
26
|
+
*
|
|
27
|
+
* @returns A unique identifier string (e.g., 'pol-a1b2c3d4')
|
|
28
|
+
*/
|
|
29
|
+
export function generatePolicyId() {
|
|
30
|
+
return `pol-${randomBytes(4).toString('hex')}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Generate a secure authentication token.
|
|
34
|
+
*
|
|
35
|
+
* @returns A 32-byte hex token string
|
|
36
|
+
*/
|
|
37
|
+
export function generateAuthToken() {
|
|
38
|
+
return randomBytes(32).toString('hex');
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Extract source IP from a SecurityEvent's metadata.
|
|
42
|
+
* Looks for common field names used across different event sources.
|
|
43
|
+
*
|
|
44
|
+
* @param metadata - The event metadata record
|
|
45
|
+
* @returns The source IP string, or undefined if not found
|
|
46
|
+
*/
|
|
47
|
+
export function extractSourceIP(metadata) {
|
|
48
|
+
const candidates = [
|
|
49
|
+
'sourceIP',
|
|
50
|
+
'remoteAddress',
|
|
51
|
+
'src_ip',
|
|
52
|
+
'source_ip',
|
|
53
|
+
'attacker_ip',
|
|
54
|
+
'client_ip',
|
|
55
|
+
];
|
|
56
|
+
for (const key of candidates) {
|
|
57
|
+
const value = metadata[key];
|
|
58
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extract a file hash from a SecurityEvent's metadata.
|
|
66
|
+
*
|
|
67
|
+
* @param metadata - The event metadata record
|
|
68
|
+
* @returns The hash string, or undefined if not found
|
|
69
|
+
*/
|
|
70
|
+
export function extractFileHash(metadata) {
|
|
71
|
+
const candidates = [
|
|
72
|
+
'sha256',
|
|
73
|
+
'sha1',
|
|
74
|
+
'md5',
|
|
75
|
+
'fileHash',
|
|
76
|
+
'hash',
|
|
77
|
+
'malwareHash',
|
|
78
|
+
];
|
|
79
|
+
for (const key of candidates) {
|
|
80
|
+
const value = metadata[key];
|
|
81
|
+
if (typeof value === 'string' && value.length > 0) {
|
|
82
|
+
return value;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;GAIG;AACH,MAAM,UAAU,eAAe;IAC7B,OAAO,MAAM,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;AAChD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,M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