@panguard-ai/threat-cloud 0.2.0 → 0.2.2
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/dist/admin-dashboard.d.ts +11 -0
- package/dist/admin-dashboard.d.ts.map +1 -0
- package/dist/admin-dashboard.js +482 -0
- package/dist/admin-dashboard.js.map +1 -0
- package/dist/backup.d.ts +40 -0
- package/dist/backup.d.ts.map +1 -0
- package/dist/backup.js +123 -0
- package/dist/backup.js.map +1 -0
- package/dist/cli.js +24 -64
- package/dist/cli.js.map +1 -1
- package/dist/database.d.ts +78 -37
- package/dist/database.d.ts.map +1 -1
- package/dist/database.js +590 -324
- package/dist/database.js.map +1 -1
- package/dist/index.d.ts +4 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -9
- package/dist/index.js.map +1 -1
- package/dist/llm-reviewer.d.ts +47 -0
- package/dist/llm-reviewer.d.ts.map +1 -0
- package/dist/llm-reviewer.js +203 -0
- package/dist/llm-reviewer.js.map +1 -0
- package/dist/server.d.ts +56 -63
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +525 -635
- package/dist/server.js.map +1 -1
- package/dist/types.d.ts +71 -301
- package/dist/types.d.ts.map +1 -1
- package/package.json +20 -18
- package/LICENSE +0 -21
- package/dist/audit-logger.d.ts +0 -46
- package/dist/audit-logger.d.ts.map +0 -1
- package/dist/audit-logger.js +0 -105
- package/dist/audit-logger.js.map +0 -1
- package/dist/correlation-engine.d.ts +0 -41
- package/dist/correlation-engine.d.ts.map +0 -1
- package/dist/correlation-engine.js +0 -313
- package/dist/correlation-engine.js.map +0 -1
- package/dist/feed-distributor.d.ts +0 -36
- package/dist/feed-distributor.d.ts.map +0 -1
- package/dist/feed-distributor.js +0 -125
- package/dist/feed-distributor.js.map +0 -1
- package/dist/ioc-store.d.ts +0 -83
- package/dist/ioc-store.d.ts.map +0 -1
- package/dist/ioc-store.js +0 -278
- package/dist/ioc-store.js.map +0 -1
- package/dist/query-handlers.d.ts +0 -40
- package/dist/query-handlers.d.ts.map +0 -1
- package/dist/query-handlers.js +0 -211
- package/dist/query-handlers.js.map +0 -1
- package/dist/reputation-engine.d.ts +0 -44
- package/dist/reputation-engine.d.ts.map +0 -1
- package/dist/reputation-engine.js +0 -169
- package/dist/reputation-engine.js.map +0 -1
- package/dist/rule-generator.d.ts +0 -47
- package/dist/rule-generator.d.ts.map +0 -1
- package/dist/rule-generator.js +0 -238
- package/dist/rule-generator.js.map +0 -1
- package/dist/scheduler.d.ts +0 -52
- package/dist/scheduler.d.ts.map +0 -1
- package/dist/scheduler.js +0 -143
- package/dist/scheduler.js.map +0 -1
- package/dist/sighting-store.d.ts +0 -61
- package/dist/sighting-store.d.ts.map +0 -1
- package/dist/sighting-store.js +0 -191
- package/dist/sighting-store.js.map +0 -1
package/dist/rule-generator.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Automatic Sigma Rule Generator
|
|
3
|
-
* 自動 Sigma 規則產生器
|
|
4
|
-
*
|
|
5
|
-
* Analyzes enriched threat events, detects recurring patterns,
|
|
6
|
-
* and generates Sigma detection rules automatically.
|
|
7
|
-
*
|
|
8
|
-
* @module @panguard-ai/threat-cloud/rule-generator
|
|
9
|
-
*/
|
|
10
|
-
import { createHash } from 'node:crypto';
|
|
11
|
-
/** MITRE technique → tactic mapping (simplified) */
|
|
12
|
-
const TECHNIQUE_TACTIC_MAP = {
|
|
13
|
-
T1110: 'credential_access',
|
|
14
|
-
T1021: 'lateral_movement',
|
|
15
|
-
T1046: 'discovery',
|
|
16
|
-
T1059: 'execution',
|
|
17
|
-
T1486: 'impact',
|
|
18
|
-
T1190: 'initial_access',
|
|
19
|
-
T1078: 'defense_evasion',
|
|
20
|
-
T1071: 'command_and_control',
|
|
21
|
-
T1048: 'exfiltration',
|
|
22
|
-
T1569: 'execution',
|
|
23
|
-
T1053: 'execution',
|
|
24
|
-
T1543: 'persistence',
|
|
25
|
-
T1547: 'persistence',
|
|
26
|
-
T1098: 'persistence',
|
|
27
|
-
T1027: 'defense_evasion',
|
|
28
|
-
T1070: 'defense_evasion',
|
|
29
|
-
T1562: 'defense_evasion',
|
|
30
|
-
T1018: 'discovery',
|
|
31
|
-
T1057: 'discovery',
|
|
32
|
-
T1082: 'discovery',
|
|
33
|
-
T1560: 'collection',
|
|
34
|
-
};
|
|
35
|
-
/** Severity mapping for pattern analysis */
|
|
36
|
-
const SEVERITY_ORDER = ['critical', 'high', 'medium', 'low'];
|
|
37
|
-
/** Default configuration */
|
|
38
|
-
const DEFAULT_CONFIG = {
|
|
39
|
-
minOccurrences: 10,
|
|
40
|
-
analysisWindowHours: 168, // 7 days
|
|
41
|
-
minDistinctIPs: 3,
|
|
42
|
-
};
|
|
43
|
-
export class RuleGenerator {
|
|
44
|
-
db;
|
|
45
|
-
config;
|
|
46
|
-
constructor(db, config) {
|
|
47
|
-
this.db = db;
|
|
48
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Analyze recent events and generate rules for recurring patterns.
|
|
52
|
-
* 分析近期事件並為反覆出現的模式產生規則
|
|
53
|
-
*/
|
|
54
|
-
generateRules() {
|
|
55
|
-
const startTime = Date.now();
|
|
56
|
-
const patterns = this.detectPatterns();
|
|
57
|
-
let rulesGenerated = 0;
|
|
58
|
-
let rulesUpdated = 0;
|
|
59
|
-
this.db.transaction(() => {
|
|
60
|
-
for (const pattern of patterns) {
|
|
61
|
-
const existing = this.db
|
|
62
|
-
.prepare('SELECT pattern_hash FROM generated_patterns WHERE pattern_hash = ?')
|
|
63
|
-
.get(pattern.patternHash);
|
|
64
|
-
if (existing) {
|
|
65
|
-
this.updatePattern(pattern);
|
|
66
|
-
rulesUpdated++;
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
this.createRuleFromPattern(pattern);
|
|
70
|
-
rulesGenerated++;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
})();
|
|
74
|
-
return {
|
|
75
|
-
patternsAnalyzed: patterns.length,
|
|
76
|
-
rulesGenerated,
|
|
77
|
-
rulesUpdated,
|
|
78
|
-
duration: Date.now() - startTime,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Detect recurring patterns in enriched threat events.
|
|
83
|
-
* 偵測豐富化威脅事件中的反覆模式
|
|
84
|
-
*/
|
|
85
|
-
detectPatterns() {
|
|
86
|
-
const sinceDate = new Date(Date.now() - this.config.analysisWindowHours * 60 * 60 * 1000).toISOString();
|
|
87
|
-
const rows = this.db
|
|
88
|
-
.prepare(`SELECT attack_type, mitre_techniques, attack_source_ip, region, severity, timestamp
|
|
89
|
-
FROM enriched_threats
|
|
90
|
-
WHERE received_at > ?
|
|
91
|
-
ORDER BY timestamp ASC`)
|
|
92
|
-
.all(sinceDate);
|
|
93
|
-
// Group by (attack_type, sorted mitre_techniques)
|
|
94
|
-
const grouped = new Map();
|
|
95
|
-
for (const row of rows) {
|
|
96
|
-
const techniques = JSON.parse(row.mitre_techniques).sort();
|
|
97
|
-
const key = `${row.attack_type}|${techniques.join(',')}`;
|
|
98
|
-
let group = grouped.get(key);
|
|
99
|
-
if (!group) {
|
|
100
|
-
group = {
|
|
101
|
-
attackType: row.attack_type,
|
|
102
|
-
techniques,
|
|
103
|
-
ips: new Set(),
|
|
104
|
-
regions: new Set(),
|
|
105
|
-
severityCounts: {},
|
|
106
|
-
occurrences: 0,
|
|
107
|
-
firstSeen: row.timestamp,
|
|
108
|
-
lastSeen: row.timestamp,
|
|
109
|
-
};
|
|
110
|
-
grouped.set(key, group);
|
|
111
|
-
}
|
|
112
|
-
group.ips.add(row.attack_source_ip);
|
|
113
|
-
group.regions.add(row.region);
|
|
114
|
-
group.severityCounts[row.severity] = (group.severityCounts[row.severity] ?? 0) + 1;
|
|
115
|
-
group.occurrences++;
|
|
116
|
-
if (row.timestamp > group.lastSeen)
|
|
117
|
-
group.lastSeen = row.timestamp;
|
|
118
|
-
}
|
|
119
|
-
// Filter by thresholds
|
|
120
|
-
const patterns = [];
|
|
121
|
-
for (const group of grouped.values()) {
|
|
122
|
-
if (group.occurrences >= this.config.minOccurrences &&
|
|
123
|
-
group.ips.size >= this.config.minDistinctIPs) {
|
|
124
|
-
const patternHash = createHash('sha256')
|
|
125
|
-
.update(group.attackType + group.techniques.join(','))
|
|
126
|
-
.digest('hex')
|
|
127
|
-
.slice(0, 16);
|
|
128
|
-
patterns.push({
|
|
129
|
-
attackType: group.attackType,
|
|
130
|
-
mitreTechniques: group.techniques,
|
|
131
|
-
patternHash,
|
|
132
|
-
occurrences: group.occurrences,
|
|
133
|
-
distinctIPs: group.ips.size,
|
|
134
|
-
regions: [...group.regions],
|
|
135
|
-
severityCounts: group.severityCounts,
|
|
136
|
-
firstSeen: group.firstSeen,
|
|
137
|
-
lastSeen: group.lastSeen,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return patterns;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Get all generated patterns.
|
|
145
|
-
* 取得所有已產生的模式
|
|
146
|
-
*/
|
|
147
|
-
getGeneratedPatterns() {
|
|
148
|
-
const rows = this.db
|
|
149
|
-
.prepare(`SELECT pattern_hash, attack_type, mitre_techniques, rule_id, occurrences, distinct_ips
|
|
150
|
-
FROM generated_patterns
|
|
151
|
-
ORDER BY occurrences DESC`)
|
|
152
|
-
.all();
|
|
153
|
-
return rows.map((r) => ({
|
|
154
|
-
patternHash: r.pattern_hash,
|
|
155
|
-
attackType: r.attack_type,
|
|
156
|
-
mitreTechniques: JSON.parse(r.mitre_techniques),
|
|
157
|
-
ruleId: r.rule_id,
|
|
158
|
-
occurrences: r.occurrences,
|
|
159
|
-
distinctIPs: r.distinct_ips,
|
|
160
|
-
}));
|
|
161
|
-
}
|
|
162
|
-
// -------------------------------------------------------------------------
|
|
163
|
-
// Private helpers / 私有輔助方法
|
|
164
|
-
// -------------------------------------------------------------------------
|
|
165
|
-
/** Create a new rule from a detected pattern */
|
|
166
|
-
createRuleFromPattern(pattern) {
|
|
167
|
-
const ruleId = `tc-auto-${pattern.patternHash}`;
|
|
168
|
-
const severity = this.pickMaxSeverity(pattern.severityCounts);
|
|
169
|
-
const sigmaYaml = this.generateSigmaYaml(pattern, ruleId, severity);
|
|
170
|
-
// Insert into rules table
|
|
171
|
-
this.db
|
|
172
|
-
.prepare(`INSERT INTO rules (rule_id, rule_content, published_at, source)
|
|
173
|
-
VALUES (?, ?, datetime('now'), 'threat-cloud-auto')
|
|
174
|
-
ON CONFLICT(rule_id) DO UPDATE SET
|
|
175
|
-
rule_content = excluded.rule_content,
|
|
176
|
-
published_at = excluded.published_at,
|
|
177
|
-
updated_at = datetime('now')`)
|
|
178
|
-
.run(ruleId, sigmaYaml);
|
|
179
|
-
// Insert into generated_patterns table
|
|
180
|
-
this.db
|
|
181
|
-
.prepare(`INSERT INTO generated_patterns
|
|
182
|
-
(pattern_hash, attack_type, mitre_techniques, rule_id, occurrences, distinct_ips, first_seen, last_seen)
|
|
183
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
|
|
184
|
-
.run(pattern.patternHash, pattern.attackType, JSON.stringify(pattern.mitreTechniques), ruleId, pattern.occurrences, pattern.distinctIPs, pattern.firstSeen, pattern.lastSeen);
|
|
185
|
-
}
|
|
186
|
-
/** Update an existing pattern's statistics */
|
|
187
|
-
updatePattern(pattern) {
|
|
188
|
-
this.db
|
|
189
|
-
.prepare(`UPDATE generated_patterns SET
|
|
190
|
-
occurrences = ?,
|
|
191
|
-
distinct_ips = ?,
|
|
192
|
-
last_seen = ?,
|
|
193
|
-
updated_at = datetime('now')
|
|
194
|
-
WHERE pattern_hash = ?`)
|
|
195
|
-
.run(pattern.occurrences, pattern.distinctIPs, pattern.lastSeen, pattern.patternHash);
|
|
196
|
-
// Also update the rule content
|
|
197
|
-
const ruleId = `tc-auto-${pattern.patternHash}`;
|
|
198
|
-
const severity = this.pickMaxSeverity(pattern.severityCounts);
|
|
199
|
-
const sigmaYaml = this.generateSigmaYaml(pattern, ruleId, severity);
|
|
200
|
-
this.db
|
|
201
|
-
.prepare(`UPDATE rules SET rule_content = ?, published_at = datetime('now'), updated_at = datetime('now')
|
|
202
|
-
WHERE rule_id = ?`)
|
|
203
|
-
.run(sigmaYaml, ruleId);
|
|
204
|
-
}
|
|
205
|
-
/** Generate Sigma YAML rule content */
|
|
206
|
-
generateSigmaYaml(pattern, ruleId, severity) {
|
|
207
|
-
const tags = pattern.mitreTechniques.map((t) => {
|
|
208
|
-
const tactic = TECHNIQUE_TACTIC_MAP[t] ?? 'unknown';
|
|
209
|
-
return ` - attack.${tactic}\n - attack.${t.toLowerCase()}`;
|
|
210
|
-
});
|
|
211
|
-
const regionList = pattern.regions.join(', ');
|
|
212
|
-
return [
|
|
213
|
-
`title: "Threat Cloud Auto: ${pattern.attackType} via ${pattern.mitreTechniques.join(', ')}"`,
|
|
214
|
-
`id: ${ruleId}`,
|
|
215
|
-
`status: experimental`,
|
|
216
|
-
`author: Panguard Threat Cloud (auto-generated)`,
|
|
217
|
-
`description: |`,
|
|
218
|
-
` Pattern observed ${pattern.occurrences} times from ${pattern.distinctIPs} distinct IPs across ${regionList}.`,
|
|
219
|
-
`date: ${new Date().toISOString().slice(0, 10)}`,
|
|
220
|
-
`detection:`,
|
|
221
|
-
` selection:`,
|
|
222
|
-
` EventType: ${pattern.attackType}`,
|
|
223
|
-
` condition: selection`,
|
|
224
|
-
`level: ${severity}`,
|
|
225
|
-
`tags:`,
|
|
226
|
-
...tags,
|
|
227
|
-
].join('\n');
|
|
228
|
-
}
|
|
229
|
-
/** Pick highest severity from counts */
|
|
230
|
-
pickMaxSeverity(severityCounts) {
|
|
231
|
-
for (const s of SEVERITY_ORDER) {
|
|
232
|
-
if (severityCounts[s] && severityCounts[s] > 0)
|
|
233
|
-
return s;
|
|
234
|
-
}
|
|
235
|
-
return 'medium';
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
//# sourceMappingURL=rule-generator.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rule-generator.js","sourceRoot":"","sources":["../src/rule-generator.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAIzC,oDAAoD;AACpD,MAAM,oBAAoB,GAA2B;IACnD,KAAK,EAAE,mBAAmB;IAC1B,KAAK,EAAE,kBAAkB;IACzB,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,QAAQ;IACf,KAAK,EAAE,gBAAgB;IACvB,KAAK,EAAE,iBAAiB;IACxB,KAAK,EAAE,qBAAqB;IAC5B,KAAK,EAAE,cAAc;IACrB,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,aAAa;IACpB,KAAK,EAAE,iBAAiB;IACxB,KAAK,EAAE,iBAAiB;IACxB,KAAK,EAAE,iBAAiB;IACxB,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,WAAW;IAClB,KAAK,EAAE,YAAY;CACpB,CAAC;AAEF,4CAA4C;AAC5C,MAAM,cAAc,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAU,CAAC;AAEtE,4BAA4B;AAC5B,MAAM,cAAc,GAAwB;IAC1C,cAAc,EAAE,EAAE;IAClB,mBAAmB,EAAE,GAAG,EAAE,SAAS;IACnC,cAAc,EAAE,CAAC;CAClB,CAAC;AAEF,MAAM,OAAO,aAAa;IAIL;IAHF,MAAM,CAAsB;IAE7C,YACmB,EAAqB,EACtC,MAAqC;QADpB,OAAE,GAAF,EAAE,CAAmB;QAGtC,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IACj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AC5D,KAAK,MAAM,CAAC,IAAI,cAAc,EAAE,CAAC;YAC/B,IAAI,cAAc,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC;gBAAE,OAAO,CAAC,CAAC;QAC3D,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
package/dist/scheduler.d.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Background Scheduler
|
|
3
|
-
* 背景排程器
|
|
4
|
-
*
|
|
5
|
-
* Manages periodic tasks: reputation recalculation, correlation scanning,
|
|
6
|
-
* rule generation, and data lifecycle cleanup.
|
|
7
|
-
*
|
|
8
|
-
* @module @panguard-ai/threat-cloud/scheduler
|
|
9
|
-
*/
|
|
10
|
-
import type Database from 'better-sqlite3';
|
|
11
|
-
import type { SchedulerConfig } from './types.js';
|
|
12
|
-
export declare class Scheduler {
|
|
13
|
-
private readonly db;
|
|
14
|
-
private readonly config;
|
|
15
|
-
private readonly reputation;
|
|
16
|
-
private readonly correlation;
|
|
17
|
-
private readonly ruleGen;
|
|
18
|
-
private readonly iocStore;
|
|
19
|
-
private timers;
|
|
20
|
-
private running;
|
|
21
|
-
constructor(db: Database.Database, config?: Partial<SchedulerConfig>);
|
|
22
|
-
/** Start all scheduled tasks / 啟動所有排程任務 */
|
|
23
|
-
start(): void;
|
|
24
|
-
/** Stop all scheduled tasks / 停止所有排程任務 */
|
|
25
|
-
stop(): void;
|
|
26
|
-
/** Check if scheduler is running */
|
|
27
|
-
isRunning(): boolean;
|
|
28
|
-
/** Run correlation scan manually */
|
|
29
|
-
runCorrelation(): {
|
|
30
|
-
newCampaigns: number;
|
|
31
|
-
eventsCorrelated: number;
|
|
32
|
-
};
|
|
33
|
-
/** Run reputation recalculation manually */
|
|
34
|
-
runReputation(): {
|
|
35
|
-
updated: number;
|
|
36
|
-
};
|
|
37
|
-
/** Run rule generation manually */
|
|
38
|
-
runRuleGeneration(): {
|
|
39
|
-
rulesGenerated: number;
|
|
40
|
-
rulesUpdated: number;
|
|
41
|
-
};
|
|
42
|
-
/** Run data lifecycle cleanup */
|
|
43
|
-
runLifecycle(): {
|
|
44
|
-
expired: number;
|
|
45
|
-
purged: number;
|
|
46
|
-
vacuumed: boolean;
|
|
47
|
-
auditPurged: number;
|
|
48
|
-
};
|
|
49
|
-
/** Run database backup / 執行資料庫備份 */
|
|
50
|
-
runBackup(backupDir: string, maxBackups?: number): string | null;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=scheduler.d.ts.map
|
package/dist/scheduler.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAK3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAYlD,qBAAa,SAAS;IAUlB,OAAO,CAAC,QAAQ,CAAC,EAAE;IATrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAkB;IACzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAoB;IAChD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,MAAM,CAA6C;IAC3D,OAAO,CAAC,OAAO,CAAS;gBAGL,EAAE,EAAE,QAAQ,CAAC,QAAQ,EACtC,MAAM,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC;IASnC,2CAA2C;IAC3C,KAAK,IAAI,IAAI;IAoBb,0CAA0C;IAC1C,IAAI,IAAI,IAAI;IAQZ,oCAAoC;IACpC,SAAS,IAAI,OAAO;IAIpB,oCAAoC;IACpC,cAAc,IAAI;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAE;IAKpE,4CAA4C;IAC5C,aAAa,IAAI;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE;IAKpC,mCAAmC;IACnC,iBAAiB,IAAI;QAAE,cAAc,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAA;KAAE;IAKrE,iCAAiC;IACjC,YAAY,IAAI;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE;IAwC3F,oCAAoC;IACpC,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,SAAK,GAAG,MAAM,GAAG,IAAI;CA4B7D"}
|
package/dist/scheduler.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Background Scheduler
|
|
3
|
-
* 背景排程器
|
|
4
|
-
*
|
|
5
|
-
* Manages periodic tasks: reputation recalculation, correlation scanning,
|
|
6
|
-
* rule generation, and data lifecycle cleanup.
|
|
7
|
-
*
|
|
8
|
-
* @module @panguard-ai/threat-cloud/scheduler
|
|
9
|
-
*/
|
|
10
|
-
import { existsSync, mkdirSync, readdirSync, unlinkSync } from 'node:fs';
|
|
11
|
-
import { join } from 'node:path';
|
|
12
|
-
import { ReputationEngine } from './reputation-engine.js';
|
|
13
|
-
import { CorrelationEngine } from './correlation-engine.js';
|
|
14
|
-
import { RuleGenerator } from './rule-generator.js';
|
|
15
|
-
import { IoCStore } from './ioc-store.js';
|
|
16
|
-
/** Default scheduler configuration */
|
|
17
|
-
const DEFAULT_CONFIG = {
|
|
18
|
-
reputationIntervalMs: 60 * 60 * 1000, // 1 hour
|
|
19
|
-
correlationIntervalMs: 5 * 60 * 1000, // 5 minutes
|
|
20
|
-
ruleGenerationIntervalMs: 6 * 60 * 60 * 1000, // 6 hours
|
|
21
|
-
threatRetentionDays: 90,
|
|
22
|
-
iocRetentionDays: 365,
|
|
23
|
-
aggregationIntervalMs: 24 * 60 * 60 * 1000, // 24 hours
|
|
24
|
-
};
|
|
25
|
-
export class Scheduler {
|
|
26
|
-
db;
|
|
27
|
-
config;
|
|
28
|
-
reputation;
|
|
29
|
-
correlation;
|
|
30
|
-
ruleGen;
|
|
31
|
-
iocStore;
|
|
32
|
-
timers = [];
|
|
33
|
-
running = false;
|
|
34
|
-
constructor(db, config) {
|
|
35
|
-
this.db = db;
|
|
36
|
-
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
37
|
-
this.reputation = new ReputationEngine(db);
|
|
38
|
-
this.correlation = new CorrelationEngine(db);
|
|
39
|
-
this.ruleGen = new RuleGenerator(db);
|
|
40
|
-
this.iocStore = new IoCStore(db);
|
|
41
|
-
}
|
|
42
|
-
/** Start all scheduled tasks / 啟動所有排程任務 */
|
|
43
|
-
start() {
|
|
44
|
-
if (this.running)
|
|
45
|
-
return;
|
|
46
|
-
this.running = true;
|
|
47
|
-
// Run correlation immediately, then on interval
|
|
48
|
-
this.runCorrelation();
|
|
49
|
-
this.timers.push(setInterval(() => this.runCorrelation(), this.config.correlationIntervalMs));
|
|
50
|
-
// Reputation recalculation
|
|
51
|
-
this.timers.push(setInterval(() => this.runReputation(), this.config.reputationIntervalMs));
|
|
52
|
-
// Rule generation
|
|
53
|
-
this.timers.push(setInterval(() => this.runRuleGeneration(), this.config.ruleGenerationIntervalMs));
|
|
54
|
-
// Data lifecycle cleanup
|
|
55
|
-
this.timers.push(setInterval(() => this.runLifecycle(), this.config.aggregationIntervalMs));
|
|
56
|
-
}
|
|
57
|
-
/** Stop all scheduled tasks / 停止所有排程任務 */
|
|
58
|
-
stop() {
|
|
59
|
-
this.running = false;
|
|
60
|
-
for (const timer of this.timers) {
|
|
61
|
-
clearInterval(timer);
|
|
62
|
-
}
|
|
63
|
-
this.timers = [];
|
|
64
|
-
}
|
|
65
|
-
/** Check if scheduler is running */
|
|
66
|
-
isRunning() {
|
|
67
|
-
return this.running;
|
|
68
|
-
}
|
|
69
|
-
/** Run correlation scan manually */
|
|
70
|
-
runCorrelation() {
|
|
71
|
-
const result = this.correlation.scanForCampaigns();
|
|
72
|
-
return { newCampaigns: result.newCampaigns, eventsCorrelated: result.eventsCorrelated };
|
|
73
|
-
}
|
|
74
|
-
/** Run reputation recalculation manually */
|
|
75
|
-
runReputation() {
|
|
76
|
-
const result = this.reputation.recalculateAll();
|
|
77
|
-
return { updated: result.updated };
|
|
78
|
-
}
|
|
79
|
-
/** Run rule generation manually */
|
|
80
|
-
runRuleGeneration() {
|
|
81
|
-
const result = this.ruleGen.generateRules();
|
|
82
|
-
return { rulesGenerated: result.rulesGenerated, rulesUpdated: result.rulesUpdated };
|
|
83
|
-
}
|
|
84
|
-
/** Run data lifecycle cleanup */
|
|
85
|
-
runLifecycle() {
|
|
86
|
-
const expireCutoff = new Date(Date.now() - this.config.iocRetentionDays * 24 * 60 * 60 * 1000).toISOString();
|
|
87
|
-
const purgeCutoff = new Date(Date.now() - (this.config.iocRetentionDays + 30) * 24 * 60 * 60 * 1000).toISOString();
|
|
88
|
-
const expired = this.iocStore.expireStaleIoCs(expireCutoff);
|
|
89
|
-
const purged = this.iocStore.purgeExpiredIoCs(purgeCutoff);
|
|
90
|
-
// Purge old enriched threats
|
|
91
|
-
const threatCutoff = new Date(Date.now() - this.config.threatRetentionDays * 24 * 60 * 60 * 1000).toISOString();
|
|
92
|
-
this.db
|
|
93
|
-
.prepare('DELETE FROM enriched_threats WHERE received_at < ? AND campaign_id IS NULL')
|
|
94
|
-
.run(threatCutoff);
|
|
95
|
-
// Purge old audit log entries (180 days retention)
|
|
96
|
-
const auditCutoff = new Date(Date.now() - 180 * 24 * 60 * 60 * 1000).toISOString();
|
|
97
|
-
const auditResult = this.db
|
|
98
|
-
.prepare('DELETE FROM audit_log WHERE created_at < ?')
|
|
99
|
-
.run(auditCutoff);
|
|
100
|
-
const auditPurged = auditResult.changes;
|
|
101
|
-
// WAL checkpoint
|
|
102
|
-
let vacuumed = false;
|
|
103
|
-
try {
|
|
104
|
-
this.db.pragma('wal_checkpoint(PASSIVE)');
|
|
105
|
-
vacuumed = true;
|
|
106
|
-
}
|
|
107
|
-
catch {
|
|
108
|
-
/* ignore checkpoint errors */
|
|
109
|
-
}
|
|
110
|
-
return { expired, purged, vacuumed, auditPurged };
|
|
111
|
-
}
|
|
112
|
-
/** Run database backup / 執行資料庫備份 */
|
|
113
|
-
runBackup(backupDir, maxBackups = 30) {
|
|
114
|
-
try {
|
|
115
|
-
if (!existsSync(backupDir)) {
|
|
116
|
-
mkdirSync(backupDir, { recursive: true });
|
|
117
|
-
}
|
|
118
|
-
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
119
|
-
const dest = join(backupDir, `threat-cloud-${timestamp}.db`);
|
|
120
|
-
this.db.exec(`VACUUM INTO '${dest.replace(/'/g, "''")}'`);
|
|
121
|
-
// Rotate: remove oldest backups beyond maxBackups
|
|
122
|
-
const backups = readdirSync(backupDir)
|
|
123
|
-
.filter((f) => f.startsWith('threat-cloud-') && f.endsWith('.db'))
|
|
124
|
-
.sort();
|
|
125
|
-
while (backups.length > maxBackups) {
|
|
126
|
-
const oldest = backups.shift();
|
|
127
|
-
if (oldest) {
|
|
128
|
-
try {
|
|
129
|
-
unlinkSync(join(backupDir, oldest));
|
|
130
|
-
}
|
|
131
|
-
catch {
|
|
132
|
-
/* best effort */
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return dest;
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
//# sourceMappingURL=scheduler.js.map
|
package/dist/scheduler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAA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CAAC;YAC7D,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,gBAAgB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YAE1D,kDAAkD;YAClD,MAAM,OAAO,GAAG,WAAW,CAAC,SAAS,CAAC;iBACnC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;iBACjE,IAAI,EAAE,CAAC;YACV,OAAO,OAAO,CAAC,MAAM,GAAG,UAAU,EAAE,CAAC;gBACnC,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;gBAC/B,IAAI,MAAM,EAAE,CAAC;oBACX,IAAI,CAAC;wBACH,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;oBACtC,CAAC;oBAAC,MAAM,CAAC;wBACP,iBAAiB;oBACnB,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
package/dist/sighting-store.d.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Sighting Store — IoC observation tracking with learning feedback
|
|
3
|
-
* 觀測儲存 — IoC 觀測追蹤與學習回饋
|
|
4
|
-
*
|
|
5
|
-
* When agents (Guard/Trap) report threats that match existing IoCs,
|
|
6
|
-
* sightings are created and feed back into the reputation engine.
|
|
7
|
-
* Positive sightings boost confidence; false positives flag for review.
|
|
8
|
-
*
|
|
9
|
-
* @module @panguard-ai/threat-cloud/sighting-store
|
|
10
|
-
*/
|
|
11
|
-
import type Database from 'better-sqlite3';
|
|
12
|
-
import type { SightingInput, SightingRecord, PaginationParams, PaginatedResponse } from './types.js';
|
|
13
|
-
export declare class SightingStore {
|
|
14
|
-
private readonly db;
|
|
15
|
-
constructor(db: Database.Database);
|
|
16
|
-
/**
|
|
17
|
-
* Record a new sighting for an IoC.
|
|
18
|
-
* Updates the IoC's confidence and status based on sighting type.
|
|
19
|
-
* 記錄新的觀測,根據觀測類型更新 IoC 信心度和狀態
|
|
20
|
-
*/
|
|
21
|
-
createSighting(input: SightingInput, actorHash?: string): SightingRecord;
|
|
22
|
-
/**
|
|
23
|
-
* Auto-create a positive sighting when agent data matches an existing IoC.
|
|
24
|
-
* Called from threat/trap-intel upload handlers.
|
|
25
|
-
* 當 Agent 資料匹配現有 IoC 時自動建立正面觀測
|
|
26
|
-
*/
|
|
27
|
-
recordAgentMatch(iocId: number, source: 'guard' | 'trap', actorHash?: string): SightingRecord;
|
|
28
|
-
/**
|
|
29
|
-
* Record cross-source correlation: same IoC seen by both Guard and Trap.
|
|
30
|
-
* Gives a larger confidence boost than single-source sightings.
|
|
31
|
-
* 跨來源關聯:同一 IoC 被 Guard 和 Trap 同時看到時,信心度提升更大
|
|
32
|
-
*/
|
|
33
|
-
recordCrossSourceMatch(iocId: number, actorHash?: string): SightingRecord | null;
|
|
34
|
-
/**
|
|
35
|
-
* Get sightings for an IoC / 取得 IoC 的觀測記錄
|
|
36
|
-
*/
|
|
37
|
-
getSightingsForIoC(iocId: number, pagination: PaginationParams): PaginatedResponse<SightingRecord>;
|
|
38
|
-
/**
|
|
39
|
-
* Get sighting summary for an IoC / 取得 IoC 的觀測摘要
|
|
40
|
-
*/
|
|
41
|
-
getSightingSummary(iocId: number): {
|
|
42
|
-
total: number;
|
|
43
|
-
positive: number;
|
|
44
|
-
negative: number;
|
|
45
|
-
falsePositive: number;
|
|
46
|
-
uniqueSources: number;
|
|
47
|
-
lastSeen: string | null;
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Get recent sighting count within time window / 取得時間窗口內的近期觀測數量
|
|
51
|
-
*/
|
|
52
|
-
getRecentSightingCount(iocId: number, windowHours?: number): number;
|
|
53
|
-
/** Get sighting by ID */
|
|
54
|
-
private getSightingById;
|
|
55
|
-
/**
|
|
56
|
-
* Apply sighting feedback to IoC confidence and status.
|
|
57
|
-
* 將觀測回饋套用到 IoC 的信心度和狀態
|
|
58
|
-
*/
|
|
59
|
-
private applyFeedback;
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=sighting-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sighting-store.d.ts","sourceRoot":"","sources":["../src/sighting-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EACV,aAAa,EACb,cAAc,EAEd,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,YAAY,CAAC;AAkCpB,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,EAAE;gBAAF,EAAE,EAAE,QAAQ,CAAC,QAAQ;IAElD;;;;OAIG;IACH,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,SAAS,SAAK,GAAG,cAAc;IAuBpE;;;;OAIG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,EAAE,SAAS,SAAK,GAAG,cAAc;IAazF;;;;OAIG;IACH,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,SAAK,GAAG,cAAc,GAAG,IAAI;IAuC5E;;OAEG;IACH,kBAAkB,CAChB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,gBAAgB,GAC3B,iBAAiB,CAAC,cAAc,CAAC;IA2BpC;;OAEG;IACH,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG;QACjC,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,QAAQ,EAAE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