@panguard-ai/panguard-trap 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/cli/index.d.ts +45 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +298 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/intel/index.d.ts +38 -0
- package/dist/intel/index.d.ts.map +1 -0
- package/dist/intel/index.js +157 -0
- package/dist/intel/index.js.map +1 -0
- package/dist/profiler/attacker-profiler.d.ts +68 -0
- package/dist/profiler/attacker-profiler.d.ts.map +1 -0
- package/dist/profiler/attacker-profiler.js +316 -0
- package/dist/profiler/attacker-profiler.js.map +1 -0
- package/dist/profiler/index.d.ts +8 -0
- package/dist/profiler/index.d.ts.map +1 -0
- package/dist/profiler/index.js +8 -0
- package/dist/profiler/index.js.map +1 -0
- package/dist/services/base-service.d.ts +61 -0
- package/dist/services/base-service.d.ts.map +1 -0
- package/dist/services/base-service.js +190 -0
- package/dist/services/base-service.js.map +1 -0
- package/dist/services/generic-trap.d.ts +22 -0
- package/dist/services/generic-trap.d.ts.map +1 -0
- package/dist/services/generic-trap.js +439 -0
- package/dist/services/generic-trap.js.map +1 -0
- package/dist/services/http-trap.d.ts +36 -0
- package/dist/services/http-trap.d.ts.map +1 -0
- package/dist/services/http-trap.js +218 -0
- package/dist/services/http-trap.js.map +1 -0
- package/dist/services/index.d.ts +26 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +52 -0
- package/dist/services/index.js.map +1 -0
- package/dist/services/mysql-trap.d.ts +22 -0
- package/dist/services/mysql-trap.d.ts.map +1 -0
- package/dist/services/mysql-trap.js +374 -0
- package/dist/services/mysql-trap.js.map +1 -0
- package/dist/services/rdp-trap.d.ts +21 -0
- package/dist/services/rdp-trap.d.ts.map +1 -0
- package/dist/services/rdp-trap.js +299 -0
- package/dist/services/rdp-trap.js.map +1 -0
- package/dist/services/redis-trap.d.ts +21 -0
- package/dist/services/redis-trap.d.ts.map +1 -0
- package/dist/services/redis-trap.js +321 -0
- package/dist/services/redis-trap.js.map +1 -0
- package/dist/services/smb-trap.d.ts +21 -0
- package/dist/services/smb-trap.d.ts.map +1 -0
- package/dist/services/smb-trap.js +358 -0
- package/dist/services/smb-trap.js.map +1 -0
- package/dist/services/ssh-trap.d.ts +43 -0
- package/dist/services/ssh-trap.d.ts.map +1 -0
- package/dist/services/ssh-trap.js +397 -0
- package/dist/services/ssh-trap.js.map +1 -0
- package/dist/threat-cloud-uploader.d.ts +48 -0
- package/dist/threat-cloud-uploader.d.ts.map +1 -0
- package/dist/threat-cloud-uploader.js +125 -0
- package/dist/threat-cloud-uploader.js.map +1 -0
- package/dist/trap-engine.d.ts +80 -0
- package/dist/trap-engine.d.ts.map +1 -0
- package/dist/trap-engine.js +279 -0
- package/dist/trap-engine.js.map +1 -0
- package/dist/types.d.ts +229 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +89 -0
- package/dist/types.js.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attacker Profiling Engine
|
|
3
|
+
* 攻擊者分析引擎
|
|
4
|
+
*
|
|
5
|
+
* Analyzes trap sessions to build attacker profiles:
|
|
6
|
+
* - Skill level estimation
|
|
7
|
+
* - Intent classification
|
|
8
|
+
* - Tool detection
|
|
9
|
+
* - Credential pattern analysis
|
|
10
|
+
* - MITRE ATT&CK technique mapping
|
|
11
|
+
*
|
|
12
|
+
* 分析蜜罐連線以建立攻擊者 profile:
|
|
13
|
+
* - 技術水準估計
|
|
14
|
+
* - 意圖分類
|
|
15
|
+
* - 工具偵測
|
|
16
|
+
* - 認證模式分析
|
|
17
|
+
* - MITRE ATT&CK 技術映射
|
|
18
|
+
*
|
|
19
|
+
* @module @panguard-ai/panguard-trap/profiler/attacker-profiler
|
|
20
|
+
*/
|
|
21
|
+
import type { TrapSession, AttackerProfile, AttackerSkillLevel, AttackerIntent } from '../types.js';
|
|
22
|
+
/**
|
|
23
|
+
* Estimate attacker skill level based on behavior
|
|
24
|
+
* 根據行為估計攻擊者技術水準
|
|
25
|
+
*/
|
|
26
|
+
export declare function estimateSkillLevel(commands: string[], mitreTechniques: string[], toolsDetected: string[]): {
|
|
27
|
+
level: AttackerSkillLevel;
|
|
28
|
+
score: number;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Classify attacker intent based on behavior
|
|
32
|
+
* 根據行為分類攻擊者意圖
|
|
33
|
+
*/
|
|
34
|
+
export declare function classifyIntent(commands: string[], mitreTechniques: string[]): AttackerIntent;
|
|
35
|
+
/**
|
|
36
|
+
* Detect tools used by attacker
|
|
37
|
+
* 偵測攻擊者使用的工具
|
|
38
|
+
*/
|
|
39
|
+
export declare function detectTools(commands: string[], userAgents?: string[]): string[];
|
|
40
|
+
/**
|
|
41
|
+
* AttackerProfiler - builds and maintains attacker profiles
|
|
42
|
+
* AttackerProfiler - 建立和維護攻擊者 profile
|
|
43
|
+
*/
|
|
44
|
+
export declare class AttackerProfiler {
|
|
45
|
+
private profiles;
|
|
46
|
+
private ipToProfile;
|
|
47
|
+
private profileCounter;
|
|
48
|
+
/**
|
|
49
|
+
* Process a completed trap session and update/create attacker profile
|
|
50
|
+
* 處理已完成的蜜罐連線並更新/建立攻擊者 profile
|
|
51
|
+
*/
|
|
52
|
+
processSession(session: TrapSession): AttackerProfile;
|
|
53
|
+
/** Get a profile by ID / 依 ID 取得 profile */
|
|
54
|
+
getProfile(profileId: string): AttackerProfile | undefined;
|
|
55
|
+
/** Get profile by IP / 依 IP 取得 profile */
|
|
56
|
+
getProfileByIP(ip: string): AttackerProfile | undefined;
|
|
57
|
+
/** Get all profiles / 取得所有 profiles */
|
|
58
|
+
getAllProfiles(): AttackerProfile[];
|
|
59
|
+
/** Get top attackers by risk score / 依風險分數取得前幾名攻擊者 */
|
|
60
|
+
getTopAttackers(limit?: number): AttackerProfile[];
|
|
61
|
+
/** Get profile count / 取得 profile 數量 */
|
|
62
|
+
getProfileCount(): number;
|
|
63
|
+
/** Clear all profiles / 清除所有 profiles */
|
|
64
|
+
clear(): void;
|
|
65
|
+
private createProfile;
|
|
66
|
+
private updateProfile;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=attacker-profiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attacker-profiler.d.ts","sourceRoot":"","sources":["../../src/profiler/attacker-profiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA2CpG;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAAE,EAClB,eAAe,EAAE,MAAM,EAAE,EACzB,aAAa,EAAE,MAAM,EAAE,GACtB;IAAE,KAAK,EAAE,kBAAkB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAoC9C;AAkCD;;;GAGG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,cAAc,CA2C5F;AAOD;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAc/E;AAOD;;;GAGG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAA2C;IAC3D,OAAO,CAAC,WAAW,CAAkC;IACrD,OAAO,CAAC,cAAc,CAAK;IAE3B;;;OAGG;IACH,cAAc,CAAC,OAAO,EAAE,WAAW,GAAG,eAAe;IAsBrD,4CAA4C;IAC5C,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAI1D,0CAA0C;IAC1C,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAKvD,uCAAuC;IACvC,cAAc,IAAI,eAAe,EAAE;IAInC,sDAAsD;IACtD,eAAe,CAAC,KAAK,SAAK,GAAG,eAAe,EAAE;IAM9C,wCAAwC;IACxC,eAAe,IAAI,MAAM;IAIzB,yCAAyC;IACzC,KAAK,IAAI,IAAI;IASb,OAAO,CAAC,aAAa;IA4BrB,OAAO,CAAC,aAAa;CA6CtB"}
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Attacker Profiling Engine
|
|
3
|
+
* 攻擊者分析引擎
|
|
4
|
+
*
|
|
5
|
+
* Analyzes trap sessions to build attacker profiles:
|
|
6
|
+
* - Skill level estimation
|
|
7
|
+
* - Intent classification
|
|
8
|
+
* - Tool detection
|
|
9
|
+
* - Credential pattern analysis
|
|
10
|
+
* - MITRE ATT&CK technique mapping
|
|
11
|
+
*
|
|
12
|
+
* 分析蜜罐連線以建立攻擊者 profile:
|
|
13
|
+
* - 技術水準估計
|
|
14
|
+
* - 意圖分類
|
|
15
|
+
* - 工具偵測
|
|
16
|
+
* - 認證模式分析
|
|
17
|
+
* - MITRE ATT&CK 技術映射
|
|
18
|
+
*
|
|
19
|
+
* @module @panguard-ai/panguard-trap/profiler/attacker-profiler
|
|
20
|
+
*/
|
|
21
|
+
import { createLogger } from '@panguard-ai/core';
|
|
22
|
+
const logger = createLogger('panguard-trap:profiler');
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
// Skill Level Estimation
|
|
25
|
+
// 技術水準估計
|
|
26
|
+
// ---------------------------------------------------------------------------
|
|
27
|
+
/** Known tool signatures / 已知工具特徵 */
|
|
28
|
+
const TOOL_SIGNATURES = [
|
|
29
|
+
{ pattern: /nmap/i, tool: 'nmap', skillBoost: 10 },
|
|
30
|
+
{ pattern: /metasploit|msfconsole|meterpreter/i, tool: 'Metasploit', skillBoost: 20 },
|
|
31
|
+
{ pattern: /hydra/i, tool: 'Hydra', skillBoost: 15 },
|
|
32
|
+
{ pattern: /sqlmap/i, tool: 'sqlmap', skillBoost: 15 },
|
|
33
|
+
{ pattern: /nikto/i, tool: 'Nikto', skillBoost: 10 },
|
|
34
|
+
{ pattern: /gobuster|dirbuster|dirb/i, tool: 'Directory Buster', skillBoost: 10 },
|
|
35
|
+
{ pattern: /burp/i, tool: 'Burp Suite', skillBoost: 20 },
|
|
36
|
+
{ pattern: /cobalt\s*strike|beacon/i, tool: 'Cobalt Strike', skillBoost: 40 },
|
|
37
|
+
{ pattern: /mimikatz/i, tool: 'Mimikatz', skillBoost: 30 },
|
|
38
|
+
{ pattern: /bloodhound/i, tool: 'BloodHound', skillBoost: 30 },
|
|
39
|
+
{ pattern: /empire|stager/i, tool: 'Empire', skillBoost: 25 },
|
|
40
|
+
{ pattern: /xmrig|minergate|cryptonight/i, tool: 'Cryptominer', skillBoost: 5 },
|
|
41
|
+
{ pattern: /masscan/i, tool: 'Masscan', skillBoost: 10 },
|
|
42
|
+
{ pattern: /wpscan/i, tool: 'WPScan', skillBoost: 10 },
|
|
43
|
+
];
|
|
44
|
+
/** Advanced command patterns that indicate higher skill / 表示較高技術的進階指令模式 */
|
|
45
|
+
const ADVANCED_PATTERNS = [
|
|
46
|
+
/base64\s+-d/i,
|
|
47
|
+
/python\s+-c/i,
|
|
48
|
+
/perl\s+-e/i,
|
|
49
|
+
/awk\s+'{/i,
|
|
50
|
+
/sed\s+-[ie]/i,
|
|
51
|
+
/\/proc\/self/i,
|
|
52
|
+
/ld_preload/i,
|
|
53
|
+
/ptrace/i,
|
|
54
|
+
/ebpf|bpf/i,
|
|
55
|
+
/\.\.\/\.\.\/\.\.\/etc/i,
|
|
56
|
+
/reverse.*shell/i,
|
|
57
|
+
/bind.*shell/i,
|
|
58
|
+
];
|
|
59
|
+
/**
|
|
60
|
+
* Estimate attacker skill level based on behavior
|
|
61
|
+
* 根據行為估計攻擊者技術水準
|
|
62
|
+
*/
|
|
63
|
+
export function estimateSkillLevel(commands, mitreTechniques, toolsDetected) {
|
|
64
|
+
let score = 0;
|
|
65
|
+
// Base score from technique count
|
|
66
|
+
score += mitreTechniques.length * 5;
|
|
67
|
+
// Tool-based scoring
|
|
68
|
+
score += toolsDetected.length * 8;
|
|
69
|
+
// Advanced command patterns
|
|
70
|
+
for (const cmd of commands) {
|
|
71
|
+
for (const pattern of ADVANCED_PATTERNS) {
|
|
72
|
+
if (pattern.test(cmd)) {
|
|
73
|
+
score += 10;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Command diversity
|
|
79
|
+
const uniqueCommands = new Set(commands.map((c) => c.split(' ')[0]?.toLowerCase()));
|
|
80
|
+
if (uniqueCommands.size > 10)
|
|
81
|
+
score += 15;
|
|
82
|
+
else if (uniqueCommands.size > 5)
|
|
83
|
+
score += 8;
|
|
84
|
+
// MITRE technique diversity
|
|
85
|
+
if (mitreTechniques.length > 5)
|
|
86
|
+
score += 20;
|
|
87
|
+
else if (mitreTechniques.length > 3)
|
|
88
|
+
score += 10;
|
|
89
|
+
// Classify
|
|
90
|
+
let level;
|
|
91
|
+
if (score >= 60)
|
|
92
|
+
level = 'apt';
|
|
93
|
+
else if (score >= 35)
|
|
94
|
+
level = 'advanced';
|
|
95
|
+
else if (score >= 15)
|
|
96
|
+
level = 'intermediate';
|
|
97
|
+
else
|
|
98
|
+
level = 'script_kiddie';
|
|
99
|
+
return { level, score: Math.min(score, 100) };
|
|
100
|
+
}
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// Intent Classification
|
|
103
|
+
// 意圖分類
|
|
104
|
+
// ---------------------------------------------------------------------------
|
|
105
|
+
/** Intent indicators / 意圖指標 */
|
|
106
|
+
const INTENT_INDICATORS = [
|
|
107
|
+
{
|
|
108
|
+
pattern: /whoami|id\s|uname|hostname|ifconfig|ip\s+addr|cat\s+\/etc\/passwd/i,
|
|
109
|
+
intent: 'reconnaissance',
|
|
110
|
+
weight: 3,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
pattern: /shadow|passwd|credential|hash|dump|mimikatz/i,
|
|
114
|
+
intent: 'credential_harvesting',
|
|
115
|
+
weight: 5,
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
pattern: /encrypt|ransom|lockbit|cryptolocker|\.locked|\.crypt/i,
|
|
119
|
+
intent: 'ransomware_deployment',
|
|
120
|
+
weight: 8,
|
|
121
|
+
},
|
|
122
|
+
{ pattern: /xmrig|miner|cryptonight|stratum|pool\./i, intent: 'cryptomining', weight: 8 },
|
|
123
|
+
{
|
|
124
|
+
pattern: /tar\s+.*\.gz|zip\s+|scp\s+|rsync|curl.*upload|wget.*post/i,
|
|
125
|
+
intent: 'data_theft',
|
|
126
|
+
weight: 5,
|
|
127
|
+
},
|
|
128
|
+
{ pattern: /irc\s|c2\s|beacon|callback|botnet|zombie/i, intent: 'botnet_recruitment', weight: 6 },
|
|
129
|
+
{ pattern: /ssh\s+\w+@|psexec|wmic|net\s+use|smbclient/i, intent: 'lateral_movement', weight: 5 },
|
|
130
|
+
];
|
|
131
|
+
/**
|
|
132
|
+
* Classify attacker intent based on behavior
|
|
133
|
+
* 根據行為分類攻擊者意圖
|
|
134
|
+
*/
|
|
135
|
+
export function classifyIntent(commands, mitreTechniques) {
|
|
136
|
+
const scores = {};
|
|
137
|
+
for (const cmd of commands) {
|
|
138
|
+
for (const indicator of INTENT_INDICATORS) {
|
|
139
|
+
if (indicator.pattern.test(cmd)) {
|
|
140
|
+
scores[indicator.intent] = (scores[indicator.intent] ?? 0) + indicator.weight;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const techniqueToIntent = {
|
|
145
|
+
T1082: 'reconnaissance',
|
|
146
|
+
T1016: 'reconnaissance',
|
|
147
|
+
T1057: 'reconnaissance',
|
|
148
|
+
T1003: 'credential_harvesting',
|
|
149
|
+
T1110: 'credential_harvesting',
|
|
150
|
+
T1486: 'ransomware_deployment',
|
|
151
|
+
T1496: 'cryptomining',
|
|
152
|
+
T1005: 'data_theft',
|
|
153
|
+
T1041: 'data_theft',
|
|
154
|
+
T1021: 'lateral_movement',
|
|
155
|
+
T1570: 'lateral_movement',
|
|
156
|
+
};
|
|
157
|
+
for (const tech of mitreTechniques) {
|
|
158
|
+
const intent = techniqueToIntent[tech];
|
|
159
|
+
if (intent) {
|
|
160
|
+
scores[intent] = (scores[intent] ?? 0) + 3;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
let maxScore = 0;
|
|
164
|
+
let maxIntent = 'unknown';
|
|
165
|
+
for (const [intent, score] of Object.entries(scores)) {
|
|
166
|
+
if (score > maxScore) {
|
|
167
|
+
maxScore = score;
|
|
168
|
+
maxIntent = intent;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return maxIntent;
|
|
172
|
+
}
|
|
173
|
+
// ---------------------------------------------------------------------------
|
|
174
|
+
// Tool Detection
|
|
175
|
+
// 工具偵測
|
|
176
|
+
// ---------------------------------------------------------------------------
|
|
177
|
+
/**
|
|
178
|
+
* Detect tools used by attacker
|
|
179
|
+
* 偵測攻擊者使用的工具
|
|
180
|
+
*/
|
|
181
|
+
export function detectTools(commands, userAgents) {
|
|
182
|
+
const tools = new Set();
|
|
183
|
+
const allInputs = [...commands, ...(userAgents ?? [])];
|
|
184
|
+
for (const input of allInputs) {
|
|
185
|
+
for (const sig of TOOL_SIGNATURES) {
|
|
186
|
+
if (sig.pattern.test(input)) {
|
|
187
|
+
tools.add(sig.tool);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return Array.from(tools);
|
|
192
|
+
}
|
|
193
|
+
// ---------------------------------------------------------------------------
|
|
194
|
+
// Attacker Profiler
|
|
195
|
+
// 攻擊者分析器
|
|
196
|
+
// ---------------------------------------------------------------------------
|
|
197
|
+
/**
|
|
198
|
+
* AttackerProfiler - builds and maintains attacker profiles
|
|
199
|
+
* AttackerProfiler - 建立和維護攻擊者 profile
|
|
200
|
+
*/
|
|
201
|
+
export class AttackerProfiler {
|
|
202
|
+
profiles = new Map();
|
|
203
|
+
ipToProfile = new Map();
|
|
204
|
+
profileCounter = 0;
|
|
205
|
+
/**
|
|
206
|
+
* Process a completed trap session and update/create attacker profile
|
|
207
|
+
* 處理已完成的蜜罐連線並更新/建立攻擊者 profile
|
|
208
|
+
*/
|
|
209
|
+
processSession(session) {
|
|
210
|
+
const existingProfileId = this.ipToProfile.get(session.sourceIP);
|
|
211
|
+
let profile;
|
|
212
|
+
if (existingProfileId) {
|
|
213
|
+
profile = this.profiles.get(existingProfileId);
|
|
214
|
+
this.updateProfile(profile, session);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
profile = this.createProfile(session);
|
|
218
|
+
this.profiles.set(profile.profileId, profile);
|
|
219
|
+
this.ipToProfile.set(session.sourceIP, profile.profileId);
|
|
220
|
+
}
|
|
221
|
+
session.attackerProfileId = profile.profileId;
|
|
222
|
+
logger.info(`Attacker profile updated: ${profile.profileId} (skill=${profile.skillLevel}, intent=${profile.intent}) / 攻擊者 profile 已更新`);
|
|
223
|
+
return profile;
|
|
224
|
+
}
|
|
225
|
+
/** Get a profile by ID / 依 ID 取得 profile */
|
|
226
|
+
getProfile(profileId) {
|
|
227
|
+
return this.profiles.get(profileId);
|
|
228
|
+
}
|
|
229
|
+
/** Get profile by IP / 依 IP 取得 profile */
|
|
230
|
+
getProfileByIP(ip) {
|
|
231
|
+
const profileId = this.ipToProfile.get(ip);
|
|
232
|
+
return profileId ? this.profiles.get(profileId) : undefined;
|
|
233
|
+
}
|
|
234
|
+
/** Get all profiles / 取得所有 profiles */
|
|
235
|
+
getAllProfiles() {
|
|
236
|
+
return Array.from(this.profiles.values());
|
|
237
|
+
}
|
|
238
|
+
/** Get top attackers by risk score / 依風險分數取得前幾名攻擊者 */
|
|
239
|
+
getTopAttackers(limit = 10) {
|
|
240
|
+
return this.getAllProfiles()
|
|
241
|
+
.sort((a, b) => b.riskScore - a.riskScore)
|
|
242
|
+
.slice(0, limit);
|
|
243
|
+
}
|
|
244
|
+
/** Get profile count / 取得 profile 數量 */
|
|
245
|
+
getProfileCount() {
|
|
246
|
+
return this.profiles.size;
|
|
247
|
+
}
|
|
248
|
+
/** Clear all profiles / 清除所有 profiles */
|
|
249
|
+
clear() {
|
|
250
|
+
this.profiles.clear();
|
|
251
|
+
this.ipToProfile.clear();
|
|
252
|
+
}
|
|
253
|
+
// -------------------------------------------------------------------------
|
|
254
|
+
// Internal
|
|
255
|
+
// -------------------------------------------------------------------------
|
|
256
|
+
createProfile(session) {
|
|
257
|
+
this.profileCounter += 1;
|
|
258
|
+
const profileId = `atk-${Date.now().toString(36)}-${this.profileCounter.toString(36).padStart(3, '0')}`;
|
|
259
|
+
const tools = detectTools(session.commands);
|
|
260
|
+
const { level, score } = estimateSkillLevel(session.commands, session.mitreTechniques, tools);
|
|
261
|
+
const intent = classifyIntent(session.commands, session.mitreTechniques);
|
|
262
|
+
return {
|
|
263
|
+
profileId,
|
|
264
|
+
sourceIPs: [session.sourceIP],
|
|
265
|
+
firstSeen: session.startTime,
|
|
266
|
+
lastSeen: session.endTime ?? session.startTime,
|
|
267
|
+
totalSessions: 1,
|
|
268
|
+
skillLevel: level,
|
|
269
|
+
intent,
|
|
270
|
+
toolsDetected: tools,
|
|
271
|
+
mitreTechniques: [...session.mitreTechniques],
|
|
272
|
+
credentialPatterns: {
|
|
273
|
+
commonUsernames: session.credentials.map((c) => c.username).filter(Boolean),
|
|
274
|
+
commonPasswords: session.credentials.map((c) => c.password).filter(Boolean),
|
|
275
|
+
totalAttempts: session.credentials.length,
|
|
276
|
+
},
|
|
277
|
+
geoHints: {},
|
|
278
|
+
riskScore: score,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
updateProfile(profile, session) {
|
|
282
|
+
if (!profile.sourceIPs.includes(session.sourceIP)) {
|
|
283
|
+
profile.sourceIPs.push(session.sourceIP);
|
|
284
|
+
}
|
|
285
|
+
profile.lastSeen = session.endTime ?? session.startTime;
|
|
286
|
+
profile.totalSessions += 1;
|
|
287
|
+
for (const tech of session.mitreTechniques) {
|
|
288
|
+
if (!profile.mitreTechniques.includes(tech)) {
|
|
289
|
+
profile.mitreTechniques.push(tech);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
const newTools = detectTools(session.commands);
|
|
293
|
+
for (const tool of newTools) {
|
|
294
|
+
if (!profile.toolsDetected.includes(tool)) {
|
|
295
|
+
profile.toolsDetected.push(tool);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
for (const cred of session.credentials) {
|
|
299
|
+
if (cred.username && !profile.credentialPatterns.commonUsernames.includes(cred.username)) {
|
|
300
|
+
profile.credentialPatterns.commonUsernames.push(cred.username);
|
|
301
|
+
}
|
|
302
|
+
if (cred.password && !profile.credentialPatterns.commonPasswords.includes(cred.password)) {
|
|
303
|
+
profile.credentialPatterns.commonPasswords.push(cred.password);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
profile.credentialPatterns.totalAttempts += session.credentials.length;
|
|
307
|
+
const { level, score } = estimateSkillLevel(session.commands, profile.mitreTechniques, profile.toolsDetected);
|
|
308
|
+
const SKILL_ORDER = ['script_kiddie', 'intermediate', 'advanced', 'apt'];
|
|
309
|
+
if (SKILL_ORDER.indexOf(level) > SKILL_ORDER.indexOf(profile.skillLevel)) {
|
|
310
|
+
profile.skillLevel = level;
|
|
311
|
+
}
|
|
312
|
+
profile.riskScore = Math.max(profile.riskScore, score);
|
|
313
|
+
profile.intent = classifyIntent(session.commands, profile.mitreTechniques);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=attacker-profiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attacker-profiler.js","sourceRoot":"","sources":["../../src/profiler/attacker-profiler.ts"],"names":[],"mappings":"A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,QAAQ,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7E,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/profiler/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,WAAW,GACZ,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/profiler/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,WAAW,GACZ,MAAM,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base trap service implementation
|
|
3
|
+
* 蜜罐基底服務實作
|
|
4
|
+
*
|
|
5
|
+
* Provides common functionality for all trap services:
|
|
6
|
+
* - TCP server lifecycle
|
|
7
|
+
* - Session management
|
|
8
|
+
* - Event recording
|
|
9
|
+
* 提供所有蜜罐服務的共用功能:
|
|
10
|
+
* - TCP 伺服器生命週期
|
|
11
|
+
* - 連線管理
|
|
12
|
+
* - 事件記錄
|
|
13
|
+
*
|
|
14
|
+
* @module @panguard-ai/panguard-trap/services/base-service
|
|
15
|
+
*/
|
|
16
|
+
import type { TrapServiceType, TrapServiceStatus, TrapServiceConfig, TrapSession, TrapEvent, TrapEventType, TrapService, SessionHandler } from '../types.js';
|
|
17
|
+
/**
|
|
18
|
+
* Abstract base class for all trap services
|
|
19
|
+
* 所有蜜罐服務的抽象基底類別
|
|
20
|
+
*/
|
|
21
|
+
export declare abstract class BaseTrapService implements TrapService {
|
|
22
|
+
readonly serviceType: TrapServiceType;
|
|
23
|
+
private _status;
|
|
24
|
+
protected readonly config: TrapServiceConfig;
|
|
25
|
+
protected activeSessions: Map<string, TrapSession>;
|
|
26
|
+
protected completedSessionCount: number;
|
|
27
|
+
private sessionHandlers;
|
|
28
|
+
constructor(config: TrapServiceConfig);
|
|
29
|
+
get status(): TrapServiceStatus;
|
|
30
|
+
protected setStatus(status: TrapServiceStatus): void;
|
|
31
|
+
/**
|
|
32
|
+
* Start the service
|
|
33
|
+
* 啟動服務
|
|
34
|
+
*/
|
|
35
|
+
start(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Stop the service
|
|
38
|
+
* 停止服務
|
|
39
|
+
*/
|
|
40
|
+
stop(): Promise<void>;
|
|
41
|
+
getActiveSessions(): TrapSession[];
|
|
42
|
+
getTotalSessionCount(): number;
|
|
43
|
+
onSession(handler: SessionHandler): void;
|
|
44
|
+
/** Create a new session / 建立新連線 */
|
|
45
|
+
protected createSession(sourceIP: string, sourcePort: number): TrapSession;
|
|
46
|
+
/** End a session / 結束連線 */
|
|
47
|
+
protected endSession(sessionId: string, session?: TrapSession): TrapSession | undefined;
|
|
48
|
+
/** Record an event in a session / 在連線中記錄事件 */
|
|
49
|
+
protected recordEvent(sessionId: string, type: TrapEventType, data: string, details?: Record<string, unknown>): TrapEvent | undefined;
|
|
50
|
+
/** Record a credential attempt / 記錄認證嘗試 */
|
|
51
|
+
protected recordCredential(sessionId: string, username: string, password: string, grantedAccess: boolean): void;
|
|
52
|
+
/** Record a command input / 記錄指令輸入 */
|
|
53
|
+
protected recordCommand(sessionId: string, command: string): void;
|
|
54
|
+
/** Add MITRE technique to session / 新增 MITRE 技術到連線 */
|
|
55
|
+
protected addMitreTechnique(sessionId: string, technique: string): void;
|
|
56
|
+
/** Subclass starts the actual TCP server / 子類別啟動實際 TCP 伺服器 */
|
|
57
|
+
protected abstract doStart(): Promise<void>;
|
|
58
|
+
/** Subclass stops the actual TCP server / 子類別停止實際 TCP 伺服器 */
|
|
59
|
+
protected abstract doStop(): Promise<void>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=base-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|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