@panguard-ai/panguard-guard 0.1.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/dist/agent/analyze-agent.d.ts +62 -0
- package/dist/agent/analyze-agent.d.ts.map +1 -0
- package/dist/agent/analyze-agent.js +327 -0
- package/dist/agent/analyze-agent.js.map +1 -0
- package/dist/agent/detect-agent.d.ts +59 -0
- package/dist/agent/detect-agent.d.ts.map +1 -0
- package/dist/agent/detect-agent.js +214 -0
- package/dist/agent/detect-agent.js.map +1 -0
- package/dist/agent/index.d.ts +15 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +14 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/report-agent.d.ts +122 -0
- package/dist/agent/report-agent.d.ts.map +1 -0
- package/dist/agent/report-agent.js +468 -0
- package/dist/agent/report-agent.js.map +1 -0
- package/dist/agent/respond-agent.d.ts +113 -0
- package/dist/agent/respond-agent.d.ts.map +1 -0
- package/dist/agent/respond-agent.js +749 -0
- package/dist/agent/respond-agent.js.map +1 -0
- package/dist/agent-client/index.d.ts +81 -0
- package/dist/agent-client/index.d.ts.map +1 -0
- package/dist/agent-client/index.js +170 -0
- package/dist/agent-client/index.js.map +1 -0
- package/dist/cli/index.d.ts +17 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +295 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/config.d.ts +23 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +108 -0
- package/dist/config.js.map +1 -0
- package/dist/daemon/index.d.ts +66 -0
- package/dist/daemon/index.d.ts.map +1 -0
- package/dist/daemon/index.js +284 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/dashboard/index.d.ts +78 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +455 -0
- package/dist/dashboard/index.js.map +1 -0
- package/dist/guard-engine.d.ts +108 -0
- package/dist/guard-engine.d.ts.map +1 -0
- package/dist/guard-engine.js +740 -0
- package/dist/guard-engine.js.map +1 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/install/index.d.ts +23 -0
- package/dist/install/index.d.ts.map +1 -0
- package/dist/install/index.js +216 -0
- package/dist/install/index.js.map +1 -0
- package/dist/investigation/index.d.ts +80 -0
- package/dist/investigation/index.d.ts.map +1 -0
- package/dist/investigation/index.js +570 -0
- package/dist/investigation/index.js.map +1 -0
- package/dist/license/index.d.ts +46 -0
- package/dist/license/index.d.ts.map +1 -0
- package/dist/license/index.js +145 -0
- package/dist/license/index.js.map +1 -0
- package/dist/memory/baseline.d.ts +34 -0
- package/dist/memory/baseline.d.ts.map +1 -0
- package/dist/memory/baseline.js +224 -0
- package/dist/memory/baseline.js.map +1 -0
- package/dist/memory/index.d.ts +32 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +58 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/memory/learning.d.ts +35 -0
- package/dist/memory/learning.d.ts.map +1 -0
- package/dist/memory/learning.js +60 -0
- package/dist/memory/learning.js.map +1 -0
- package/dist/monitors/falco-monitor.d.ts +62 -0
- package/dist/monitors/falco-monitor.d.ts.map +1 -0
- package/dist/monitors/falco-monitor.js +226 -0
- package/dist/monitors/falco-monitor.js.map +1 -0
- package/dist/monitors/suricata-monitor.d.ts +80 -0
- package/dist/monitors/suricata-monitor.d.ts.map +1 -0
- package/dist/monitors/suricata-monitor.js +227 -0
- package/dist/monitors/suricata-monitor.js.map +1 -0
- package/dist/notify/email.d.ts +23 -0
- package/dist/notify/email.d.ts.map +1 -0
- package/dist/notify/email.js +124 -0
- package/dist/notify/email.js.map +1 -0
- package/dist/notify/index.d.ts +31 -0
- package/dist/notify/index.d.ts.map +1 -0
- package/dist/notify/index.js +70 -0
- package/dist/notify/index.js.map +1 -0
- package/dist/notify/line-notify.d.ts.map +1 -0
- package/dist/notify/slack.d.ts +21 -0
- package/dist/notify/slack.d.ts.map +1 -0
- package/dist/notify/slack.js +92 -0
- package/dist/notify/slack.js.map +1 -0
- package/dist/notify/telegram.d.ts +21 -0
- package/dist/notify/telegram.d.ts.map +1 -0
- package/dist/notify/telegram.js +89 -0
- package/dist/notify/telegram.js.map +1 -0
- package/dist/response/file-quarantine.d.ts +63 -0
- package/dist/response/file-quarantine.d.ts.map +1 -0
- package/dist/response/file-quarantine.js +137 -0
- package/dist/response/file-quarantine.js.map +1 -0
- package/dist/response/index.d.ts +4 -0
- package/dist/response/index.d.ts.map +1 -0
- package/dist/response/index.js +4 -0
- package/dist/response/index.js.map +1 -0
- package/dist/response/ip-blocker.d.ts +69 -0
- package/dist/response/ip-blocker.d.ts.map +1 -0
- package/dist/response/ip-blocker.js +191 -0
- package/dist/response/ip-blocker.js.map +1 -0
- package/dist/response/process-killer.d.ts +49 -0
- package/dist/response/process-killer.d.ts.map +1 -0
- package/dist/response/process-killer.js +230 -0
- package/dist/response/process-killer.js.map +1 -0
- package/dist/rules/builtin-rules.d.ts +12 -0
- package/dist/rules/builtin-rules.d.ts.map +1 -0
- package/dist/rules/builtin-rules.js +471 -0
- package/dist/rules/builtin-rules.js.map +1 -0
- package/dist/threat-cloud/client-id.d.ts +13 -0
- package/dist/threat-cloud/client-id.d.ts.map +1 -0
- package/dist/threat-cloud/client-id.js +38 -0
- package/dist/threat-cloud/client-id.js.map +1 -0
- package/dist/threat-cloud/index.d.ts +103 -0
- package/dist/threat-cloud/index.d.ts.map +1 -0
- package/dist/threat-cloud/index.js +386 -0
- package/dist/threat-cloud/index.js.map +1 -0
- package/dist/types.d.ts +336 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +42 -0
- package/dist/types.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analyze Agent - Threat analysis with Dynamic Reasoning, Feedback Loop, and Attack Chain Awareness
|
|
3
|
+
* 分析代理 - 使用動態推理、回饋迴路和攻擊鏈感知進行威脅分析
|
|
4
|
+
*
|
|
5
|
+
* Second stage of the multi-agent pipeline. Receives DetectionResults,
|
|
6
|
+
* performs deep analysis using rule evidence, baseline comparison,
|
|
7
|
+
* attack chain correlation, feedback history, and optional AI reasoning,
|
|
8
|
+
* then produces a ThreatVerdict.
|
|
9
|
+
*
|
|
10
|
+
* @module @panguard-ai/panguard-guard/agent/analyze-agent
|
|
11
|
+
*/
|
|
12
|
+
import type { DetectionResult, ThreatVerdict, EnvironmentBaseline, AnalyzeLLM } from '../types.js';
|
|
13
|
+
/** Feedback record for false positive/negative tracking */
|
|
14
|
+
interface FeedbackRecord {
|
|
15
|
+
ruleId: string;
|
|
16
|
+
falsePositives: number;
|
|
17
|
+
truePositives: number;
|
|
18
|
+
lastUpdated: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Analyze Agent performs deep analysis on detected threats
|
|
22
|
+
* with feedback-driven confidence adjustment and attack chain awareness.
|
|
23
|
+
*/
|
|
24
|
+
export declare class AnalyzeAgent {
|
|
25
|
+
private readonly llm;
|
|
26
|
+
private analysisCount;
|
|
27
|
+
/** Feedback history: ruleId → FeedbackRecord */
|
|
28
|
+
private readonly feedbackHistory;
|
|
29
|
+
constructor(llm: AnalyzeLLM | null);
|
|
30
|
+
/**
|
|
31
|
+
* Analyze a detection result and produce a verdict
|
|
32
|
+
*
|
|
33
|
+
* Evidence collection pipeline:
|
|
34
|
+
* 1. Sigma rule match evidence (weighted 0.4) with feedback adjustment
|
|
35
|
+
* 2. Threat intelligence evidence
|
|
36
|
+
* 3. Baseline deviation check (weighted 0.3) with time-of-day awareness
|
|
37
|
+
* 4. Attack chain correlation boost
|
|
38
|
+
* 5. AI analysis if available (weighted 0.3)
|
|
39
|
+
* 6. Calculate final weighted confidence
|
|
40
|
+
* 7. Determine conclusion and recommended action
|
|
41
|
+
*/
|
|
42
|
+
analyze(detection: DetectionResult, baseline: EnvironmentBaseline): Promise<ThreatVerdict>;
|
|
43
|
+
/**
|
|
44
|
+
* Record user feedback: mark a verdict as false positive or true positive.
|
|
45
|
+
* This adjusts future confidence for the same rule.
|
|
46
|
+
*/
|
|
47
|
+
recordFeedback(ruleId: string, isFalsePositive: boolean): void;
|
|
48
|
+
/**
|
|
49
|
+
* Apply feedback adjustment to rule confidence.
|
|
50
|
+
* Rules with high false positive rate get reduced confidence.
|
|
51
|
+
* Rules with high true positive rate get boosted confidence.
|
|
52
|
+
*/
|
|
53
|
+
private applyFeedbackAdjustment;
|
|
54
|
+
/**
|
|
55
|
+
* Get feedback statistics
|
|
56
|
+
*/
|
|
57
|
+
getFeedbackStats(): Map<string, FeedbackRecord>;
|
|
58
|
+
/** Get total analysis count */
|
|
59
|
+
getAnalysisCount(): number;
|
|
60
|
+
}
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=analyze-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze-agent.d.ts","sourceRoot":"","sources":["../../src/agent/analyze-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EAGb,mBAAmB,EAEnB,UAAU,EAGX,MAAM,aAAa,CAAC;AAcrB,2DAA2D;AAC3D,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;CACrB;AAWD;;;GAGG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAoB;IACxC,OAAO,CAAC,aAAa,CAAK;IAE1B,gDAAgD;IAChD,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqC;gBAEzD,GAAG,EAAE,UAAU,GAAG,IAAI;IAIlC;;;;;;;;;;;OAWG;IACG,OAAO,CAAC,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,mBAAmB,GAAG,OAAO,CAAC,aAAa,CAAC;IAuJhG;;;OAGG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;IAsB9D;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAwB/B;;OAEG;IACH,gBAAgB,IAAI,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC;IAI/C,+BAA+B;IAC/B,gBAAgB,IAAI,MAAM;CAG3B"}
|
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analyze Agent - Threat analysis with Dynamic Reasoning, Feedback Loop, and Attack Chain Awareness
|
|
3
|
+
* 分析代理 - 使用動態推理、回饋迴路和攻擊鏈感知進行威脅分析
|
|
4
|
+
*
|
|
5
|
+
* Second stage of the multi-agent pipeline. Receives DetectionResults,
|
|
6
|
+
* performs deep analysis using rule evidence, baseline comparison,
|
|
7
|
+
* attack chain correlation, feedback history, and optional AI reasoning,
|
|
8
|
+
* then produces a ThreatVerdict.
|
|
9
|
+
*
|
|
10
|
+
* @module @panguard-ai/panguard-guard/agent/analyze-agent
|
|
11
|
+
*/
|
|
12
|
+
import { createLogger } from '@panguard-ai/core';
|
|
13
|
+
import { checkDeviation } from '../memory/baseline.js';
|
|
14
|
+
const logger = createLogger('panguard-guard:analyze-agent');
|
|
15
|
+
/** Severity to base confidence mapping */
|
|
16
|
+
const SEVERITY_CONFIDENCE = {
|
|
17
|
+
critical: 90,
|
|
18
|
+
high: 75,
|
|
19
|
+
medium: 55,
|
|
20
|
+
low: 35,
|
|
21
|
+
info: 15,
|
|
22
|
+
};
|
|
23
|
+
/** Time-of-day risk multiplier for unusual hours */
|
|
24
|
+
const UNUSUAL_HOUR_MULTIPLIER = 1.15;
|
|
25
|
+
/** Attack chain confidence boost per correlated event */
|
|
26
|
+
const ATTACK_CHAIN_BOOST_PER_EVENT = 5;
|
|
27
|
+
/** Max attack chain boost */
|
|
28
|
+
const ATTACK_CHAIN_BOOST_MAX = 25;
|
|
29
|
+
/**
|
|
30
|
+
* Analyze Agent performs deep analysis on detected threats
|
|
31
|
+
* with feedback-driven confidence adjustment and attack chain awareness.
|
|
32
|
+
*/
|
|
33
|
+
export class AnalyzeAgent {
|
|
34
|
+
llm;
|
|
35
|
+
analysisCount = 0;
|
|
36
|
+
/** Feedback history: ruleId → FeedbackRecord */
|
|
37
|
+
feedbackHistory = new Map();
|
|
38
|
+
constructor(llm) {
|
|
39
|
+
this.llm = llm;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Analyze a detection result and produce a verdict
|
|
43
|
+
*
|
|
44
|
+
* Evidence collection pipeline:
|
|
45
|
+
* 1. Sigma rule match evidence (weighted 0.4) with feedback adjustment
|
|
46
|
+
* 2. Threat intelligence evidence
|
|
47
|
+
* 3. Baseline deviation check (weighted 0.3) with time-of-day awareness
|
|
48
|
+
* 4. Attack chain correlation boost
|
|
49
|
+
* 5. AI analysis if available (weighted 0.3)
|
|
50
|
+
* 6. Calculate final weighted confidence
|
|
51
|
+
* 7. Determine conclusion and recommended action
|
|
52
|
+
*/
|
|
53
|
+
async analyze(detection, baseline) {
|
|
54
|
+
logger.info(`Analyzing detection for event ${detection.event.id}`);
|
|
55
|
+
this.analysisCount++;
|
|
56
|
+
const evidenceList = [];
|
|
57
|
+
// Step 1: Collect rule match evidence with feedback adjustment
|
|
58
|
+
for (const match of detection.ruleMatches) {
|
|
59
|
+
const baseConfidence = SEVERITY_CONFIDENCE[match.severity] ?? 50;
|
|
60
|
+
const adjustedConfidence = this.applyFeedbackAdjustment(match.ruleId, baseConfidence);
|
|
61
|
+
evidenceList.push({
|
|
62
|
+
source: 'rule_match',
|
|
63
|
+
description: `Sigma rule matched: ${match.ruleName} (${match.ruleId})`,
|
|
64
|
+
confidence: adjustedConfidence,
|
|
65
|
+
data: { ruleId: match.ruleId, severity: match.severity },
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
// Step 2: Collect threat intel evidence
|
|
69
|
+
if (detection.threatIntelMatch) {
|
|
70
|
+
evidenceList.push({
|
|
71
|
+
source: 'threat_intel',
|
|
72
|
+
description: `Known malicious IP: ${detection.threatIntelMatch.ip} - ` +
|
|
73
|
+
detection.threatIntelMatch.threat,
|
|
74
|
+
confidence: 85,
|
|
75
|
+
data: detection.threatIntelMatch,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
// Step 3: Baseline deviation check with time-of-day awareness
|
|
79
|
+
const deviation = checkDeviation(baseline, detection.event);
|
|
80
|
+
if (deviation.isDeviation) {
|
|
81
|
+
let deviationConfidence = deviation.confidence;
|
|
82
|
+
// Boost confidence if event occurs at unusual hour (00:00-05:59)
|
|
83
|
+
const eventHour = new Date(detection.event.timestamp).getHours();
|
|
84
|
+
if (eventHour >= 0 && eventHour < 6) {
|
|
85
|
+
deviationConfidence = Math.min(100, Math.round(deviationConfidence * UNUSUAL_HOUR_MULTIPLIER));
|
|
86
|
+
}
|
|
87
|
+
evidenceList.push({
|
|
88
|
+
source: 'baseline_deviation',
|
|
89
|
+
description: deviation.description,
|
|
90
|
+
confidence: deviationConfidence,
|
|
91
|
+
data: {
|
|
92
|
+
deviationType: deviation.deviationType,
|
|
93
|
+
...(eventHour >= 0 && eventHour < 6 ? { unusualHour: true, hour: eventHour } : {}),
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// Step 4: Attack chain correlation boost
|
|
98
|
+
if (detection.attackChain) {
|
|
99
|
+
const chainBoost = Math.min(ATTACK_CHAIN_BOOST_MAX, detection.attackChain.eventCount * ATTACK_CHAIN_BOOST_PER_EVENT);
|
|
100
|
+
evidenceList.push({
|
|
101
|
+
source: 'rule_match', // counts toward rule weight
|
|
102
|
+
description: `Attack chain detected: ${detection.attackChain.eventCount} correlated events ` +
|
|
103
|
+
`from ${detection.attackChain.sourceIP} within ${detection.attackChain.windowMs / 1000}s`,
|
|
104
|
+
confidence: Math.min(95, 70 + chainBoost),
|
|
105
|
+
data: {
|
|
106
|
+
attackChain: true,
|
|
107
|
+
eventCount: detection.attackChain.eventCount,
|
|
108
|
+
sourceIP: detection.attackChain.sourceIP,
|
|
109
|
+
uniqueRules: detection.attackChain.ruleIds.length,
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
// Step 5: AI analysis (if available)
|
|
114
|
+
let aiAnalysis = null;
|
|
115
|
+
let aiClassification = null;
|
|
116
|
+
if (this.llm) {
|
|
117
|
+
try {
|
|
118
|
+
const available = await this.llm.isAvailable();
|
|
119
|
+
if (available) {
|
|
120
|
+
const prompt = buildAnalysisPrompt(detection, deviation);
|
|
121
|
+
aiAnalysis = await this.llm.analyze(prompt);
|
|
122
|
+
aiClassification = await this.llm.classify(detection.event);
|
|
123
|
+
evidenceList.push({
|
|
124
|
+
source: 'ai_analysis',
|
|
125
|
+
description: aiAnalysis.summary,
|
|
126
|
+
confidence: Math.round(aiAnalysis.confidence * 100),
|
|
127
|
+
data: {
|
|
128
|
+
severity: aiAnalysis.severity,
|
|
129
|
+
recommendations: aiAnalysis.recommendations,
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
logger.info('AI unavailable, using rule-based analysis only');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
catch (err) {
|
|
138
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
139
|
+
logger.error(`AI analysis failed: ${msg}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Step 6: Calculate final confidence (weighted average)
|
|
143
|
+
const hasAI = this.llm !== null && aiAnalysis !== null;
|
|
144
|
+
let finalConfidence = calculateFinalConfidence(evidenceList, hasAI);
|
|
145
|
+
// Contradiction detection: if rule says high but baseline says normal, slight reduce
|
|
146
|
+
const hasHighRule = evidenceList.some((e) => e.source === 'rule_match' &&
|
|
147
|
+
e.confidence >= 70 &&
|
|
148
|
+
!e.data?.['attackChain']);
|
|
149
|
+
const noDeviation = !deviation.isDeviation;
|
|
150
|
+
if (hasHighRule && noDeviation && baseline.learningComplete) {
|
|
151
|
+
finalConfidence = Math.max(0, finalConfidence - 10);
|
|
152
|
+
logger.info(`Contradiction: high rule match but no baseline deviation. Confidence reduced by 10.`);
|
|
153
|
+
}
|
|
154
|
+
// Step 7: Determine conclusion and recommended action
|
|
155
|
+
const conclusion = determineConclusion(finalConfidence);
|
|
156
|
+
const recommendedAction = determineAction(finalConfidence, detection);
|
|
157
|
+
const verdict = {
|
|
158
|
+
conclusion,
|
|
159
|
+
confidence: finalConfidence,
|
|
160
|
+
reasoning: buildReasoning(evidenceList, deviation, aiAnalysis),
|
|
161
|
+
evidence: evidenceList,
|
|
162
|
+
recommendedAction,
|
|
163
|
+
mitreTechnique: aiClassification?.technique,
|
|
164
|
+
};
|
|
165
|
+
logger.info(`Verdict for event ${detection.event.id}: ${conclusion} (confidence: ${finalConfidence}%)`);
|
|
166
|
+
return verdict;
|
|
167
|
+
}
|
|
168
|
+
// ---------------------------------------------------------------------------
|
|
169
|
+
// Feedback Loop
|
|
170
|
+
// ---------------------------------------------------------------------------
|
|
171
|
+
/**
|
|
172
|
+
* Record user feedback: mark a verdict as false positive or true positive.
|
|
173
|
+
* This adjusts future confidence for the same rule.
|
|
174
|
+
*/
|
|
175
|
+
recordFeedback(ruleId, isFalsePositive) {
|
|
176
|
+
const existing = this.feedbackHistory.get(ruleId) ?? {
|
|
177
|
+
ruleId,
|
|
178
|
+
falsePositives: 0,
|
|
179
|
+
truePositives: 0,
|
|
180
|
+
lastUpdated: new Date().toISOString(),
|
|
181
|
+
};
|
|
182
|
+
if (isFalsePositive) {
|
|
183
|
+
existing.falsePositives += 1;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
existing.truePositives += 1;
|
|
187
|
+
}
|
|
188
|
+
existing.lastUpdated = new Date().toISOString();
|
|
189
|
+
this.feedbackHistory.set(ruleId, existing);
|
|
190
|
+
logger.info(`Feedback recorded for rule ${ruleId}: ` +
|
|
191
|
+
`FP=${existing.falsePositives}, TP=${existing.truePositives}`);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Apply feedback adjustment to rule confidence.
|
|
195
|
+
* Rules with high false positive rate get reduced confidence.
|
|
196
|
+
* Rules with high true positive rate get boosted confidence.
|
|
197
|
+
*/
|
|
198
|
+
applyFeedbackAdjustment(ruleId, baseConfidence) {
|
|
199
|
+
const feedback = this.feedbackHistory.get(ruleId);
|
|
200
|
+
if (!feedback)
|
|
201
|
+
return baseConfidence;
|
|
202
|
+
const total = feedback.falsePositives + feedback.truePositives;
|
|
203
|
+
if (total < 3)
|
|
204
|
+
return baseConfidence; // Not enough data
|
|
205
|
+
const fpRate = feedback.falsePositives / total;
|
|
206
|
+
// High FP rate → reduce confidence (max -30%)
|
|
207
|
+
// Low FP rate → boost confidence (max +10%)
|
|
208
|
+
if (fpRate > 0.5) {
|
|
209
|
+
const reduction = Math.min(30, Math.round(fpRate * 40));
|
|
210
|
+
return Math.max(10, baseConfidence - reduction);
|
|
211
|
+
}
|
|
212
|
+
if (fpRate < 0.1 && total >= 5) {
|
|
213
|
+
const boost = Math.min(10, Math.round((1 - fpRate) * 10));
|
|
214
|
+
return Math.min(100, baseConfidence + boost);
|
|
215
|
+
}
|
|
216
|
+
return baseConfidence;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get feedback statistics
|
|
220
|
+
*/
|
|
221
|
+
getFeedbackStats() {
|
|
222
|
+
return new Map(this.feedbackHistory);
|
|
223
|
+
}
|
|
224
|
+
/** Get total analysis count */
|
|
225
|
+
getAnalysisCount() {
|
|
226
|
+
return this.analysisCount;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// ---------------------------------------------------------------------------
|
|
230
|
+
// Internal scoring functions
|
|
231
|
+
// ---------------------------------------------------------------------------
|
|
232
|
+
function calculateFinalConfidence(evidence, hasAI) {
|
|
233
|
+
const bySource = groupBySource(evidence);
|
|
234
|
+
const ruleConfidence = maxConfidence(bySource['rule_match']);
|
|
235
|
+
const baselineConfidence = maxConfidence(bySource['baseline_deviation']);
|
|
236
|
+
const threatIntelConfidence = maxConfidence(bySource['threat_intel']);
|
|
237
|
+
const aiConfidence = maxConfidence(bySource['ai_analysis']);
|
|
238
|
+
const ebpfConfidence = Math.max(maxConfidence(bySource['falco']), maxConfidence(bySource['suricata']));
|
|
239
|
+
const ruleScore = Math.max(ruleConfidence, threatIntelConfidence);
|
|
240
|
+
const hasEbpf = ebpfConfidence > 0;
|
|
241
|
+
if (hasEbpf && hasAI) {
|
|
242
|
+
return Math.round(ebpfConfidence * 0.2 + ruleScore * 0.3 + baselineConfidence * 0.2 + aiConfidence * 0.3);
|
|
243
|
+
}
|
|
244
|
+
if (hasEbpf) {
|
|
245
|
+
return Math.round(ebpfConfidence * 0.25 + ruleScore * 0.4 + baselineConfidence * 0.35);
|
|
246
|
+
}
|
|
247
|
+
if (hasAI) {
|
|
248
|
+
return Math.round(ruleScore * 0.4 + baselineConfidence * 0.3 + aiConfidence * 0.3);
|
|
249
|
+
}
|
|
250
|
+
return Math.round(ruleScore * 0.6 + baselineConfidence * 0.4);
|
|
251
|
+
}
|
|
252
|
+
function groupBySource(evidence) {
|
|
253
|
+
const result = {};
|
|
254
|
+
for (const e of evidence) {
|
|
255
|
+
const key = e.source;
|
|
256
|
+
if (!result[key]) {
|
|
257
|
+
result[key] = [];
|
|
258
|
+
}
|
|
259
|
+
result[key].push(e);
|
|
260
|
+
}
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
function maxConfidence(items) {
|
|
264
|
+
if (!items || items.length === 0)
|
|
265
|
+
return 0;
|
|
266
|
+
return Math.max(...items.map((e) => e.confidence));
|
|
267
|
+
}
|
|
268
|
+
function determineConclusion(confidence) {
|
|
269
|
+
if (confidence >= 75)
|
|
270
|
+
return 'malicious';
|
|
271
|
+
if (confidence >= 40)
|
|
272
|
+
return 'suspicious';
|
|
273
|
+
return 'benign';
|
|
274
|
+
}
|
|
275
|
+
function determineAction(confidence, detection) {
|
|
276
|
+
const hasCritical = detection.ruleMatches.some((m) => m.severity === 'critical');
|
|
277
|
+
const hasAttackChain = !!detection.attackChain;
|
|
278
|
+
// Attack chains lower the auto-respond threshold
|
|
279
|
+
const autoThreshold = hasAttackChain ? 75 : 85;
|
|
280
|
+
if (confidence >= autoThreshold || (hasCritical && confidence >= 70)) {
|
|
281
|
+
if (detection.event.source === 'network' || detection.event.source === 'suricata')
|
|
282
|
+
return 'block_ip';
|
|
283
|
+
if (detection.event.source === 'process' || detection.event.source === 'falco')
|
|
284
|
+
return 'kill_process';
|
|
285
|
+
return 'notify';
|
|
286
|
+
}
|
|
287
|
+
if (confidence >= 50)
|
|
288
|
+
return 'notify';
|
|
289
|
+
return 'log_only';
|
|
290
|
+
}
|
|
291
|
+
function buildAnalysisPrompt(detection, deviation) {
|
|
292
|
+
const parts = [
|
|
293
|
+
'Security Event Analysis',
|
|
294
|
+
`Event: ${detection.event.description}`,
|
|
295
|
+
`Source: ${detection.event.source}`,
|
|
296
|
+
`Severity: ${detection.event.severity}`,
|
|
297
|
+
`Category: ${detection.event.category}`,
|
|
298
|
+
];
|
|
299
|
+
if (detection.ruleMatches.length > 0) {
|
|
300
|
+
parts.push(`Rule Matches: ${detection.ruleMatches.map((m) => m.ruleName).join(', ')}`);
|
|
301
|
+
}
|
|
302
|
+
if (detection.threatIntelMatch) {
|
|
303
|
+
parts.push(`Threat Intel: ${detection.threatIntelMatch.ip} - ${detection.threatIntelMatch.threat}`);
|
|
304
|
+
}
|
|
305
|
+
if (deviation.isDeviation) {
|
|
306
|
+
parts.push(`Baseline Deviation: ${deviation.description}`);
|
|
307
|
+
}
|
|
308
|
+
if (detection.attackChain) {
|
|
309
|
+
parts.push(`Attack Chain: ${detection.attackChain.eventCount} correlated events from ${detection.attackChain.sourceIP}`);
|
|
310
|
+
}
|
|
311
|
+
parts.push('Analyze the threat level and provide recommendations.');
|
|
312
|
+
return parts.join('\n');
|
|
313
|
+
}
|
|
314
|
+
function buildReasoning(evidence, _deviation, aiAnalysis) {
|
|
315
|
+
const parts = [];
|
|
316
|
+
for (const e of evidence) {
|
|
317
|
+
parts.push(`[${e.source}] ${e.description} (confidence: ${e.confidence}%)`);
|
|
318
|
+
}
|
|
319
|
+
if (aiAnalysis) {
|
|
320
|
+
parts.push(`AI Summary: ${aiAnalysis.summary}`);
|
|
321
|
+
if (aiAnalysis.recommendations.length > 0) {
|
|
322
|
+
parts.push(`Recommendations: ${aiAnalysis.recommendations.join('; ')}`);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return parts.join('\n');
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=analyze-agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analyze-agent.js","sourceRoot":"","sources":["../../src/agent/analyze-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAYjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,MAAM,GAAG,YAAY,CAAC,8BAA8B,CAAC,CAAC;AAE5D,0CAA0C;AAC1C,MAAM,mBAAmB,GAA2B;IAClD,QAAQ,EAAE,EAAE;IACZ,IAAI,EAAE,EAAE;IACR,MAAM,EAAE,EAAE;IACV,GAAG,EAAE,EAAE;IACP,IAAI,EAAE,EAAE;CACT,CAAC;AAUF,oDAAoD;AACpD,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAErC,yDAAyD;AACzD,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAEvC,6BAA6B;AAC7B,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAElC;;;GAGG;AACH,MAAM,OAAO,YAAY;IACN,GAAG,CAAoB;IAChC,aAAa,GAAG,CAAC,CAAC;IAE1B,gDAAgD;IAC/B,eAAe,GAAG,IAAI,GAAG,EAA0B,CAAC;IAErE,YAAY,GAA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,CAAC,CAAC;IAEpE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,SAAS,cAAc,CACrB,QAAoB,EACpB,UAA2B,EAC3B,UAAoC;IAEpC,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QACzB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,WAAW,iBAAiB,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC;IAC9E,CAAC;IAED,IAAI,UAAU,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,eAAe,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;QAChD,IAAI,UAAU,CAAC,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1C,KAAK,CAAC,IAAI,CAAC,oBAAoB,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1E,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Detect Agent - Event detection through rules, threat intelligence, and correlation
|
|
3
|
+
* 偵測代理 - 透過規則、威脅情報和事件關聯進行事件偵測
|
|
4
|
+
*
|
|
5
|
+
* First stage of the multi-agent pipeline. Receives raw SecurityEvents,
|
|
6
|
+
* runs them through the Sigma rule engine and threat intelligence feeds,
|
|
7
|
+
* correlates events within a sliding time window to detect attack chains,
|
|
8
|
+
* and emits DetectionResults for events that match.
|
|
9
|
+
*
|
|
10
|
+
* @module @panguard-ai/panguard-guard/agent/detect-agent
|
|
11
|
+
*/
|
|
12
|
+
import type { SecurityEvent, RuleEngine } from '@panguard-ai/core';
|
|
13
|
+
import type { DetectionResult } from '../types.js';
|
|
14
|
+
/**
|
|
15
|
+
* Detect Agent processes security events through rule matching,
|
|
16
|
+
* threat intelligence, event correlation, and deduplication.
|
|
17
|
+
*/
|
|
18
|
+
export declare class DetectAgent {
|
|
19
|
+
private readonly ruleEngine;
|
|
20
|
+
private detectionCount;
|
|
21
|
+
/** Sliding window for event correlation */
|
|
22
|
+
private readonly correlationBuffer;
|
|
23
|
+
/** Deduplication tracker: key → last detection timestamp */
|
|
24
|
+
private readonly dedupMap;
|
|
25
|
+
constructor(ruleEngine: RuleEngine);
|
|
26
|
+
/**
|
|
27
|
+
* Process a security event and detect threats
|
|
28
|
+
*
|
|
29
|
+
* Steps:
|
|
30
|
+
* 1. Match the event against loaded Sigma rules
|
|
31
|
+
* 2. Check threat intelligence for network events (IP lookup, IPv4 + IPv6)
|
|
32
|
+
* 3. Deduplicate: skip if same source+rule fired within dedup window
|
|
33
|
+
* 4. Correlate: check sliding window for attack chain patterns
|
|
34
|
+
* 5. If any matches found, return a DetectionResult; otherwise null
|
|
35
|
+
*/
|
|
36
|
+
detect(event: SecurityEvent): DetectionResult | null;
|
|
37
|
+
/**
|
|
38
|
+
* Extract IP address from event metadata (IPv4 + IPv6 support)
|
|
39
|
+
*/
|
|
40
|
+
private extractIP;
|
|
41
|
+
/** Build a dedup key from event source + matched rule IDs */
|
|
42
|
+
private buildDedupKey;
|
|
43
|
+
/** Check if this key was seen within the dedup window */
|
|
44
|
+
private isDuplicate;
|
|
45
|
+
/** Record a dedup entry and evict old entries if over limit */
|
|
46
|
+
private recordDedup;
|
|
47
|
+
/**
|
|
48
|
+
* Correlate events within a sliding time window.
|
|
49
|
+
* Returns attack chain metadata if multiple events from same source detected.
|
|
50
|
+
*/
|
|
51
|
+
private correlate;
|
|
52
|
+
/** Get total number of detections */
|
|
53
|
+
getDetectionCount(): number;
|
|
54
|
+
/** Get current correlation buffer size (for monitoring) */
|
|
55
|
+
getCorrelationBufferSize(): number;
|
|
56
|
+
/** Get current dedup map size (for monitoring) */
|
|
57
|
+
getDedupMapSize(): number;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=detect-agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detect-agent.d.ts","sourceRoot":"","sources":["../../src/agent/detect-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAa,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAkCnD;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,cAAc,CAAK;IAE3B,2CAA2C;IAC3C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAyB;IAE3D,4DAA4D;IAC5D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;gBAE1C,UAAU,EAAE,UAAU;IAIlC;;;;;;;;;OASG;IACH,MAAM,CAAC,KAAK,EAAE,aAAa,GAAG,eAAe,GAAG,IAAI;IA4DpD;;OAEG;IACH,OAAO,CAAC,SAAS;IA4BjB,6DAA6D;IAC7D,OAAO,CAAC,aAAa;IASrB,yDAAyD;IACzD,OAAO,CAAC,WAAW;IAMnB,+DAA+D;IAC/D,OAAO,CAAC,WAAW;IAkBnB;;;OAGG;IACH,OAAO,CAAC,SAAS;IA6DjB,qCAAqC;IACrC,iBAAiB,IAAI,MAAM;IAI3B,2DAA2D;IAC3D,wBAAwB,IAAI,MAAM;IAIlC,kDAAkD;IAClD,eAAe,IAAI,MAAM;CAG1B"}
|