@nahisaho/musubix-security 1.8.0 → 1.8.5
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/README.md +27 -0
- package/dist/analyzers/ai/index.d.ts +6 -0
- package/dist/analyzers/ai/index.d.ts.map +1 -0
- package/dist/analyzers/ai/index.js +6 -0
- package/dist/analyzers/ai/index.js.map +1 -0
- package/dist/analyzers/ai/prompt-injection-detector.d.ts +152 -0
- package/dist/analyzers/ai/prompt-injection-detector.d.ts.map +1 -0
- package/dist/analyzers/ai/prompt-injection-detector.js +468 -0
- package/dist/analyzers/ai/prompt-injection-detector.js.map +1 -0
- package/dist/analyzers/api/api-security-analyzer.d.ts +263 -0
- package/dist/analyzers/api/api-security-analyzer.d.ts.map +1 -0
- package/dist/analyzers/api/api-security-analyzer.js +581 -0
- package/dist/analyzers/api/api-security-analyzer.js.map +1 -0
- package/dist/analyzers/compliance/compliance-checker.d.ts +201 -0
- package/dist/analyzers/compliance/compliance-checker.d.ts.map +1 -0
- package/dist/analyzers/compliance/compliance-checker.js +772 -0
- package/dist/analyzers/compliance/compliance-checker.js.map +1 -0
- package/dist/analyzers/container/image-scanner.d.ts +163 -0
- package/dist/analyzers/container/image-scanner.d.ts.map +1 -0
- package/dist/analyzers/container/image-scanner.js +459 -0
- package/dist/analyzers/container/image-scanner.js.map +1 -0
- package/dist/analyzers/container/index.d.ts +6 -0
- package/dist/analyzers/container/index.d.ts.map +1 -0
- package/dist/analyzers/container/index.js +6 -0
- package/dist/analyzers/container/index.js.map +1 -0
- package/dist/analyzers/dashboard/security-dashboard.d.ts +286 -0
- package/dist/analyzers/dashboard/security-dashboard.d.ts.map +1 -0
- package/dist/analyzers/dashboard/security-dashboard.js +796 -0
- package/dist/analyzers/dashboard/security-dashboard.js.map +1 -0
- package/dist/analyzers/iac/iac-checker.d.ts +124 -0
- package/dist/analyzers/iac/iac-checker.d.ts.map +1 -0
- package/dist/analyzers/iac/iac-checker.js +755 -0
- package/dist/analyzers/iac/iac-checker.js.map +1 -0
- package/dist/analyzers/iac/index.d.ts +6 -0
- package/dist/analyzers/iac/index.d.ts.map +1 -0
- package/dist/analyzers/iac/index.js +6 -0
- package/dist/analyzers/iac/index.js.map +1 -0
- package/dist/analyzers/index.d.ts +9 -0
- package/dist/analyzers/index.d.ts.map +1 -0
- package/dist/analyzers/index.js +13 -0
- package/dist/analyzers/index.js.map +1 -0
- package/dist/analyzers/monitor/realtime-monitor.d.ts +216 -0
- package/dist/analyzers/monitor/realtime-monitor.d.ts.map +1 -0
- package/dist/analyzers/monitor/realtime-monitor.js +601 -0
- package/dist/analyzers/monitor/realtime-monitor.js.map +1 -0
- package/dist/analyzers/sast/index.d.ts +7 -0
- package/dist/analyzers/sast/index.d.ts.map +1 -0
- package/dist/analyzers/sast/index.js +7 -0
- package/dist/analyzers/sast/index.js.map +1 -0
- package/dist/analyzers/sast/interprocedural-analyzer.d.ts +276 -0
- package/dist/analyzers/sast/interprocedural-analyzer.d.ts.map +1 -0
- package/dist/analyzers/sast/interprocedural-analyzer.js +635 -0
- package/dist/analyzers/sast/interprocedural-analyzer.js.map +1 -0
- package/dist/analyzers/sast/zero-day-detector.d.ts +183 -0
- package/dist/analyzers/sast/zero-day-detector.d.ts.map +1 -0
- package/dist/analyzers/sast/zero-day-detector.js +593 -0
- package/dist/analyzers/sast/zero-day-detector.js.map +1 -0
- package/dist/analyzers/sca/dependency-scanner.d.ts +275 -0
- package/dist/analyzers/sca/dependency-scanner.d.ts.map +1 -0
- package/dist/analyzers/sca/dependency-scanner.js +642 -0
- package/dist/analyzers/sca/dependency-scanner.js.map +1 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +10 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/pipeline-manager.d.ts +105 -0
- package/dist/core/pipeline-manager.d.ts.map +1 -0
- package/dist/core/pipeline-manager.js +449 -0
- package/dist/core/pipeline-manager.js.map +1 -0
- package/dist/core/result-aggregator.d.ts +96 -0
- package/dist/core/result-aggregator.d.ts.map +1 -0
- package/dist/core/result-aggregator.js +462 -0
- package/dist/core/result-aggregator.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -1
- package/dist/integrations/ci-integration.d.ts +227 -0
- package/dist/integrations/ci-integration.d.ts.map +1 -0
- package/dist/integrations/ci-integration.js +472 -0
- package/dist/integrations/ci-integration.js.map +1 -0
- package/dist/integrations/git-hooks.d.ts +155 -0
- package/dist/integrations/git-hooks.d.ts.map +1 -0
- package/dist/integrations/git-hooks.js +425 -0
- package/dist/integrations/git-hooks.js.map +1 -0
- package/dist/integrations/index.d.ts +9 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +9 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/integrations/report-aggregator.d.ts +250 -0
- package/dist/integrations/report-aggregator.d.ts.map +1 -0
- package/dist/integrations/report-aggregator.js +488 -0
- package/dist/integrations/report-aggregator.js.map +1 -0
- package/dist/integrations/vscode-integration.d.ts +245 -0
- package/dist/integrations/vscode-integration.d.ts.map +1 -0
- package/dist/integrations/vscode-integration.js +449 -0
- package/dist/integrations/vscode-integration.js.map +1 -0
- package/dist/intelligence/attack-pattern-matcher.d.ts +217 -0
- package/dist/intelligence/attack-pattern-matcher.d.ts.map +1 -0
- package/dist/intelligence/attack-pattern-matcher.js +887 -0
- package/dist/intelligence/attack-pattern-matcher.js.map +1 -0
- package/dist/intelligence/index.d.ts +12 -0
- package/dist/intelligence/index.d.ts.map +1 -0
- package/dist/intelligence/index.js +18 -0
- package/dist/intelligence/index.js.map +1 -0
- package/dist/intelligence/neuro-symbolic-core.d.ts +88 -0
- package/dist/intelligence/neuro-symbolic-core.d.ts.map +1 -0
- package/dist/intelligence/neuro-symbolic-core.js +403 -0
- package/dist/intelligence/neuro-symbolic-core.js.map +1 -0
- package/dist/intelligence/predictive-analyzer.d.ts +317 -0
- package/dist/intelligence/predictive-analyzer.d.ts.map +1 -0
- package/dist/intelligence/predictive-analyzer.js +714 -0
- package/dist/intelligence/predictive-analyzer.js.map +1 -0
- package/dist/intelligence/risk-scorer.d.ts +333 -0
- package/dist/intelligence/risk-scorer.d.ts.map +1 -0
- package/dist/intelligence/risk-scorer.js +824 -0
- package/dist/intelligence/risk-scorer.js.map +1 -0
- package/dist/intelligence/security-analytics.d.ts +349 -0
- package/dist/intelligence/security-analytics.d.ts.map +1 -0
- package/dist/intelligence/security-analytics.js +813 -0
- package/dist/intelligence/security-analytics.js.map +1 -0
- package/dist/intelligence/threat-intelligence.d.ts +288 -0
- package/dist/intelligence/threat-intelligence.d.ts.map +1 -0
- package/dist/intelligence/threat-intelligence.js +639 -0
- package/dist/intelligence/threat-intelligence.js.map +1 -0
- package/dist/policy/index.d.ts +6 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +6 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/policy-engine.d.ts +254 -0
- package/dist/policy/policy-engine.d.ts.map +1 -0
- package/dist/policy/policy-engine.js +651 -0
- package/dist/policy/policy-engine.js.map +1 -0
- package/dist/remediation/auto-fixer.d.ts +179 -0
- package/dist/remediation/auto-fixer.d.ts.map +1 -0
- package/dist/remediation/auto-fixer.js +540 -0
- package/dist/remediation/auto-fixer.js.map +1 -0
- package/dist/remediation/fix-validator.d.ts +195 -0
- package/dist/remediation/fix-validator.d.ts.map +1 -0
- package/dist/remediation/fix-validator.js +462 -0
- package/dist/remediation/fix-validator.js.map +1 -0
- package/dist/remediation/index.d.ts +10 -0
- package/dist/remediation/index.d.ts.map +1 -0
- package/dist/remediation/index.js +15 -0
- package/dist/remediation/index.js.map +1 -0
- package/dist/remediation/patch-generator.d.ts +203 -0
- package/dist/remediation/patch-generator.d.ts.map +1 -0
- package/dist/remediation/patch-generator.js +533 -0
- package/dist/remediation/patch-generator.js.map +1 -0
- package/dist/remediation/remediation-planner.d.ts +262 -0
- package/dist/remediation/remediation-planner.d.ts.map +1 -0
- package/dist/remediation/remediation-planner.js +531 -0
- package/dist/remediation/remediation-planner.js.map +1 -0
- package/dist/remediation/secure-code-transformer.d.ts +222 -0
- package/dist/remediation/secure-code-transformer.d.ts.map +1 -0
- package/dist/remediation/secure-code-transformer.js +625 -0
- package/dist/remediation/secure-code-transformer.js.map +1 -0
- package/dist/types/fix.d.ts +3 -1
- package/dist/types/fix.d.ts.map +1 -1
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/interprocedural.d.ts +203 -0
- package/dist/types/interprocedural.d.ts.map +1 -0
- package/dist/types/interprocedural.js +7 -0
- package/dist/types/interprocedural.js.map +1 -0
- package/dist/types/neuro-symbolic.d.ts +179 -0
- package/dist/types/neuro-symbolic.d.ts.map +1 -0
- package/dist/types/neuro-symbolic.js +7 -0
- package/dist/types/neuro-symbolic.js.map +1 -0
- package/dist/types/pipeline.d.ts +173 -0
- package/dist/types/pipeline.d.ts.map +1 -0
- package/dist/types/pipeline.js +7 -0
- package/dist/types/pipeline.js.map +1 -0
- package/dist/types/result.d.ts +134 -0
- package/dist/types/result.d.ts.map +1 -0
- package/dist/types/result.js +25 -0
- package/dist/types/result.js.map +1 -0
- package/dist/types/vulnerability.d.ts +2 -2
- package/dist/types/vulnerability.d.ts.map +1 -1
- package/dist/types/zero-day.d.ts +146 -0
- package/dist/types/zero-day.d.ts.map +1 -0
- package/dist/types/zero-day.js +7 -0
- package/dist/types/zero-day.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,887 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Attack Pattern Matcher with MITRE ATT&CK Integration
|
|
3
|
+
* @module @nahisaho/musubix-security/intelligence/attack-pattern-matcher
|
|
4
|
+
*
|
|
5
|
+
* Provides MITRE ATT&CK framework integration, attack pattern recognition,
|
|
6
|
+
* and technique mapping for security analysis.
|
|
7
|
+
*/
|
|
8
|
+
// ============================================================================
|
|
9
|
+
// MITRE ATT&CK Database (Subset)
|
|
10
|
+
// ============================================================================
|
|
11
|
+
const MITRE_TECHNIQUES = {
|
|
12
|
+
'T1059': {
|
|
13
|
+
id: 'T1059',
|
|
14
|
+
name: 'Command and Scripting Interpreter',
|
|
15
|
+
description: 'Adversaries may abuse command and script interpreters to execute commands, scripts, or binaries.',
|
|
16
|
+
tactics: ['execution'],
|
|
17
|
+
platforms: ['windows', 'macos', 'linux'],
|
|
18
|
+
detection: ['Process monitoring', 'Command-line logging', 'Script block logging'],
|
|
19
|
+
mitigations: ['Execution Prevention', 'Disable or Remove Feature or Program'],
|
|
20
|
+
dataSources: ['Command', 'Process', 'Script'],
|
|
21
|
+
references: ['https://attack.mitre.org/techniques/T1059'],
|
|
22
|
+
subTechniques: [
|
|
23
|
+
{
|
|
24
|
+
id: 'T1059.001',
|
|
25
|
+
name: 'PowerShell',
|
|
26
|
+
description: 'Adversaries may abuse PowerShell commands and scripts for execution.',
|
|
27
|
+
tactics: ['execution'],
|
|
28
|
+
platforms: ['windows'],
|
|
29
|
+
detection: ['PowerShell logging', 'Script block logging'],
|
|
30
|
+
mitigations: ['Code Signing', 'Disable or Remove Feature'],
|
|
31
|
+
dataSources: ['Command', 'Process', 'Script'],
|
|
32
|
+
references: ['https://attack.mitre.org/techniques/T1059/001'],
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 'T1059.007',
|
|
36
|
+
name: 'JavaScript',
|
|
37
|
+
description: 'Adversaries may abuse JavaScript for execution.',
|
|
38
|
+
tactics: ['execution'],
|
|
39
|
+
platforms: ['windows', 'macos', 'linux'],
|
|
40
|
+
detection: ['Script execution monitoring'],
|
|
41
|
+
mitigations: ['Execution Prevention'],
|
|
42
|
+
dataSources: ['Command', 'Process', 'Script'],
|
|
43
|
+
references: ['https://attack.mitre.org/techniques/T1059/007'],
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
'T1190': {
|
|
48
|
+
id: 'T1190',
|
|
49
|
+
name: 'Exploit Public-Facing Application',
|
|
50
|
+
description: 'Adversaries may attempt to exploit a weakness in an Internet-facing host or system.',
|
|
51
|
+
tactics: ['initial-access'],
|
|
52
|
+
platforms: ['windows', 'linux', 'macos', 'cloud', 'containers'],
|
|
53
|
+
detection: ['Application logs', 'Web Application Firewall logs', 'Network traffic analysis'],
|
|
54
|
+
mitigations: ['Application Isolation', 'Exploit Protection', 'Network Segmentation', 'Update Software', 'Vulnerability Scanning'],
|
|
55
|
+
dataSources: ['Application Log', 'Network Traffic'],
|
|
56
|
+
references: ['https://attack.mitre.org/techniques/T1190'],
|
|
57
|
+
},
|
|
58
|
+
'T1505': {
|
|
59
|
+
id: 'T1505',
|
|
60
|
+
name: 'Server Software Component',
|
|
61
|
+
description: 'Adversaries may abuse legitimate server software components.',
|
|
62
|
+
tactics: ['persistence'],
|
|
63
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
64
|
+
detection: ['File monitoring', 'Process monitoring', 'Application logs'],
|
|
65
|
+
mitigations: ['Audit', 'Code Signing', 'Privileged Account Management'],
|
|
66
|
+
dataSources: ['Application Log', 'File', 'Network Traffic', 'Process'],
|
|
67
|
+
references: ['https://attack.mitre.org/techniques/T1505'],
|
|
68
|
+
subTechniques: [
|
|
69
|
+
{
|
|
70
|
+
id: 'T1505.003',
|
|
71
|
+
name: 'Web Shell',
|
|
72
|
+
description: 'Adversaries may use web shells to persist on a victim system.',
|
|
73
|
+
tactics: ['persistence'],
|
|
74
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
75
|
+
detection: ['File monitoring', 'Network traffic analysis', 'Process monitoring'],
|
|
76
|
+
mitigations: ['Disable or Remove Feature', 'Network Segmentation'],
|
|
77
|
+
dataSources: ['Application Log', 'File', 'Network Traffic', 'Process'],
|
|
78
|
+
references: ['https://attack.mitre.org/techniques/T1505/003'],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
},
|
|
82
|
+
'T1552': {
|
|
83
|
+
id: 'T1552',
|
|
84
|
+
name: 'Unsecured Credentials',
|
|
85
|
+
description: 'Adversaries may search compromised systems to find and obtain insecurely stored credentials.',
|
|
86
|
+
tactics: ['credential-access'],
|
|
87
|
+
platforms: ['windows', 'linux', 'macos', 'cloud', 'containers'],
|
|
88
|
+
detection: ['File access monitoring', 'Command-line logging'],
|
|
89
|
+
mitigations: ['Active Directory Configuration', 'Encrypt Sensitive Information', 'Password Policies', 'Privileged Account Management'],
|
|
90
|
+
dataSources: ['Command', 'File', 'Process', 'Windows Registry'],
|
|
91
|
+
references: ['https://attack.mitre.org/techniques/T1552'],
|
|
92
|
+
subTechniques: [
|
|
93
|
+
{
|
|
94
|
+
id: 'T1552.001',
|
|
95
|
+
name: 'Credentials In Files',
|
|
96
|
+
description: 'Adversaries may search for credentials in files.',
|
|
97
|
+
tactics: ['credential-access'],
|
|
98
|
+
platforms: ['windows', 'linux', 'macos', 'containers'],
|
|
99
|
+
detection: ['File access monitoring'],
|
|
100
|
+
mitigations: ['Audit', 'Password Policies', 'Restrict File and Directory Permissions'],
|
|
101
|
+
dataSources: ['Command', 'File', 'Process'],
|
|
102
|
+
references: ['https://attack.mitre.org/techniques/T1552/001'],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
'T1078': {
|
|
107
|
+
id: 'T1078',
|
|
108
|
+
name: 'Valid Accounts',
|
|
109
|
+
description: 'Adversaries may obtain and abuse credentials of existing accounts.',
|
|
110
|
+
tactics: ['defense-evasion', 'persistence', 'privilege-escalation', 'initial-access'],
|
|
111
|
+
platforms: ['windows', 'linux', 'macos', 'cloud', 'containers', 'network'],
|
|
112
|
+
detection: ['Authentication logs', 'User account monitoring'],
|
|
113
|
+
mitigations: ['Account Use Policies', 'Multi-factor Authentication', 'Password Policies', 'Privileged Account Management', 'User Account Management'],
|
|
114
|
+
dataSources: ['Logon Session', 'User Account'],
|
|
115
|
+
references: ['https://attack.mitre.org/techniques/T1078'],
|
|
116
|
+
},
|
|
117
|
+
'T1041': {
|
|
118
|
+
id: 'T1041',
|
|
119
|
+
name: 'Exfiltration Over C2 Channel',
|
|
120
|
+
description: 'Adversaries may steal data by exfiltrating it over an existing command and control channel.',
|
|
121
|
+
tactics: ['exfiltration'],
|
|
122
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
123
|
+
detection: ['Network traffic analysis', 'Command-line logging'],
|
|
124
|
+
mitigations: ['Network Intrusion Prevention', 'Network Segmentation'],
|
|
125
|
+
dataSources: ['Command', 'File', 'Network Traffic'],
|
|
126
|
+
references: ['https://attack.mitre.org/techniques/T1041'],
|
|
127
|
+
},
|
|
128
|
+
'T1055': {
|
|
129
|
+
id: 'T1055',
|
|
130
|
+
name: 'Process Injection',
|
|
131
|
+
description: 'Adversaries may inject code into processes in order to evade process-based defenses.',
|
|
132
|
+
tactics: ['defense-evasion', 'privilege-escalation'],
|
|
133
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
134
|
+
detection: ['Process monitoring', 'OS API execution'],
|
|
135
|
+
mitigations: ['Behavior Prevention on Endpoint', 'Privileged Account Management'],
|
|
136
|
+
dataSources: ['File', 'Module', 'Process'],
|
|
137
|
+
references: ['https://attack.mitre.org/techniques/T1055'],
|
|
138
|
+
},
|
|
139
|
+
'T1185': {
|
|
140
|
+
id: 'T1185',
|
|
141
|
+
name: 'Browser Session Hijacking',
|
|
142
|
+
description: 'Adversaries may take advantage of security vulnerabilities and browser capabilities.',
|
|
143
|
+
tactics: ['collection'],
|
|
144
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
145
|
+
detection: ['Authentication logs', 'Process monitoring'],
|
|
146
|
+
mitigations: ['User Account Management', 'User Training'],
|
|
147
|
+
dataSources: ['Logon Session', 'Process'],
|
|
148
|
+
references: ['https://attack.mitre.org/techniques/T1185'],
|
|
149
|
+
},
|
|
150
|
+
'T1005': {
|
|
151
|
+
id: 'T1005',
|
|
152
|
+
name: 'Data from Local System',
|
|
153
|
+
description: 'Adversaries may search local system sources, such as file systems.',
|
|
154
|
+
tactics: ['collection'],
|
|
155
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
156
|
+
detection: ['Command-line logging', 'File monitoring'],
|
|
157
|
+
mitigations: ['Data Loss Prevention'],
|
|
158
|
+
dataSources: ['Command', 'File', 'Script'],
|
|
159
|
+
references: ['https://attack.mitre.org/techniques/T1005'],
|
|
160
|
+
},
|
|
161
|
+
'T1083': {
|
|
162
|
+
id: 'T1083',
|
|
163
|
+
name: 'File and Directory Discovery',
|
|
164
|
+
description: 'Adversaries may enumerate files and directories.',
|
|
165
|
+
tactics: ['discovery'],
|
|
166
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
167
|
+
detection: ['Command-line logging', 'Process monitoring'],
|
|
168
|
+
mitigations: [],
|
|
169
|
+
dataSources: ['Command', 'Process'],
|
|
170
|
+
references: ['https://attack.mitre.org/techniques/T1083'],
|
|
171
|
+
},
|
|
172
|
+
'T1090': {
|
|
173
|
+
id: 'T1090',
|
|
174
|
+
name: 'Proxy',
|
|
175
|
+
description: 'Adversaries may use a connection proxy to direct network traffic.',
|
|
176
|
+
tactics: ['command-and-control'],
|
|
177
|
+
platforms: ['windows', 'linux', 'macos', 'network'],
|
|
178
|
+
detection: ['Network traffic analysis'],
|
|
179
|
+
mitigations: ['Filter Network Traffic', 'Network Intrusion Prevention', 'SSL/TLS Inspection'],
|
|
180
|
+
dataSources: ['Network Traffic'],
|
|
181
|
+
references: ['https://attack.mitre.org/techniques/T1090'],
|
|
182
|
+
},
|
|
183
|
+
'T1071': {
|
|
184
|
+
id: 'T1071',
|
|
185
|
+
name: 'Application Layer Protocol',
|
|
186
|
+
description: 'Adversaries may communicate using application layer protocols.',
|
|
187
|
+
tactics: ['command-and-control'],
|
|
188
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
189
|
+
detection: ['Network traffic analysis'],
|
|
190
|
+
mitigations: ['Network Intrusion Prevention'],
|
|
191
|
+
dataSources: ['Network Traffic'],
|
|
192
|
+
references: ['https://attack.mitre.org/techniques/T1071'],
|
|
193
|
+
},
|
|
194
|
+
'T1132': {
|
|
195
|
+
id: 'T1132',
|
|
196
|
+
name: 'Data Encoding',
|
|
197
|
+
description: 'Adversaries may encode data to make the content of command and control traffic more difficult to detect.',
|
|
198
|
+
tactics: ['command-and-control'],
|
|
199
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
200
|
+
detection: ['Network traffic analysis'],
|
|
201
|
+
mitigations: ['Network Intrusion Prevention'],
|
|
202
|
+
dataSources: ['Network Traffic'],
|
|
203
|
+
references: ['https://attack.mitre.org/techniques/T1132'],
|
|
204
|
+
},
|
|
205
|
+
'T1203': {
|
|
206
|
+
id: 'T1203',
|
|
207
|
+
name: 'Exploitation for Client Execution',
|
|
208
|
+
description: 'Adversaries may exploit software vulnerabilities in client applications.',
|
|
209
|
+
tactics: ['execution'],
|
|
210
|
+
platforms: ['windows', 'linux', 'macos'],
|
|
211
|
+
detection: ['Application logs', 'Process monitoring'],
|
|
212
|
+
mitigations: ['Application Isolation', 'Exploit Protection', 'Update Software'],
|
|
213
|
+
dataSources: ['Application Log', 'Process'],
|
|
214
|
+
references: ['https://attack.mitre.org/techniques/T1203'],
|
|
215
|
+
},
|
|
216
|
+
'T1496': {
|
|
217
|
+
id: 'T1496',
|
|
218
|
+
name: 'Resource Hijacking',
|
|
219
|
+
description: 'Adversaries may leverage the resources of co-opted systems in order to solve resource intensive problems.',
|
|
220
|
+
tactics: ['impact'],
|
|
221
|
+
platforms: ['windows', 'linux', 'macos', 'containers', 'iaas'],
|
|
222
|
+
detection: ['Process monitoring', 'Network traffic analysis'],
|
|
223
|
+
mitigations: ['Network Intrusion Prevention', 'Resource Management'],
|
|
224
|
+
dataSources: ['Command', 'File', 'Network Traffic', 'Process', 'Sensor Health'],
|
|
225
|
+
references: ['https://attack.mitre.org/techniques/T1496'],
|
|
226
|
+
},
|
|
227
|
+
'T1600': {
|
|
228
|
+
id: 'T1600',
|
|
229
|
+
name: 'Weaken Encryption',
|
|
230
|
+
description: 'Adversaries may compromise a network device encryption key.',
|
|
231
|
+
tactics: ['defense-evasion'],
|
|
232
|
+
platforms: ['network'],
|
|
233
|
+
detection: ['Network traffic analysis', 'File monitoring'],
|
|
234
|
+
mitigations: ['Encryption', 'Multi-factor Authentication'],
|
|
235
|
+
dataSources: ['File', 'Network Traffic'],
|
|
236
|
+
references: ['https://attack.mitre.org/techniques/T1600'],
|
|
237
|
+
},
|
|
238
|
+
'T1040': {
|
|
239
|
+
id: 'T1040',
|
|
240
|
+
name: 'Network Sniffing',
|
|
241
|
+
description: 'Adversaries may sniff network traffic to capture information.',
|
|
242
|
+
tactics: ['credential-access', 'discovery'],
|
|
243
|
+
platforms: ['windows', 'linux', 'macos', 'network'],
|
|
244
|
+
detection: ['Process monitoring', 'Host network interface monitoring'],
|
|
245
|
+
mitigations: ['Encrypt Sensitive Information', 'Multi-factor Authentication'],
|
|
246
|
+
dataSources: ['Command', 'Process'],
|
|
247
|
+
references: ['https://attack.mitre.org/techniques/T1040'],
|
|
248
|
+
},
|
|
249
|
+
'T1110': {
|
|
250
|
+
id: 'T1110',
|
|
251
|
+
name: 'Brute Force',
|
|
252
|
+
description: 'Adversaries may use brute force techniques to gain access to accounts.',
|
|
253
|
+
tactics: ['credential-access'],
|
|
254
|
+
platforms: ['windows', 'linux', 'macos', 'cloud', 'containers', 'network', 'azure-ad', 'office-365', 'saas', 'google-workspace'],
|
|
255
|
+
detection: ['Authentication logs', 'User account monitoring'],
|
|
256
|
+
mitigations: ['Account Use Policies', 'Multi-factor Authentication', 'Password Policies', 'User Account Management'],
|
|
257
|
+
dataSources: ['Application Log', 'User Account'],
|
|
258
|
+
references: ['https://attack.mitre.org/techniques/T1110'],
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
// ============================================================================
|
|
262
|
+
// Built-in Attack Patterns
|
|
263
|
+
// ============================================================================
|
|
264
|
+
const BUILTIN_ATTACK_PATTERNS = [
|
|
265
|
+
// Command Injection
|
|
266
|
+
{
|
|
267
|
+
id: 'ATK-CMD-001',
|
|
268
|
+
name: 'Command Injection via exec/spawn',
|
|
269
|
+
description: 'Direct use of exec/spawn with user input',
|
|
270
|
+
patterns: [
|
|
271
|
+
'exec\\s*\\([^)]*\\$\\{',
|
|
272
|
+
'execSync\\s*\\([^)]*\\+',
|
|
273
|
+
'spawn\\s*\\([^)]*\\$\\{',
|
|
274
|
+
'child_process.*exec',
|
|
275
|
+
],
|
|
276
|
+
techniques: ['T1059', 'T1203'],
|
|
277
|
+
severity: 'critical',
|
|
278
|
+
confidence: 0.9,
|
|
279
|
+
tags: ['command-injection', 'rce'],
|
|
280
|
+
examples: ['exec(`rm -rf ${userInput}`)'],
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
id: 'ATK-CMD-002',
|
|
284
|
+
name: 'Shell Command Construction',
|
|
285
|
+
description: 'Dynamic shell command construction',
|
|
286
|
+
patterns: [
|
|
287
|
+
'/bin/(?:ba)?sh.*-c.*\\$\\{',
|
|
288
|
+
'cmd\\.exe.*\\/c.*\\+',
|
|
289
|
+
'powershell.*-(?:Command|c).*\\$',
|
|
290
|
+
],
|
|
291
|
+
techniques: ['T1059', 'T1059.001'],
|
|
292
|
+
severity: 'critical',
|
|
293
|
+
confidence: 0.85,
|
|
294
|
+
tags: ['command-injection', 'shell'],
|
|
295
|
+
},
|
|
296
|
+
// SQL Injection
|
|
297
|
+
{
|
|
298
|
+
id: 'ATK-SQL-001',
|
|
299
|
+
name: 'SQL Injection via String Concatenation',
|
|
300
|
+
description: 'SQL query built with string concatenation',
|
|
301
|
+
patterns: [
|
|
302
|
+
'SELECT.*FROM.*WHERE.*\\+.*["\']',
|
|
303
|
+
'INSERT\\s+INTO.*VALUES.*\\$\\{',
|
|
304
|
+
'UPDATE.*SET.*=.*\\+.*req\\.',
|
|
305
|
+
'DELETE.*WHERE.*\\+.*input',
|
|
306
|
+
],
|
|
307
|
+
techniques: ['T1190', 'T1505'],
|
|
308
|
+
severity: 'critical',
|
|
309
|
+
confidence: 0.9,
|
|
310
|
+
tags: ['sql-injection', 'database'],
|
|
311
|
+
},
|
|
312
|
+
{
|
|
313
|
+
id: 'ATK-SQL-002',
|
|
314
|
+
name: 'NoSQL Injection',
|
|
315
|
+
description: 'NoSQL query with user input',
|
|
316
|
+
patterns: [
|
|
317
|
+
'\\.find\\s*\\(\\s*\\{[^}]*\\$where',
|
|
318
|
+
'\\$where.*function',
|
|
319
|
+
'eval\\s*\\([^)]*db\\.',
|
|
320
|
+
],
|
|
321
|
+
techniques: ['T1190'],
|
|
322
|
+
severity: 'high',
|
|
323
|
+
confidence: 0.8,
|
|
324
|
+
tags: ['nosql-injection', 'mongodb'],
|
|
325
|
+
},
|
|
326
|
+
// XSS Patterns
|
|
327
|
+
{
|
|
328
|
+
id: 'ATK-XSS-001',
|
|
329
|
+
name: 'DOM-based XSS',
|
|
330
|
+
description: 'Direct innerHTML assignment',
|
|
331
|
+
patterns: [
|
|
332
|
+
'\\.innerHTML\\s*=',
|
|
333
|
+
'\\.outerHTML\\s*=',
|
|
334
|
+
'document\\.write\\s*\\(',
|
|
335
|
+
'document\\.writeln\\s*\\(',
|
|
336
|
+
],
|
|
337
|
+
techniques: ['T1059.007', 'T1185'],
|
|
338
|
+
severity: 'high',
|
|
339
|
+
confidence: 0.75,
|
|
340
|
+
tags: ['xss', 'dom'],
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
id: 'ATK-XSS-002',
|
|
344
|
+
name: 'React dangerouslySetInnerHTML',
|
|
345
|
+
description: 'Unsafe HTML rendering in React',
|
|
346
|
+
patterns: [
|
|
347
|
+
'dangerouslySetInnerHTML\\s*=\\s*\\{\\{\\s*__html:',
|
|
348
|
+
],
|
|
349
|
+
techniques: ['T1059.007', 'T1185'],
|
|
350
|
+
severity: 'medium',
|
|
351
|
+
confidence: 0.7,
|
|
352
|
+
tags: ['xss', 'react'],
|
|
353
|
+
},
|
|
354
|
+
// Path Traversal
|
|
355
|
+
{
|
|
356
|
+
id: 'ATK-PATH-001',
|
|
357
|
+
name: 'Path Traversal',
|
|
358
|
+
description: 'File path construction with user input',
|
|
359
|
+
patterns: [
|
|
360
|
+
'fs\\.readFile(?:Sync)?\\s*\\([^)]*\\+',
|
|
361
|
+
'path\\.join\\s*\\([^)]*req\\.',
|
|
362
|
+
'path\\.resolve\\s*\\([^)]*user',
|
|
363
|
+
'__dirname.*\\+.*input',
|
|
364
|
+
],
|
|
365
|
+
techniques: ['T1083', 'T1005'],
|
|
366
|
+
severity: 'high',
|
|
367
|
+
confidence: 0.85,
|
|
368
|
+
tags: ['path-traversal', 'lfi'],
|
|
369
|
+
},
|
|
370
|
+
// SSRF
|
|
371
|
+
{
|
|
372
|
+
id: 'ATK-SSRF-001',
|
|
373
|
+
name: 'Server-Side Request Forgery',
|
|
374
|
+
description: 'HTTP request with user-controlled URL',
|
|
375
|
+
patterns: [
|
|
376
|
+
'fetch\\s*\\([^)]*\\$\\{',
|
|
377
|
+
'axios\\.[a-z]+\\s*\\([^)]*\\+',
|
|
378
|
+
'request\\s*\\(\\s*\\{[^}]*url.*\\+',
|
|
379
|
+
'http\\.(?:get|request)\\s*\\([^)]*\\+',
|
|
380
|
+
],
|
|
381
|
+
techniques: ['T1090', 'T1071'],
|
|
382
|
+
severity: 'high',
|
|
383
|
+
confidence: 0.8,
|
|
384
|
+
tags: ['ssrf', 'network'],
|
|
385
|
+
},
|
|
386
|
+
// Credential Exposure
|
|
387
|
+
{
|
|
388
|
+
id: 'ATK-CRED-001',
|
|
389
|
+
name: 'Hardcoded Credentials',
|
|
390
|
+
description: 'Credentials embedded in code',
|
|
391
|
+
patterns: [
|
|
392
|
+
'password\\s*[=:]\\s*["\'][^"\']{8,}["\']',
|
|
393
|
+
'api[_-]?key\\s*[=:]\\s*["\'][^"\']{16,}["\']',
|
|
394
|
+
'secret\\s*[=:]\\s*["\'][^"\']{8,}["\']',
|
|
395
|
+
'token\\s*[=:]\\s*["\'][a-zA-Z0-9_-]{20,}["\']',
|
|
396
|
+
],
|
|
397
|
+
techniques: ['T1552.001', 'T1078'],
|
|
398
|
+
severity: 'high',
|
|
399
|
+
confidence: 0.7,
|
|
400
|
+
tags: ['credentials', 'secrets'],
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
id: 'ATK-CRED-002',
|
|
404
|
+
name: 'AWS Credentials',
|
|
405
|
+
description: 'AWS credentials in code',
|
|
406
|
+
patterns: [
|
|
407
|
+
'AKIA[0-9A-Z]{16}',
|
|
408
|
+
'aws_access_key_id\\s*[=:]',
|
|
409
|
+
'aws_secret_access_key\\s*[=:]',
|
|
410
|
+
],
|
|
411
|
+
techniques: ['T1552.001', 'T1078'],
|
|
412
|
+
severity: 'critical',
|
|
413
|
+
confidence: 0.95,
|
|
414
|
+
tags: ['aws', 'credentials', 'cloud'],
|
|
415
|
+
},
|
|
416
|
+
// Deserialization
|
|
417
|
+
{
|
|
418
|
+
id: 'ATK-DESER-001',
|
|
419
|
+
name: 'Unsafe Deserialization',
|
|
420
|
+
description: 'Dangerous deserialization patterns',
|
|
421
|
+
patterns: [
|
|
422
|
+
'JSON\\.parse\\s*\\(.*req\\.',
|
|
423
|
+
'eval\\s*\\(.*JSON',
|
|
424
|
+
'serialize\\s*\\(.*user',
|
|
425
|
+
'unserialize\\s*\\(',
|
|
426
|
+
],
|
|
427
|
+
techniques: ['T1059', 'T1055'],
|
|
428
|
+
severity: 'high',
|
|
429
|
+
confidence: 0.75,
|
|
430
|
+
tags: ['deserialization', 'rce'],
|
|
431
|
+
},
|
|
432
|
+
// Crypto Weaknesses
|
|
433
|
+
{
|
|
434
|
+
id: 'ATK-CRYPTO-001',
|
|
435
|
+
name: 'Weak Cryptography',
|
|
436
|
+
description: 'Use of weak cryptographic algorithms',
|
|
437
|
+
patterns: [
|
|
438
|
+
'createHash\\s*\\(["\'](?:md5|sha1)["\']\\)',
|
|
439
|
+
'createCipher\\s*\\(["\'](?:des|rc4)',
|
|
440
|
+
'Math\\.random\\s*\\(\\).*(?:key|token|secret|password)',
|
|
441
|
+
],
|
|
442
|
+
techniques: ['T1600', 'T1040'],
|
|
443
|
+
severity: 'medium',
|
|
444
|
+
confidence: 0.85,
|
|
445
|
+
tags: ['crypto', 'weak-algorithm'],
|
|
446
|
+
},
|
|
447
|
+
// Prototype Pollution
|
|
448
|
+
{
|
|
449
|
+
id: 'ATK-PROTO-001',
|
|
450
|
+
name: 'Prototype Pollution',
|
|
451
|
+
description: 'Potential prototype pollution vectors',
|
|
452
|
+
patterns: [
|
|
453
|
+
'\\[\\s*["\']__proto__["\']\\s*\\]',
|
|
454
|
+
'\\[\\s*["\']constructor["\']\\s*\\]\\[\\s*["\']prototype',
|
|
455
|
+
'Object\\.assign\\s*\\([^)]*req\\.',
|
|
456
|
+
'\\.merge\\s*\\([^)]*input',
|
|
457
|
+
],
|
|
458
|
+
techniques: ['T1059.007'],
|
|
459
|
+
severity: 'high',
|
|
460
|
+
confidence: 0.8,
|
|
461
|
+
tags: ['prototype-pollution', 'javascript'],
|
|
462
|
+
},
|
|
463
|
+
// Data Exfiltration
|
|
464
|
+
{
|
|
465
|
+
id: 'ATK-EXFIL-001',
|
|
466
|
+
name: 'Data Exfiltration Pattern',
|
|
467
|
+
description: 'Patterns indicating data exfiltration',
|
|
468
|
+
patterns: [
|
|
469
|
+
'btoa\\s*\\(.*(?:password|secret|key|token)',
|
|
470
|
+
'encodeURIComponent\\s*\\(.*(?:password|secret)',
|
|
471
|
+
'fetch\\s*\\([^)]*\\+.*(?:password|secret|key)',
|
|
472
|
+
],
|
|
473
|
+
techniques: ['T1041', 'T1132'],
|
|
474
|
+
severity: 'high',
|
|
475
|
+
confidence: 0.7,
|
|
476
|
+
tags: ['exfiltration', 'data-theft'],
|
|
477
|
+
},
|
|
478
|
+
// Backdoor Patterns
|
|
479
|
+
{
|
|
480
|
+
id: 'ATK-BACKDOOR-001',
|
|
481
|
+
name: 'Potential Backdoor',
|
|
482
|
+
description: 'Patterns indicating backdoor functionality',
|
|
483
|
+
patterns: [
|
|
484
|
+
'eval\\s*\\(\\s*(?:atob|Buffer\\.from)',
|
|
485
|
+
'Function\\s*\\([^)]*\\)\\s*\\(\\)',
|
|
486
|
+
'require\\s*\\([^)]*\\+.*\\)\\s*\\(',
|
|
487
|
+
],
|
|
488
|
+
techniques: ['T1059', 'T1505.003'],
|
|
489
|
+
severity: 'critical',
|
|
490
|
+
confidence: 0.75,
|
|
491
|
+
tags: ['backdoor', 'malware'],
|
|
492
|
+
},
|
|
493
|
+
];
|
|
494
|
+
// Kill Chain Phases
|
|
495
|
+
const KILL_CHAIN_PHASES = {
|
|
496
|
+
'reconnaissance': 'Reconnaissance',
|
|
497
|
+
'resource-development': 'Weaponization',
|
|
498
|
+
'initial-access': 'Delivery',
|
|
499
|
+
'execution': 'Exploitation',
|
|
500
|
+
'persistence': 'Installation',
|
|
501
|
+
'privilege-escalation': 'Installation',
|
|
502
|
+
'defense-evasion': 'Installation',
|
|
503
|
+
'credential-access': 'Installation',
|
|
504
|
+
'discovery': 'Command & Control',
|
|
505
|
+
'lateral-movement': 'Command & Control',
|
|
506
|
+
'collection': 'Actions on Objectives',
|
|
507
|
+
'command-and-control': 'Command & Control',
|
|
508
|
+
'exfiltration': 'Actions on Objectives',
|
|
509
|
+
'impact': 'Actions on Objectives',
|
|
510
|
+
};
|
|
511
|
+
// ============================================================================
|
|
512
|
+
// AttackPatternMatcher Class
|
|
513
|
+
// ============================================================================
|
|
514
|
+
/**
|
|
515
|
+
* Attack Pattern Matcher with MITRE ATT&CK integration
|
|
516
|
+
*/
|
|
517
|
+
export class AttackPatternMatcher {
|
|
518
|
+
options;
|
|
519
|
+
patterns = new Map();
|
|
520
|
+
techniques = new Map();
|
|
521
|
+
constructor(options = {}) {
|
|
522
|
+
this.options = {
|
|
523
|
+
enableMitreMapping: options.enableMitreMapping ?? true,
|
|
524
|
+
minConfidence: options.minConfidence ?? 0.7,
|
|
525
|
+
enableChainAnalysis: options.enableChainAnalysis ?? true,
|
|
526
|
+
customPatterns: options.customPatterns ?? [],
|
|
527
|
+
platforms: options.platforms ?? ['windows', 'linux', 'macos'],
|
|
528
|
+
};
|
|
529
|
+
// Load built-in patterns
|
|
530
|
+
this.loadBuiltinPatterns();
|
|
531
|
+
// Load custom patterns
|
|
532
|
+
for (const pattern of this.options.customPatterns) {
|
|
533
|
+
this.patterns.set(pattern.id, pattern);
|
|
534
|
+
}
|
|
535
|
+
// Load MITRE techniques
|
|
536
|
+
this.loadMitreTechniques();
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* Load built-in attack patterns
|
|
540
|
+
*/
|
|
541
|
+
loadBuiltinPatterns() {
|
|
542
|
+
for (const pattern of BUILTIN_ATTACK_PATTERNS) {
|
|
543
|
+
this.patterns.set(pattern.id, pattern);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Load MITRE ATT&CK techniques
|
|
548
|
+
*/
|
|
549
|
+
loadMitreTechniques() {
|
|
550
|
+
for (const [id, technique] of Object.entries(MITRE_TECHNIQUES)) {
|
|
551
|
+
this.techniques.set(id, technique);
|
|
552
|
+
// Also load sub-techniques
|
|
553
|
+
if (technique.subTechniques) {
|
|
554
|
+
for (const sub of technique.subTechniques) {
|
|
555
|
+
this.techniques.set(sub.id, sub);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Add custom pattern
|
|
562
|
+
*/
|
|
563
|
+
addPattern(pattern) {
|
|
564
|
+
this.patterns.set(pattern.id, pattern);
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Remove pattern
|
|
568
|
+
*/
|
|
569
|
+
removePattern(patternId) {
|
|
570
|
+
return this.patterns.delete(patternId);
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Get all patterns
|
|
574
|
+
*/
|
|
575
|
+
getPatterns() {
|
|
576
|
+
return Array.from(this.patterns.values());
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Get pattern by ID
|
|
580
|
+
*/
|
|
581
|
+
getPattern(id) {
|
|
582
|
+
return this.patterns.get(id);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Get MITRE technique by ID
|
|
586
|
+
*/
|
|
587
|
+
getTechnique(id) {
|
|
588
|
+
return this.techniques.get(id);
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* Get all techniques
|
|
592
|
+
*/
|
|
593
|
+
getAllTechniques() {
|
|
594
|
+
return Array.from(this.techniques.values());
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Get techniques by tactic
|
|
598
|
+
*/
|
|
599
|
+
getTechniquesByTactic(tactic) {
|
|
600
|
+
return this.getAllTechniques().filter(t => t.tactics.includes(tactic));
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Match code against patterns
|
|
604
|
+
*/
|
|
605
|
+
matchCode(code, filePath) {
|
|
606
|
+
const matches = [];
|
|
607
|
+
const lines = code.split('\n');
|
|
608
|
+
for (const pattern of this.patterns.values()) {
|
|
609
|
+
for (const patternStr of pattern.patterns) {
|
|
610
|
+
try {
|
|
611
|
+
const regex = new RegExp(patternStr, 'gi');
|
|
612
|
+
for (let lineNum = 0; lineNum < lines.length; lineNum++) {
|
|
613
|
+
const line = lines[lineNum];
|
|
614
|
+
const match = regex.exec(line);
|
|
615
|
+
if (match && pattern.confidence >= this.options.minConfidence) {
|
|
616
|
+
// Get mapped techniques
|
|
617
|
+
const techniques = pattern.techniques
|
|
618
|
+
.map(id => this.techniques.get(id))
|
|
619
|
+
.filter((t) => t !== undefined);
|
|
620
|
+
// Determine kill chain phase
|
|
621
|
+
const killChainPhase = techniques.length > 0
|
|
622
|
+
? KILL_CHAIN_PHASES[techniques[0].tactics[0]]
|
|
623
|
+
: 'Unknown';
|
|
624
|
+
matches.push({
|
|
625
|
+
id: `MATCH-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
|
|
626
|
+
pattern,
|
|
627
|
+
location: {
|
|
628
|
+
file: filePath,
|
|
629
|
+
startLine: lineNum + 1,
|
|
630
|
+
endLine: lineNum + 1,
|
|
631
|
+
startColumn: match.index,
|
|
632
|
+
endColumn: match.index + match[0].length,
|
|
633
|
+
},
|
|
634
|
+
codeSnippet: line.trim(),
|
|
635
|
+
confidence: pattern.confidence,
|
|
636
|
+
techniques,
|
|
637
|
+
killChainPhase,
|
|
638
|
+
recommendations: this.generateRecommendations(pattern, techniques),
|
|
639
|
+
});
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
catch {
|
|
644
|
+
// Invalid regex, skip
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
return matches;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Generate recommendations based on pattern and techniques
|
|
653
|
+
*/
|
|
654
|
+
generateRecommendations(pattern, techniques) {
|
|
655
|
+
const recommendations = [];
|
|
656
|
+
// Add pattern-specific recommendations
|
|
657
|
+
switch (pattern.id.split('-')[1]) {
|
|
658
|
+
case 'CMD':
|
|
659
|
+
recommendations.push('Avoid using shell commands with user input');
|
|
660
|
+
recommendations.push('Use parameterized commands or libraries');
|
|
661
|
+
recommendations.push('Implement strict input validation');
|
|
662
|
+
break;
|
|
663
|
+
case 'SQL':
|
|
664
|
+
recommendations.push('Use parameterized queries or prepared statements');
|
|
665
|
+
recommendations.push('Implement input validation and sanitization');
|
|
666
|
+
recommendations.push('Use an ORM with built-in escaping');
|
|
667
|
+
break;
|
|
668
|
+
case 'XSS':
|
|
669
|
+
recommendations.push('Use context-aware output encoding');
|
|
670
|
+
recommendations.push('Implement Content Security Policy');
|
|
671
|
+
recommendations.push('Use framework-provided safe rendering methods');
|
|
672
|
+
break;
|
|
673
|
+
case 'PATH':
|
|
674
|
+
recommendations.push('Validate and sanitize file paths');
|
|
675
|
+
recommendations.push('Use path.resolve() with base directory checks');
|
|
676
|
+
recommendations.push('Implement allow-lists for accessible paths');
|
|
677
|
+
break;
|
|
678
|
+
case 'SSRF':
|
|
679
|
+
recommendations.push('Validate and whitelist allowed URLs/domains');
|
|
680
|
+
recommendations.push('Block internal IP ranges');
|
|
681
|
+
recommendations.push('Use URL parsing to prevent bypass attempts');
|
|
682
|
+
break;
|
|
683
|
+
case 'CRED':
|
|
684
|
+
recommendations.push('Move credentials to environment variables');
|
|
685
|
+
recommendations.push('Use a secrets management solution');
|
|
686
|
+
recommendations.push('Implement credential rotation');
|
|
687
|
+
break;
|
|
688
|
+
default:
|
|
689
|
+
recommendations.push('Review and remediate the identified pattern');
|
|
690
|
+
}
|
|
691
|
+
// Add technique-based mitigations
|
|
692
|
+
for (const technique of techniques) {
|
|
693
|
+
for (const mitigation of technique.mitigations.slice(0, 2)) {
|
|
694
|
+
if (!recommendations.includes(mitigation)) {
|
|
695
|
+
recommendations.push(`MITRE Mitigation: ${mitigation}`);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return recommendations;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Map vulnerability to MITRE ATT&CK
|
|
703
|
+
*/
|
|
704
|
+
mapVulnerabilityToMitre(vulnerability) {
|
|
705
|
+
if (!this.options.enableMitreMapping) {
|
|
706
|
+
return [];
|
|
707
|
+
}
|
|
708
|
+
const typeMapping = {
|
|
709
|
+
'xss': ['T1059.007', 'T1185'],
|
|
710
|
+
'sql-injection': ['T1190', 'T1505'],
|
|
711
|
+
'command-injection': ['T1059', 'T1203'],
|
|
712
|
+
'path-traversal': ['T1083', 'T1005'],
|
|
713
|
+
'ssrf': ['T1090', 'T1071'],
|
|
714
|
+
'xxe': ['T1005', 'T1083'],
|
|
715
|
+
'deserialization': ['T1059', 'T1055'],
|
|
716
|
+
'hardcoded-secret': ['T1552.001', 'T1078'],
|
|
717
|
+
'weak-crypto': ['T1600', 'T1040'],
|
|
718
|
+
'insecure-auth': ['T1078', 'T1110'],
|
|
719
|
+
'prototype-pollution': ['T1059.007'],
|
|
720
|
+
'open-redirect': ['T1090'],
|
|
721
|
+
'code-injection': ['T1059', 'T1203'],
|
|
722
|
+
};
|
|
723
|
+
const techniqueIds = typeMapping[vulnerability.type] || [];
|
|
724
|
+
return techniqueIds
|
|
725
|
+
.map(id => this.techniques.get(id))
|
|
726
|
+
.filter((t) => t !== undefined);
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Analyze attack chain from multiple matches
|
|
730
|
+
*/
|
|
731
|
+
analyzeAttackChain(matches) {
|
|
732
|
+
if (!this.options.enableChainAnalysis || matches.length < 2) {
|
|
733
|
+
return null;
|
|
734
|
+
}
|
|
735
|
+
// Group by kill chain stage
|
|
736
|
+
const stageMap = new Map();
|
|
737
|
+
for (const match of matches) {
|
|
738
|
+
const stage = match.killChainPhase;
|
|
739
|
+
if (!stageMap.has(stage)) {
|
|
740
|
+
stageMap.set(stage, []);
|
|
741
|
+
}
|
|
742
|
+
stageMap.get(stage).push(match);
|
|
743
|
+
}
|
|
744
|
+
// Calculate risk score
|
|
745
|
+
let riskScore = 0;
|
|
746
|
+
for (const match of matches) {
|
|
747
|
+
const severityScore = {
|
|
748
|
+
critical: 40,
|
|
749
|
+
high: 30,
|
|
750
|
+
medium: 20,
|
|
751
|
+
low: 10,
|
|
752
|
+
}[match.pattern.severity];
|
|
753
|
+
riskScore += severityScore * match.confidence;
|
|
754
|
+
}
|
|
755
|
+
// Cap at 100
|
|
756
|
+
riskScore = Math.min(100, riskScore);
|
|
757
|
+
// Get kill chain stages covered
|
|
758
|
+
const killChainStages = Array.from(stageMap.keys()).sort();
|
|
759
|
+
// Generate narrative
|
|
760
|
+
const narrative = this.generateAttackNarrative(matches, killChainStages);
|
|
761
|
+
// Identify detection gaps
|
|
762
|
+
const detectionGaps = this.identifyDetectionGaps(matches);
|
|
763
|
+
// Aggregate mitigations
|
|
764
|
+
const mitigations = new Set();
|
|
765
|
+
for (const match of matches) {
|
|
766
|
+
for (const rec of match.recommendations) {
|
|
767
|
+
mitigations.add(rec);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
return {
|
|
771
|
+
id: `CHAIN-${Date.now()}`,
|
|
772
|
+
name: `Attack Chain (${killChainStages.length} stages)`,
|
|
773
|
+
patterns: matches,
|
|
774
|
+
killChainStages,
|
|
775
|
+
riskScore,
|
|
776
|
+
narrative,
|
|
777
|
+
detectionGaps,
|
|
778
|
+
mitigations: Array.from(mitigations),
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Generate attack narrative
|
|
783
|
+
*/
|
|
784
|
+
generateAttackNarrative(matches, stages) {
|
|
785
|
+
const parts = [];
|
|
786
|
+
if (stages.includes('Delivery') || stages.includes('Exploitation')) {
|
|
787
|
+
parts.push('Initial access may be gained through');
|
|
788
|
+
const initialPatterns = matches.filter(m => m.killChainPhase === 'Delivery' || m.killChainPhase === 'Exploitation');
|
|
789
|
+
parts.push(initialPatterns.map(p => p.pattern.name).join(', '));
|
|
790
|
+
}
|
|
791
|
+
if (stages.includes('Installation')) {
|
|
792
|
+
parts.push('Persistence could be established via');
|
|
793
|
+
const persistPatterns = matches.filter(m => m.killChainPhase === 'Installation');
|
|
794
|
+
parts.push(persistPatterns.map(p => p.pattern.name).join(', '));
|
|
795
|
+
}
|
|
796
|
+
if (stages.includes('Actions on Objectives')) {
|
|
797
|
+
parts.push('Ultimate goals may include');
|
|
798
|
+
const actionPatterns = matches.filter(m => m.killChainPhase === 'Actions on Objectives');
|
|
799
|
+
parts.push(actionPatterns.map(p => p.pattern.name).join(', '));
|
|
800
|
+
}
|
|
801
|
+
return parts.join('. ') + '.';
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Identify detection gaps
|
|
805
|
+
*/
|
|
806
|
+
identifyDetectionGaps(matches) {
|
|
807
|
+
const gaps = new Set();
|
|
808
|
+
const allDataSources = new Set();
|
|
809
|
+
for (const match of matches) {
|
|
810
|
+
for (const technique of match.techniques) {
|
|
811
|
+
for (const ds of technique.dataSources) {
|
|
812
|
+
allDataSources.add(ds);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
}
|
|
816
|
+
// Check common detection capabilities
|
|
817
|
+
if (allDataSources.has('Network Traffic')) {
|
|
818
|
+
gaps.add('Ensure network traffic monitoring is in place');
|
|
819
|
+
}
|
|
820
|
+
if (allDataSources.has('Process')) {
|
|
821
|
+
gaps.add('Enable process execution monitoring');
|
|
822
|
+
}
|
|
823
|
+
if (allDataSources.has('Command')) {
|
|
824
|
+
gaps.add('Enable command-line logging');
|
|
825
|
+
}
|
|
826
|
+
if (allDataSources.has('File')) {
|
|
827
|
+
gaps.add('Implement file integrity monitoring');
|
|
828
|
+
}
|
|
829
|
+
return Array.from(gaps);
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Get statistics
|
|
833
|
+
*/
|
|
834
|
+
getStatistics() {
|
|
835
|
+
const byCategory = {};
|
|
836
|
+
const bySeverity = {};
|
|
837
|
+
const byTactic = {};
|
|
838
|
+
for (const pattern of this.patterns.values()) {
|
|
839
|
+
const category = pattern.id.split('-')[1];
|
|
840
|
+
byCategory[category] = (byCategory[category] || 0) + 1;
|
|
841
|
+
bySeverity[pattern.severity] = (bySeverity[pattern.severity] || 0) + 1;
|
|
842
|
+
}
|
|
843
|
+
for (const technique of this.techniques.values()) {
|
|
844
|
+
for (const tactic of technique.tactics) {
|
|
845
|
+
byTactic[tactic] = (byTactic[tactic] || 0) + 1;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
return {
|
|
849
|
+
totalPatterns: this.patterns.size,
|
|
850
|
+
byCategory,
|
|
851
|
+
bySeverity,
|
|
852
|
+
totalTechniques: this.techniques.size,
|
|
853
|
+
byTactic,
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
// ============================================================================
|
|
858
|
+
// Factory Functions
|
|
859
|
+
// ============================================================================
|
|
860
|
+
/**
|
|
861
|
+
* Create an AttackPatternMatcher instance
|
|
862
|
+
*/
|
|
863
|
+
export function createAttackPatternMatcher(options) {
|
|
864
|
+
return new AttackPatternMatcher(options);
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Quick pattern match
|
|
868
|
+
*/
|
|
869
|
+
export function quickPatternMatch(code, filePath) {
|
|
870
|
+
const matcher = createAttackPatternMatcher();
|
|
871
|
+
return matcher.matchCode(code, filePath);
|
|
872
|
+
}
|
|
873
|
+
/**
|
|
874
|
+
* Map vulnerability to MITRE techniques
|
|
875
|
+
*/
|
|
876
|
+
export function mapToMitre(vulnerability) {
|
|
877
|
+
const matcher = createAttackPatternMatcher();
|
|
878
|
+
return matcher.mapVulnerabilityToMitre(vulnerability);
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Get MITRE technique by ID
|
|
882
|
+
*/
|
|
883
|
+
export function getMitreTechnique(id) {
|
|
884
|
+
const matcher = createAttackPatternMatcher();
|
|
885
|
+
return matcher.getTechnique(id);
|
|
886
|
+
}
|
|
887
|
+
//# sourceMappingURL=attack-pattern-matcher.js.map
|